lib/widget/input_complete.c: minor refactoring and optimization.
[midnight-commander.git] / src / setup.c
blob1e5e8c6487ef907e1954c9a84f0bc121e74e5da0
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 /* Ask file name before start the editor */
119 int editor_ask_filename_before_edit = 0;
121 panel_view_mode_t startup_left_mode;
122 panel_view_mode_t startup_right_mode;
124 int setup_copymove_persistent_attr = 1;
126 /* Tab size */
127 int option_tab_spacing = DEFAULT_TAB_SPACING;
129 /* Ugly hack to allow panel_save_setup to work as a place holder for */
130 /* default panel values */
131 int saving_setup;
133 panels_options_t panels_options = {
134 .show_mini_info = TRUE,
135 .kilobyte_si = FALSE,
136 .mix_all_files = FALSE,
137 .show_backups = TRUE,
138 .show_dot_files = TRUE,
139 .fast_reload = FALSE,
140 .fast_reload_msg_shown = FALSE,
141 .mark_moves_down = TRUE,
142 .reverse_files_only = TRUE,
143 .auto_save_setup = FALSE,
144 .navigate_with_arrows = FALSE,
145 .scroll_pages = TRUE,
146 .mouse_move_pages = TRUE,
147 .filetype_mode = TRUE,
148 .permission_mode = FALSE,
149 .qsearch_mode = QSEARCH_PANEL_CASE,
150 .torben_fj_mode = FALSE
153 int easy_patterns = 1;
155 /* It true saves the setup when quitting */
156 int auto_save_setup = 1;
158 /* If true, then the +, - and \ keys have their special meaning only if the
159 * command line is emtpy, otherwise they behave like regular letters
161 int only_leading_plus_minus = 1;
163 /* Automatically fills name with current selected item name on mkdir */
164 int auto_fill_mkdir_name = 1;
166 /* If set and you don't have subshell support,then C-o will give you a shell */
167 int output_starts_shell = 0;
169 /* If set, we execute the file command to check the file type */
170 int use_file_to_check_type = 1;
172 int verbose = 1;
175 * Whether the Midnight Commander tries to provide more
176 * information about copy/move sizes and bytes transfered
177 * at the expense of some speed
179 int file_op_compute_totals = 1;
181 /* If true use the internal viewer */
182 int use_internal_view = 1;
183 /* If set, use the builtin editor */
184 int use_internal_edit = 1;
186 #ifdef HAVE_CHARSET
187 /* Numbers of (file I/O) and (input/display) codepages. -1 if not selected */
188 int default_source_codepage = -1;
189 char *autodetect_codeset = NULL;
190 gboolean is_autodetect_codeset_enabled = FALSE;
191 #endif /* !HAVE_CHARSET */
193 #ifdef HAVE_ASPELL
194 char *spell_language = NULL;
195 #endif
197 /* If set, then print to the given file the last directory we were at */
198 char *last_wd_string = NULL;
200 /* Set when main loop should be terminated */
201 int quit = 0;
203 /* Set to TRUE to suppress printing the last directory */
204 int print_last_revert = FALSE;
206 /* index to record_macro_buf[], -1 if not recording a macro */
207 int macro_index = -1;
209 /* macro stuff */
210 struct macro_action_t record_macro_buf[MAX_MACRO_LENGTH];
212 GArray *macros_list;
214 /*** file scope macro definitions ****************************************************************/
216 /* In order to use everywhere the same setup for the locale we use defines */
217 #define FMTYEAR _("%b %e %Y")
218 #define FMTTIME _("%b %e %H:%M")
220 /*** file scope type declarations ****************************************************************/
222 /*** file scope variables ************************************************************************/
224 static char *panels_profile_name = NULL; /* ${XDG_CACHE_HOME}/mc/panels.ini */
226 /* *INDENT-OFF* */
227 static const struct
229 const char *key;
230 int list_type;
231 } list_types [] = {
232 { "full", list_full },
233 { "brief", list_brief },
234 { "long", list_long },
235 { "user", list_user },
236 { NULL, 0 }
239 static const struct
241 const char *opt_name;
242 panel_view_mode_t opt_type;
243 } panel_types [] = {
244 { "listing", view_listing },
245 { "quickview", view_quick },
246 { "info", view_info },
247 { "tree", view_tree },
248 { NULL, view_listing }
251 static const struct
253 const char *opt_name;
254 int *opt_addr;
255 } layout [] = {
256 { "message_visible", &mc_global.message_visible },
257 { "keybar_visible", &mc_global.keybar_visible },
258 { "xterm_title", &xterm_title },
259 { "output_lines", &output_lines },
260 { "command_prompt", &command_prompt },
261 { "menubar_visible", &menubar_visible },
262 { "free_space", &free_space },
263 { "horizontal_split", &panels_layout.horizontal_split },
264 { "vertical_equal", &panels_layout.vertical_equal },
265 { "left_panel_size", &panels_layout.left_panel_size },
266 { "horizontal_equal", &panels_layout.horizontal_equal },
267 { "top_panel_size", &panels_layout.top_panel_size },
268 { NULL, NULL }
271 static const struct
273 const char *opt_name;
274 int *opt_addr;
275 } int_options [] = {
276 { "verbose", &verbose },
277 { "pause_after_run", &pause_after_run },
278 { "shell_patterns", &easy_patterns },
279 { "auto_save_setup", &auto_save_setup },
280 { "preallocate_space", &mc_global.vfs.preallocate_space },
281 { "auto_menu", &auto_menu },
282 { "use_internal_view", &use_internal_view },
283 { "use_internal_edit", &use_internal_edit },
284 { "clear_before_exec", &clear_before_exec },
285 { "confirm_delete", &confirm_delete },
286 { "confirm_overwrite", &confirm_overwrite },
287 { "confirm_execute", &confirm_execute },
288 { "confirm_history_cleanup", &mc_global.widget.confirm_history_cleanup },
289 { "confirm_exit", &confirm_exit },
290 { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete },
291 { "safe_delete", &safe_delete },
292 { "mouse_repeat_rate", &mou_auto_repeat },
293 { "double_click_speed", &double_click_speed },
294 #ifndef HAVE_CHARSET
295 { "eight_bit_clean", &mc_global.eight_bit_clean },
296 { "full_eight_bits", &mc_global.full_eight_bits },
297 #endif /* !HAVE_CHARSET */
298 { "use_8th_bit_as_meta", &use_8th_bit_as_meta },
299 { "confirm_view_dir", &confirm_view_dir },
300 { "mouse_move_pages_viewer", &mcview_mouse_move_pages },
301 { "mouse_close_dialog", &mouse_close_dialog},
302 { "fast_refresh", &fast_refresh },
303 { "drop_menus", &drop_menus },
304 { "wrap_mode", &mcview_global_wrap_mode},
305 { "old_esc_mode", &old_esc_mode },
306 { "old_esc_mode_timeout", &old_esc_mode_timeout },
307 { "cd_symlinks", &mc_global.vfs.cd_symlinks },
308 { "show_all_if_ambiguous", &mc_global.widget.show_all_if_ambiguous },
309 { "max_dirt_limit", &mcview_max_dirt_limit },
310 { "use_file_to_guess_type", &use_file_to_check_type },
311 { "alternate_plus_minus", &mc_global.tty.alternate_plus_minus },
312 { "only_leading_plus_minus", &only_leading_plus_minus },
313 { "show_output_starts_shell", &output_starts_shell },
314 { "xtree_mode", &xtree_mode },
315 { "num_history_items_recorded", &num_history_items_recorded },
316 { "file_op_compute_totals", &file_op_compute_totals },
317 { "classic_progressbar", &classic_progressbar},
318 #ifdef ENABLE_VFS
319 { "vfs_timeout", &vfs_timeout },
320 #ifdef ENABLE_VFS_FTP
321 { "ftpfs_directory_timeout", &ftpfs_directory_timeout },
322 { "use_netrc", &ftpfs_use_netrc },
323 { "ftpfs_retry_seconds", &ftpfs_retry_seconds },
324 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy },
325 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections },
326 { "ftpfs_use_passive_connections_over_proxy", &ftpfs_use_passive_connections_over_proxy },
327 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options },
328 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls },
329 #endif /* ENABLE_VFS_FTP */
330 #ifdef ENABLE_VFS_FISH
331 { "fish_directory_timeout", &fish_directory_timeout },
332 #endif /* ENABLE_VFS_FISH */
333 #endif /* ENABLE_VFS */
334 /* option_tab_spacing is used in internal viewer */
335 { "editor_tab_spacing", &option_tab_spacing },
336 #ifdef USE_INTERNAL_EDIT
337 { "editor_word_wrap_line_length", &option_word_wrap_line_length },
338 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces },
339 { "editor_return_does_auto_indent", &option_return_does_auto_indent },
340 { "editor_backspace_through_tabs", &option_backspace_through_tabs },
341 { "editor_fake_half_tabs", &option_fake_half_tabs },
342 { "editor_option_save_mode", &option_save_mode },
343 { "editor_option_save_position", &option_save_position },
344 { "editor_option_auto_para_formatting", &option_auto_para_formatting },
345 { "editor_option_typewriter_wrap", &option_typewriter_wrap },
346 { "editor_edit_confirm_save", &edit_confirm_save },
347 { "editor_syntax_highlighting", &option_syntax_highlighting },
348 { "editor_persistent_selections", &option_persistent_selections },
349 { "editor_cursor_beyond_eol", &option_cursor_beyond_eol },
350 { "editor_cursor_after_inserted_block", &option_cursor_after_inserted_block },
351 { "editor_visible_tabs", &visible_tabs },
352 { "editor_visible_spaces", &visible_tws },
353 { "editor_line_state", &option_line_state },
354 { "editor_simple_statusbar", &simple_statusbar },
355 { "editor_check_new_line", &option_check_nl_at_eof },
356 { "editor_show_right_margin", &show_right_margin },
357 { "editor_group_undo", &option_group_undo },
358 #endif /* USE_INTERNAL_EDIT */
359 { "editor_ask_filename_before_edit", &editor_ask_filename_before_edit },
360 { "nice_rotating_dash", &nice_rotating_dash },
361 { "mcview_remember_file_position", &mcview_remember_file_position },
362 { "auto_fill_mkdir_name", &auto_fill_mkdir_name },
363 { "copymove_persistent_attr", &setup_copymove_persistent_attr },
364 { "select_flags", &select_flags },
365 { NULL, NULL }
368 static const struct
370 const char *opt_name;
371 char **opt_addr;
372 const char *opt_defval;
373 } str_options[] = {
374 #ifdef USE_INTERNAL_EDIT
375 { "editor_backup_extension", &option_backup_ext, "~" },
376 #endif
377 { "mcview_eof", &mcview_show_eof, "" },
378 { NULL, NULL, NULL }
381 static const struct
383 const char *opt_name;
384 gboolean *opt_addr;
385 } panels_ini_options[] = {
386 { "show_mini_info", &panels_options.show_mini_info },
387 { "kilobyte_si", &panels_options.kilobyte_si },
388 { "mix_all_files", &panels_options.mix_all_files },
389 { "show_backups", &panels_options.show_backups },
390 { "show_dot_files", &panels_options.show_dot_files },
391 { "fast_reload", &panels_options.fast_reload },
392 { "fast_reload_msg_shown", &panels_options.fast_reload_msg_shown },
393 { "mark_moves_down", &panels_options.mark_moves_down },
394 { "reverse_files_only", &panels_options.reverse_files_only },
395 { "auto_save_setup_panels", &panels_options.auto_save_setup },
396 { "navigate_with_arrows", &panels_options.navigate_with_arrows },
397 { "panel_scroll_pages", &panels_options.scroll_pages },
398 { "mouse_move_pages", &panels_options.mouse_move_pages },
399 { "filetype_mode", &panels_options.filetype_mode },
400 { "permission_mode", &panels_options.permission_mode },
401 { "torben_fj_mode", &panels_options.torben_fj_mode },
402 { NULL, NULL }
404 /* *INDENT-ON* */
406 /*** file scope functions ************************************************************************/
407 /* --------------------------------------------------------------------------------------------- */
410 * Get name of config file.
412 * @param subdir If not NULL, config is also searched in specified subdir.
413 * @param config_file_name If relative, file if searched in standard paths.
415 * @return newly allocated string with config name or NULL if file is not found.
418 static char *
419 load_setup_get_full_config_name (const char *subdir, const char *config_file_name)
422 TODO: IMHO, in future, this function shall be placed in mcconfig module.
424 char *lc_basename, *ret;
425 char *file_name;
427 if (config_file_name == NULL)
428 return NULL;
430 /* check for .keymap suffix */
431 if (g_str_has_suffix (config_file_name, ".keymap"))
432 file_name = g_strdup (config_file_name);
433 else
434 file_name = g_strconcat (config_file_name, ".keymap", (char *) NULL);
436 canonicalize_pathname (file_name);
438 if (g_path_is_absolute (file_name))
439 return file_name;
441 lc_basename = g_path_get_basename (file_name);
442 g_free (file_name);
444 if (lc_basename == NULL)
445 return NULL;
447 if (subdir != NULL)
448 ret = g_build_filename (mc_config_get_path (), subdir, lc_basename, NULL);
449 else
450 ret = g_build_filename (mc_config_get_path (), lc_basename, NULL);
452 if (exist_file (ret))
454 g_free (lc_basename);
455 canonicalize_pathname (ret);
456 return ret;
458 g_free (ret);
460 if (subdir != NULL)
461 ret = g_build_filename (mc_global.sysconfig_dir, subdir, lc_basename, NULL);
462 else
463 ret = g_build_filename (mc_global.sysconfig_dir, lc_basename, NULL);
465 if (exist_file (ret))
467 g_free (lc_basename);
468 canonicalize_pathname (ret);
469 return ret;
471 g_free (ret);
473 if (subdir != NULL)
474 ret = g_build_filename (mc_global.share_data_dir, subdir, lc_basename, NULL);
475 else
476 ret = g_build_filename (mc_global.share_data_dir, lc_basename, NULL);
478 g_free (lc_basename);
480 if (exist_file (ret))
482 canonicalize_pathname (ret);
483 return ret;
486 g_free (ret);
487 return NULL;
490 /* --------------------------------------------------------------------------------------------- */
492 static const char *
493 setup__is_cfg_group_must_panel_config (const char *grp)
495 return (!strcasecmp ("Dirs", grp) ||
496 !strcasecmp ("Temporal:New Right Panel", grp) ||
497 !strcasecmp ("Temporal:New Left Panel", grp) ||
498 !strcasecmp ("New Left Panel", grp) || !strcasecmp ("New Right Panel", grp))
499 ? grp : NULL;
502 /* --------------------------------------------------------------------------------------------- */
504 static void
505 setup__move_panels_config_into_separate_file (const char *profile)
507 mc_config_t *tmp_cfg;
508 char **groups, **curr_grp;
509 const char *need_grp;
511 if (!exist_file (profile))
512 return;
514 tmp_cfg = mc_config_init (profile, FALSE);
515 if (!tmp_cfg)
516 return;
518 curr_grp = groups = mc_config_get_groups (tmp_cfg, NULL);
519 if (!groups)
521 mc_config_deinit (tmp_cfg);
522 return;
525 while (*curr_grp)
527 if (setup__is_cfg_group_must_panel_config (*curr_grp) == NULL)
528 mc_config_del_group (tmp_cfg, *curr_grp);
529 curr_grp++;
532 mc_config_save_to_file (tmp_cfg, panels_profile_name, NULL);
533 mc_config_deinit (tmp_cfg);
535 tmp_cfg = mc_config_init (profile, FALSE);
536 if (!tmp_cfg)
538 g_strfreev (groups);
539 return;
542 curr_grp = groups;
544 while (*curr_grp)
546 need_grp = setup__is_cfg_group_must_panel_config (*curr_grp);
547 if (need_grp != NULL)
549 mc_config_del_group (tmp_cfg, need_grp);
551 curr_grp++;
553 g_strfreev (groups);
555 mc_config_save_file (tmp_cfg, NULL);
556 mc_config_deinit (tmp_cfg);
559 /* --------------------------------------------------------------------------------------------- */
561 Create new mc_config object from specified ini-file or
562 append data to existing mc_config object from ini-file
565 static void
566 load_setup_init_config_from_file (mc_config_t ** config, const char *fname, gboolean read_only)
569 TODO: IMHO, in future, this function shall be placed in mcconfig module.
571 if (exist_file (fname))
573 if (*config != NULL)
574 mc_config_read_file (*config, fname, read_only, TRUE);
575 else
576 *config = mc_config_init (fname, read_only);
580 /* --------------------------------------------------------------------------------------------- */
582 static void
583 load_layout (void)
585 size_t i;
586 int equal_split;
587 int first_panel_size;
589 /* legacy options */
590 panels_layout.horizontal_split = mc_config_get_int (mc_main_config, CONFIG_APP_SECTION,
591 "horizontal_split", 0);
592 equal_split = mc_config_get_int (mc_main_config, "Layout", "equal_split", 1);
593 first_panel_size = mc_config_get_int (mc_main_config, "Layout", "first_panel_size", 1);
594 if (panels_layout.horizontal_split)
596 panels_layout.horizontal_equal = equal_split;
597 panels_layout.left_panel_size = first_panel_size;
599 else
601 panels_layout.vertical_equal = equal_split;
602 panels_layout.top_panel_size = first_panel_size;
605 /* actual options override legacy ones */
606 for (i = 0; layout[i].opt_name != NULL; i++)
607 *layout[i].opt_addr = mc_config_get_int (mc_main_config, CONFIG_LAYOUT_SECTION,
608 layout[i].opt_name, *layout[i].opt_addr);
610 /* remove legacy options */
611 mc_config_del_key (mc_main_config, CONFIG_APP_SECTION, "horizontal_split");
612 mc_config_del_key (mc_main_config, "Layout", "equal_split");
613 mc_config_del_key (mc_main_config, "Layout", "first_panel_size");
616 /* --------------------------------------------------------------------------------------------- */
618 static void
619 load_keys_from_section (const char *terminal, mc_config_t * cfg)
621 char *section_name;
622 gchar **profile_keys, **keys;
623 gchar **values, **curr_values;
624 char *valcopy, *value;
625 long key_code;
626 gsize len, values_len;
628 if (terminal == NULL)
629 return;
631 section_name = g_strconcat ("terminal:", terminal, (char *) NULL);
632 profile_keys = keys = mc_config_get_keys (cfg, section_name, &len);
634 while (*profile_keys != NULL)
636 /* copy=other causes all keys from [terminal:other] to be loaded. */
637 if (g_ascii_strcasecmp (*profile_keys, "copy") == 0)
639 valcopy = mc_config_get_string (cfg, section_name, *profile_keys, "");
640 load_keys_from_section (valcopy, cfg);
641 g_free (valcopy);
642 profile_keys++;
643 continue;
646 curr_values = values =
647 mc_config_get_string_list (cfg, section_name, *profile_keys, &values_len);
649 key_code = lookup_key (*profile_keys, NULL);
651 if (key_code != 0)
653 if (curr_values != NULL)
655 while (*curr_values != NULL)
657 valcopy = convert_controls (*curr_values);
658 define_sequence (key_code, valcopy, MCKEY_NOACTION);
659 g_free (valcopy);
660 curr_values++;
663 else
665 value = mc_config_get_string (cfg, section_name, *profile_keys, "");
666 valcopy = convert_controls (value);
667 define_sequence (key_code, valcopy, MCKEY_NOACTION);
668 g_free (valcopy);
669 g_free (value);
673 profile_keys++;
674 g_strfreev (values);
676 g_strfreev (keys);
677 g_free (section_name);
680 /* --------------------------------------------------------------------------------------------- */
682 static void
683 load_keymap_from_section (const char *section_name, GArray * keymap, mc_config_t * cfg)
685 gchar **profile_keys, **keys;
686 gsize len;
688 if (section_name == NULL)
689 return;
691 profile_keys = keys = mc_config_get_keys (cfg, section_name, &len);
693 while (*profile_keys != NULL)
695 gchar **values, **curr_values;
697 curr_values = values = mc_config_get_string_list (cfg, section_name, *profile_keys, &len);
699 if (curr_values != NULL)
701 int action;
703 action = keybind_lookup_action (*profile_keys);
704 if (action > 0)
705 while (*curr_values != NULL)
707 keybind_cmd_bind (keymap, *curr_values, action);
708 curr_values++;
711 g_strfreev (values);
714 profile_keys++;
717 g_strfreev (keys);
720 /* --------------------------------------------------------------------------------------------- */
722 static mc_config_t *
723 load_setup_get_keymap_profile_config (gboolean load_from_file)
726 TODO: IMHO, in future, this function shall be placed in mcconfig module.
728 mc_config_t *keymap_config;
729 char *share_keymap, *sysconfig_keymap;
730 char *fname, *fname2;
732 /* 0) Create default keymap */
733 keymap_config = create_default_keymap ();
734 if (!load_from_file)
735 return keymap_config;
737 /* load and merge global keymaps */
739 /* 1) /usr/share/mc (mc_global.share_data_dir) */
740 share_keymap = g_build_filename (mc_global.share_data_dir, GLOBAL_KEYMAP_FILE, NULL);
741 load_setup_init_config_from_file (&keymap_config, share_keymap, TRUE);
743 /* 2) /etc/mc (mc_global.sysconfig_dir) */
744 sysconfig_keymap = g_build_filename (mc_global.sysconfig_dir, GLOBAL_KEYMAP_FILE, NULL);
745 load_setup_init_config_from_file (&keymap_config, sysconfig_keymap, TRUE);
747 /* then load and merge one of user-defined keymap */
749 /* 3) --keymap=<keymap> */
750 fname = load_setup_get_full_config_name (NULL, mc_args__keymap_file);
751 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
753 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
754 goto done;
756 g_free (fname);
758 /* 4) getenv("MC_KEYMAP") */
759 fname = load_setup_get_full_config_name (NULL, g_getenv ("MC_KEYMAP"));
760 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
762 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
763 goto done;
765 g_free (fname);
767 /* 5) main config; [Midnight Commander] -> keymap */
768 fname2 = mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, "keymap", NULL);
769 if (fname2 != NULL && *fname2 != '\0')
770 fname = load_setup_get_full_config_name (NULL, fname2);
771 g_free (fname2);
772 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
774 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
775 goto done;
777 g_free (fname);
779 /* 6) ${XDG_CONFIG_HOME}/mc/mc.keymap */
780 fname = mc_config_get_full_path (GLOBAL_KEYMAP_FILE);
781 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
783 done:
784 g_free (fname);
785 g_free (sysconfig_keymap);
786 g_free (share_keymap);
788 return keymap_config;
791 /* --------------------------------------------------------------------------------------------- */
793 static panel_view_mode_t
794 setup__load_panel_state (const char *section)
796 char *buffer;
797 size_t i;
798 panel_view_mode_t mode = view_listing;
800 /* Load the display mode */
801 buffer = mc_config_get_string (mc_panels_config, section, "display", "listing");
803 for (i = 0; panel_types[i].opt_name != NULL; i++)
804 if (g_ascii_strcasecmp (panel_types[i].opt_name, buffer) == 0)
806 mode = panel_types[i].opt_type;
807 break;
810 g_free (buffer);
812 return mode;
815 /* --------------------------------------------------------------------------------------------- */
817 static void
818 panel_save_type (const char *section, panel_view_mode_t type)
820 size_t i;
822 for (i = 0; panel_types[i].opt_name != NULL; i++)
823 if (panel_types[i].opt_type == type)
825 mc_config_set_string (mc_panels_config, section, "display", panel_types[i].opt_name);
826 break;
830 /* --------------------------------------------------------------------------------------------- */
832 /* save panels.ini */
833 static void
834 save_panel_types (void)
836 panel_view_mode_t type;
838 if (mc_global.mc_run_mode != MC_RUN_FULL)
839 return;
841 type = get_display_type (0);
842 panel_save_type ("New Left Panel", type);
843 if (type == view_listing)
844 panel_save_setup (left_panel, left_panel->panel_name);
845 type = get_display_type (1);
846 panel_save_type ("New Right Panel", type);
847 if (type == view_listing)
848 panel_save_setup (right_panel, right_panel->panel_name);
851 char *dirs;
853 dirs = get_panel_dir_for (other_panel);
854 mc_config_set_string (mc_panels_config, "Dirs", "other_dir", dirs);
855 g_free (dirs);
858 if (current_panel != NULL)
859 mc_config_set_bool (mc_panels_config, "Dirs", "current_is_left", get_current_index () == 0);
861 if (mc_panels_config->ini_path == NULL)
862 mc_panels_config->ini_path = g_strdup (panels_profile_name);
864 mc_config_del_group (mc_panels_config, "Temporal:New Left Panel");
865 mc_config_del_group (mc_panels_config, "Temporal:New Right Panel");
867 mc_config_save_file (mc_panels_config, NULL);
870 /* --------------------------------------------------------------------------------------------- */
871 /*** public functions ****************************************************************************/
872 /* --------------------------------------------------------------------------------------------- */
874 char *
875 setup_init (void)
877 char *profile;
878 char *inifile;
880 if (profile_name != NULL)
881 return profile_name;
883 profile = mc_config_get_full_path (MC_CONFIG_FILE);
884 if (!exist_file (profile))
886 inifile = mc_build_filename (mc_global.sysconfig_dir, "mc.ini", NULL);
887 if (exist_file (inifile))
889 g_free (profile);
890 profile = inifile;
892 else
894 g_free (inifile);
895 inifile = mc_build_filename (mc_global.share_data_dir, "mc.ini", NULL);
896 if (exist_file (inifile))
898 g_free (profile);
899 profile = inifile;
901 else
902 g_free (inifile);
906 profile_name = profile;
908 return profile;
911 /* --------------------------------------------------------------------------------------------- */
913 void
914 load_setup (void)
916 char *profile;
917 size_t i;
918 char *buffer;
919 const char *kt;
921 #ifdef HAVE_CHARSET
922 load_codepages_list ();
923 #endif /* HAVE_CHARSET */
925 profile = setup_init ();
927 /* mc.lib is common for all users, but has priority lower than
928 ${XDG_CONFIG_HOME}/mc/ini. FIXME: it's only used for keys and treestore now */
929 global_profile_name =
930 g_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
931 if (!exist_file (global_profile_name))
933 g_free (global_profile_name);
934 global_profile_name =
935 g_build_filename (mc_global.share_data_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
938 panels_profile_name = mc_config_get_full_path (MC_PANELS_FILE);
940 mc_main_config = mc_config_init (profile, FALSE);
942 if (!exist_file (panels_profile_name))
943 setup__move_panels_config_into_separate_file (profile);
945 mc_panels_config = mc_config_init (panels_profile_name, FALSE);
947 /* Load integer boolean options */
948 for (i = 0; int_options[i].opt_name != NULL; i++)
949 *int_options[i].opt_addr =
950 mc_config_get_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
951 *int_options[i].opt_addr);
952 #ifndef USE_INTERNAL_EDIT
953 /* reset forced in case of build without internal editor */
954 use_internal_edit = 0;
955 #endif /* USE_INTERNAL_EDIT */
957 if (option_tab_spacing <= 0)
958 option_tab_spacing = DEFAULT_TAB_SPACING;
960 #ifdef USE_INTERNAL_EDIT
961 if (option_word_wrap_line_length <= 0)
962 option_word_wrap_line_length = DEFAULT_WRAP_LINE_LENGTH;
963 #endif /* USE_INTERNAL_EDIT */
965 /* overwrite old_esc_mode_timeout */
966 kt = getenv ("KEYBOARD_KEY_TIMEOUT_US");
967 if ((kt != NULL) && (kt[0] != '\0'))
968 old_esc_mode_timeout = atoi (kt);
970 /* Load string options */
971 for (i = 0; str_options[i].opt_name != NULL; i++)
972 *str_options[i].opt_addr =
973 mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
974 str_options[i].opt_defval);
976 load_layout ();
977 panels_load_options ();
978 load_panelize ();
980 startup_left_mode = setup__load_panel_state ("New Left Panel");
981 startup_right_mode = setup__load_panel_state ("New Right Panel");
983 /* At least one of the panels is a listing panel */
984 if (startup_left_mode != view_listing && startup_right_mode != view_listing)
985 startup_left_mode = view_listing;
987 if (mc_run_param1 == NULL)
989 vfs_path_t *vpath;
990 buffer = mc_config_get_string (mc_panels_config, "Dirs", "other_dir", ".");
991 vpath = vfs_path_from_str (buffer);
992 if (vfs_file_is_local (vpath))
993 mc_run_param1 = buffer;
994 else
995 g_free (buffer);
996 vfs_path_free (vpath);
999 boot_current_is_left = mc_config_get_bool (mc_panels_config, "Dirs", "current_is_left", TRUE);
1001 /* Load time formats */
1002 user_recent_timeformat =
1003 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "timeformat_recent", FMTTIME);
1004 user_old_timeformat =
1005 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "timeformat_old", FMTYEAR);
1007 #ifdef ENABLE_VFS_FTP
1008 ftpfs_proxy_host =
1009 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "ftp_proxy_host", "gate");
1010 ftpfs_ignore_chattr_errors =
1011 mc_config_get_bool (mc_main_config, CONFIG_APP_SECTION, "ignore_ftp_chattr_errors", TRUE);
1012 ftpfs_init_passwd ();
1013 #endif /* ENABLE_VFS_FTP */
1015 /* The default color and the terminal dependent color */
1016 mc_global.tty.setup_color_string =
1017 mc_config_get_string (mc_main_config, "Colors", "base_color", "");
1018 mc_global.tty.term_color_string =
1019 mc_config_get_string (mc_main_config, "Colors", getenv ("TERM"), "");
1020 mc_global.tty.color_terminal_string =
1021 mc_config_get_string (mc_main_config, "Colors", "color_terminals", "");
1023 /* Load the directory history */
1024 /* directory_history_load (); */
1025 /* Remove the temporal entries */
1027 #ifdef HAVE_CHARSET
1028 if (codepages->len > 1)
1030 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "display_codepage", "");
1031 if (buffer[0] != '\0')
1033 mc_global.display_codepage = get_codepage_index (buffer);
1034 cp_display = get_codepage_id (mc_global.display_codepage);
1036 g_free (buffer);
1037 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "source_codepage", "");
1038 if (buffer[0] != '\0')
1040 default_source_codepage = get_codepage_index (buffer);
1041 mc_global.source_codepage = default_source_codepage; /* May be source_codepage doesn't need this */
1042 cp_source = get_codepage_id (mc_global.source_codepage);
1044 g_free (buffer);
1047 autodetect_codeset =
1048 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "autodetect_codeset", "");
1049 if ((autodetect_codeset[0] != '\0') && (strcmp (autodetect_codeset, "off") != 0))
1050 is_autodetect_codeset_enabled = TRUE;
1052 g_free (init_translation_table (mc_global.source_codepage, mc_global.display_codepage));
1053 buffer = (char *) get_codepage_id (mc_global.display_codepage);
1054 if (buffer != NULL)
1055 mc_global.utf8_display = str_isutf8 (buffer);
1056 #endif /* HAVE_CHARSET */
1058 #ifdef HAVE_ASPELL
1059 spell_language =
1060 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "spell_language", "en");
1061 #endif /* HAVE_ASPELL */
1063 clipboard_store_path =
1064 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_store", "");
1065 clipboard_paste_path =
1066 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_paste", "");
1069 /* --------------------------------------------------------------------------------------------- */
1071 gboolean
1072 save_setup (gboolean save_options, gboolean save_panel_options)
1074 gboolean ret = TRUE;
1076 saving_setup = 1;
1078 save_hotlist ();
1080 if (save_panel_options)
1081 save_panel_types ();
1083 if (save_options)
1085 char *tmp_profile;
1087 save_config ();
1088 save_layout ();
1089 panels_save_options ();
1090 save_panelize ();
1091 /* directory_history_save (); */
1093 #ifdef ENABLE_VFS_FTP
1094 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "ftpfs_password",
1095 ftpfs_anonymous_passwd);
1096 if (ftpfs_proxy_host)
1097 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "ftp_proxy_host",
1098 ftpfs_proxy_host);
1099 #endif /* ENABLE_VFS_FTP */
1101 #ifdef HAVE_CHARSET
1102 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "display_codepage",
1103 get_codepage_id (mc_global.display_codepage));
1104 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "source_codepage",
1105 get_codepage_id (default_source_codepage));
1106 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "autodetect_codeset",
1107 autodetect_codeset);
1108 #endif /* HAVE_CHARSET */
1110 #ifdef HAVE_ASPELL
1111 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "spell_language",
1112 spell_language);
1113 #endif /* HAVE_ASPELL */
1115 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_store",
1116 clipboard_store_path);
1117 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_paste",
1118 clipboard_paste_path);
1120 tmp_profile = mc_config_get_full_path (MC_CONFIG_FILE);
1121 ret = mc_config_save_to_file (mc_main_config, tmp_profile, NULL);
1122 g_free (tmp_profile);
1125 saving_setup = 0;
1127 return ret;
1130 /* --------------------------------------------------------------------------------------------- */
1132 void
1133 done_setup (void)
1135 size_t i;
1137 g_free (clipboard_store_path);
1138 g_free (clipboard_paste_path);
1139 g_free (profile_name);
1140 g_free (global_profile_name);
1141 g_free (mc_global.tty.color_terminal_string);
1142 g_free (mc_global.tty.term_color_string);
1143 g_free (mc_global.tty.setup_color_string);
1144 g_free (panels_profile_name);
1145 mc_config_deinit (mc_main_config);
1146 mc_config_deinit (mc_panels_config);
1148 g_free (user_recent_timeformat);
1149 g_free (user_old_timeformat);
1151 for (i = 0; str_options[i].opt_name != NULL; i++)
1152 g_free (*str_options[i].opt_addr);
1154 done_hotlist ();
1155 done_panelize ();
1156 /* directory_history_free (); */
1158 #ifdef HAVE_CHARSET
1159 g_free (autodetect_codeset);
1160 free_codepages_list ();
1161 #endif
1163 #ifdef HAVE_ASPELL
1164 g_free (spell_language);
1165 #endif /* HAVE_ASPELL */
1168 /* --------------------------------------------------------------------------------------------- */
1170 void
1171 save_config (void)
1173 size_t i;
1175 /* Save integer options */
1176 for (i = 0; int_options[i].opt_name != NULL; i++)
1177 mc_config_set_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
1178 *int_options[i].opt_addr);
1180 /* Save string options */
1181 for (i = 0; str_options[i].opt_name != NULL; i++)
1182 mc_config_set_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
1183 *str_options[i].opt_addr);
1186 /* --------------------------------------------------------------------------------------------- */
1188 void
1189 setup_save_config_show_error (const char *filename, GError ** error)
1191 if (error != NULL && *error != NULL)
1193 message (D_ERROR, MSG_ERROR, _("Cannot save file %s:\n%s"), filename, (*error)->message);
1194 g_error_free (*error);
1195 *error = NULL;
1199 /* --------------------------------------------------------------------------------------------- */
1201 void
1202 save_layout (void)
1204 size_t i;
1206 /* Save integer options */
1207 for (i = 0; layout[i].opt_name != NULL; i++)
1208 mc_config_set_int (mc_main_config, CONFIG_LAYOUT_SECTION, layout[i].opt_name,
1209 *layout[i].opt_addr);
1212 /* --------------------------------------------------------------------------------------------- */
1214 void
1215 load_key_defs (void)
1218 * Load keys from mc.lib before ${XDG_CONFIG_HOME}/mc/ini, so that the user
1219 * definitions override global settings.
1221 mc_config_t *mc_global_config;
1223 mc_global_config = mc_config_init (global_profile_name, FALSE);
1224 if (mc_global_config != NULL)
1226 load_keys_from_section ("general", mc_global_config);
1227 load_keys_from_section (getenv ("TERM"), mc_global_config);
1228 mc_config_deinit (mc_global_config);
1231 load_keys_from_section ("general", mc_main_config);
1232 load_keys_from_section (getenv ("TERM"), mc_main_config);
1235 /* --------------------------------------------------------------------------------------------- */
1237 #ifdef ENABLE_VFS_FTP
1238 char *
1239 load_anon_passwd (void)
1241 char *buffer;
1243 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "ftpfs_password", "");
1245 if ((buffer != NULL) && (buffer[0] != '\0'))
1246 return buffer;
1248 g_free (buffer);
1249 return NULL;
1251 #endif /* ENABLE_VFS_FTP */
1253 /* --------------------------------------------------------------------------------------------- */
1255 void
1256 load_keymap_defs (gboolean load_from_file)
1259 * Load keymap from GLOBAL_KEYMAP_FILE before ${XDG_CONFIG_HOME}/mc/mc.keymap, so that the user
1260 * definitions override global settings.
1262 mc_config_t *mc_global_keymap;
1264 mc_global_keymap = load_setup_get_keymap_profile_config (load_from_file);
1266 if (mc_global_keymap != NULL)
1268 main_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1269 load_keymap_from_section (KEYMAP_SECTION_MAIN, main_keymap, mc_global_keymap);
1270 main_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1271 load_keymap_from_section (KEYMAP_SECTION_MAIN_EXT, main_x_keymap, mc_global_keymap);
1273 panel_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1274 load_keymap_from_section (KEYMAP_SECTION_PANEL, panel_keymap, mc_global_keymap);
1276 dialog_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1277 load_keymap_from_section (KEYMAP_SECTION_DIALOG, dialog_keymap, mc_global_keymap);
1279 input_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1280 load_keymap_from_section (KEYMAP_SECTION_INPUT, input_keymap, mc_global_keymap);
1282 listbox_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1283 load_keymap_from_section (KEYMAP_SECTION_LISTBOX, listbox_keymap, mc_global_keymap);
1285 tree_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1286 load_keymap_from_section (KEYMAP_SECTION_TREE, tree_keymap, mc_global_keymap);
1288 help_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1289 load_keymap_from_section (KEYMAP_SECTION_HELP, help_keymap, mc_global_keymap);
1291 #ifdef USE_INTERNAL_EDIT
1292 editor_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1293 load_keymap_from_section (KEYMAP_SECTION_EDITOR, editor_keymap, mc_global_keymap);
1294 editor_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1295 load_keymap_from_section (KEYMAP_SECTION_EDITOR_EXT, editor_x_keymap, mc_global_keymap);
1296 #endif
1298 viewer_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1299 load_keymap_from_section (KEYMAP_SECTION_VIEWER, viewer_keymap, mc_global_keymap);
1300 viewer_hex_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1301 load_keymap_from_section (KEYMAP_SECTION_VIEWER_HEX, viewer_hex_keymap, mc_global_keymap);
1303 #ifdef USE_DIFF_VIEW
1304 diff_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1305 load_keymap_from_section (KEYMAP_SECTION_DIFFVIEWER, diff_keymap, mc_global_keymap);
1306 #endif
1308 mc_config_deinit (mc_global_keymap);
1311 main_map = (global_keymap_t *) main_keymap->data;
1312 main_x_map = (global_keymap_t *) main_x_keymap->data;
1313 panel_map = (global_keymap_t *) panel_keymap->data;
1314 dialog_map = (global_keymap_t *) dialog_keymap->data;
1315 input_map = (global_keymap_t *) input_keymap->data;
1316 listbox_map = (global_keymap_t *) listbox_keymap->data;
1317 tree_map = (global_keymap_t *) tree_keymap->data;
1318 help_map = (global_keymap_t *) help_keymap->data;
1319 #ifdef USE_INTERNAL_EDIT
1320 editor_map = (global_keymap_t *) editor_keymap->data;
1321 editor_x_map = (global_keymap_t *) editor_x_keymap->data;
1322 #endif
1323 viewer_map = (global_keymap_t *) viewer_keymap->data;
1324 viewer_hex_map = (global_keymap_t *) viewer_hex_keymap->data;
1325 #ifdef USE_DIFF_VIEW
1326 diff_map = (global_keymap_t *) diff_keymap->data;
1327 #endif
1330 /* --------------------------------------------------------------------------------------------- */
1332 void
1333 free_keymap_defs (void)
1335 if (main_keymap != NULL)
1336 g_array_free (main_keymap, TRUE);
1337 if (main_x_keymap != NULL)
1338 g_array_free (main_x_keymap, TRUE);
1339 if (panel_keymap != NULL)
1340 g_array_free (panel_keymap, TRUE);
1341 if (dialog_keymap != NULL)
1342 g_array_free (dialog_keymap, TRUE);
1343 if (input_keymap != NULL)
1344 g_array_free (input_keymap, TRUE);
1345 if (listbox_keymap != NULL)
1346 g_array_free (listbox_keymap, TRUE);
1347 if (tree_keymap != NULL)
1348 g_array_free (tree_keymap, TRUE);
1349 if (help_keymap != NULL)
1350 g_array_free (help_keymap, TRUE);
1351 #ifdef USE_INTERNAL_EDIT
1352 if (editor_keymap != NULL)
1353 g_array_free (editor_keymap, TRUE);
1354 if (editor_x_keymap != NULL)
1355 g_array_free (editor_x_keymap, TRUE);
1356 #endif
1357 if (viewer_keymap != NULL)
1358 g_array_free (viewer_keymap, TRUE);
1359 if (viewer_hex_keymap != NULL)
1360 g_array_free (viewer_hex_keymap, TRUE);
1361 #ifdef USE_DIFF_VIEW
1362 if (diff_keymap != NULL)
1363 g_array_free (diff_keymap, TRUE);
1364 #endif
1367 /* --------------------------------------------------------------------------------------------- */
1369 void
1370 panel_load_setup (WPanel * panel, const char *section)
1372 size_t i;
1373 char *buffer, buffer2[BUF_TINY];
1375 panel->sort_info.reverse = mc_config_get_int (mc_panels_config, section, "reverse", 0);
1376 panel->sort_info.case_sensitive =
1377 mc_config_get_int (mc_panels_config, section, "case_sensitive",
1378 OS_SORT_CASE_SENSITIVE_DEFAULT);
1379 panel->sort_info.exec_first = mc_config_get_int (mc_panels_config, section, "exec_first", 0);
1381 /* Load sort order */
1382 buffer = mc_config_get_string (mc_panels_config, section, "sort_order", "name");
1383 panel->sort_info.sort_field = panel_get_field_by_id (buffer);
1384 if (panel->sort_info.sort_field == NULL)
1385 panel->sort_info.sort_field = panel_get_field_by_id ("name");
1387 g_free (buffer);
1389 /* Load the listing mode */
1390 buffer = mc_config_get_string (mc_panels_config, section, "list_mode", "full");
1391 panel->list_type = list_full;
1392 for (i = 0; list_types[i].key != NULL; i++)
1393 if (g_ascii_strcasecmp (list_types[i].key, buffer) == 0)
1395 panel->list_type = list_types[i].list_type;
1396 break;
1398 g_free (buffer);
1400 /* User formats */
1401 g_free (panel->user_format);
1402 panel->user_format =
1403 mc_config_get_string (mc_panels_config, section, "user_format", DEFAULT_USER_FORMAT);
1405 for (i = 0; i < LIST_TYPES; i++)
1407 g_free (panel->user_status_format[i]);
1408 g_snprintf (buffer2, BUF_TINY, "user_status%lld", (long long) i);
1409 panel->user_status_format[i] =
1410 mc_config_get_string (mc_panels_config, section, buffer2, DEFAULT_USER_FORMAT);
1413 panel->user_mini_status = mc_config_get_int (mc_panels_config, section, "user_mini_status", 0);
1416 /* --------------------------------------------------------------------------------------------- */
1418 void
1419 panel_save_setup (struct WPanel *panel, const char *section)
1421 char buffer[BUF_TINY];
1422 size_t i;
1424 mc_config_set_int (mc_panels_config, section, "reverse", panel->sort_info.reverse);
1425 mc_config_set_int (mc_panels_config, section, "case_sensitive",
1426 panel->sort_info.case_sensitive);
1427 mc_config_set_int (mc_panels_config, section, "exec_first", panel->sort_info.exec_first);
1429 mc_config_set_string (mc_panels_config, section, "sort_order", panel->sort_info.sort_field->id);
1431 for (i = 0; list_types[i].key != NULL; i++)
1432 if (list_types[i].list_type == panel->list_type)
1434 mc_config_set_string (mc_panels_config, section, "list_mode", list_types[i].key);
1435 break;
1438 mc_config_set_string (mc_panels_config, section, "user_format", panel->user_format);
1440 for (i = 0; i < LIST_TYPES; i++)
1442 g_snprintf (buffer, BUF_TINY, "user_status%lld", (long long) i);
1443 mc_config_set_string (mc_panels_config, section, buffer, panel->user_status_format[i]);
1446 mc_config_set_int (mc_panels_config, section, "user_mini_status", panel->user_mini_status);
1449 /* --------------------------------------------------------------------------------------------- */
1452 Load panels options from [Panels] section.
1454 void
1455 panels_load_options (void)
1457 if (mc_config_has_group (mc_main_config, CONFIG_PANELS_SECTION))
1459 size_t i;
1460 int qmode;
1462 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
1463 *panels_ini_options[i].opt_addr =
1464 mc_config_get_bool (mc_main_config, CONFIG_PANELS_SECTION,
1465 panels_ini_options[i].opt_name,
1466 *panels_ini_options[i].opt_addr);
1468 qmode = mc_config_get_int (mc_main_config, CONFIG_PANELS_SECTION,
1469 "quick_search_mode", (int) panels_options.qsearch_mode);
1470 if (qmode < 0)
1471 panels_options.qsearch_mode = QSEARCH_CASE_INSENSITIVE;
1472 else if (qmode >= QSEARCH_NUM)
1473 panels_options.qsearch_mode = QSEARCH_PANEL_CASE;
1474 else
1475 panels_options.qsearch_mode = (qsearch_mode_t) qmode;
1479 /* --------------------------------------------------------------------------------------------- */
1482 Save panels options in [Panels] section.
1484 void
1485 panels_save_options (void)
1487 size_t i;
1489 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
1490 mc_config_set_bool (mc_main_config, CONFIG_PANELS_SECTION,
1491 panels_ini_options[i].opt_name, *panels_ini_options[i].opt_addr);
1493 mc_config_set_int (mc_main_config, CONFIG_PANELS_SECTION,
1494 "quick_search_mode", (int) panels_options.qsearch_mode);
1497 /* --------------------------------------------------------------------------------------------- */