Merge branch '2953_editor_fpe'
[midnight-commander.git] / src / setup.c
blobbbe1f36dd246a52f8845e7ce47cd9358e2ec3cba
1 /*
2 Setup loading/saving.
4 Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
5 2006, 2007, 2009, 2010, 2011
6 The Free Software Foundation, Inc.
8 This file is part of the Midnight Commander.
10 The Midnight Commander is free software: you can redistribute it
11 and/or modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation, either version 3 of the License,
13 or (at your option) any later version.
15 The Midnight Commander is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 /** \file setup.c
25 * \brief Source: setup loading/saving
28 #include <config.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <stdio.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
36 #include "lib/global.h"
38 #include "lib/tty/tty.h"
39 #include "lib/tty/key.h"
40 #include "lib/mcconfig.h"
41 #include "lib/fileloc.h"
42 #include "lib/timefmt.h"
43 #include "lib/util.h"
44 #include "lib/widget.h"
46 #include "lib/vfs/vfs.h"
48 #ifdef ENABLE_VFS_FTP
49 #include "src/vfs/ftpfs/ftpfs.h"
50 #endif
51 #ifdef ENABLE_VFS_FISH
52 #include "src/vfs/fish/fish.h"
53 #endif
55 #ifdef HAVE_CHARSET
56 #include "lib/charsets.h"
57 #endif
59 #include "filemanager/dir.h"
60 #include "filemanager/midnight.h"
61 #include "filemanager/tree.h" /* xtree_mode */
62 #include "filemanager/hotlist.h" /* load/save/done hotlist */
63 #include "filemanager/panelize.h" /* load/save/done panelize */
64 #include "filemanager/layout.h"
65 #include "filemanager/cmd.h"
67 #include "args.h"
68 #include "execute.h" /* pause_after_run */
69 #include "clipboard.h"
70 #include "keybind-defaults.h" /* keybind_lookup_action */
72 #ifdef HAVE_CHARSET
73 #include "selcodepage.h"
74 #endif
76 #ifdef USE_INTERNAL_EDIT
77 #include "src/editor/edit.h"
78 #endif
80 #include "src/viewer/mcviewer.h" /* For the externs */
82 #include "setup.h"
84 /*** global variables ****************************************************************************/
86 char *profile_name; /* ${XDG_CONFIG_HOME}/mc/ini */
87 char *global_profile_name; /* mc.lib */
89 /* Only used at program boot */
90 gboolean boot_current_is_left = TRUE;
92 /* If on, default for "No" in delete operations */
93 int safe_delete = 0;
95 /* Controls screen clearing before an exec */
96 int clear_before_exec = 1;
98 /* Asks for confirmation before deleting a file */
99 int confirm_delete = 1;
100 /* Asks for confirmation before deleting a hotlist entry */
101 int confirm_directory_hotlist_delete = 1;
102 /* Asks for confirmation before overwriting a file */
103 int confirm_overwrite = 1;
104 /* Asks for confirmation before executing a program by pressing enter */
105 int confirm_execute = 0;
106 /* Asks for confirmation before leaving the program */
107 int confirm_exit = 1;
109 /* If true, at startup the user-menu is invoked */
110 int auto_menu = 0;
111 /* This flag indicates if the pull down menus by default drop down */
112 int drop_menus = 0;
114 /* Asks for confirmation when using F3 to view a directory and there
115 are tagged files */
116 int confirm_view_dir = 0;
118 panel_view_mode_t startup_left_mode;
119 panel_view_mode_t startup_right_mode;
121 int setup_copymove_persistent_attr = 1;
123 /* Tab size */
124 int option_tab_spacing = DEFAULT_TAB_SPACING;
126 /* Ugly hack to allow panel_save_setup to work as a place holder for */
127 /* default panel values */
128 int saving_setup;
130 panels_options_t panels_options = {
131 .show_mini_info = TRUE,
132 .kilobyte_si = FALSE,
133 .mix_all_files = FALSE,
134 .show_backups = TRUE,
135 .show_dot_files = TRUE,
136 .fast_reload = FALSE,
137 .fast_reload_msg_shown = FALSE,
138 .mark_moves_down = TRUE,
139 .reverse_files_only = TRUE,
140 .auto_save_setup = FALSE,
141 .navigate_with_arrows = FALSE,
142 .scroll_pages = TRUE,
143 .mouse_move_pages = TRUE,
144 .filetype_mode = TRUE,
145 .permission_mode = FALSE,
146 .qsearch_mode = QSEARCH_PANEL_CASE,
147 .torben_fj_mode = FALSE
150 int easy_patterns = 1;
152 /* It true saves the setup when quitting */
153 int auto_save_setup = 1;
155 /* If true, then the +, - and \ keys have their special meaning only if the
156 * command line is emtpy, otherwise they behave like regular letters
158 int only_leading_plus_minus = 1;
160 /* Automatically fills name with current selected item name on mkdir */
161 int auto_fill_mkdir_name = 1;
163 /* If set and you don't have subshell support,then C-o will give you a shell */
164 int output_starts_shell = 0;
166 /* If set, we execute the file command to check the file type */
167 int use_file_to_check_type = 1;
169 int verbose = 1;
172 * Whether the Midnight Commander tries to provide more
173 * information about copy/move sizes and bytes transfered
174 * at the expense of some speed
176 int file_op_compute_totals = 1;
178 /* If true use the internal viewer */
179 int use_internal_view = 1;
180 /* If set, use the builtin editor */
181 int use_internal_edit = 1;
183 #ifdef HAVE_CHARSET
184 /* Numbers of (file I/O) and (input/display) codepages. -1 if not selected */
185 int default_source_codepage = -1;
186 char *autodetect_codeset = NULL;
187 gboolean is_autodetect_codeset_enabled = FALSE;
188 #endif /* !HAVE_CHARSET */
190 #ifdef HAVE_ASPELL
191 char *spell_language = NULL;
192 #endif
194 /* If set, then print to the given file the last directory we were at */
195 char *last_wd_string = NULL;
197 /* Set when main loop should be terminated */
198 int quit = 0;
200 /* Set to TRUE to suppress printing the last directory */
201 int print_last_revert = FALSE;
203 /* index to record_macro_buf[], -1 if not recording a macro */
204 int macro_index = -1;
206 /* macro stuff */
207 struct macro_action_t record_macro_buf[MAX_MACRO_LENGTH];
209 GArray *macros_list;
211 /*** file scope macro definitions ****************************************************************/
213 /* In order to use everywhere the same setup for the locale we use defines */
214 #define FMTYEAR _("%b %e %Y")
215 #define FMTTIME _("%b %e %H:%M")
217 /*** file scope type declarations ****************************************************************/
219 /*** file scope variables ************************************************************************/
221 static char *panels_profile_name = NULL; /* ${XDG_CACHE_HOME}/mc/panels.ini */
223 /* *INDENT-OFF* */
224 static const struct
226 const char *key;
227 int list_type;
228 } list_types [] = {
229 { "full", list_full },
230 { "brief", list_brief },
231 { "long", list_long },
232 { "user", list_user },
233 { NULL, 0 }
236 static const struct
238 const char *opt_name;
239 panel_view_mode_t opt_type;
240 } panel_types [] = {
241 { "listing", view_listing },
242 { "quickview", view_quick },
243 { "info", view_info },
244 { "tree", view_tree },
245 { NULL, view_listing }
248 static const struct
250 const char *opt_name;
251 int *opt_addr;
252 } layout [] = {
253 { "message_visible", &mc_global.message_visible },
254 { "keybar_visible", &mc_global.keybar_visible },
255 { "xterm_title", &xterm_title },
256 { "output_lines", &output_lines },
257 { "command_prompt", &command_prompt },
258 { "menubar_visible", &menubar_visible },
259 { "free_space", &free_space },
260 { "horizontal_split", &panels_layout.horizontal_split },
261 { "vertical_equal", &panels_layout.vertical_equal },
262 { "left_panel_size", &panels_layout.left_panel_size },
263 { "horizontal_equal", &panels_layout.horizontal_equal },
264 { "top_panel_size", &panels_layout.top_panel_size },
265 { NULL, NULL }
268 static const struct
270 const char *opt_name;
271 int *opt_addr;
272 } int_options [] = {
273 { "verbose", &verbose },
274 { "pause_after_run", &pause_after_run },
275 { "shell_patterns", &easy_patterns },
276 { "auto_save_setup", &auto_save_setup },
277 { "preallocate_space", &mc_global.vfs.preallocate_space },
278 { "auto_menu", &auto_menu },
279 { "use_internal_view", &use_internal_view },
280 { "use_internal_edit", &use_internal_edit },
281 { "clear_before_exec", &clear_before_exec },
282 { "confirm_delete", &confirm_delete },
283 { "confirm_overwrite", &confirm_overwrite },
284 { "confirm_execute", &confirm_execute },
285 { "confirm_history_cleanup", &mc_global.widget.confirm_history_cleanup },
286 { "confirm_exit", &confirm_exit },
287 { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete },
288 { "safe_delete", &safe_delete },
289 { "mouse_repeat_rate", &mou_auto_repeat },
290 { "double_click_speed", &double_click_speed },
291 #ifndef HAVE_CHARSET
292 { "eight_bit_clean", &mc_global.eight_bit_clean },
293 { "full_eight_bits", &mc_global.full_eight_bits },
294 #endif /* !HAVE_CHARSET */
295 { "use_8th_bit_as_meta", &use_8th_bit_as_meta },
296 { "confirm_view_dir", &confirm_view_dir },
297 { "mouse_move_pages_viewer", &mcview_mouse_move_pages },
298 { "mouse_close_dialog", &mouse_close_dialog},
299 { "fast_refresh", &fast_refresh },
300 { "drop_menus", &drop_menus },
301 { "wrap_mode", &mcview_global_wrap_mode},
302 { "old_esc_mode", &old_esc_mode },
303 { "old_esc_mode_timeout", &old_esc_mode_timeout },
304 { "cd_symlinks", &mc_global.vfs.cd_symlinks },
305 { "show_all_if_ambiguous", &mc_global.widget.show_all_if_ambiguous },
306 { "max_dirt_limit", &mcview_max_dirt_limit },
307 { "use_file_to_guess_type", &use_file_to_check_type },
308 { "alternate_plus_minus", &mc_global.tty.alternate_plus_minus },
309 { "only_leading_plus_minus", &only_leading_plus_minus },
310 { "show_output_starts_shell", &output_starts_shell },
311 { "xtree_mode", &xtree_mode },
312 { "num_history_items_recorded", &num_history_items_recorded },
313 { "file_op_compute_totals", &file_op_compute_totals },
314 { "classic_progressbar", &classic_progressbar},
315 #ifdef ENABLE_VFS
316 { "vfs_timeout", &vfs_timeout },
317 #ifdef ENABLE_VFS_FTP
318 { "ftpfs_directory_timeout", &ftpfs_directory_timeout },
319 { "use_netrc", &ftpfs_use_netrc },
320 { "ftpfs_retry_seconds", &ftpfs_retry_seconds },
321 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy },
322 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections },
323 { "ftpfs_use_passive_connections_over_proxy", &ftpfs_use_passive_connections_over_proxy },
324 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options },
325 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls },
326 #endif /* ENABLE_VFS_FTP */
327 #ifdef ENABLE_VFS_FISH
328 { "fish_directory_timeout", &fish_directory_timeout },
329 #endif /* ENABLE_VFS_FISH */
330 #endif /* ENABLE_VFS */
331 /* option_tab_spacing is used in internal viewer */
332 { "editor_tab_spacing", &option_tab_spacing },
333 #ifdef USE_INTERNAL_EDIT
334 { "editor_word_wrap_line_length", &option_word_wrap_line_length },
335 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces },
336 { "editor_return_does_auto_indent", &option_return_does_auto_indent },
337 { "editor_backspace_through_tabs", &option_backspace_through_tabs },
338 { "editor_fake_half_tabs", &option_fake_half_tabs },
339 { "editor_option_save_mode", &option_save_mode },
340 { "editor_option_save_position", &option_save_position },
341 { "editor_option_auto_para_formatting", &option_auto_para_formatting },
342 { "editor_option_typewriter_wrap", &option_typewriter_wrap },
343 { "editor_edit_confirm_save", &edit_confirm_save },
344 { "editor_syntax_highlighting", &option_syntax_highlighting },
345 { "editor_persistent_selections", &option_persistent_selections },
346 { "editor_cursor_beyond_eol", &option_cursor_beyond_eol },
347 { "editor_cursor_after_inserted_block", &option_cursor_after_inserted_block },
348 { "editor_visible_tabs", &visible_tabs },
349 { "editor_visible_spaces", &visible_tws },
350 { "editor_line_state", &option_line_state },
351 { "editor_simple_statusbar", &simple_statusbar },
352 { "editor_check_new_line", &option_check_nl_at_eof },
353 { "editor_show_right_margin", &show_right_margin },
354 { "editor_group_undo", &option_group_undo },
355 #endif /* USE_INTERNAL_EDIT */
356 { "nice_rotating_dash", &nice_rotating_dash },
357 { "mcview_remember_file_position", &mcview_remember_file_position },
358 { "auto_fill_mkdir_name", &auto_fill_mkdir_name },
359 { "copymove_persistent_attr", &setup_copymove_persistent_attr },
360 { "select_flags", &select_flags },
361 { NULL, NULL }
364 static const struct
366 const char *opt_name;
367 char **opt_addr;
368 const char *opt_defval;
369 } str_options[] = {
370 #ifdef USE_INTERNAL_EDIT
371 { "editor_backup_extension", &option_backup_ext, "~" },
372 #endif
373 { "mcview_eof", &mcview_show_eof, "" },
374 { NULL, NULL, NULL }
377 static const struct
379 const char *opt_name;
380 gboolean *opt_addr;
381 } panels_ini_options[] = {
382 { "show_mini_info", &panels_options.show_mini_info },
383 { "kilobyte_si", &panels_options.kilobyte_si },
384 { "mix_all_files", &panels_options.mix_all_files },
385 { "show_backups", &panels_options.show_backups },
386 { "show_dot_files", &panels_options.show_dot_files },
387 { "fast_reload", &panels_options.fast_reload },
388 { "fast_reload_msg_shown", &panels_options.fast_reload_msg_shown },
389 { "mark_moves_down", &panels_options.mark_moves_down },
390 { "reverse_files_only", &panels_options.reverse_files_only },
391 { "auto_save_setup_panels", &panels_options.auto_save_setup },
392 { "navigate_with_arrows", &panels_options.navigate_with_arrows },
393 { "panel_scroll_pages", &panels_options.scroll_pages },
394 { "mouse_move_pages", &panels_options.mouse_move_pages },
395 { "filetype_mode", &panels_options.filetype_mode },
396 { "permission_mode", &panels_options.permission_mode },
397 { "torben_fj_mode", &panels_options.torben_fj_mode },
398 { NULL, NULL }
400 /* *INDENT-ON* */
402 /*** file scope functions ************************************************************************/
403 /* --------------------------------------------------------------------------------------------- */
406 * Get name of config file.
408 * @param subdir If not NULL, config is also searched in specified subdir.
409 * @param config_file_name If relative, file if searched in standard paths.
411 * @return newly allocated string with config name or NULL if file is not found.
414 static char *
415 load_setup_get_full_config_name (const char *subdir, const char *config_file_name)
418 TODO: IMHO, in future, this function shall be placed in mcconfig module.
420 char *lc_basename, *ret;
421 char *file_name;
423 if (config_file_name == NULL)
424 return NULL;
426 /* check for .keymap suffix */
427 if (g_str_has_suffix (config_file_name, ".keymap"))
428 file_name = g_strdup (config_file_name);
429 else
430 file_name = g_strconcat (config_file_name, ".keymap", (char *) NULL);
432 canonicalize_pathname (file_name);
434 if (g_path_is_absolute (file_name))
435 return file_name;
437 lc_basename = g_path_get_basename (file_name);
438 g_free (file_name);
440 if (lc_basename == NULL)
441 return NULL;
443 if (subdir != NULL)
444 ret = g_build_filename (mc_config_get_path (), subdir, lc_basename, NULL);
445 else
446 ret = g_build_filename (mc_config_get_path (), lc_basename, NULL);
448 if (exist_file (ret))
450 g_free (lc_basename);
451 canonicalize_pathname (ret);
452 return ret;
454 g_free (ret);
456 if (subdir != NULL)
457 ret = g_build_filename (mc_global.sysconfig_dir, subdir, lc_basename, NULL);
458 else
459 ret = g_build_filename (mc_global.sysconfig_dir, lc_basename, NULL);
461 if (exist_file (ret))
463 g_free (lc_basename);
464 canonicalize_pathname (ret);
465 return ret;
467 g_free (ret);
469 if (subdir != NULL)
470 ret = g_build_filename (mc_global.share_data_dir, subdir, lc_basename, NULL);
471 else
472 ret = g_build_filename (mc_global.share_data_dir, lc_basename, NULL);
474 g_free (lc_basename);
476 if (exist_file (ret))
478 canonicalize_pathname (ret);
479 return ret;
482 g_free (ret);
483 return NULL;
486 /* --------------------------------------------------------------------------------------------- */
488 static const char *
489 setup__is_cfg_group_must_panel_config (const char *grp)
491 return (!strcasecmp ("Dirs", grp) ||
492 !strcasecmp ("Temporal:New Right Panel", grp) ||
493 !strcasecmp ("Temporal:New Left Panel", grp) ||
494 !strcasecmp ("New Left Panel", grp) || !strcasecmp ("New Right Panel", grp))
495 ? grp : NULL;
498 /* --------------------------------------------------------------------------------------------- */
500 static void
501 setup__move_panels_config_into_separate_file (const char *profile)
503 mc_config_t *tmp_cfg;
504 char **groups, **curr_grp;
505 const char *need_grp;
507 if (!exist_file (profile))
508 return;
510 tmp_cfg = mc_config_init (profile, FALSE);
511 if (!tmp_cfg)
512 return;
514 curr_grp = groups = mc_config_get_groups (tmp_cfg, NULL);
515 if (!groups)
517 mc_config_deinit (tmp_cfg);
518 return;
521 while (*curr_grp)
523 if (setup__is_cfg_group_must_panel_config (*curr_grp) == NULL)
524 mc_config_del_group (tmp_cfg, *curr_grp);
525 curr_grp++;
528 mc_config_save_to_file (tmp_cfg, panels_profile_name, NULL);
529 mc_config_deinit (tmp_cfg);
531 tmp_cfg = mc_config_init (profile, FALSE);
532 if (!tmp_cfg)
534 g_strfreev (groups);
535 return;
538 curr_grp = groups;
540 while (*curr_grp)
542 need_grp = setup__is_cfg_group_must_panel_config (*curr_grp);
543 if (need_grp != NULL)
545 mc_config_del_group (tmp_cfg, need_grp);
547 curr_grp++;
549 g_strfreev (groups);
551 mc_config_save_file (tmp_cfg, NULL);
552 mc_config_deinit (tmp_cfg);
555 /* --------------------------------------------------------------------------------------------- */
557 Create new mc_config object from specified ini-file or
558 append data to existing mc_config object from ini-file
561 static void
562 load_setup_init_config_from_file (mc_config_t ** config, const char *fname, gboolean read_only)
565 TODO: IMHO, in future, this function shall be placed in mcconfig module.
567 if (exist_file (fname))
569 if (*config != NULL)
570 mc_config_read_file (*config, fname, read_only, TRUE);
571 else
572 *config = mc_config_init (fname, read_only);
576 /* --------------------------------------------------------------------------------------------- */
578 static void
579 load_layout (void)
581 size_t i;
582 int equal_split;
583 int first_panel_size;
585 /* legacy options */
586 panels_layout.horizontal_split = mc_config_get_int (mc_main_config, CONFIG_APP_SECTION,
587 "horizontal_split", 0);
588 equal_split = mc_config_get_int (mc_main_config, "Layout", "equal_split", 1);
589 first_panel_size = mc_config_get_int (mc_main_config, "Layout", "first_panel_size", 1);
590 if (panels_layout.horizontal_split)
592 panels_layout.horizontal_equal = equal_split;
593 panels_layout.left_panel_size = first_panel_size;
595 else
597 panels_layout.vertical_equal = equal_split;
598 panels_layout.top_panel_size = first_panel_size;
601 /* actual options override legacy ones */
602 for (i = 0; layout[i].opt_name != NULL; i++)
603 *layout[i].opt_addr = mc_config_get_int (mc_main_config, CONFIG_LAYOUT_SECTION,
604 layout[i].opt_name, *layout[i].opt_addr);
606 /* remove legacy options */
607 mc_config_del_key (mc_main_config, CONFIG_APP_SECTION, "horizontal_split");
608 mc_config_del_key (mc_main_config, "Layout", "equal_split");
609 mc_config_del_key (mc_main_config, "Layout", "first_panel_size");
612 /* --------------------------------------------------------------------------------------------- */
614 static void
615 load_keys_from_section (const char *terminal, mc_config_t * cfg)
617 char *section_name;
618 gchar **profile_keys, **keys;
619 gchar **values, **curr_values;
620 char *valcopy, *value;
621 long key_code;
622 gsize len, values_len;
624 if (terminal == NULL)
625 return;
627 section_name = g_strconcat ("terminal:", terminal, (char *) NULL);
628 profile_keys = keys = mc_config_get_keys (cfg, section_name, &len);
630 while (*profile_keys != NULL)
632 /* copy=other causes all keys from [terminal:other] to be loaded. */
633 if (g_ascii_strcasecmp (*profile_keys, "copy") == 0)
635 valcopy = mc_config_get_string (cfg, section_name, *profile_keys, "");
636 load_keys_from_section (valcopy, cfg);
637 g_free (valcopy);
638 profile_keys++;
639 continue;
642 curr_values = values =
643 mc_config_get_string_list (cfg, section_name, *profile_keys, &values_len);
645 key_code = lookup_key (*profile_keys, NULL);
647 if (key_code != 0)
649 if (curr_values != NULL)
651 while (*curr_values != NULL)
653 valcopy = convert_controls (*curr_values);
654 define_sequence (key_code, valcopy, MCKEY_NOACTION);
655 g_free (valcopy);
656 curr_values++;
659 else
661 value = mc_config_get_string (cfg, section_name, *profile_keys, "");
662 valcopy = convert_controls (value);
663 define_sequence (key_code, valcopy, MCKEY_NOACTION);
664 g_free (valcopy);
665 g_free (value);
669 profile_keys++;
670 g_strfreev (values);
672 g_strfreev (keys);
673 g_free (section_name);
676 /* --------------------------------------------------------------------------------------------- */
678 static void
679 load_keymap_from_section (const char *section_name, GArray * keymap, mc_config_t * cfg)
681 gchar **profile_keys, **keys;
682 gsize len;
684 if (section_name == NULL)
685 return;
687 profile_keys = keys = mc_config_get_keys (cfg, section_name, &len);
689 while (*profile_keys != NULL)
691 gchar **values, **curr_values;
693 curr_values = values = mc_config_get_string_list (cfg, section_name, *profile_keys, &len);
695 if (curr_values != NULL)
697 int action;
699 action = keybind_lookup_action (*profile_keys);
700 if (action > 0)
701 while (*curr_values != NULL)
703 keybind_cmd_bind (keymap, *curr_values, action);
704 curr_values++;
707 g_strfreev (values);
710 profile_keys++;
713 g_strfreev (keys);
716 /* --------------------------------------------------------------------------------------------- */
718 static mc_config_t *
719 load_setup_get_keymap_profile_config (gboolean load_from_file)
722 TODO: IMHO, in future, this function shall be placed in mcconfig module.
724 mc_config_t *keymap_config;
725 char *share_keymap, *sysconfig_keymap;
726 char *fname, *fname2;
728 /* 0) Create default keymap */
729 keymap_config = create_default_keymap ();
730 if (!load_from_file)
731 return keymap_config;
733 /* load and merge global keymaps */
735 /* 1) /usr/share/mc (mc_global.share_data_dir) */
736 share_keymap = g_build_filename (mc_global.share_data_dir, GLOBAL_KEYMAP_FILE, NULL);
737 load_setup_init_config_from_file (&keymap_config, share_keymap, TRUE);
739 /* 2) /etc/mc (mc_global.sysconfig_dir) */
740 sysconfig_keymap = g_build_filename (mc_global.sysconfig_dir, GLOBAL_KEYMAP_FILE, NULL);
741 load_setup_init_config_from_file (&keymap_config, sysconfig_keymap, TRUE);
743 /* then load and merge one of user-defined keymap */
745 /* 3) --keymap=<keymap> */
746 fname = load_setup_get_full_config_name (NULL, mc_args__keymap_file);
747 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
749 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
750 goto done;
752 g_free (fname);
754 /* 4) getenv("MC_KEYMAP") */
755 fname = load_setup_get_full_config_name (NULL, g_getenv ("MC_KEYMAP"));
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 /* 5) main config; [Midnight Commander] -> keymap */
764 fname2 = mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, "keymap", NULL);
765 if (fname2 != NULL && *fname2 != '\0')
766 fname = load_setup_get_full_config_name (NULL, fname2);
767 g_free (fname2);
768 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
770 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
771 goto done;
773 g_free (fname);
775 /* 6) ${XDG_CONFIG_HOME}/mc/mc.keymap */
776 fname = mc_config_get_full_path (GLOBAL_KEYMAP_FILE);
777 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
779 done:
780 g_free (fname);
781 g_free (sysconfig_keymap);
782 g_free (share_keymap);
784 return keymap_config;
787 /* --------------------------------------------------------------------------------------------- */
789 static panel_view_mode_t
790 setup__load_panel_state (const char *section)
792 char *buffer;
793 size_t i;
794 panel_view_mode_t mode = view_listing;
796 /* Load the display mode */
797 buffer = mc_config_get_string (mc_panels_config, section, "display", "listing");
799 for (i = 0; panel_types[i].opt_name != NULL; i++)
800 if (g_ascii_strcasecmp (panel_types[i].opt_name, buffer) == 0)
802 mode = panel_types[i].opt_type;
803 break;
806 g_free (buffer);
808 return mode;
811 /* --------------------------------------------------------------------------------------------- */
813 static void
814 panel_save_type (const char *section, panel_view_mode_t type)
816 size_t i;
818 for (i = 0; panel_types[i].opt_name != NULL; i++)
819 if (panel_types[i].opt_type == type)
821 mc_config_set_string (mc_panels_config, section, "display", panel_types[i].opt_name);
822 break;
826 /* --------------------------------------------------------------------------------------------- */
828 /* save panels.ini */
829 static void
830 save_panel_types (void)
832 panel_view_mode_t type;
834 if (mc_global.mc_run_mode != MC_RUN_FULL)
835 return;
837 type = get_display_type (0);
838 panel_save_type ("New Left Panel", type);
839 if (type == view_listing)
840 panel_save_setup (left_panel, left_panel->panel_name);
841 type = get_display_type (1);
842 panel_save_type ("New Right Panel", type);
843 if (type == view_listing)
844 panel_save_setup (right_panel, right_panel->panel_name);
847 char *dirs;
849 dirs = get_panel_dir_for (other_panel);
850 mc_config_set_string (mc_panels_config, "Dirs", "other_dir", dirs);
851 g_free (dirs);
854 if (current_panel != NULL)
855 mc_config_set_bool (mc_panels_config, "Dirs", "current_is_left", get_current_index () == 0);
857 if (mc_panels_config->ini_path == NULL)
858 mc_panels_config->ini_path = g_strdup (panels_profile_name);
860 mc_config_del_group (mc_panels_config, "Temporal:New Left Panel");
861 mc_config_del_group (mc_panels_config, "Temporal:New Right Panel");
863 mc_config_save_file (mc_panels_config, NULL);
866 /* --------------------------------------------------------------------------------------------- */
867 /*** public functions ****************************************************************************/
868 /* --------------------------------------------------------------------------------------------- */
870 char *
871 setup_init (void)
873 char *profile;
874 char *inifile;
876 if (profile_name != NULL)
877 return profile_name;
879 profile = mc_config_get_full_path (MC_CONFIG_FILE);
880 if (!exist_file (profile))
882 inifile = mc_build_filename (mc_global.sysconfig_dir, "mc.ini", NULL);
883 if (exist_file (inifile))
885 g_free (profile);
886 profile = inifile;
888 else
890 g_free (inifile);
891 inifile = mc_build_filename (mc_global.share_data_dir, "mc.ini", NULL);
892 if (exist_file (inifile))
894 g_free (profile);
895 profile = inifile;
897 else
898 g_free (inifile);
902 profile_name = profile;
904 return profile;
907 /* --------------------------------------------------------------------------------------------- */
909 void
910 load_setup (void)
912 char *profile;
913 size_t i;
914 char *buffer;
915 const char *kt;
917 #ifdef HAVE_CHARSET
918 load_codepages_list ();
919 #endif /* HAVE_CHARSET */
921 profile = setup_init ();
923 /* mc.lib is common for all users, but has priority lower than
924 ${XDG_CONFIG_HOME}/mc/ini. FIXME: it's only used for keys and treestore now */
925 global_profile_name =
926 g_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
927 if (!exist_file (global_profile_name))
929 g_free (global_profile_name);
930 global_profile_name =
931 g_build_filename (mc_global.share_data_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
934 panels_profile_name = mc_config_get_full_path (MC_PANELS_FILE);
936 mc_main_config = mc_config_init (profile, FALSE);
938 if (!exist_file (panels_profile_name))
939 setup__move_panels_config_into_separate_file (profile);
941 mc_panels_config = mc_config_init (panels_profile_name, FALSE);
943 /* Load integer boolean options */
944 for (i = 0; int_options[i].opt_name != NULL; i++)
945 *int_options[i].opt_addr =
946 mc_config_get_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
947 *int_options[i].opt_addr);
948 #ifndef USE_INTERNAL_EDIT
949 /* reset forced in case of build without internal editor */
950 use_internal_edit = 0;
951 #endif /* USE_INTERNAL_EDIT */
953 if (option_tab_spacing <= 0)
954 option_tab_spacing = DEFAULT_TAB_SPACING;
956 #ifdef USE_INTERNAL_EDIT
957 if (option_word_wrap_line_length <= 0)
958 option_word_wrap_line_length = DEFAULT_WRAP_LINE_LENGTH;
959 #endif /* USE_INTERNAL_EDIT */
961 /* overwrite old_esc_mode_timeout */
962 kt = getenv ("KEYBOARD_KEY_TIMEOUT_US");
963 if ((kt != NULL) && (kt[0] != '\0'))
964 old_esc_mode_timeout = atoi (kt);
966 /* Load string options */
967 for (i = 0; str_options[i].opt_name != NULL; i++)
968 *str_options[i].opt_addr =
969 mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
970 str_options[i].opt_defval);
972 load_layout ();
973 panels_load_options ();
974 load_panelize ();
976 startup_left_mode = setup__load_panel_state ("New Left Panel");
977 startup_right_mode = setup__load_panel_state ("New Right Panel");
979 /* At least one of the panels is a listing panel */
980 if (startup_left_mode != view_listing && startup_right_mode != view_listing)
981 startup_left_mode = view_listing;
983 if (mc_run_param1 == NULL)
985 vfs_path_t *vpath;
986 buffer = mc_config_get_string (mc_panels_config, "Dirs", "other_dir", ".");
987 vpath = vfs_path_from_str (buffer);
988 if (vfs_file_is_local (vpath))
989 mc_run_param1 = buffer;
990 else
991 g_free (buffer);
992 vfs_path_free (vpath);
995 boot_current_is_left = mc_config_get_bool (mc_panels_config, "Dirs", "current_is_left", TRUE);
997 /* Load time formats */
998 user_recent_timeformat =
999 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "timeformat_recent", FMTTIME);
1000 user_old_timeformat =
1001 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "timeformat_old", FMTYEAR);
1003 #ifdef ENABLE_VFS_FTP
1004 ftpfs_proxy_host =
1005 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "ftp_proxy_host", "gate");
1006 ftpfs_ignore_chattr_errors =
1007 mc_config_get_bool (mc_main_config, CONFIG_APP_SECTION, "ignore_ftp_chattr_errors", TRUE);
1008 ftpfs_init_passwd ();
1009 #endif /* ENABLE_VFS_FTP */
1011 /* The default color and the terminal dependent color */
1012 mc_global.tty.setup_color_string =
1013 mc_config_get_string (mc_main_config, "Colors", "base_color", "");
1014 mc_global.tty.term_color_string =
1015 mc_config_get_string (mc_main_config, "Colors", getenv ("TERM"), "");
1016 mc_global.tty.color_terminal_string =
1017 mc_config_get_string (mc_main_config, "Colors", "color_terminals", "");
1019 /* Load the directory history */
1020 /* directory_history_load (); */
1021 /* Remove the temporal entries */
1023 #ifdef HAVE_CHARSET
1024 if (codepages->len > 1)
1026 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "display_codepage", "");
1027 if (buffer[0] != '\0')
1029 mc_global.display_codepage = get_codepage_index (buffer);
1030 cp_display = get_codepage_id (mc_global.display_codepage);
1032 g_free (buffer);
1033 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "source_codepage", "");
1034 if (buffer[0] != '\0')
1036 default_source_codepage = get_codepage_index (buffer);
1037 mc_global.source_codepage = default_source_codepage; /* May be source_codepage doesn't need this */
1038 cp_source = get_codepage_id (mc_global.source_codepage);
1040 g_free (buffer);
1043 autodetect_codeset =
1044 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "autodetect_codeset", "");
1045 if ((autodetect_codeset[0] != '\0') && (strcmp (autodetect_codeset, "off") != 0))
1046 is_autodetect_codeset_enabled = TRUE;
1048 g_free (init_translation_table (mc_global.source_codepage, mc_global.display_codepage));
1049 buffer = (char *) get_codepage_id (mc_global.display_codepage);
1050 if (buffer != NULL)
1051 mc_global.utf8_display = str_isutf8 (buffer);
1052 #endif /* HAVE_CHARSET */
1054 #ifdef HAVE_ASPELL
1055 spell_language =
1056 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "spell_language", "en");
1057 #endif /* HAVE_ASPELL */
1059 clipboard_store_path =
1060 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_store", "");
1061 clipboard_paste_path =
1062 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_paste", "");
1065 /* --------------------------------------------------------------------------------------------- */
1067 gboolean
1068 save_setup (gboolean save_options, gboolean save_panel_options)
1070 gboolean ret = TRUE;
1072 saving_setup = 1;
1074 save_hotlist ();
1076 if (save_panel_options)
1077 save_panel_types ();
1079 if (save_options)
1081 char *tmp_profile;
1083 save_config ();
1084 save_layout ();
1085 panels_save_options ();
1086 save_panelize ();
1087 /* directory_history_save (); */
1089 #ifdef ENABLE_VFS_FTP
1090 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "ftpfs_password",
1091 ftpfs_anonymous_passwd);
1092 if (ftpfs_proxy_host)
1093 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "ftp_proxy_host",
1094 ftpfs_proxy_host);
1095 #endif /* ENABLE_VFS_FTP */
1097 #ifdef HAVE_CHARSET
1098 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "display_codepage",
1099 get_codepage_id (mc_global.display_codepage));
1100 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "source_codepage",
1101 get_codepage_id (default_source_codepage));
1102 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "autodetect_codeset",
1103 autodetect_codeset);
1104 #endif /* HAVE_CHARSET */
1106 #ifdef HAVE_ASPELL
1107 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "spell_language",
1108 spell_language);
1109 #endif /* HAVE_ASPELL */
1111 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_store",
1112 clipboard_store_path);
1113 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_paste",
1114 clipboard_paste_path);
1116 tmp_profile = mc_config_get_full_path (MC_CONFIG_FILE);
1117 ret = mc_config_save_to_file (mc_main_config, tmp_profile, NULL);
1118 g_free (tmp_profile);
1121 saving_setup = 0;
1123 return ret;
1126 /* --------------------------------------------------------------------------------------------- */
1128 void
1129 done_setup (void)
1131 size_t i;
1133 g_free (clipboard_store_path);
1134 g_free (clipboard_paste_path);
1135 g_free (profile_name);
1136 g_free (global_profile_name);
1137 g_free (mc_global.tty.color_terminal_string);
1138 g_free (mc_global.tty.term_color_string);
1139 g_free (mc_global.tty.setup_color_string);
1140 g_free (panels_profile_name);
1141 mc_config_deinit (mc_main_config);
1142 mc_config_deinit (mc_panels_config);
1144 g_free (user_recent_timeformat);
1145 g_free (user_old_timeformat);
1147 for (i = 0; str_options[i].opt_name != NULL; i++)
1148 g_free (*str_options[i].opt_addr);
1150 done_hotlist ();
1151 done_panelize ();
1152 /* directory_history_free (); */
1154 #ifdef HAVE_CHARSET
1155 g_free (autodetect_codeset);
1156 free_codepages_list ();
1157 #endif
1159 #ifdef HAVE_ASPELL
1160 g_free (spell_language);
1161 #endif /* HAVE_ASPELL */
1164 /* --------------------------------------------------------------------------------------------- */
1166 void
1167 save_config (void)
1169 size_t i;
1171 /* Save integer options */
1172 for (i = 0; int_options[i].opt_name != NULL; i++)
1173 mc_config_set_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
1174 *int_options[i].opt_addr);
1176 /* Save string options */
1177 for (i = 0; str_options[i].opt_name != NULL; i++)
1178 mc_config_set_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
1179 *str_options[i].opt_addr);
1182 /* --------------------------------------------------------------------------------------------- */
1184 void
1185 setup_save_config_show_error (const char *filename, GError ** error)
1187 if (error != NULL && *error != NULL)
1189 message (D_ERROR, MSG_ERROR, _("Cannot save file %s:\n%s"), filename, (*error)->message);
1190 g_error_free (*error);
1191 *error = NULL;
1195 /* --------------------------------------------------------------------------------------------- */
1197 void
1198 save_layout (void)
1200 size_t i;
1202 /* Save integer options */
1203 for (i = 0; layout[i].opt_name != NULL; i++)
1204 mc_config_set_int (mc_main_config, CONFIG_LAYOUT_SECTION, layout[i].opt_name,
1205 *layout[i].opt_addr);
1208 /* --------------------------------------------------------------------------------------------- */
1210 void
1211 load_key_defs (void)
1214 * Load keys from mc.lib before ${XDG_CONFIG_HOME}/mc/ini, so that the user
1215 * definitions override global settings.
1217 mc_config_t *mc_global_config;
1219 mc_global_config = mc_config_init (global_profile_name, FALSE);
1220 if (mc_global_config != NULL)
1222 load_keys_from_section ("general", mc_global_config);
1223 load_keys_from_section (getenv ("TERM"), mc_global_config);
1224 mc_config_deinit (mc_global_config);
1227 load_keys_from_section ("general", mc_main_config);
1228 load_keys_from_section (getenv ("TERM"), mc_main_config);
1231 /* --------------------------------------------------------------------------------------------- */
1233 #ifdef ENABLE_VFS_FTP
1234 char *
1235 load_anon_passwd (void)
1237 char *buffer;
1239 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "ftpfs_password", "");
1241 if ((buffer != NULL) && (buffer[0] != '\0'))
1242 return buffer;
1244 g_free (buffer);
1245 return NULL;
1247 #endif /* ENABLE_VFS_FTP */
1249 /* --------------------------------------------------------------------------------------------- */
1251 void
1252 load_keymap_defs (gboolean load_from_file)
1255 * Load keymap from GLOBAL_KEYMAP_FILE before ${XDG_CONFIG_HOME}/mc/mc.keymap, so that the user
1256 * definitions override global settings.
1258 mc_config_t *mc_global_keymap;
1260 mc_global_keymap = load_setup_get_keymap_profile_config (load_from_file);
1262 if (mc_global_keymap != NULL)
1264 main_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1265 load_keymap_from_section (KEYMAP_SECTION_MAIN, main_keymap, mc_global_keymap);
1266 main_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1267 load_keymap_from_section (KEYMAP_SECTION_MAIN_EXT, main_x_keymap, mc_global_keymap);
1269 panel_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1270 load_keymap_from_section (KEYMAP_SECTION_PANEL, panel_keymap, mc_global_keymap);
1272 dialog_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1273 load_keymap_from_section (KEYMAP_SECTION_DIALOG, dialog_keymap, mc_global_keymap);
1275 input_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1276 load_keymap_from_section (KEYMAP_SECTION_INPUT, input_keymap, mc_global_keymap);
1278 listbox_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1279 load_keymap_from_section (KEYMAP_SECTION_LISTBOX, listbox_keymap, mc_global_keymap);
1281 tree_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1282 load_keymap_from_section (KEYMAP_SECTION_TREE, tree_keymap, mc_global_keymap);
1284 help_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1285 load_keymap_from_section (KEYMAP_SECTION_HELP, help_keymap, mc_global_keymap);
1287 #ifdef USE_INTERNAL_EDIT
1288 editor_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1289 load_keymap_from_section (KEYMAP_SECTION_EDITOR, editor_keymap, mc_global_keymap);
1290 editor_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1291 load_keymap_from_section (KEYMAP_SECTION_EDITOR_EXT, editor_x_keymap, mc_global_keymap);
1292 #endif
1294 viewer_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1295 load_keymap_from_section (KEYMAP_SECTION_VIEWER, viewer_keymap, mc_global_keymap);
1296 viewer_hex_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1297 load_keymap_from_section (KEYMAP_SECTION_VIEWER_HEX, viewer_hex_keymap, mc_global_keymap);
1299 #ifdef USE_DIFF_VIEW
1300 diff_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1301 load_keymap_from_section (KEYMAP_SECTION_DIFFVIEWER, diff_keymap, mc_global_keymap);
1302 #endif
1304 mc_config_deinit (mc_global_keymap);
1307 main_map = (global_keymap_t *) main_keymap->data;
1308 main_x_map = (global_keymap_t *) main_x_keymap->data;
1309 panel_map = (global_keymap_t *) panel_keymap->data;
1310 dialog_map = (global_keymap_t *) dialog_keymap->data;
1311 input_map = (global_keymap_t *) input_keymap->data;
1312 listbox_map = (global_keymap_t *) listbox_keymap->data;
1313 tree_map = (global_keymap_t *) tree_keymap->data;
1314 help_map = (global_keymap_t *) help_keymap->data;
1315 #ifdef USE_INTERNAL_EDIT
1316 editor_map = (global_keymap_t *) editor_keymap->data;
1317 editor_x_map = (global_keymap_t *) editor_x_keymap->data;
1318 #endif
1319 viewer_map = (global_keymap_t *) viewer_keymap->data;
1320 viewer_hex_map = (global_keymap_t *) viewer_hex_keymap->data;
1321 #ifdef USE_DIFF_VIEW
1322 diff_map = (global_keymap_t *) diff_keymap->data;
1323 #endif
1326 /* --------------------------------------------------------------------------------------------- */
1328 void
1329 free_keymap_defs (void)
1331 if (main_keymap != NULL)
1332 g_array_free (main_keymap, TRUE);
1333 if (main_x_keymap != NULL)
1334 g_array_free (main_x_keymap, TRUE);
1335 if (panel_keymap != NULL)
1336 g_array_free (panel_keymap, TRUE);
1337 if (dialog_keymap != NULL)
1338 g_array_free (dialog_keymap, TRUE);
1339 if (input_keymap != NULL)
1340 g_array_free (input_keymap, TRUE);
1341 if (listbox_keymap != NULL)
1342 g_array_free (listbox_keymap, TRUE);
1343 if (tree_keymap != NULL)
1344 g_array_free (tree_keymap, TRUE);
1345 if (help_keymap != NULL)
1346 g_array_free (help_keymap, TRUE);
1347 #ifdef USE_INTERNAL_EDIT
1348 if (editor_keymap != NULL)
1349 g_array_free (editor_keymap, TRUE);
1350 if (editor_x_keymap != NULL)
1351 g_array_free (editor_x_keymap, TRUE);
1352 #endif
1353 if (viewer_keymap != NULL)
1354 g_array_free (viewer_keymap, TRUE);
1355 if (viewer_hex_keymap != NULL)
1356 g_array_free (viewer_hex_keymap, TRUE);
1357 #ifdef USE_DIFF_VIEW
1358 if (diff_keymap != NULL)
1359 g_array_free (diff_keymap, TRUE);
1360 #endif
1363 /* --------------------------------------------------------------------------------------------- */
1365 void
1366 panel_load_setup (WPanel * panel, const char *section)
1368 size_t i;
1369 char *buffer, buffer2[BUF_TINY];
1371 panel->sort_info.reverse = mc_config_get_int (mc_panels_config, section, "reverse", 0);
1372 panel->sort_info.case_sensitive =
1373 mc_config_get_int (mc_panels_config, section, "case_sensitive",
1374 OS_SORT_CASE_SENSITIVE_DEFAULT);
1375 panel->sort_info.exec_first = mc_config_get_int (mc_panels_config, section, "exec_first", 0);
1377 /* Load sort order */
1378 buffer = mc_config_get_string (mc_panels_config, section, "sort_order", "name");
1379 panel->sort_info.sort_field = panel_get_field_by_id (buffer);
1380 if (panel->sort_info.sort_field == NULL)
1381 panel->sort_info.sort_field = panel_get_field_by_id ("name");
1383 g_free (buffer);
1385 /* Load the listing mode */
1386 buffer = mc_config_get_string (mc_panels_config, section, "list_mode", "full");
1387 panel->list_type = list_full;
1388 for (i = 0; list_types[i].key != NULL; i++)
1389 if (g_ascii_strcasecmp (list_types[i].key, buffer) == 0)
1391 panel->list_type = list_types[i].list_type;
1392 break;
1394 g_free (buffer);
1396 /* User formats */
1397 g_free (panel->user_format);
1398 panel->user_format =
1399 mc_config_get_string (mc_panels_config, section, "user_format", DEFAULT_USER_FORMAT);
1401 for (i = 0; i < LIST_TYPES; i++)
1403 g_free (panel->user_status_format[i]);
1404 g_snprintf (buffer2, BUF_TINY, "user_status%lld", (long long) i);
1405 panel->user_status_format[i] =
1406 mc_config_get_string (mc_panels_config, section, buffer2, DEFAULT_USER_FORMAT);
1409 panel->user_mini_status = mc_config_get_int (mc_panels_config, section, "user_mini_status", 0);
1412 /* --------------------------------------------------------------------------------------------- */
1414 void
1415 panel_save_setup (struct WPanel *panel, const char *section)
1417 char buffer[BUF_TINY];
1418 size_t i;
1420 mc_config_set_int (mc_panels_config, section, "reverse", panel->sort_info.reverse);
1421 mc_config_set_int (mc_panels_config, section, "case_sensitive",
1422 panel->sort_info.case_sensitive);
1423 mc_config_set_int (mc_panels_config, section, "exec_first", panel->sort_info.exec_first);
1425 mc_config_set_string (mc_panels_config, section, "sort_order", panel->sort_info.sort_field->id);
1427 for (i = 0; list_types[i].key != NULL; i++)
1428 if (list_types[i].list_type == panel->list_type)
1430 mc_config_set_string (mc_panels_config, section, "list_mode", list_types[i].key);
1431 break;
1434 mc_config_set_string (mc_panels_config, section, "user_format", panel->user_format);
1436 for (i = 0; i < LIST_TYPES; i++)
1438 g_snprintf (buffer, BUF_TINY, "user_status%lld", (long long) i);
1439 mc_config_set_string (mc_panels_config, section, buffer, panel->user_status_format[i]);
1442 mc_config_set_int (mc_panels_config, section, "user_mini_status", panel->user_mini_status);
1445 /* --------------------------------------------------------------------------------------------- */
1448 Load panels options from [Panels] section.
1450 void
1451 panels_load_options (void)
1453 if (mc_config_has_group (mc_main_config, CONFIG_PANELS_SECTION))
1455 size_t i;
1456 int qmode;
1458 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
1459 *panels_ini_options[i].opt_addr =
1460 mc_config_get_bool (mc_main_config, CONFIG_PANELS_SECTION,
1461 panels_ini_options[i].opt_name,
1462 *panels_ini_options[i].opt_addr);
1464 qmode = mc_config_get_int (mc_main_config, CONFIG_PANELS_SECTION,
1465 "quick_search_mode", (int) panels_options.qsearch_mode);
1466 if (qmode < 0)
1467 panels_options.qsearch_mode = QSEARCH_CASE_INSENSITIVE;
1468 else if (qmode >= QSEARCH_NUM)
1469 panels_options.qsearch_mode = QSEARCH_PANEL_CASE;
1470 else
1471 panels_options.qsearch_mode = (qsearch_mode_t) qmode;
1475 /* --------------------------------------------------------------------------------------------- */
1478 Save panels options in [Panels] section.
1480 void
1481 panels_save_options (void)
1483 size_t i;
1485 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
1486 mc_config_set_bool (mc_main_config, CONFIG_PANELS_SECTION,
1487 panels_ini_options[i].opt_name, *panels_ini_options[i].opt_addr);
1489 mc_config_set_int (mc_main_config, CONFIG_PANELS_SECTION,
1490 "quick_search_mode", (int) panels_options.qsearch_mode);
1493 /* --------------------------------------------------------------------------------------------- */