Refactoring.
[midnight-commander.git] / src / setup.c
blobcb927136cef1c438271c3a40f16ca9f48f65d470
1 /* Setup loading/saving.
2 Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 /** \file setup.c
20 * \brief Source: setup loading/saving
23 #include <config.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <stdio.h>
28 #include <sys/types.h>
29 #include <sys/stat.h>
31 #include "lib/global.h"
33 #include "lib/tty/tty.h"
34 #include "lib/tty/key.h"
35 #include "lib/mcconfig.h"
36 #include "lib/fileloc.h"
37 #include "lib/timefmt.h"
39 #include "lib/vfs/mc-vfs/vfs.h"
41 #ifdef ENABLE_VFS_FTP
42 #include "lib/vfs/mc-vfs/ftpfs.h"
43 #endif
44 #ifdef ENABLE_VFS_FISH
45 #include "lib/vfs/mc-vfs/fish.h"
46 #endif
48 #include "lib/util.h"
49 #include "lib/widget.h"
50 #ifdef HAVE_CHARSET
51 #include "lib/charsets.h"
52 #endif
54 #include "filemanager/dir.h"
55 #include "filemanager/midnight.h"
56 #include "filemanager/tree.h" /* xtree_mode */
57 #include "filemanager/hotlist.h" /* load/save/done hotlist */
58 #include "filemanager/panelize.h" /* load/save/done panelize */
59 #include "filemanager/layout.h"
60 #include "filemanager/cmd.h"
62 #include "args.h"
63 #include "execute.h" /* pause_after_run */
64 #include "clipboard.h"
65 #include "keybind-defaults.h" /* keybind_lookup_action */
67 #ifdef HAVE_CHARSET
68 #include "selcodepage.h"
69 #endif
71 #ifdef USE_INTERNAL_EDIT
72 #include "src/editor/edit.h"
73 #endif
75 #include "src/viewer/mcviewer.h" /* For the externs */
77 #include "setup.h"
79 /*** global variables ****************************************************************************/
81 char *profile_name; /* .mc/ini */
82 char *global_profile_name; /* mc.lib */
84 /* Only used at program boot */
85 gboolean boot_current_is_left = TRUE;
87 char *setup_color_string;
88 char *term_color_string;
89 char *color_terminal_string;
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;
107 /* Asks for confirmation before clean up of history */
108 int confirm_history_cleanup = 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 .kilobyte_si = FALSE,
133 .mix_all_files = FALSE,
134 .show_backups = TRUE,
135 .show_dot_files = TRUE,
136 .fast_reload = FALSE,
137 .fast_reload_msg_shown = FALSE,
138 .mark_moves_down = TRUE,
139 .reverse_files_only = TRUE,
140 .auto_save_setup = FALSE,
141 .navigate_with_arrows = FALSE,
142 .scroll_pages = TRUE,
143 .mouse_move_pages = TRUE,
144 .filetype_mode = TRUE,
145 .permission_mode = FALSE,
146 .qsearch_mode = QSEARCH_PANEL_CASE
149 int easy_patterns = 1;
151 /* It true saves the setup when quitting */
152 int auto_save_setup = 1;
154 /* If true, then the +, - and \ keys have their special meaning only if the
155 * command line is emtpy, otherwise they behave like regular letters
157 int only_leading_plus_minus = 1;
159 /* Set when cd symlink following is desirable (bash mode) */
160 int cd_symlinks = 1;
162 /* Set if you want the possible completions dialog for the first time */
163 int show_all_if_ambiguous = 0;
165 /* Automatically fills name with current selected item name on mkdir */
166 int auto_fill_mkdir_name = 1;
168 /* If set and you don't have subshell support,then C-o will give you a shell */
169 int output_starts_shell = 0;
171 /* If set, we execute the file command to check the file type */
172 int use_file_to_check_type = 1;
174 int verbose = 1;
177 * Whether the Midnight Commander tries to provide more
178 * information about copy/move sizes and bytes transfered
179 * at the expense of some speed
181 int file_op_compute_totals = 1;
183 /*** file scope macro definitions ****************************************************************/
185 /* In order to use everywhere the same setup for the locale we use defines */
186 #define FMTYEAR _("%b %e %Y")
187 #define FMTTIME _("%b %e %H:%M")
189 /*** file scope type declarations ****************************************************************/
191 /*** file scope variables ************************************************************************/
193 static char *panels_profile_name = NULL; /* .mc/panels.ini */
195 /* *INDENT-OFF* */
196 static const struct
198 const char *key;
199 int list_type;
200 } list_types [] = {
201 { "full", list_full },
202 { "brief", list_brief },
203 { "long", list_long },
204 { "user", list_user },
205 { NULL, 0 }
208 static const struct
210 const char *opt_name;
211 panel_view_mode_t opt_type;
212 } panel_types [] = {
213 { "listing", view_listing },
214 { "quickview", view_quick },
215 { "info", view_info },
216 { "tree", view_tree },
217 { NULL, view_listing }
220 static const struct
222 const char *opt_name;
223 int *opt_addr;
224 } layout [] = {
225 { "equal_split", &equal_split },
226 { "first_panel_size", &first_panel_size },
227 { "message_visible", &message_visible },
228 { "keybar_visible", &keybar_visible },
229 { "xterm_title", &xterm_title },
230 { "output_lines", &output_lines },
231 { "command_prompt", &command_prompt },
232 { "menubar_visible", &menubar_visible },
233 { "show_mini_info", &show_mini_info },
234 { "free_space", &free_space },
235 { NULL, NULL }
238 static const struct
240 const char *opt_name;
241 int *opt_addr;
242 } int_options [] = {
243 { "verbose", &verbose },
244 { "pause_after_run", &pause_after_run },
245 { "shell_patterns", &easy_patterns },
246 { "auto_save_setup", &auto_save_setup },
247 { "auto_menu", &auto_menu },
248 { "use_internal_view", &use_internal_view },
249 { "use_internal_edit", &use_internal_edit },
250 { "clear_before_exec", &clear_before_exec },
251 { "confirm_delete", &confirm_delete },
252 { "confirm_overwrite", &confirm_overwrite },
253 { "confirm_execute", &confirm_execute },
254 { "confirm_history_cleanup", &confirm_history_cleanup },
255 { "confirm_exit", &confirm_exit },
256 { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete },
257 { "safe_delete", &safe_delete },
258 { "mouse_repeat_rate", &mou_auto_repeat },
259 { "double_click_speed", &double_click_speed },
260 #ifndef HAVE_CHARSET
261 { "eight_bit_clean", &eight_bit_clean },
262 { "full_eight_bits", &full_eight_bits },
263 #endif /* !HAVE_CHARSET */
264 { "use_8th_bit_as_meta", &use_8th_bit_as_meta },
265 { "confirm_view_dir", &confirm_view_dir },
266 { "mouse_move_pages_viewer", &mcview_mouse_move_pages },
267 { "mouse_close_dialog", &mouse_close_dialog},
268 { "fast_refresh", &fast_refresh },
269 { "drop_menus", &drop_menus },
270 { "wrap_mode", &mcview_global_wrap_mode},
271 { "old_esc_mode", &old_esc_mode },
272 { "old_esc_mode_timeout", &old_esc_mode_timeout },
273 { "cd_symlinks", &cd_symlinks },
274 { "show_all_if_ambiguous", &show_all_if_ambiguous },
275 { "max_dirt_limit", &mcview_max_dirt_limit },
276 { "torben_fj_mode", &torben_fj_mode },
277 { "use_file_to_guess_type", &use_file_to_check_type },
278 { "alternate_plus_minus", &alternate_plus_minus },
279 { "only_leading_plus_minus", &only_leading_plus_minus },
280 { "show_output_starts_shell", &output_starts_shell },
281 { "xtree_mode", &xtree_mode },
282 { "num_history_items_recorded", &num_history_items_recorded },
283 { "file_op_compute_totals", &file_op_compute_totals },
284 { "classic_progressbar", &classic_progressbar},
285 #ifdef ENABLE_VFS
286 { "vfs_timeout", &vfs_timeout },
287 #ifdef ENABLE_VFS_FTP
288 { "ftpfs_directory_timeout", &ftpfs_directory_timeout },
289 { "use_netrc", &ftpfs_use_netrc },
290 { "ftpfs_retry_seconds", &ftpfs_retry_seconds },
291 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy },
292 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections },
293 { "ftpfs_use_passive_connections_over_proxy", &ftpfs_use_passive_connections_over_proxy },
294 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options },
295 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls },
296 #endif /* ENABLE_VFS_FTP */
297 #ifdef ENABLE_VFS_FISH
298 { "fish_directory_timeout", &fish_directory_timeout },
299 #endif /* ENABLE_VFS_FISH */
300 #endif /* ENABLE_VFS */
301 /* option_tab_spacing is used in internal viewer */
302 { "editor_tab_spacing", &option_tab_spacing },
303 #ifdef USE_INTERNAL_EDIT
304 { "editor_word_wrap_line_length", &option_word_wrap_line_length },
305 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces },
306 { "editor_return_does_auto_indent", &option_return_does_auto_indent },
307 { "editor_backspace_through_tabs", &option_backspace_through_tabs },
308 { "editor_fake_half_tabs", &option_fake_half_tabs },
309 { "editor_option_save_mode", &option_save_mode },
310 { "editor_option_save_position", &option_save_position },
311 { "editor_option_auto_para_formatting", &option_auto_para_formatting },
312 { "editor_option_typewriter_wrap", &option_typewriter_wrap },
313 { "editor_edit_confirm_save", &edit_confirm_save },
314 { "editor_syntax_highlighting", &option_syntax_highlighting },
315 { "editor_persistent_selections", &option_persistent_selections },
316 { "editor_cursor_beyond_eol", &option_cursor_beyond_eol },
317 { "editor_visible_tabs", &visible_tabs },
318 { "editor_visible_spaces", &visible_tws },
319 { "editor_line_state", &option_line_state },
320 { "editor_simple_statusbar", &simple_statusbar },
321 { "editor_check_new_line", &option_check_nl_at_eof },
322 { "editor_show_right_margin", &show_right_margin },
323 #endif /* USE_INTERNAL_EDIT */
324 { "nice_rotating_dash", &nice_rotating_dash },
325 { "horizontal_split", &horizontal_split },
326 { "mcview_remember_file_position", &mcview_remember_file_position },
327 { "auto_fill_mkdir_name", &auto_fill_mkdir_name },
328 { "copymove_persistent_attr", &setup_copymove_persistent_attr },
329 { "select_flags", &select_flags },
330 { NULL, NULL }
333 static const struct
335 const char *opt_name;
336 char **opt_addr;
337 const char *opt_defval;
338 } str_options[] = {
339 #ifdef USE_INTERNAL_EDIT
340 { "editor_backup_extension", &option_backup_ext, "~" },
341 #endif
342 { "mcview_eof", &mcview_show_eof, "" },
343 { NULL, NULL, NULL }
346 static const struct
348 const char *opt_name;
349 const char *opt_old_name;
350 gboolean *opt_addr;
351 } panels_ini_options[] = {
352 { "kilobyte_si", NULL, &panels_options.kilobyte_si },
353 { "mix_all_files", NULL, &panels_options.mix_all_files },
354 { "show_backups", NULL, &panels_options.show_backups },
355 { "show_dot_files", NULL, &panels_options.show_dot_files },
356 { "fast_reload", NULL, &panels_options.fast_reload },
357 { "fast_reload_msg_shown", NULL, &panels_options.fast_reload_msg_shown },
358 { "mark_moves_down", NULL, &panels_options.mark_moves_down },
359 { "reverse_files_only", NULL, &panels_options.reverse_files_only },
360 { "auto_save_setup_panels", "auto_save_setup", &panels_options.auto_save_setup },
361 { "navigate_with_arrows", NULL, &panels_options.navigate_with_arrows },
362 { "panel_scroll_pages", "scroll_pages", &panels_options.scroll_pages },
363 { "mouse_move_pages", NULL, &panels_options.mouse_move_pages },
364 { "filetype_mode", NULL, &panels_options.filetype_mode },
365 { "permission_mode", NULL, &panels_options.permission_mode },
366 { NULL, NULL, NULL }
368 /* *INDENT-ON* */
370 /*** file scope functions ************************************************************************/
371 /* --------------------------------------------------------------------------------------------- */
374 Get name of config file.
376 \param subdir
377 if not NULL, then config also search into specified subdir.
379 \param config_file_name
380 If specified filename is relative, then will search in standart patches.
382 \return
383 Newly allocated path to config name or NULL if file not found.
385 If config_file_name is a relative path, then search config in stantart pathes.
387 static char *
388 load_setup_get_full_config_name (const char *subdir, const char *config_file_name)
391 TODO: IMHO, in future this function must be placed into mc_config module.
392 Also, need to rename stupid mc_home and mc_home_alt to mc_sysconfdir and mc_datadir;
393 home_mc => mc_user_homedir
395 char *lc_basename, *ret;
397 if (config_file_name == NULL)
398 return NULL;
400 if (g_path_is_absolute (config_file_name))
401 return g_strdup (config_file_name);
404 lc_basename = g_path_get_basename (config_file_name);
405 if (lc_basename == NULL)
406 return NULL;
408 if (subdir != NULL)
409 ret = g_build_filename (home_dir, MC_USERCONF_DIR, subdir, lc_basename, NULL);
410 else
411 ret = g_build_filename (home_dir, MC_USERCONF_DIR, lc_basename, NULL);
413 if (exist_file (ret))
415 g_free (lc_basename);
416 return ret;
418 g_free (ret);
420 if (subdir != NULL)
421 ret = g_build_filename (mc_home, subdir, lc_basename, NULL);
422 else
423 ret = g_build_filename (mc_home, lc_basename, NULL);
425 if (exist_file (ret))
427 g_free (lc_basename);
428 return ret;
430 g_free (ret);
432 if (subdir != NULL)
433 ret = g_build_filename (mc_home_alt, subdir, lc_basename, NULL);
434 else
435 ret = g_build_filename (mc_home_alt, lc_basename, NULL);
437 g_free (lc_basename);
439 if (exist_file (ret))
440 return ret;
442 g_free (ret);
443 return NULL;
447 /* --------------------------------------------------------------------------------------------- */
449 static const char *
450 setup__is_cfg_group_must_panel_config (const char *grp)
452 return (!strcasecmp ("Dirs", grp) ||
453 !strcasecmp ("Temporal:New Right Panel", grp) ||
454 !strcasecmp ("Temporal:New Left Panel", grp) ||
455 !strcasecmp ("New Left Panel", grp) || !strcasecmp ("New Right Panel", grp))
456 ? grp : NULL;
459 /* --------------------------------------------------------------------------------------------- */
461 static void
462 setup__move_panels_config_into_separate_file (const char *profile)
464 mc_config_t *tmp_cfg;
465 char **groups, **curr_grp;
466 const char *need_grp;
468 if (!exist_file (profile))
469 return;
471 tmp_cfg = mc_config_init (profile);
472 if (!tmp_cfg)
473 return;
475 curr_grp = groups = mc_config_get_groups (tmp_cfg, NULL);
476 if (!groups)
478 mc_config_deinit (tmp_cfg);
479 return;
482 while (*curr_grp)
484 if (setup__is_cfg_group_must_panel_config (*curr_grp) == NULL)
485 mc_config_del_group (tmp_cfg, *curr_grp);
486 curr_grp++;
489 mc_config_save_to_file (tmp_cfg, panels_profile_name, NULL);
490 mc_config_deinit (tmp_cfg);
492 tmp_cfg = mc_config_init (profile);
493 if (!tmp_cfg)
495 g_strfreev (groups);
496 return;
499 curr_grp = groups;
501 while (*curr_grp)
503 need_grp = setup__is_cfg_group_must_panel_config (*curr_grp);
504 if (need_grp != NULL)
506 mc_config_del_group (tmp_cfg, need_grp);
508 curr_grp++;
510 g_strfreev (groups);
512 mc_config_save_file (tmp_cfg, NULL);
513 mc_config_deinit (tmp_cfg);
516 /* --------------------------------------------------------------------------------------------- */
518 Create new mc_config object from specified ini-file or
519 append data to existing mc_config object from ini-file
523 static void
524 load_setup_init_config_from_file (mc_config_t ** config, const char *fname)
527 TODO: IMHO, in future this function must be placed into mc_config module.
529 if (exist_file (fname))
531 if (*config != NULL)
532 mc_config_read_file (*config, fname);
533 else
534 *config = mc_config_init (fname);
538 /* --------------------------------------------------------------------------------------------- */
540 static void
541 load_layout (void)
543 size_t i;
545 for (i = 0; layout[i].opt_name != NULL; i++)
546 *layout[i].opt_addr = mc_config_get_int (mc_main_config, "Layout",
547 layout[i].opt_name, *layout[i].opt_addr);
550 /* --------------------------------------------------------------------------------------------- */
552 static void
553 load_keys_from_section (const char *terminal, mc_config_t * cfg)
555 char *section_name;
556 gchar **profile_keys, **keys;
557 gchar **values, **curr_values;
558 char *valcopy, *value;
559 long key_code;
560 gsize len, values_len;
562 if (terminal == NULL)
563 return;
565 section_name = g_strconcat ("terminal:", terminal, (char *) NULL);
566 profile_keys = keys = mc_config_get_keys (cfg, section_name, &len);
568 while (*profile_keys != NULL)
570 /* copy=other causes all keys from [terminal:other] to be loaded. */
571 if (g_ascii_strcasecmp (*profile_keys, "copy") == 0)
573 valcopy = mc_config_get_string (cfg, section_name, *profile_keys, "");
574 load_keys_from_section (valcopy, cfg);
575 g_free (valcopy);
576 profile_keys++;
577 continue;
580 curr_values = values =
581 mc_config_get_string_list (cfg, section_name, *profile_keys, &values_len);
583 key_code = lookup_key (*profile_keys, NULL);
585 if (key_code != 0)
587 if (curr_values != NULL)
589 while (*curr_values != NULL)
591 valcopy = convert_controls (*curr_values);
592 define_sequence (key_code, valcopy, MCKEY_NOACTION);
593 g_free (valcopy);
594 curr_values++;
597 else
599 value = mc_config_get_string (cfg, section_name, *profile_keys, "");
600 valcopy = convert_controls (value);
601 define_sequence (key_code, valcopy, MCKEY_NOACTION);
602 g_free (valcopy);
603 g_free (value);
607 profile_keys++;
609 if (values != NULL)
610 g_strfreev (values);
612 g_strfreev (keys);
613 g_free (section_name);
616 /* --------------------------------------------------------------------------------------------- */
618 static void
619 load_keymap_from_section (const char *section_name, GArray * keymap, mc_config_t * cfg)
621 gchar **profile_keys, **keys;
622 gchar **values, **curr_values;
623 char *valcopy, *value;
624 int action;
625 gsize len, values_len;
627 if (section_name == NULL)
628 return;
630 profile_keys = keys = mc_config_get_keys (cfg, section_name, &len);
632 while (*profile_keys != NULL)
634 curr_values = values =
635 mc_config_get_string_list (cfg, section_name, *profile_keys, &values_len);
637 action = keybind_lookup_action (*profile_keys);
639 if (action > 0)
641 if (curr_values != NULL)
643 while (*curr_values != NULL)
645 valcopy = convert_controls (*curr_values);
646 keybind_cmd_bind (keymap, valcopy, action);
647 g_free (valcopy);
648 curr_values++;
651 else
653 value = mc_config_get_string (cfg, section_name, *profile_keys, "");
654 valcopy = convert_controls (value);
655 /* define_sequence (key_code, valcopy, MCKEY_NOACTION); */
656 g_free (valcopy);
657 g_free (value);
661 profile_keys++;
663 if (values != NULL)
664 g_strfreev (values);
666 g_strfreev (keys);
669 /* --------------------------------------------------------------------------------------------- */
671 static mc_config_t *
672 load_setup_get_keymap_profile_config (void)
675 TODO: IMHO, in future this function must be placed into mc_config module.
677 mc_config_t *keymap_config = NULL;
678 char *fname, *fname2;
680 /* 1) /usr/share/mc (mc_home_alt) */
681 fname = g_build_filename (mc_home_alt, GLOBAL_KEYMAP_FILE, NULL);
682 load_setup_init_config_from_file (&keymap_config, fname);
683 g_free (fname);
685 /* 2) /etc/mc (mc_home) */
686 fname = g_build_filename (mc_home, GLOBAL_KEYMAP_FILE, NULL);
687 load_setup_init_config_from_file (&keymap_config, fname);
688 g_free (fname);
690 /* 3) ~/.mc (home_dir?) */
691 fname = g_build_filename (home_dir, MC_USERCONF_DIR, GLOBAL_KEYMAP_FILE, NULL);
692 load_setup_init_config_from_file (&keymap_config, fname);
693 g_free (fname);
695 /* 4) main config; [Midnight Commander] -> keymap */
697 fname2 =
698 mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, "keymap", GLOBAL_KEYMAP_FILE);
699 fname = load_setup_get_full_config_name (NULL, fname2);
700 if (fname != NULL)
702 load_setup_init_config_from_file (&keymap_config, fname);
703 g_free (fname);
705 g_free (fname2);
707 /* 5) getenv("MC_KEYMAP") */
708 fname = load_setup_get_full_config_name (NULL, g_getenv ("MC_KEYMAP"));
709 if (fname != NULL)
711 load_setup_init_config_from_file (&keymap_config, fname);
712 g_free (fname);
715 /* 6) --keymap=<keymap> */
716 fname = load_setup_get_full_config_name (NULL, mc_args__keymap_file);
717 if (fname != NULL)
719 load_setup_init_config_from_file (&keymap_config, fname);
720 g_free (fname);
723 return keymap_config;
726 /* --------------------------------------------------------------------------------------------- */
728 static panel_view_mode_t
729 setup__load_panel_state (const char *section)
731 char *buffer;
732 size_t i;
733 panel_view_mode_t mode = view_listing;
735 /* Load the display mode */
736 buffer = mc_config_get_string (mc_panels_config, section, "display", "listing");
738 for (i = 0; panel_types[i].opt_name != NULL; i++)
739 if (g_ascii_strcasecmp (panel_types[i].opt_name, buffer) == 0)
741 mode = panel_types[i].opt_type;
742 break;
745 g_free (buffer);
747 return mode;
750 /* --------------------------------------------------------------------------------------------- */
752 static void
753 panel_save_type (const char *section, panel_view_mode_t type)
755 size_t i;
757 for (i = 0; panel_types[i].opt_name != NULL; i++)
758 if (panel_types[i].opt_type == type)
760 mc_config_set_string (mc_panels_config, section, "display", panel_types[i].opt_name);
761 break;
765 /* --------------------------------------------------------------------------------------------- */
767 /* save panels.ini */
768 static void
769 save_panel_types (void)
771 panel_view_mode_t type;
773 if (mc_run_mode != MC_RUN_FULL)
774 return;
776 type = get_display_type (0);
777 panel_save_type ("New Left Panel", type);
778 if (type == view_listing)
779 panel_save_setup (left_panel, left_panel->panel_name);
780 type = get_display_type (1);
781 panel_save_type ("New Right Panel", type);
782 if (type == view_listing)
783 panel_save_setup (right_panel, right_panel->panel_name);
785 mc_config_set_string (mc_panels_config, "Dirs", "other_dir", get_panel_dir_for (other_panel));
787 if (current_panel != NULL)
788 mc_config_set_string (mc_panels_config, "Dirs", "current_is_left",
789 get_current_index () == 0 ? "1" : "0");
791 if (mc_panels_config->ini_path == NULL)
792 mc_panels_config->ini_path = g_strdup (panels_profile_name);
794 mc_config_del_group (mc_panels_config, "Temporal:New Left Panel");
795 mc_config_del_group (mc_panels_config, "Temporal:New Right Panel");
797 mc_config_save_file (mc_panels_config, NULL);
800 /* --------------------------------------------------------------------------------------------- */
801 /*** public functions ****************************************************************************/
802 /* --------------------------------------------------------------------------------------------- */
804 char *
805 setup_init (void)
807 char *profile;
808 char *inifile;
810 if (profile_name != NULL)
811 return profile_name;
813 profile = g_build_filename (home_dir, MC_USERCONF_DIR, MC_CONFIG_FILE, NULL);
814 if (!exist_file (profile))
816 inifile = concat_dir_and_file (mc_home, "mc.ini");
817 if (exist_file (inifile))
819 g_free (profile);
820 profile = inifile;
822 else
824 g_free (inifile);
825 inifile = concat_dir_and_file (mc_home_alt, "mc.ini");
826 if (exist_file (inifile))
828 g_free (profile);
829 profile = inifile;
831 else
832 g_free (inifile);
836 profile_name = profile;
838 return profile;
841 /* --------------------------------------------------------------------------------------------- */
843 void
844 load_setup (void)
846 char *profile;
847 size_t i;
848 char *buffer;
849 const char *kt;
851 #ifdef HAVE_CHARSET
852 load_codepages_list ();
853 #endif /* HAVE_CHARSET */
855 profile = setup_init ();
857 /* mc.lib is common for all users, but has priority lower than
858 ~/.mc/ini. FIXME: it's only used for keys and treestore now */
859 global_profile_name = g_build_filename (mc_home, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
860 if (!exist_file (global_profile_name))
862 g_free (global_profile_name);
863 global_profile_name = g_build_filename (mc_home_alt, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
866 panels_profile_name = g_build_filename (home_dir, MC_USERCONF_DIR, MC_PANELS_FILE, NULL);
868 mc_main_config = mc_config_init (profile);
870 if (!exist_file (panels_profile_name))
871 setup__move_panels_config_into_separate_file (profile);
873 mc_panels_config = mc_config_init (panels_profile_name);
875 /* Load integer boolean options */
876 for (i = 0; int_options[i].opt_name != NULL; i++)
877 *int_options[i].opt_addr =
878 mc_config_get_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
879 *int_options[i].opt_addr);
881 if (option_tab_spacing <= 0)
882 option_tab_spacing = DEFAULT_TAB_SPACING;
884 #ifdef USE_INTERNAL_EDIT
885 if (option_word_wrap_line_length <= 0)
886 option_word_wrap_line_length = DEFAULT_WRAP_LINE_LENGTH;
887 #endif /* USE_INTERNAL_EDIT */
889 /* overwrite old_esc_mode_timeout */
890 kt = getenv ("KEYBOARD_KEY_TIMEOUT_US");
891 if ((kt != NULL) && (kt[0] != '\0'))
892 old_esc_mode_timeout = atoi (kt);
894 /* Load string options */
895 for (i = 0; str_options[i].opt_name != NULL; i++)
896 *str_options[i].opt_addr =
897 mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
898 str_options[i].opt_defval);
900 load_layout ();
901 panels_load_options ();
902 load_panelize ();
904 startup_left_mode = setup__load_panel_state ("New Left Panel");
905 startup_right_mode = setup__load_panel_state ("New Right Panel");
907 /* At least one of the panels is a listing panel */
908 if (startup_left_mode != view_listing && startup_right_mode != view_listing)
909 startup_left_mode = view_listing;
911 if (mc_run_param1 == NULL)
913 buffer = mc_config_get_string (mc_panels_config, "Dirs", "other_dir", ".");
914 if (vfs_file_is_local (buffer))
915 mc_run_param1 = buffer;
916 else
917 g_free (buffer);
920 boot_current_is_left = mc_config_get_bool (mc_panels_config, "Dirs", "current_is_left", TRUE);
922 /* Load time formats */
923 user_recent_timeformat =
924 mc_config_get_string (mc_main_config, "Misc", "timeformat_recent", FMTTIME);
925 user_old_timeformat = mc_config_get_string (mc_main_config, "Misc", "timeformat_old", FMTYEAR);
927 #ifdef ENABLE_VFS_FTP
928 ftpfs_proxy_host = mc_config_get_string (mc_main_config, "Misc", "ftp_proxy_host", "gate");
929 ftpfs_ignore_chattr_errors = mc_config_get_bool (mc_main_config, CONFIG_APP_SECTION,
930 "ignore_ftp_chattr_errors", TRUE);
931 ftpfs_init_passwd ();
932 #endif /* ENABLE_VFS_FTP */
934 /* The default color and the terminal dependent color */
935 setup_color_string = mc_config_get_string (mc_main_config, "Colors", "base_color", "");
936 term_color_string = mc_config_get_string (mc_main_config, "Colors", getenv ("TERM"), "");
937 color_terminal_string = mc_config_get_string (mc_main_config, "Colors", "color_terminals", "");
939 /* Load the directory history */
940 /* directory_history_load (); */
941 /* Remove the temporal entries */
943 #ifdef HAVE_CHARSET
944 if (codepages->len > 1)
946 buffer = mc_config_get_string (mc_main_config, "Misc", "display_codepage", "");
947 if (buffer[0] != '\0')
949 display_codepage = get_codepage_index (buffer);
950 cp_display = get_codepage_id (display_codepage);
952 g_free (buffer);
953 buffer = mc_config_get_string (mc_main_config, "Misc", "source_codepage", "");
954 if (buffer[0] != '\0')
956 default_source_codepage = get_codepage_index (buffer);
957 source_codepage = default_source_codepage; /* May be source_codepage doesn't need this */
958 cp_source = get_codepage_id (source_codepage);
960 g_free (buffer);
963 autodetect_codeset = mc_config_get_string (mc_main_config, "Misc", "autodetect_codeset", "");
964 if ((autodetect_codeset[0] != '\0') && (strcmp (autodetect_codeset, "off") != 0))
965 is_autodetect_codeset_enabled = TRUE;
967 g_free (init_translation_table (source_codepage, display_codepage));
968 buffer = (char *) get_codepage_id (display_codepage);
969 if (buffer != NULL)
970 utf8_display = str_isutf8 (buffer);
971 #endif /* HAVE_CHARSET */
973 clipboard_store_path = mc_config_get_string (mc_main_config, "Misc", "clipboard_store", "");
974 clipboard_paste_path = mc_config_get_string (mc_main_config, "Misc", "clipboard_paste", "");
977 /* --------------------------------------------------------------------------------------------- */
979 gboolean
980 save_setup (gboolean save_options, gboolean save_panel_options)
982 gboolean ret = TRUE;
984 saving_setup = 1;
986 save_hotlist ();
988 if (save_panel_options)
989 save_panel_types ();
991 if (save_options)
993 char *tmp_profile;
995 save_config ();
996 save_layout ();
997 panels_save_options ();
998 save_panelize ();
999 /* directory_history_save (); */
1001 #ifdef ENABLE_VFS_FTP
1002 mc_config_set_string (mc_main_config, "Misc", "ftpfs_password", ftpfs_anonymous_passwd);
1003 if (ftpfs_proxy_host)
1004 mc_config_set_string (mc_main_config, "Misc", "ftp_proxy_host", ftpfs_proxy_host);
1005 #endif /* ENABLE_VFS_FTP */
1007 #ifdef HAVE_CHARSET
1008 mc_config_set_string (mc_main_config, "Misc", "display_codepage",
1009 get_codepage_id (display_codepage));
1010 mc_config_set_string (mc_main_config, "Misc", "source_codepage",
1011 get_codepage_id (default_source_codepage));
1012 mc_config_set_string (mc_main_config, "Misc", "autodetect_codeset", autodetect_codeset);
1013 #endif /* HAVE_CHARSET */
1014 mc_config_set_string (mc_main_config, "Misc", "clipboard_store", clipboard_store_path);
1015 mc_config_set_string (mc_main_config, "Misc", "clipboard_paste", clipboard_paste_path);
1017 tmp_profile = g_build_filename (home_dir, MC_USERCONF_DIR, MC_CONFIG_FILE, NULL);
1018 ret = mc_config_save_to_file (mc_main_config, tmp_profile, NULL);
1020 g_free (tmp_profile);
1023 saving_setup = 0;
1025 return ret;
1028 /* --------------------------------------------------------------------------------------------- */
1030 void
1031 done_setup (void)
1033 size_t i;
1035 g_free (clipboard_store_path);
1036 g_free (clipboard_paste_path);
1037 g_free (profile_name);
1038 g_free (global_profile_name);
1039 g_free (color_terminal_string);
1040 g_free (term_color_string);
1041 g_free (setup_color_string);
1042 g_free (panels_profile_name);
1043 mc_config_deinit (mc_main_config);
1044 mc_config_deinit (mc_panels_config);
1046 g_free (user_recent_timeformat);
1047 g_free (user_old_timeformat);
1049 for (i = 0; str_options[i].opt_name != NULL; i++)
1050 g_free (*str_options[i].opt_addr);
1052 done_hotlist ();
1053 done_panelize ();
1054 /* directory_history_free (); */
1056 #ifdef HAVE_CHARSET
1057 g_free (autodetect_codeset);
1058 free_codepages_list ();
1059 #endif
1062 /* --------------------------------------------------------------------------------------------- */
1064 void
1065 save_config (void)
1067 char *profile;
1068 GError *error = NULL;
1069 size_t i;
1071 profile = g_build_filename (home_dir, MC_USERCONF_DIR, MC_CONFIG_FILE, NULL);
1073 /* Save integer options */
1074 for (i = 0; int_options[i].opt_name != NULL; i++)
1075 mc_config_set_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
1076 *int_options[i].opt_addr);
1078 /* Save string options */
1079 for (i = 0; str_options[i].opt_name != NULL; i++)
1080 mc_config_set_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
1081 *str_options[i].opt_addr);
1083 if (!mc_config_save_to_file (mc_main_config, profile, &error))
1084 setup_save_config_show_error (profile, &error);
1086 g_free (profile);
1089 /* --------------------------------------------------------------------------------------------- */
1091 void
1092 setup_save_config_show_error (const char *filename, GError ** error)
1094 if (error != NULL && *error != NULL)
1096 message (D_ERROR, MSG_ERROR, _("Cannot save file %s:\n%s"), filename, (*error)->message);
1097 g_error_free (*error);
1098 *error = NULL;
1102 /* --------------------------------------------------------------------------------------------- */
1104 void
1105 save_layout (void)
1107 char *profile;
1108 size_t i;
1110 profile = g_build_filename (home_dir, MC_USERCONF_DIR, MC_CONFIG_FILE, NULL);
1111 /* Save integer options */
1112 for (i = 0; layout[i].opt_name != NULL; i++)
1113 mc_config_set_int (mc_main_config, "Layout", layout[i].opt_name, *layout[i].opt_addr);
1114 mc_config_save_to_file (mc_main_config, profile, NULL);
1115 g_free (profile);
1118 /* --------------------------------------------------------------------------------------------- */
1120 void
1121 load_key_defs (void)
1124 * Load keys from mc.lib before ~/.mc/ini, so that the user
1125 * definitions override global settings.
1127 mc_config_t *mc_global_config;
1129 mc_global_config = mc_config_init (global_profile_name);
1130 if (mc_global_config != NULL)
1132 load_keys_from_section ("general", mc_global_config);
1133 load_keys_from_section (getenv ("TERM"), mc_global_config);
1134 mc_config_deinit (mc_global_config);
1137 load_keys_from_section ("general", mc_main_config);
1138 load_keys_from_section (getenv ("TERM"), mc_main_config);
1141 /* --------------------------------------------------------------------------------------------- */
1143 #ifdef ENABLE_VFS_FTP
1144 char *
1145 load_anon_passwd (void)
1147 char *buffer;
1149 buffer = mc_config_get_string (mc_main_config, "Misc", "ftpfs_password", "");
1151 if ((buffer != NULL) && (buffer[0] != '\0'))
1152 return buffer;
1154 g_free (buffer);
1155 return NULL;
1157 #endif /* ENABLE_VFS_FTP */
1159 /* --------------------------------------------------------------------------------------------- */
1161 void
1162 load_keymap_defs (void)
1165 * Load keymap from GLOBAL_KEYMAP_FILE before ~/.mc/keymap, so that the user
1166 * definitions override global settings.
1168 mc_config_t *mc_global_keymap;
1170 mc_global_keymap = load_setup_get_keymap_profile_config ();
1172 if (mc_global_keymap != NULL)
1174 #ifdef USE_INTERNAL_EDIT
1175 editor_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1176 load_keymap_from_section ("editor", editor_keymap, mc_global_keymap);
1177 editor_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1178 load_keymap_from_section ("editor:xmap", editor_x_keymap, mc_global_keymap);
1179 #endif
1181 viewer_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1182 load_keymap_from_section ("viewer", viewer_keymap, mc_global_keymap);
1183 viewer_hex_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1184 load_keymap_from_section ("viewer:hex", viewer_hex_keymap, mc_global_keymap);
1186 main_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1187 load_keymap_from_section ("main", main_keymap, mc_global_keymap);
1188 main_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1189 load_keymap_from_section ("main:xmap", main_x_keymap, mc_global_keymap);
1191 panel_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1192 load_keymap_from_section ("panel", panel_keymap, mc_global_keymap);
1194 input_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1195 load_keymap_from_section ("input", input_keymap, mc_global_keymap);
1197 listbox_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1198 load_keymap_from_section ("listbox", listbox_keymap, mc_global_keymap);
1200 tree_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1201 load_keymap_from_section ("tree", tree_keymap, mc_global_keymap);
1203 help_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1204 load_keymap_from_section ("help", help_keymap, mc_global_keymap);
1206 dialog_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1207 load_keymap_from_section ("dialog", dialog_keymap, mc_global_keymap);
1209 #ifdef USE_DIFF_VIEW
1210 diff_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1211 load_keymap_from_section ("diffviewer", diff_keymap, mc_global_keymap);
1212 #endif
1213 mc_config_deinit (mc_global_keymap);
1216 main_map = default_main_map;
1217 if (main_keymap && main_keymap->len > 0)
1218 main_map = (global_keymap_t *) main_keymap->data;
1220 main_x_map = default_main_x_map;
1221 if (main_x_keymap && main_x_keymap->len > 0)
1222 main_x_map = (global_keymap_t *) main_x_keymap->data;
1224 panel_map = default_panel_keymap;
1225 if (panel_keymap && panel_keymap->len > 0)
1226 panel_map = (global_keymap_t *) panel_keymap->data;
1228 input_map = default_input_keymap;
1229 if (input_keymap && input_keymap->len > 0)
1230 input_map = (global_keymap_t *) input_keymap->data;
1232 listbox_map = default_listbox_keymap;
1233 if (listbox_keymap && listbox_keymap->len > 0)
1234 listbox_map = (global_keymap_t *) listbox_keymap->data;
1236 tree_map = default_tree_keymap;
1237 if (tree_keymap && tree_keymap->len > 0)
1238 tree_map = (global_keymap_t *) tree_keymap->data;
1240 help_map = default_help_keymap;
1241 if (help_keymap && help_keymap->len > 0)
1242 help_map = (global_keymap_t *) help_keymap->data;
1244 dialog_map = default_dialog_keymap;
1245 if (dialog_keymap && dialog_keymap->len > 0)
1246 dialog_map = (global_keymap_t *) dialog_keymap->data;
1248 #ifdef USE_DIFF_VIEW
1249 diff_map = default_diff_keymap;
1250 if (diff_keymap && diff_keymap->len > 0)
1251 diff_map = (global_keymap_t *) diff_keymap->data;
1252 #endif
1256 /* --------------------------------------------------------------------------------------------- */
1258 void
1259 free_keymap_defs (void)
1261 #ifdef USE_INTERNAL_EDIT
1262 if (editor_keymap != NULL)
1263 g_array_free (editor_keymap, TRUE);
1264 if (editor_x_keymap != NULL)
1265 g_array_free (editor_x_keymap, TRUE);
1266 #endif
1267 if (viewer_keymap != NULL)
1268 g_array_free (viewer_keymap, TRUE);
1269 if (viewer_hex_keymap != NULL)
1270 g_array_free (viewer_hex_keymap, TRUE);
1271 if (main_keymap != NULL)
1272 g_array_free (main_keymap, TRUE);
1273 if (main_x_keymap != NULL)
1274 g_array_free (main_x_keymap, TRUE);
1275 if (panel_keymap != NULL)
1276 g_array_free (panel_keymap, TRUE);
1277 if (input_keymap != NULL)
1278 g_array_free (input_keymap, TRUE);
1279 if (listbox_keymap != NULL)
1280 g_array_free (listbox_keymap, TRUE);
1281 if (tree_keymap != NULL)
1282 g_array_free (tree_keymap, TRUE);
1283 if (help_keymap != NULL)
1284 g_array_free (help_keymap, TRUE);
1285 if (dialog_keymap != NULL)
1286 g_array_free (dialog_keymap, TRUE);
1287 #ifdef USE_DIFF_VIEW
1288 if (diff_keymap != NULL)
1289 g_array_free (diff_keymap, TRUE);
1290 #endif
1293 /* --------------------------------------------------------------------------------------------- */
1295 void
1296 panel_load_setup (WPanel * panel, const char *section)
1298 size_t i;
1299 char *buffer, buffer2[BUF_TINY];
1301 panel->sort_info.reverse = mc_config_get_int (mc_panels_config, section, "reverse", 0);
1302 panel->sort_info.case_sensitive =
1303 mc_config_get_int (mc_panels_config, section, "case_sensitive",
1304 OS_SORT_CASE_SENSITIVE_DEFAULT);
1305 panel->sort_info.exec_first = mc_config_get_int (mc_panels_config, section, "exec_first", 0);
1307 /* Load sort order */
1308 buffer = mc_config_get_string (mc_panels_config, section, "sort_order", "name");
1309 panel->sort_info.sort_field = panel_get_field_by_id (buffer);
1310 if (panel->sort_info.sort_field == NULL)
1311 panel->sort_info.sort_field = panel_get_field_by_id ("name");
1313 g_free (buffer);
1315 /* Load the listing mode */
1316 buffer = mc_config_get_string (mc_panels_config, section, "list_mode", "full");
1317 panel->list_type = list_full;
1318 for (i = 0; list_types[i].key != NULL; i++)
1319 if (g_ascii_strcasecmp (list_types[i].key, buffer) == 0)
1321 panel->list_type = list_types[i].list_type;
1322 break;
1324 g_free (buffer);
1326 /* User formats */
1327 g_free (panel->user_format);
1328 panel->user_format =
1329 mc_config_get_string (mc_panels_config, section, "user_format", DEFAULT_USER_FORMAT);
1331 for (i = 0; i < LIST_TYPES; i++)
1333 g_free (panel->user_status_format[i]);
1334 g_snprintf (buffer2, BUF_TINY, "user_status%lld", (long long) i);
1335 panel->user_status_format[i] =
1336 mc_config_get_string (mc_panels_config, section, buffer2, DEFAULT_USER_FORMAT);
1339 panel->user_mini_status = mc_config_get_int (mc_panels_config, section, "user_mini_status", 0);
1342 /* --------------------------------------------------------------------------------------------- */
1344 void
1345 panel_save_setup (struct WPanel *panel, const char *section)
1347 char buffer[BUF_TINY];
1348 size_t i;
1350 mc_config_set_int (mc_panels_config, section, "reverse", panel->sort_info.reverse);
1351 mc_config_set_int (mc_panels_config, section, "case_sensitive", panel->sort_info.case_sensitive);
1352 mc_config_set_int (mc_panels_config, section, "exec_first", panel->sort_info.exec_first);
1354 mc_config_set_string (mc_panels_config, section, "sort_order", panel->sort_info.sort_field->id);
1356 for (i = 0; list_types[i].key != NULL; i++)
1357 if (list_types[i].list_type == panel->list_type)
1359 mc_config_set_string (mc_panels_config, section, "list_mode", list_types[i].key);
1360 break;
1363 mc_config_set_string (mc_panels_config, section, "user_format", panel->user_format);
1365 for (i = 0; i < LIST_TYPES; i++)
1367 g_snprintf (buffer, BUF_TINY, "user_status%lld", (long long) i);
1368 mc_config_set_string (mc_panels_config, section, buffer, panel->user_status_format[i]);
1371 mc_config_set_int (mc_panels_config, section, "user_mini_status", panel->user_mini_status);
1374 /* --------------------------------------------------------------------------------------------- */
1377 Load panels options from [Panels] section.
1379 void
1380 panels_load_options (void)
1382 size_t i;
1383 int qmode;
1385 /* Backward compatibility: load old parameters */
1386 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
1387 *panels_ini_options[i].opt_addr =
1388 mc_config_get_int (mc_main_config, CONFIG_APP_SECTION,
1389 panels_ini_options[i].opt_old_name != NULL
1390 ? panels_ini_options[i].opt_old_name : panels_ini_options[i].
1391 opt_name, *panels_ini_options[i].opt_addr);
1393 qmode = mc_config_get_int (mc_main_config, CONFIG_APP_SECTION,
1394 "quick_search_case_sensitive", (int) panels_options.qsearch_mode);
1395 if (qmode < 0)
1396 panels_options.qsearch_mode = QSEARCH_CASE_INSENSITIVE;
1397 else if (qmode >= QSEARCH_NUM)
1398 panels_options.qsearch_mode = QSEARCH_PANEL_CASE;
1399 else
1400 panels_options.qsearch_mode = (qsearch_mode_t) qmode;
1402 /* overwrite by new parameters */
1403 if (mc_config_has_group (mc_main_config, CONFIG_PANELS_SECTION))
1405 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
1406 *panels_ini_options[i].opt_addr =
1407 mc_config_get_bool (mc_main_config, CONFIG_PANELS_SECTION,
1408 panels_ini_options[i].opt_name,
1409 *panels_ini_options[i].opt_addr);
1411 qmode = mc_config_get_int (mc_main_config, CONFIG_PANELS_SECTION,
1412 "quick_search_mode", (int) panels_options.qsearch_mode);
1413 if (qmode < 0)
1414 panels_options.qsearch_mode = QSEARCH_CASE_INSENSITIVE;
1415 else if (qmode >= QSEARCH_NUM)
1416 panels_options.qsearch_mode = QSEARCH_PANEL_CASE;
1417 else
1418 panels_options.qsearch_mode = (qsearch_mode_t) qmode;
1422 /* --------------------------------------------------------------------------------------------- */
1425 Save panels options in [Panels] section.
1427 void
1428 panels_save_options (void)
1430 size_t i;
1432 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
1433 mc_config_set_bool (mc_main_config, CONFIG_PANELS_SECTION,
1434 panels_ini_options[i].opt_name, *panels_ini_options[i].opt_addr);
1436 mc_config_set_int (mc_main_config, CONFIG_PANELS_SECTION,
1437 "quick_search_mode", (int) panels_options.qsearch_mode);
1440 /* --------------------------------------------------------------------------------------------- */