4 Copyright (C) 1994-2018
5 Free Software Foundation, Inc.
7 This file is part of the Midnight Commander.
9 The Midnight Commander is free software: you can redistribute it
10 and/or modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation, either version 3 of the License,
12 or (at your option) any later version.
14 The Midnight Commander is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * \brief Source: setup loading/saving
32 #include <sys/types.h>
35 #include "lib/global.h"
37 #include "lib/tty/tty.h"
38 #include "lib/tty/key.h"
39 #include "lib/mcconfig.h"
40 #include "lib/fileloc.h"
41 #include "lib/timefmt.h"
43 #include "lib/widget.h"
46 #include "src/vfs/ftpfs/ftpfs.h"
48 #ifdef ENABLE_VFS_FISH
49 #include "src/vfs/fish/fish.h"
53 #include "lib/charsets.h"
56 #include "filemanager/dir.h"
57 #include "filemanager/midnight.h"
58 #include "filemanager/tree.h" /* xtree_mode */
59 #include "filemanager/hotlist.h" /* load/save/done hotlist */
60 #include "filemanager/panelize.h" /* load/save/done panelize */
61 #include "filemanager/layout.h"
62 #include "filemanager/cmd.h"
65 #include "execute.h" /* pause_after_run */
66 #include "clipboard.h"
67 #include "keybind-defaults.h" /* keybind_lookup_action */
70 #include "selcodepage.h"
73 #ifdef USE_INTERNAL_EDIT
74 #include "src/editor/edit.h"
77 #include "src/viewer/mcviewer.h" /* For the externs */
81 /*** global variables ****************************************************************************/
83 char *global_profile_name
; /* mc.lib */
85 /* Only used at program boot */
86 gboolean boot_current_is_left
= TRUE
;
88 /* If on, default for "No" in delete operations */
89 gboolean safe_delete
= FALSE
;
90 /* If on, default for "No" in overwrite files */
91 gboolean safe_overwrite
= FALSE
;
93 /* Controls screen clearing before an exec */
94 gboolean clear_before_exec
= TRUE
;
96 /* Asks for confirmation before deleting a file */
97 gboolean confirm_delete
= TRUE
;
98 /* Asks for confirmation before deleting a hotlist entry */
99 gboolean confirm_directory_hotlist_delete
= FALSE
;
100 /* Asks for confirmation before overwriting a file */
101 gboolean confirm_overwrite
= TRUE
;
102 /* Asks for confirmation before executing a program by pressing enter */
103 gboolean confirm_execute
= FALSE
;
104 /* Asks for confirmation before leaving the program */
105 gboolean confirm_exit
= FALSE
;
107 /* If true, at startup the user-menu is invoked */
108 gboolean auto_menu
= FALSE
;
109 /* This flag indicates if the pull down menus by default drop down */
110 gboolean drop_menus
= FALSE
;
112 /* Asks for confirmation when using F3 to view a directory and there
114 gboolean confirm_view_dir
= FALSE
;
116 /* Ask file name before start the editor */
117 gboolean editor_ask_filename_before_edit
= FALSE
;
119 panel_view_mode_t startup_left_mode
;
120 panel_view_mode_t startup_right_mode
;
122 gboolean copymove_persistent_attr
= TRUE
;
125 int option_tab_spacing
= DEFAULT_TAB_SPACING
;
127 /* Ugly hack to allow panel_save_setup to work as a place holder for */
128 /* default panel values */
131 panels_options_t panels_options
= {
132 .show_mini_info
= TRUE
,
133 .kilobyte_si
= FALSE
,
134 .mix_all_files
= FALSE
,
135 .show_backups
= TRUE
,
136 .show_dot_files
= TRUE
,
137 .fast_reload
= FALSE
,
138 .fast_reload_msg_shown
= FALSE
,
139 .mark_moves_down
= TRUE
,
140 .reverse_files_only
= TRUE
,
141 .auto_save_setup
= FALSE
,
142 .navigate_with_arrows
= FALSE
,
143 .scroll_pages
= TRUE
,
144 .scroll_center
= FALSE
,
145 .mouse_move_pages
= TRUE
,
146 .filetype_mode
= TRUE
,
147 .permission_mode
= FALSE
,
148 .qsearch_mode
= QSEARCH_PANEL_CASE
,
149 .torben_fj_mode
= FALSE
,
150 .select_flags
= SELECT_MATCH_CASE
| SELECT_SHELL_PATTERNS
153 gboolean easy_patterns
= TRUE
;
155 /* It true saves the setup when quitting */
156 gboolean auto_save_setup
= TRUE
;
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 gboolean only_leading_plus_minus
= TRUE
;
163 /* Automatically fills name with current selected item name on mkdir */
164 gboolean auto_fill_mkdir_name
= TRUE
;
166 /* If set and you don't have subshell support,then C-o will give you a shell */
167 gboolean output_starts_shell
= FALSE
;
169 /* If set, we execute the file command to check the file type */
170 gboolean use_file_to_check_type
= TRUE
;
172 gboolean verbose
= TRUE
;
175 * Whether the Midnight Commander tries to provide more
176 * information about copy/move sizes and bytes transferred
177 * at the expense of some speed
179 gboolean file_op_compute_totals
= TRUE
;
181 /* If true use the internal viewer */
182 gboolean use_internal_view
= TRUE
;
183 /* If set, use the builtin editor */
184 gboolean use_internal_edit
= TRUE
;
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 */
194 char *spell_language
= NULL
;
197 /* Value of "other_dir" key in ini file */
198 char *saved_other_dir
= NULL
;
200 /* If set, then print to the given file the last directory we were at */
201 char *last_wd_string
= NULL
;
203 /* Set when main loop should be terminated */
206 /* Set to TRUE to suppress printing the last directory */
207 int print_last_revert
= FALSE
;
209 #ifdef USE_INTERNAL_EDIT
210 /* index to record_macro_buf[], -1 if not recording a macro */
211 int macro_index
= -1;
214 struct macro_action_t record_macro_buf
[MAX_MACRO_LENGTH
];
217 #endif /* USE_INTERNAL_EDIT */
219 /*** file scope macro definitions ****************************************************************/
221 /* In order to use everywhere the same setup for the locale we use defines */
222 #define FMTYEAR _("%b %e %Y")
223 #define FMTTIME _("%b %e %H:%M")
225 /*** file scope type declarations ****************************************************************/
227 /*** file scope variables ************************************************************************/
229 static char *profile_name
= NULL
; /* ${XDG_CONFIG_HOME}/mc/ini */
230 static char *panels_profile_name
= NULL
; /* ${XDG_CACHE_HOME}/mc/panels.ini */
237 } list_formats
[] = {
238 { "full", list_full
},
239 { "brief", list_brief
},
240 { "long", list_long
},
241 { "user", list_user
},
247 const char *opt_name
;
248 panel_view_mode_t opt_type
;
250 { "listing", view_listing
},
251 { "quickview", view_quick
},
252 { "info", view_info
},
253 { "tree", view_tree
},
254 { NULL
, view_listing
}
259 const char *opt_name
;
262 { "message_visible", &mc_global
.message_visible
},
263 { "keybar_visible", &mc_global
.keybar_visible
},
264 { "xterm_title", &xterm_title
},
265 { "output_lines", &output_lines
},
266 { "command_prompt", &command_prompt
},
267 { "menubar_visible", &menubar_visible
},
268 { "free_space", &free_space
},
269 { "horizontal_split", &panels_layout
.horizontal_split
},
270 { "vertical_equal", &panels_layout
.vertical_equal
},
271 { "left_panel_size", &panels_layout
.left_panel_size
},
272 { "horizontal_equal", &panels_layout
.horizontal_equal
},
273 { "top_panel_size", &panels_layout
.top_panel_size
},
279 const char *opt_name
;
281 } bool_options
[] = {
282 { "verbose", &verbose
},
283 { "shell_patterns", &easy_patterns
},
284 { "auto_save_setup", &auto_save_setup
},
285 { "preallocate_space", &mc_global
.vfs
.preallocate_space
},
286 { "auto_menu", &auto_menu
},
287 { "use_internal_view", &use_internal_view
},
288 { "use_internal_edit", &use_internal_edit
},
289 { "clear_before_exec", &clear_before_exec
},
290 { "confirm_delete", &confirm_delete
},
291 { "confirm_overwrite", &confirm_overwrite
},
292 { "confirm_execute", &confirm_execute
},
293 { "confirm_history_cleanup", &mc_global
.widget
.confirm_history_cleanup
},
294 { "confirm_exit", &confirm_exit
},
295 { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete
},
296 { "confirm_view_dir", &confirm_view_dir
},
297 { "safe_delete", &safe_delete
},
298 { "safe_overwrite", &safe_overwrite
},
300 { "eight_bit_clean", &mc_global
.eight_bit_clean
},
301 { "full_eight_bits", &mc_global
.full_eight_bits
},
302 #endif /* !HAVE_CHARSET */
303 { "use_8th_bit_as_meta", &use_8th_bit_as_meta
},
304 { "mouse_move_pages_viewer", &mcview_mouse_move_pages
},
305 { "mouse_close_dialog", &mouse_close_dialog
},
306 { "fast_refresh", &fast_refresh
},
307 { "drop_menus", &drop_menus
},
308 { "wrap_mode", &mcview_global_flags
.wrap
},
309 { "old_esc_mode", &old_esc_mode
},
310 { "cd_symlinks", &mc_global
.vfs
.cd_symlinks
},
311 { "show_all_if_ambiguous", &mc_global
.widget
.show_all_if_ambiguous
},
312 { "use_file_to_guess_type", &use_file_to_check_type
},
313 { "alternate_plus_minus", &mc_global
.tty
.alternate_plus_minus
},
314 { "only_leading_plus_minus", &only_leading_plus_minus
},
315 { "show_output_starts_shell", &output_starts_shell
},
316 { "xtree_mode", &xtree_mode
},
317 { "file_op_compute_totals", &file_op_compute_totals
},
318 { "classic_progressbar", &classic_progressbar
},
320 #ifdef ENABLE_VFS_FTP
321 { "use_netrc", &ftpfs_use_netrc
},
322 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy
},
323 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections
},
324 { "ftpfs_use_passive_connections_over_proxy", &ftpfs_use_passive_connections_over_proxy
},
325 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options
},
326 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls
},
327 { "ignore_ftp_chattr_errors", & ftpfs_ignore_chattr_errors
} ,
328 #endif /* ENABLE_VFS_FTP */
329 #endif /* ENABLE_VFS */
330 #ifdef USE_INTERNAL_EDIT
331 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces
},
332 { "editor_return_does_auto_indent", &option_return_does_auto_indent
},
333 { "editor_backspace_through_tabs", &option_backspace_through_tabs
},
334 { "editor_fake_half_tabs", &option_fake_half_tabs
},
335 { "editor_option_save_position", &option_save_position
},
336 { "editor_option_auto_para_formatting", &option_auto_para_formatting
},
337 { "editor_option_typewriter_wrap", &option_typewriter_wrap
},
338 { "editor_edit_confirm_save", &edit_confirm_save
},
339 { "editor_syntax_highlighting", &option_syntax_highlighting
},
340 { "editor_persistent_selections", &option_persistent_selections
},
341 { "editor_drop_selection_on_copy", &option_drop_selection_on_copy
},
342 { "editor_cursor_beyond_eol", &option_cursor_beyond_eol
},
343 { "editor_cursor_after_inserted_block", &option_cursor_after_inserted_block
},
344 { "editor_visible_tabs", &visible_tabs
},
345 { "editor_visible_spaces", &visible_tws
},
346 { "editor_line_state", &option_line_state
},
347 { "editor_simple_statusbar", &simple_statusbar
},
348 { "editor_check_new_line", &option_check_nl_at_eof
},
349 { "editor_show_right_margin", &show_right_margin
},
350 { "editor_group_undo", &option_group_undo
},
351 { "editor_state_full_filename", &option_state_full_filename
},
352 #endif /* USE_INTERNAL_EDIT */
353 { "editor_ask_filename_before_edit", &editor_ask_filename_before_edit
},
354 { "nice_rotating_dash", &nice_rotating_dash
},
355 { "mcview_remember_file_position", &mcview_remember_file_position
},
356 { "auto_fill_mkdir_name", &auto_fill_mkdir_name
},
357 { "copymove_persistent_attr", ©move_persistent_attr
},
363 const char *opt_name
;
366 { "pause_after_run", &pause_after_run
},
367 { "mouse_repeat_rate", &mou_auto_repeat
},
368 { "double_click_speed", &double_click_speed
},
369 { "old_esc_mode_timeout", &old_esc_mode_timeout
},
370 { "max_dirt_limit", &mcview_max_dirt_limit
},
371 { "num_history_items_recorded", &num_history_items_recorded
},
373 { "vfs_timeout", &vfs_timeout
},
374 #ifdef ENABLE_VFS_FTP
375 { "ftpfs_directory_timeout", &ftpfs_directory_timeout
},
376 { "ftpfs_retry_seconds", &ftpfs_retry_seconds
},
377 #endif /* ENABLE_VFS_FTP */
378 #ifdef ENABLE_VFS_FISH
379 { "fish_directory_timeout", &fish_directory_timeout
},
380 #endif /* ENABLE_VFS_FISH */
381 #endif /* ENABLE_VFS */
382 /* option_tab_spacing is used in internal viewer */
383 { "editor_tab_spacing", &option_tab_spacing
},
384 #ifdef USE_INTERNAL_EDIT
385 { "editor_word_wrap_line_length", &option_word_wrap_line_length
},
386 { "editor_option_save_mode", &option_save_mode
},
387 #endif /* USE_INTERNAL_EDIT */
393 const char *opt_name
;
395 const char *opt_defval
;
397 #ifdef USE_INTERNAL_EDIT
398 { "editor_backup_extension", &option_backup_ext
, "~" },
399 { "editor_filesize_threshold", &option_filesize_threshold
, "64M" },
400 { "editor_stop_format_chars", &option_stop_format_chars
, "-+*\\,.;:&>" },
402 { "mcview_eof", &mcview_show_eof
, "" },
408 const char *opt_name
;
410 } panels_ini_options
[] = {
411 { "show_mini_info", &panels_options
.show_mini_info
},
412 { "kilobyte_si", &panels_options
.kilobyte_si
},
413 { "mix_all_files", &panels_options
.mix_all_files
},
414 { "show_backups", &panels_options
.show_backups
},
415 { "show_dot_files", &panels_options
.show_dot_files
},
416 { "fast_reload", &panels_options
.fast_reload
},
417 { "fast_reload_msg_shown", &panels_options
.fast_reload_msg_shown
},
418 { "mark_moves_down", &panels_options
.mark_moves_down
},
419 { "reverse_files_only", &panels_options
.reverse_files_only
},
420 { "auto_save_setup_panels", &panels_options
.auto_save_setup
},
421 { "navigate_with_arrows", &panels_options
.navigate_with_arrows
},
422 { "panel_scroll_pages", &panels_options
.scroll_pages
},
423 { "panel_scroll_center", &panels_options
.scroll_center
},
424 { "mouse_move_pages", &panels_options
.mouse_move_pages
},
425 { "filetype_mode", &panels_options
.filetype_mode
},
426 { "permission_mode", &panels_options
.permission_mode
},
427 { "torben_fj_mode", &panels_options
.torben_fj_mode
},
432 /*** file scope functions ************************************************************************/
433 /* --------------------------------------------------------------------------------------------- */
436 * Get name of config file.
438 * @param subdir If not NULL, config is also searched in specified subdir.
439 * @param config_file_name If relative, file if searched in standard paths.
441 * @return newly allocated string with config name or NULL if file is not found.
445 load_setup_get_full_config_name (const char *subdir
, const char *config_file_name
)
448 TODO: IMHO, in future, this function shall be placed in mcconfig module.
450 char *lc_basename
, *ret
;
453 if (config_file_name
== NULL
)
456 /* check for .keymap suffix */
457 if (g_str_has_suffix (config_file_name
, ".keymap"))
458 file_name
= g_strdup (config_file_name
);
460 file_name
= g_strconcat (config_file_name
, ".keymap", (char *) NULL
);
462 canonicalize_pathname (file_name
);
464 if (g_path_is_absolute (file_name
))
467 lc_basename
= g_path_get_basename (file_name
);
470 if (lc_basename
== NULL
)
474 ret
= g_build_filename (mc_config_get_path (), subdir
, lc_basename
, (char *) NULL
);
476 ret
= g_build_filename (mc_config_get_path (), lc_basename
, (char *) NULL
);
478 if (exist_file (ret
))
480 g_free (lc_basename
);
481 canonicalize_pathname (ret
);
487 ret
= g_build_filename (mc_global
.sysconfig_dir
, subdir
, lc_basename
, (char *) NULL
);
489 ret
= g_build_filename (mc_global
.sysconfig_dir
, lc_basename
, (char *) NULL
);
491 if (exist_file (ret
))
493 g_free (lc_basename
);
494 canonicalize_pathname (ret
);
500 ret
= g_build_filename (mc_global
.share_data_dir
, subdir
, lc_basename
, (char *) NULL
);
502 ret
= g_build_filename (mc_global
.share_data_dir
, lc_basename
, (char *) NULL
);
504 g_free (lc_basename
);
506 if (exist_file (ret
))
508 canonicalize_pathname (ret
);
516 /* --------------------------------------------------------------------------------------------- */
519 setup__is_cfg_group_must_panel_config (const char *grp
)
521 return (!strcasecmp ("Dirs", grp
) ||
522 !strcasecmp ("Temporal:New Right Panel", grp
) ||
523 !strcasecmp ("Temporal:New Left Panel", grp
) ||
524 !strcasecmp ("New Left Panel", grp
) || !strcasecmp ("New Right Panel", grp
))
528 /* --------------------------------------------------------------------------------------------- */
531 setup__move_panels_config_into_separate_file (const char *profile
)
533 mc_config_t
*tmp_cfg
;
534 char **groups
, **curr_grp
;
536 if (!exist_file (profile
))
539 tmp_cfg
= mc_config_init (profile
, FALSE
);
543 groups
= mc_config_get_groups (tmp_cfg
, NULL
);
547 mc_config_deinit (tmp_cfg
);
551 for (curr_grp
= groups
; *curr_grp
!= NULL
; curr_grp
++)
552 if (setup__is_cfg_group_must_panel_config (*curr_grp
) == NULL
)
553 mc_config_del_group (tmp_cfg
, *curr_grp
);
555 mc_config_save_to_file (tmp_cfg
, panels_profile_name
, NULL
);
556 mc_config_deinit (tmp_cfg
);
558 tmp_cfg
= mc_config_init (profile
, FALSE
);
565 for (curr_grp
= groups
; *curr_grp
!= NULL
; curr_grp
++)
567 const char *need_grp
;
569 need_grp
= setup__is_cfg_group_must_panel_config (*curr_grp
);
570 if (need_grp
!= NULL
)
571 mc_config_del_group (tmp_cfg
, need_grp
);
575 mc_config_save_file (tmp_cfg
, NULL
);
576 mc_config_deinit (tmp_cfg
);
579 /* --------------------------------------------------------------------------------------------- */
581 Create new mc_config object from specified ini-file or
582 append data to existing mc_config object from ini-file
586 load_setup_init_config_from_file (mc_config_t
** config
, const char *fname
, gboolean read_only
)
589 TODO: IMHO, in future, this function shall be placed in mcconfig module.
591 if (exist_file (fname
))
594 mc_config_read_file (*config
, fname
, read_only
, TRUE
);
596 *config
= mc_config_init (fname
, read_only
);
600 /* --------------------------------------------------------------------------------------------- */
608 /* Load boolean options */
609 for (i
= 0; bool_options
[i
].opt_name
!= NULL
; i
++)
610 *bool_options
[i
].opt_addr
=
611 mc_config_get_bool (mc_global
.main_config
, CONFIG_APP_SECTION
, bool_options
[i
].opt_name
,
612 *bool_options
[i
].opt_addr
);
614 /* Load integer options */
615 for (i
= 0; int_options
[i
].opt_name
!= NULL
; i
++)
616 *int_options
[i
].opt_addr
=
617 mc_config_get_int (mc_global
.main_config
, CONFIG_APP_SECTION
, int_options
[i
].opt_name
,
618 *int_options
[i
].opt_addr
);
620 /* Load string options */
621 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
622 *str_options
[i
].opt_addr
=
623 mc_config_get_string (mc_global
.main_config
, CONFIG_APP_SECTION
,
624 str_options
[i
].opt_name
, str_options
[i
].opt_defval
);
626 /* Overwrite some options */
627 #ifdef USE_INTERNAL_EDIT
628 if (option_word_wrap_line_length
<= 0)
629 option_word_wrap_line_length
= DEFAULT_WRAP_LINE_LENGTH
;
631 /* Reset forced in case of build without internal editor */
632 use_internal_edit
= FALSE
;
633 #endif /* USE_INTERNAL_EDIT */
635 if (option_tab_spacing
<= 0)
636 option_tab_spacing
= DEFAULT_TAB_SPACING
;
638 kt
= getenv ("KEYBOARD_KEY_TIMEOUT_US");
639 if (kt
!= NULL
&& kt
[0] != '\0')
640 old_esc_mode_timeout
= atoi (kt
);
643 /* --------------------------------------------------------------------------------------------- */
645 static panel_view_mode_t
646 setup__load_panel_state (const char *section
)
650 panel_view_mode_t mode
= view_listing
;
652 /* Load the display mode */
653 buffer
= mc_config_get_string (mc_global
.panels_config
, section
, "display", "listing");
655 for (i
= 0; panel_types
[i
].opt_name
!= NULL
; i
++)
656 if (g_ascii_strcasecmp (panel_types
[i
].opt_name
, buffer
) == 0)
658 mode
= panel_types
[i
].opt_type
;
667 /* --------------------------------------------------------------------------------------------- */
674 int first_panel_size
;
677 panels_layout
.horizontal_split
= mc_config_get_int (mc_global
.main_config
, CONFIG_APP_SECTION
,
678 "horizontal_split", 0);
679 equal_split
= mc_config_get_int (mc_global
.main_config
, "Layout", "equal_split", 1);
680 first_panel_size
= mc_config_get_int (mc_global
.main_config
, "Layout", "first_panel_size", 1);
681 if (panels_layout
.horizontal_split
)
683 panels_layout
.horizontal_equal
= equal_split
;
684 panels_layout
.left_panel_size
= first_panel_size
;
688 panels_layout
.vertical_equal
= equal_split
;
689 panels_layout
.top_panel_size
= first_panel_size
;
692 /* actual options override legacy ones */
693 for (i
= 0; layout
[i
].opt_name
!= NULL
; i
++)
694 *layout
[i
].opt_addr
= mc_config_get_int (mc_global
.main_config
, CONFIG_LAYOUT_SECTION
,
695 layout
[i
].opt_name
, *layout
[i
].opt_addr
);
697 /* remove legacy options */
698 mc_config_del_key (mc_global
.main_config
, CONFIG_APP_SECTION
, "horizontal_split");
699 mc_config_del_key (mc_global
.main_config
, "Layout", "equal_split");
700 mc_config_del_key (mc_global
.main_config
, "Layout", "first_panel_size");
702 startup_left_mode
= setup__load_panel_state ("New Left Panel");
703 startup_right_mode
= setup__load_panel_state ("New Right Panel");
705 /* At least one of the panels is a listing panel */
706 if (startup_left_mode
!= view_listing
&& startup_right_mode
!= view_listing
)
707 startup_left_mode
= view_listing
;
709 boot_current_is_left
=
710 mc_config_get_bool (mc_global
.panels_config
, "Dirs", "current_is_left", TRUE
);
713 /* --------------------------------------------------------------------------------------------- */
716 load_keys_from_section (const char *terminal
, mc_config_t
* cfg
)
719 gchar
**profile_keys
, **keys
;
720 char *valcopy
, *value
;
723 if (terminal
== NULL
)
726 section_name
= g_strconcat ("terminal:", terminal
, (char *) NULL
);
727 keys
= mc_config_get_keys (cfg
, section_name
, NULL
);
729 for (profile_keys
= keys
; *profile_keys
!= NULL
; profile_keys
++)
731 /* copy=other causes all keys from [terminal:other] to be loaded. */
732 if (g_ascii_strcasecmp (*profile_keys
, "copy") == 0)
734 valcopy
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
735 load_keys_from_section (valcopy
, cfg
);
740 key_code
= lookup_key (*profile_keys
, NULL
);
745 values
= mc_config_get_string_list (cfg
, section_name
, *profile_keys
, NULL
);
750 for (curr_values
= values
; *curr_values
!= NULL
; curr_values
++)
752 valcopy
= convert_controls (*curr_values
);
753 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
761 value
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
762 valcopy
= convert_controls (value
);
763 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
770 g_free (section_name
);
773 /* --------------------------------------------------------------------------------------------- */
776 load_keymap_from_section (const char *section_name
, GArray
* keymap
, mc_config_t
* cfg
)
778 gchar
**profile_keys
, **keys
;
780 if (section_name
== NULL
)
783 keys
= mc_config_get_keys (cfg
, section_name
, NULL
);
785 for (profile_keys
= keys
; *profile_keys
!= NULL
; profile_keys
++)
789 values
= mc_config_get_string_list (cfg
, section_name
, *profile_keys
, NULL
);
794 action
= keybind_lookup_action (*profile_keys
);
799 for (curr_values
= values
; *curr_values
!= NULL
; curr_values
++)
800 keybind_cmd_bind (keymap
, *curr_values
, action
);
810 /* --------------------------------------------------------------------------------------------- */
813 load_setup_get_keymap_profile_config (gboolean load_from_file
)
816 TODO: IMHO, in future, this function shall be placed in mcconfig module.
818 mc_config_t
*keymap_config
;
819 char *share_keymap
, *sysconfig_keymap
;
820 char *fname
, *fname2
;
822 /* 0) Create default keymap */
823 keymap_config
= create_default_keymap ();
825 return keymap_config
;
827 /* load and merge global keymaps */
829 /* 1) /usr/share/mc (mc_global.share_data_dir) */
830 share_keymap
= g_build_filename (mc_global
.share_data_dir
, GLOBAL_KEYMAP_FILE
, (char *) NULL
);
831 load_setup_init_config_from_file (&keymap_config
, share_keymap
, TRUE
);
833 /* 2) /etc/mc (mc_global.sysconfig_dir) */
835 g_build_filename (mc_global
.sysconfig_dir
, GLOBAL_KEYMAP_FILE
, (char *) NULL
);
836 load_setup_init_config_from_file (&keymap_config
, sysconfig_keymap
, TRUE
);
838 /* then load and merge one of user-defined keymap */
840 /* 3) --keymap=<keymap> */
841 fname
= load_setup_get_full_config_name (NULL
, mc_args__keymap_file
);
842 if (fname
!= NULL
&& strcmp (fname
, sysconfig_keymap
) != 0 && strcmp (fname
, share_keymap
) != 0)
844 load_setup_init_config_from_file (&keymap_config
, fname
, TRUE
);
849 /* 4) getenv("MC_KEYMAP") */
850 fname
= load_setup_get_full_config_name (NULL
, g_getenv ("MC_KEYMAP"));
851 if (fname
!= NULL
&& strcmp (fname
, sysconfig_keymap
) != 0 && strcmp (fname
, share_keymap
) != 0)
853 load_setup_init_config_from_file (&keymap_config
, fname
, TRUE
);
858 /* 5) main config; [Midnight Commander] -> keymap */
859 fname2
= mc_config_get_string (mc_global
.main_config
, CONFIG_APP_SECTION
, "keymap", NULL
);
860 if (fname2
!= NULL
&& *fname2
!= '\0')
861 fname
= load_setup_get_full_config_name (NULL
, fname2
);
863 if (fname
!= NULL
&& strcmp (fname
, sysconfig_keymap
) != 0 && strcmp (fname
, share_keymap
) != 0)
865 load_setup_init_config_from_file (&keymap_config
, fname
, TRUE
);
870 /* 6) ${XDG_CONFIG_HOME}/mc/mc.keymap */
871 fname
= mc_config_get_full_path (GLOBAL_KEYMAP_FILE
);
872 load_setup_init_config_from_file (&keymap_config
, fname
, TRUE
);
876 g_free (sysconfig_keymap
);
877 g_free (share_keymap
);
879 return keymap_config
;
882 /* --------------------------------------------------------------------------------------------- */
885 panel_save_type (const char *section
, panel_view_mode_t type
)
889 for (i
= 0; panel_types
[i
].opt_name
!= NULL
; i
++)
890 if (panel_types
[i
].opt_type
== type
)
892 mc_config_set_string (mc_global
.panels_config
, section
, "display",
893 panel_types
[i
].opt_name
);
898 /* --------------------------------------------------------------------------------------------- */
901 * Load panels options from [Panels] section.
904 panels_load_options (void)
906 if (mc_config_has_group (mc_global
.main_config
, CONFIG_PANELS_SECTION
))
911 for (i
= 0; panels_ini_options
[i
].opt_name
!= NULL
; i
++)
912 *panels_ini_options
[i
].opt_addr
=
913 mc_config_get_bool (mc_global
.main_config
, CONFIG_PANELS_SECTION
,
914 panels_ini_options
[i
].opt_name
,
915 *panels_ini_options
[i
].opt_addr
);
917 qmode
= mc_config_get_int (mc_global
.main_config
, CONFIG_PANELS_SECTION
,
918 "quick_search_mode", (int) panels_options
.qsearch_mode
);
920 panels_options
.qsearch_mode
= QSEARCH_CASE_INSENSITIVE
;
921 else if (qmode
>= QSEARCH_NUM
)
922 panels_options
.qsearch_mode
= QSEARCH_PANEL_CASE
;
924 panels_options
.qsearch_mode
= (qsearch_mode_t
) qmode
;
926 panels_options
.select_flags
=
927 mc_config_get_int (mc_global
.main_config
, CONFIG_PANELS_SECTION
, "select_flags",
928 (int) panels_options
.select_flags
);
932 /* --------------------------------------------------------------------------------------------- */
935 * Save panels options in [Panels] section.
938 panels_save_options (void)
942 for (i
= 0; panels_ini_options
[i
].opt_name
!= NULL
; i
++)
943 mc_config_set_bool (mc_global
.main_config
, CONFIG_PANELS_SECTION
,
944 panels_ini_options
[i
].opt_name
, *panels_ini_options
[i
].opt_addr
);
946 mc_config_set_int (mc_global
.main_config
, CONFIG_PANELS_SECTION
,
947 "quick_search_mode", (int) panels_options
.qsearch_mode
);
948 mc_config_set_int (mc_global
.main_config
, CONFIG_PANELS_SECTION
,
949 "select_flags", (int) panels_options
.select_flags
);
952 /* --------------------------------------------------------------------------------------------- */
959 /* Save boolean options */
960 for (i
= 0; bool_options
[i
].opt_name
!= NULL
; i
++)
961 mc_config_set_bool (mc_global
.main_config
, CONFIG_APP_SECTION
, bool_options
[i
].opt_name
,
962 *bool_options
[i
].opt_addr
);
964 /* Save integer options */
965 for (i
= 0; int_options
[i
].opt_name
!= NULL
; i
++)
966 mc_config_set_int (mc_global
.main_config
, CONFIG_APP_SECTION
, int_options
[i
].opt_name
,
967 *int_options
[i
].opt_addr
);
969 /* Save string options */
970 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
971 mc_config_set_string (mc_global
.main_config
, CONFIG_APP_SECTION
, str_options
[i
].opt_name
,
972 *str_options
[i
].opt_addr
);
975 /* --------------------------------------------------------------------------------------------- */
982 /* Save integer options */
983 for (i
= 0; layout
[i
].opt_name
!= NULL
; i
++)
984 mc_config_set_int (mc_global
.main_config
, CONFIG_LAYOUT_SECTION
, layout
[i
].opt_name
,
985 *layout
[i
].opt_addr
);
988 /* --------------------------------------------------------------------------------------------- */
990 /* save panels.ini */
992 save_panel_types (void)
994 panel_view_mode_t type
;
996 if (mc_global
.mc_run_mode
!= MC_RUN_FULL
)
999 type
= get_display_type (0);
1000 panel_save_type ("New Left Panel", type
);
1001 if (type
== view_listing
)
1002 panel_save_setup (left_panel
, left_panel
->panel_name
);
1003 type
= get_display_type (1);
1004 panel_save_type ("New Right Panel", type
);
1005 if (type
== view_listing
)
1006 panel_save_setup (right_panel
, right_panel
->panel_name
);
1011 dirs
= get_panel_dir_for (other_panel
);
1012 mc_config_set_string (mc_global
.panels_config
, "Dirs", "other_dir", dirs
);
1016 if (current_panel
!= NULL
)
1017 mc_config_set_bool (mc_global
.panels_config
, "Dirs", "current_is_left",
1018 get_current_index () == 0);
1020 if (mc_global
.panels_config
->ini_path
== NULL
)
1021 mc_global
.panels_config
->ini_path
= g_strdup (panels_profile_name
);
1023 mc_config_del_group (mc_global
.panels_config
, "Temporal:New Left Panel");
1024 mc_config_del_group (mc_global
.panels_config
, "Temporal:New Right Panel");
1026 mc_config_save_file (mc_global
.panels_config
, NULL
);
1029 /* --------------------------------------------------------------------------------------------- */
1030 /*** public functions ****************************************************************************/
1031 /* --------------------------------------------------------------------------------------------- */
1036 if (profile_name
== NULL
)
1040 profile
= mc_config_get_full_path (MC_CONFIG_FILE
);
1041 if (!exist_file (profile
))
1045 inifile
= mc_build_filename (mc_global
.sysconfig_dir
, "mc.ini", (char *) NULL
);
1046 if (exist_file (inifile
))
1054 inifile
= mc_build_filename (mc_global
.share_data_dir
, "mc.ini", (char *) NULL
);
1055 if (!exist_file (inifile
))
1065 profile_name
= profile
;
1068 return profile_name
;
1071 /* --------------------------------------------------------------------------------------------- */
1076 const char *profile
;
1080 const char *cbuffer
;
1082 load_codepages_list ();
1083 #endif /* HAVE_CHARSET */
1085 profile
= setup_init ();
1087 /* mc.lib is common for all users, but has priority lower than
1088 ${XDG_CONFIG_HOME}/mc/ini. FIXME: it's only used for keys and treestore now */
1089 global_profile_name
=
1090 g_build_filename (mc_global
.sysconfig_dir
, MC_GLOBAL_CONFIG_FILE
, (char *) NULL
);
1091 if (!exist_file (global_profile_name
))
1093 g_free (global_profile_name
);
1094 global_profile_name
=
1095 g_build_filename (mc_global
.share_data_dir
, MC_GLOBAL_CONFIG_FILE
, (char *) NULL
);
1098 panels_profile_name
= mc_config_get_full_path (MC_PANELS_FILE
);
1100 mc_global
.main_config
= mc_config_init (profile
, FALSE
);
1102 if (!exist_file (panels_profile_name
))
1103 setup__move_panels_config_into_separate_file (profile
);
1105 mc_global
.panels_config
= mc_config_init (panels_profile_name
, FALSE
);
1109 panels_load_options ();
1112 /* Load time formats */
1113 user_recent_timeformat
=
1114 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "timeformat_recent",
1116 user_old_timeformat
=
1117 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "timeformat_old",
1120 #ifdef ENABLE_VFS_FTP
1122 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "ftp_proxy_host", "gate");
1123 ftpfs_init_passwd ();
1124 #endif /* ENABLE_VFS_FTP */
1126 /* The default color and the terminal dependent color */
1127 mc_global
.tty
.setup_color_string
=
1128 mc_config_get_string (mc_global
.main_config
, "Colors", "base_color", "");
1129 mc_global
.tty
.term_color_string
=
1130 mc_config_get_string (mc_global
.main_config
, "Colors", getenv ("TERM"), "");
1131 mc_global
.tty
.color_terminal_string
=
1132 mc_config_get_string (mc_global
.main_config
, "Colors", "color_terminals", "");
1134 /* Load the directory history */
1135 /* directory_history_load (); */
1136 /* Remove the temporal entries */
1139 if (codepages
->len
> 1)
1142 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "display_codepage",
1144 if (buffer
[0] != '\0')
1146 mc_global
.display_codepage
= get_codepage_index (buffer
);
1147 cp_display
= get_codepage_id (mc_global
.display_codepage
);
1151 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "source_codepage",
1153 if (buffer
[0] != '\0')
1155 default_source_codepage
= get_codepage_index (buffer
);
1156 mc_global
.source_codepage
= default_source_codepage
; /* May be source_codepage doesn't need this */
1157 cp_source
= get_codepage_id (mc_global
.source_codepage
);
1162 autodetect_codeset
=
1163 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "autodetect_codeset", "");
1164 if ((autodetect_codeset
[0] != '\0') && (strcmp (autodetect_codeset
, "off") != 0))
1165 is_autodetect_codeset_enabled
= TRUE
;
1167 g_free (init_translation_table (mc_global
.source_codepage
, mc_global
.display_codepage
));
1168 cbuffer
= get_codepage_id (mc_global
.display_codepage
);
1169 if (cbuffer
!= NULL
)
1170 mc_global
.utf8_display
= str_isutf8 (cbuffer
);
1171 #endif /* HAVE_CHARSET */
1175 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "spell_language", "en");
1176 #endif /* HAVE_ASPELL */
1178 clipboard_store_path
=
1179 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "clipboard_store", "");
1180 clipboard_paste_path
=
1181 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "clipboard_paste", "");
1184 /* --------------------------------------------------------------------------------------------- */
1187 save_setup (gboolean save_options
, gboolean save_panel_options
)
1189 gboolean ret
= TRUE
;
1195 if (save_panel_options
)
1196 save_panel_types ();
1204 panels_save_options ();
1206 /* directory_history_save (); */
1208 #ifdef ENABLE_VFS_FTP
1209 mc_config_set_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "ftpfs_password",
1210 ftpfs_anonymous_passwd
);
1211 if (ftpfs_proxy_host
)
1212 mc_config_set_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "ftp_proxy_host",
1214 #endif /* ENABLE_VFS_FTP */
1217 mc_config_set_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "display_codepage",
1218 get_codepage_id (mc_global
.display_codepage
));
1219 mc_config_set_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "source_codepage",
1220 get_codepage_id (default_source_codepage
));
1221 mc_config_set_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "autodetect_codeset",
1222 autodetect_codeset
);
1223 #endif /* HAVE_CHARSET */
1226 mc_config_set_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "spell_language",
1228 #endif /* HAVE_ASPELL */
1230 mc_config_set_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "clipboard_store",
1231 clipboard_store_path
);
1232 mc_config_set_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "clipboard_paste",
1233 clipboard_paste_path
);
1235 tmp_profile
= mc_config_get_full_path (MC_CONFIG_FILE
);
1236 ret
= mc_config_save_to_file (mc_global
.main_config
, tmp_profile
, NULL
);
1237 g_free (tmp_profile
);
1245 /* --------------------------------------------------------------------------------------------- */
1252 g_free (clipboard_store_path
);
1253 g_free (clipboard_paste_path
);
1254 g_free (global_profile_name
);
1255 g_free (mc_global
.tty
.color_terminal_string
);
1256 g_free (mc_global
.tty
.term_color_string
);
1257 g_free (mc_global
.tty
.setup_color_string
);
1258 g_free (profile_name
);
1259 g_free (panels_profile_name
);
1260 mc_config_deinit (mc_global
.main_config
);
1261 mc_config_deinit (mc_global
.panels_config
);
1263 g_free (user_recent_timeformat
);
1264 g_free (user_old_timeformat
);
1266 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
1267 g_free (*str_options
[i
].opt_addr
);
1271 /* directory_history_free (); */
1274 g_free (autodetect_codeset
);
1275 free_codepages_list ();
1279 g_free (spell_language
);
1280 #endif /* HAVE_ASPELL */
1284 /* --------------------------------------------------------------------------------------------- */
1287 setup_save_config_show_error (const char *filename
, GError
** mcerror
)
1289 if (mcerror
!= NULL
&& *mcerror
!= NULL
)
1291 message (D_ERROR
, MSG_ERROR
, _("Cannot save file %s:\n%s"), filename
, (*mcerror
)->message
);
1292 g_error_free (*mcerror
);
1298 /* --------------------------------------------------------------------------------------------- */
1301 load_key_defs (void)
1304 * Load keys from mc.lib before ${XDG_CONFIG_HOME}/mc/ini, so that the user
1305 * definitions override global settings.
1307 mc_config_t
*mc_global_config
;
1309 mc_global_config
= mc_config_init (global_profile_name
, FALSE
);
1310 if (mc_global_config
!= NULL
)
1312 load_keys_from_section ("general", mc_global_config
);
1313 load_keys_from_section (getenv ("TERM"), mc_global_config
);
1314 mc_config_deinit (mc_global_config
);
1317 load_keys_from_section ("general", mc_global
.main_config
);
1318 load_keys_from_section (getenv ("TERM"), mc_global
.main_config
);
1321 /* --------------------------------------------------------------------------------------------- */
1323 #ifdef ENABLE_VFS_FTP
1325 load_anon_passwd (void)
1330 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "ftpfs_password", "");
1332 if ((buffer
!= NULL
) && (buffer
[0] != '\0'))
1338 #endif /* ENABLE_VFS_FTP */
1340 /* --------------------------------------------------------------------------------------------- */
1343 load_keymap_defs (gboolean load_from_file
)
1346 * Load keymap from GLOBAL_KEYMAP_FILE before ${XDG_CONFIG_HOME}/mc/mc.keymap, so that the user
1347 * definitions override global settings.
1349 mc_config_t
*mc_global_keymap
;
1351 mc_global_keymap
= load_setup_get_keymap_profile_config (load_from_file
);
1353 if (mc_global_keymap
!= NULL
)
1355 main_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1356 load_keymap_from_section (KEYMAP_SECTION_MAIN
, main_keymap
, mc_global_keymap
);
1357 main_x_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1358 load_keymap_from_section (KEYMAP_SECTION_MAIN_EXT
, main_x_keymap
, mc_global_keymap
);
1360 panel_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1361 load_keymap_from_section (KEYMAP_SECTION_PANEL
, panel_keymap
, mc_global_keymap
);
1363 dialog_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1364 load_keymap_from_section (KEYMAP_SECTION_DIALOG
, dialog_keymap
, mc_global_keymap
);
1366 input_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1367 load_keymap_from_section (KEYMAP_SECTION_INPUT
, input_keymap
, mc_global_keymap
);
1369 listbox_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1370 load_keymap_from_section (KEYMAP_SECTION_LISTBOX
, listbox_keymap
, mc_global_keymap
);
1372 tree_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1373 load_keymap_from_section (KEYMAP_SECTION_TREE
, tree_keymap
, mc_global_keymap
);
1375 help_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1376 load_keymap_from_section (KEYMAP_SECTION_HELP
, help_keymap
, mc_global_keymap
);
1378 #ifdef USE_INTERNAL_EDIT
1379 editor_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1380 load_keymap_from_section (KEYMAP_SECTION_EDITOR
, editor_keymap
, mc_global_keymap
);
1381 editor_x_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1382 load_keymap_from_section (KEYMAP_SECTION_EDITOR_EXT
, editor_x_keymap
, mc_global_keymap
);
1385 viewer_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1386 load_keymap_from_section (KEYMAP_SECTION_VIEWER
, viewer_keymap
, mc_global_keymap
);
1387 viewer_hex_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1388 load_keymap_from_section (KEYMAP_SECTION_VIEWER_HEX
, viewer_hex_keymap
, mc_global_keymap
);
1390 #ifdef USE_DIFF_VIEW
1391 diff_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1392 load_keymap_from_section (KEYMAP_SECTION_DIFFVIEWER
, diff_keymap
, mc_global_keymap
);
1395 mc_config_deinit (mc_global_keymap
);
1398 main_map
= (global_keymap_t
*) main_keymap
->data
;
1399 main_x_map
= (global_keymap_t
*) main_x_keymap
->data
;
1400 panel_map
= (global_keymap_t
*) panel_keymap
->data
;
1401 dialog_map
= (global_keymap_t
*) dialog_keymap
->data
;
1402 input_map
= (global_keymap_t
*) input_keymap
->data
;
1403 listbox_map
= (global_keymap_t
*) listbox_keymap
->data
;
1404 tree_map
= (global_keymap_t
*) tree_keymap
->data
;
1405 help_map
= (global_keymap_t
*) help_keymap
->data
;
1406 #ifdef USE_INTERNAL_EDIT
1407 editor_map
= (global_keymap_t
*) editor_keymap
->data
;
1408 editor_x_map
= (global_keymap_t
*) editor_x_keymap
->data
;
1410 viewer_map
= (global_keymap_t
*) viewer_keymap
->data
;
1411 viewer_hex_map
= (global_keymap_t
*) viewer_hex_keymap
->data
;
1412 #ifdef USE_DIFF_VIEW
1413 diff_map
= (global_keymap_t
*) diff_keymap
->data
;
1417 /* --------------------------------------------------------------------------------------------- */
1420 free_keymap_defs (void)
1422 if (main_keymap
!= NULL
)
1423 g_array_free (main_keymap
, TRUE
);
1424 if (main_x_keymap
!= NULL
)
1425 g_array_free (main_x_keymap
, TRUE
);
1426 if (panel_keymap
!= NULL
)
1427 g_array_free (panel_keymap
, TRUE
);
1428 if (dialog_keymap
!= NULL
)
1429 g_array_free (dialog_keymap
, TRUE
);
1430 if (input_keymap
!= NULL
)
1431 g_array_free (input_keymap
, TRUE
);
1432 if (listbox_keymap
!= NULL
)
1433 g_array_free (listbox_keymap
, TRUE
);
1434 if (tree_keymap
!= NULL
)
1435 g_array_free (tree_keymap
, TRUE
);
1436 if (help_keymap
!= NULL
)
1437 g_array_free (help_keymap
, TRUE
);
1438 #ifdef USE_INTERNAL_EDIT
1439 if (editor_keymap
!= NULL
)
1440 g_array_free (editor_keymap
, TRUE
);
1441 if (editor_x_keymap
!= NULL
)
1442 g_array_free (editor_x_keymap
, TRUE
);
1444 if (viewer_keymap
!= NULL
)
1445 g_array_free (viewer_keymap
, TRUE
);
1446 if (viewer_hex_keymap
!= NULL
)
1447 g_array_free (viewer_hex_keymap
, TRUE
);
1448 #ifdef USE_DIFF_VIEW
1449 if (diff_keymap
!= NULL
)
1450 g_array_free (diff_keymap
, TRUE
);
1454 /* --------------------------------------------------------------------------------------------- */
1457 panel_load_setup (WPanel
* panel
, const char *section
)
1460 char *buffer
, buffer2
[BUF_TINY
];
1462 panel
->sort_info
.reverse
=
1463 mc_config_get_bool (mc_global
.panels_config
, section
, "reverse", FALSE
);
1464 panel
->sort_info
.case_sensitive
=
1465 mc_config_get_bool (mc_global
.panels_config
, section
, "case_sensitive",
1466 OS_SORT_CASE_SENSITIVE_DEFAULT
);
1467 panel
->sort_info
.exec_first
=
1468 mc_config_get_bool (mc_global
.panels_config
, section
, "exec_first", FALSE
);
1470 /* Load sort order */
1471 buffer
= mc_config_get_string (mc_global
.panels_config
, section
, "sort_order", "name");
1472 panel
->sort_field
= panel_get_field_by_id (buffer
);
1473 if (panel
->sort_field
== NULL
)
1474 panel
->sort_field
= panel_get_field_by_id ("name");
1478 /* Load the listing format */
1479 buffer
= mc_config_get_string (mc_global
.panels_config
, section
, "list_format", NULL
);
1482 /* fallback to old option */
1483 buffer
= mc_config_get_string (mc_global
.panels_config
, section
, "list_mode", "full");
1485 panel
->list_format
= list_full
;
1486 for (i
= 0; list_formats
[i
].key
!= NULL
; i
++)
1487 if (g_ascii_strcasecmp (list_formats
[i
].key
, buffer
) == 0)
1489 panel
->list_format
= list_formats
[i
].list_format
;
1494 panel
->brief_cols
= mc_config_get_int (mc_global
.panels_config
, section
, "brief_cols", 2);
1497 g_free (panel
->user_format
);
1498 panel
->user_format
=
1499 mc_config_get_string (mc_global
.panels_config
, section
, "user_format", DEFAULT_USER_FORMAT
);
1501 for (i
= 0; i
< LIST_FORMATS
; i
++)
1503 g_free (panel
->user_status_format
[i
]);
1504 g_snprintf (buffer2
, sizeof (buffer2
), "user_status%lld", (long long) i
);
1505 panel
->user_status_format
[i
] =
1506 mc_config_get_string (mc_global
.panels_config
, section
, buffer2
, DEFAULT_USER_FORMAT
);
1509 panel
->user_mini_status
=
1510 mc_config_get_bool (mc_global
.panels_config
, section
, "user_mini_status", FALSE
);
1513 /* --------------------------------------------------------------------------------------------- */
1516 panel_save_setup (WPanel
* panel
, const char *section
)
1518 char buffer
[BUF_TINY
];
1521 mc_config_set_bool (mc_global
.panels_config
, section
, "reverse", panel
->sort_info
.reverse
);
1522 mc_config_set_bool (mc_global
.panels_config
, section
, "case_sensitive",
1523 panel
->sort_info
.case_sensitive
);
1524 mc_config_set_bool (mc_global
.panels_config
, section
, "exec_first",
1525 panel
->sort_info
.exec_first
);
1527 mc_config_set_string (mc_global
.panels_config
, section
, "sort_order", panel
->sort_field
->id
);
1529 for (i
= 0; list_formats
[i
].key
!= NULL
; i
++)
1530 if (list_formats
[i
].list_format
== (int) panel
->list_format
)
1532 mc_config_set_string (mc_global
.panels_config
, section
, "list_format",
1533 list_formats
[i
].key
);
1537 mc_config_set_int (mc_global
.panels_config
, section
, "brief_cols", panel
->brief_cols
);
1539 mc_config_set_string (mc_global
.panels_config
, section
, "user_format", panel
->user_format
);
1541 for (i
= 0; i
< LIST_FORMATS
; i
++)
1543 g_snprintf (buffer
, sizeof (buffer
), "user_status%lld", (long long) i
);
1544 mc_config_set_string (mc_global
.panels_config
, section
, buffer
,
1545 panel
->user_status_format
[i
]);
1548 mc_config_set_bool (mc_global
.panels_config
, section
, "user_mini_status",
1549 panel
->user_mini_status
);
1552 /* --------------------------------------------------------------------------------------------- */