4 Copyright (C) 1994-2017
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
;
91 /* Controls screen clearing before an exec */
92 gboolean clear_before_exec
= TRUE
;
94 /* Asks for confirmation before deleting a file */
95 gboolean confirm_delete
= TRUE
;
96 /* Asks for confirmation before deleting a hotlist entry */
97 gboolean confirm_directory_hotlist_delete
= FALSE
;
98 /* Asks for confirmation before overwriting a file */
99 gboolean confirm_overwrite
= TRUE
;
100 /* Asks for confirmation before executing a program by pressing enter */
101 gboolean confirm_execute
= FALSE
;
102 /* Asks for confirmation before leaving the program */
103 gboolean confirm_exit
= FALSE
;
105 /* If true, at startup the user-menu is invoked */
106 gboolean auto_menu
= FALSE
;
107 /* This flag indicates if the pull down menus by default drop down */
108 gboolean drop_menus
= FALSE
;
110 /* Asks for confirmation when using F3 to view a directory and there
112 gboolean confirm_view_dir
= FALSE
;
114 /* Ask file name before start the editor */
115 gboolean editor_ask_filename_before_edit
= FALSE
;
117 panel_view_mode_t startup_left_mode
;
118 panel_view_mode_t startup_right_mode
;
120 gboolean copymove_persistent_attr
= TRUE
;
123 int option_tab_spacing
= DEFAULT_TAB_SPACING
;
125 /* Ugly hack to allow panel_save_setup to work as a place holder for */
126 /* default panel values */
129 panels_options_t panels_options
= {
130 .show_mini_info
= TRUE
,
131 .kilobyte_si
= FALSE
,
132 .mix_all_files
= FALSE
,
133 .show_backups
= TRUE
,
134 .show_dot_files
= TRUE
,
135 .fast_reload
= FALSE
,
136 .fast_reload_msg_shown
= FALSE
,
137 .mark_moves_down
= TRUE
,
138 .reverse_files_only
= TRUE
,
139 .auto_save_setup
= FALSE
,
140 .navigate_with_arrows
= FALSE
,
141 .scroll_pages
= TRUE
,
142 .scroll_center
= FALSE
,
143 .mouse_move_pages
= TRUE
,
144 .filetype_mode
= TRUE
,
145 .permission_mode
= FALSE
,
146 .qsearch_mode
= QSEARCH_PANEL_CASE
,
147 .torben_fj_mode
= FALSE
,
148 .select_flags
= SELECT_MATCH_CASE
| SELECT_SHELL_PATTERNS
151 gboolean easy_patterns
= TRUE
;
153 /* It true saves the setup when quitting */
154 gboolean auto_save_setup
= TRUE
;
156 /* If true, then the +, - and \ keys have their special meaning only if the
157 * command line is emtpy, otherwise they behave like regular letters
159 gboolean only_leading_plus_minus
= TRUE
;
161 /* Automatically fills name with current selected item name on mkdir */
162 gboolean auto_fill_mkdir_name
= TRUE
;
164 /* If set and you don't have subshell support,then C-o will give you a shell */
165 gboolean output_starts_shell
= FALSE
;
167 /* If set, we execute the file command to check the file type */
168 gboolean use_file_to_check_type
= TRUE
;
170 gboolean verbose
= TRUE
;
173 * Whether the Midnight Commander tries to provide more
174 * information about copy/move sizes and bytes transferred
175 * at the expense of some speed
177 gboolean file_op_compute_totals
= TRUE
;
179 /* If true use the internal viewer */
180 gboolean use_internal_view
= TRUE
;
181 /* If set, use the builtin editor */
182 gboolean use_internal_edit
= TRUE
;
185 /* Numbers of (file I/O) and (input/display) codepages. -1 if not selected */
186 int default_source_codepage
= -1;
187 char *autodetect_codeset
= NULL
;
188 gboolean is_autodetect_codeset_enabled
= FALSE
;
189 #endif /* !HAVE_CHARSET */
192 char *spell_language
= NULL
;
195 /* Value of "other_dir" key in ini file */
196 char *saved_other_dir
= NULL
;
198 /* If set, then print to the given file the last directory we were at */
199 char *last_wd_string
= NULL
;
201 /* Set when main loop should be terminated */
204 /* Set to TRUE to suppress printing the last directory */
205 int print_last_revert
= FALSE
;
207 #ifdef USE_INTERNAL_EDIT
208 /* index to record_macro_buf[], -1 if not recording a macro */
209 int macro_index
= -1;
212 struct macro_action_t record_macro_buf
[MAX_MACRO_LENGTH
];
215 #endif /* USE_INTERNAL_EDIT */
217 /*** file scope macro definitions ****************************************************************/
219 /* In order to use everywhere the same setup for the locale we use defines */
220 #define FMTYEAR _("%b %e %Y")
221 #define FMTTIME _("%b %e %H:%M")
223 /*** file scope type declarations ****************************************************************/
225 /*** file scope variables ************************************************************************/
227 static char *profile_name
= NULL
; /* ${XDG_CONFIG_HOME}/mc/ini */
228 static char *panels_profile_name
= NULL
; /* ${XDG_CACHE_HOME}/mc/panels.ini */
236 { "full", list_full
},
237 { "brief", list_brief
},
238 { "long", list_long
},
239 { "user", list_user
},
245 const char *opt_name
;
246 panel_view_mode_t opt_type
;
248 { "listing", view_listing
},
249 { "quickview", view_quick
},
250 { "info", view_info
},
251 { "tree", view_tree
},
252 { NULL
, view_listing
}
257 const char *opt_name
;
260 { "message_visible", &mc_global
.message_visible
},
261 { "keybar_visible", &mc_global
.keybar_visible
},
262 { "xterm_title", &xterm_title
},
263 { "output_lines", &output_lines
},
264 { "command_prompt", &command_prompt
},
265 { "menubar_visible", &menubar_visible
},
266 { "free_space", &free_space
},
267 { "horizontal_split", &panels_layout
.horizontal_split
},
268 { "vertical_equal", &panels_layout
.vertical_equal
},
269 { "left_panel_size", &panels_layout
.left_panel_size
},
270 { "horizontal_equal", &panels_layout
.horizontal_equal
},
271 { "top_panel_size", &panels_layout
.top_panel_size
},
277 const char *opt_name
;
279 } bool_options
[] = {
280 { "verbose", &verbose
},
281 { "shell_patterns", &easy_patterns
},
282 { "auto_save_setup", &auto_save_setup
},
283 { "preallocate_space", &mc_global
.vfs
.preallocate_space
},
284 { "auto_menu", &auto_menu
},
285 { "use_internal_view", &use_internal_view
},
286 { "use_internal_edit", &use_internal_edit
},
287 { "clear_before_exec", &clear_before_exec
},
288 { "confirm_delete", &confirm_delete
},
289 { "confirm_overwrite", &confirm_overwrite
},
290 { "confirm_execute", &confirm_execute
},
291 { "confirm_history_cleanup", &mc_global
.widget
.confirm_history_cleanup
},
292 { "confirm_exit", &confirm_exit
},
293 { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete
},
294 { "confirm_view_dir", &confirm_view_dir
},
295 { "safe_delete", &safe_delete
},
297 { "eight_bit_clean", &mc_global
.eight_bit_clean
},
298 { "full_eight_bits", &mc_global
.full_eight_bits
},
299 #endif /* !HAVE_CHARSET */
300 { "use_8th_bit_as_meta", &use_8th_bit_as_meta
},
301 { "mouse_move_pages_viewer", &mcview_mouse_move_pages
},
302 { "mouse_close_dialog", &mouse_close_dialog
},
303 { "fast_refresh", &fast_refresh
},
304 { "drop_menus", &drop_menus
},
305 { "wrap_mode", &mcview_global_wrap_mode
},
306 { "old_esc_mode", &old_esc_mode
},
307 { "cd_symlinks", &mc_global
.vfs
.cd_symlinks
},
308 { "show_all_if_ambiguous", &mc_global
.widget
.show_all_if_ambiguous
},
309 { "use_file_to_guess_type", &use_file_to_check_type
},
310 { "alternate_plus_minus", &mc_global
.tty
.alternate_plus_minus
},
311 { "only_leading_plus_minus", &only_leading_plus_minus
},
312 { "show_output_starts_shell", &output_starts_shell
},
313 { "xtree_mode", &xtree_mode
},
314 { "file_op_compute_totals", &file_op_compute_totals
},
315 { "classic_progressbar", &classic_progressbar
},
317 #ifdef ENABLE_VFS_FTP
318 { "use_netrc", &ftpfs_use_netrc
},
319 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy
},
320 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections
},
321 { "ftpfs_use_passive_connections_over_proxy", &ftpfs_use_passive_connections_over_proxy
},
322 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options
},
323 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls
},
324 { "ignore_ftp_chattr_errors", & ftpfs_ignore_chattr_errors
} ,
325 #endif /* ENABLE_VFS_FTP */
326 #endif /* ENABLE_VFS */
327 #ifdef USE_INTERNAL_EDIT
328 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces
},
329 { "editor_return_does_auto_indent", &option_return_does_auto_indent
},
330 { "editor_backspace_through_tabs", &option_backspace_through_tabs
},
331 { "editor_fake_half_tabs", &option_fake_half_tabs
},
332 { "editor_option_save_position", &option_save_position
},
333 { "editor_option_auto_para_formatting", &option_auto_para_formatting
},
334 { "editor_option_typewriter_wrap", &option_typewriter_wrap
},
335 { "editor_edit_confirm_save", &edit_confirm_save
},
336 { "editor_syntax_highlighting", &option_syntax_highlighting
},
337 { "editor_persistent_selections", &option_persistent_selections
},
338 { "editor_drop_selection_on_copy", &option_drop_selection_on_copy
},
339 { "editor_cursor_beyond_eol", &option_cursor_beyond_eol
},
340 { "editor_cursor_after_inserted_block", &option_cursor_after_inserted_block
},
341 { "editor_visible_tabs", &visible_tabs
},
342 { "editor_visible_spaces", &visible_tws
},
343 { "editor_line_state", &option_line_state
},
344 { "editor_simple_statusbar", &simple_statusbar
},
345 { "editor_check_new_line", &option_check_nl_at_eof
},
346 { "editor_show_right_margin", &show_right_margin
},
347 { "editor_group_undo", &option_group_undo
},
348 { "editor_state_full_filename", &option_state_full_filename
},
349 #endif /* USE_INTERNAL_EDIT */
350 { "editor_ask_filename_before_edit", &editor_ask_filename_before_edit
},
351 { "nice_rotating_dash", &nice_rotating_dash
},
352 { "mcview_remember_file_position", &mcview_remember_file_position
},
353 { "auto_fill_mkdir_name", &auto_fill_mkdir_name
},
354 { "copymove_persistent_attr", ©move_persistent_attr
},
360 const char *opt_name
;
363 { "pause_after_run", &pause_after_run
},
364 { "mouse_repeat_rate", &mou_auto_repeat
},
365 { "double_click_speed", &double_click_speed
},
366 { "old_esc_mode_timeout", &old_esc_mode_timeout
},
367 { "max_dirt_limit", &mcview_max_dirt_limit
},
368 { "num_history_items_recorded", &num_history_items_recorded
},
370 { "vfs_timeout", &vfs_timeout
},
371 #ifdef ENABLE_VFS_FTP
372 { "ftpfs_directory_timeout", &ftpfs_directory_timeout
},
373 { "ftpfs_retry_seconds", &ftpfs_retry_seconds
},
374 #endif /* ENABLE_VFS_FTP */
375 #ifdef ENABLE_VFS_FISH
376 { "fish_directory_timeout", &fish_directory_timeout
},
377 #endif /* ENABLE_VFS_FISH */
378 #endif /* ENABLE_VFS */
379 /* option_tab_spacing is used in internal viewer */
380 { "editor_tab_spacing", &option_tab_spacing
},
381 #ifdef USE_INTERNAL_EDIT
382 { "editor_word_wrap_line_length", &option_word_wrap_line_length
},
383 { "editor_option_save_mode", &option_save_mode
},
384 #endif /* USE_INTERNAL_EDIT */
390 const char *opt_name
;
392 const char *opt_defval
;
394 #ifdef USE_INTERNAL_EDIT
395 { "editor_backup_extension", &option_backup_ext
, "~" },
396 { "editor_filesize_threshold", &option_filesize_threshold
, "64M" },
397 { "editor_stop_format_chars", &option_stop_format_chars
, "-+*\\,.;:&>" },
399 { "mcview_eof", &mcview_show_eof
, "" },
405 const char *opt_name
;
407 } panels_ini_options
[] = {
408 { "show_mini_info", &panels_options
.show_mini_info
},
409 { "kilobyte_si", &panels_options
.kilobyte_si
},
410 { "mix_all_files", &panels_options
.mix_all_files
},
411 { "show_backups", &panels_options
.show_backups
},
412 { "show_dot_files", &panels_options
.show_dot_files
},
413 { "fast_reload", &panels_options
.fast_reload
},
414 { "fast_reload_msg_shown", &panels_options
.fast_reload_msg_shown
},
415 { "mark_moves_down", &panels_options
.mark_moves_down
},
416 { "reverse_files_only", &panels_options
.reverse_files_only
},
417 { "auto_save_setup_panels", &panels_options
.auto_save_setup
},
418 { "navigate_with_arrows", &panels_options
.navigate_with_arrows
},
419 { "panel_scroll_pages", &panels_options
.scroll_pages
},
420 { "panel_scroll_center", &panels_options
.scroll_center
},
421 { "mouse_move_pages", &panels_options
.mouse_move_pages
},
422 { "filetype_mode", &panels_options
.filetype_mode
},
423 { "permission_mode", &panels_options
.permission_mode
},
424 { "torben_fj_mode", &panels_options
.torben_fj_mode
},
429 /*** file scope functions ************************************************************************/
430 /* --------------------------------------------------------------------------------------------- */
433 * Get name of config file.
435 * @param subdir If not NULL, config is also searched in specified subdir.
436 * @param config_file_name If relative, file if searched in standard paths.
438 * @return newly allocated string with config name or NULL if file is not found.
442 load_setup_get_full_config_name (const char *subdir
, const char *config_file_name
)
445 TODO: IMHO, in future, this function shall be placed in mcconfig module.
447 char *lc_basename
, *ret
;
450 if (config_file_name
== NULL
)
453 /* check for .keymap suffix */
454 if (g_str_has_suffix (config_file_name
, ".keymap"))
455 file_name
= g_strdup (config_file_name
);
457 file_name
= g_strconcat (config_file_name
, ".keymap", (char *) NULL
);
459 canonicalize_pathname (file_name
);
461 if (g_path_is_absolute (file_name
))
464 lc_basename
= g_path_get_basename (file_name
);
467 if (lc_basename
== NULL
)
471 ret
= g_build_filename (mc_config_get_path (), subdir
, lc_basename
, (char *) NULL
);
473 ret
= g_build_filename (mc_config_get_path (), lc_basename
, (char *) NULL
);
475 if (exist_file (ret
))
477 g_free (lc_basename
);
478 canonicalize_pathname (ret
);
484 ret
= g_build_filename (mc_global
.sysconfig_dir
, subdir
, lc_basename
, (char *) NULL
);
486 ret
= g_build_filename (mc_global
.sysconfig_dir
, lc_basename
, (char *) NULL
);
488 if (exist_file (ret
))
490 g_free (lc_basename
);
491 canonicalize_pathname (ret
);
497 ret
= g_build_filename (mc_global
.share_data_dir
, subdir
, lc_basename
, (char *) NULL
);
499 ret
= g_build_filename (mc_global
.share_data_dir
, lc_basename
, (char *) NULL
);
501 g_free (lc_basename
);
503 if (exist_file (ret
))
505 canonicalize_pathname (ret
);
513 /* --------------------------------------------------------------------------------------------- */
516 setup__is_cfg_group_must_panel_config (const char *grp
)
518 return (!strcasecmp ("Dirs", grp
) ||
519 !strcasecmp ("Temporal:New Right Panel", grp
) ||
520 !strcasecmp ("Temporal:New Left Panel", grp
) ||
521 !strcasecmp ("New Left Panel", grp
) || !strcasecmp ("New Right Panel", grp
))
525 /* --------------------------------------------------------------------------------------------- */
528 setup__move_panels_config_into_separate_file (const char *profile
)
530 mc_config_t
*tmp_cfg
;
531 char **groups
, **curr_grp
;
533 if (!exist_file (profile
))
536 tmp_cfg
= mc_config_init (profile
, FALSE
);
540 groups
= mc_config_get_groups (tmp_cfg
, NULL
);
544 mc_config_deinit (tmp_cfg
);
548 for (curr_grp
= groups
; *curr_grp
!= NULL
; curr_grp
++)
549 if (setup__is_cfg_group_must_panel_config (*curr_grp
) == NULL
)
550 mc_config_del_group (tmp_cfg
, *curr_grp
);
552 mc_config_save_to_file (tmp_cfg
, panels_profile_name
, NULL
);
553 mc_config_deinit (tmp_cfg
);
555 tmp_cfg
= mc_config_init (profile
, FALSE
);
562 for (curr_grp
= groups
; *curr_grp
!= NULL
; curr_grp
++)
564 const char *need_grp
;
566 need_grp
= setup__is_cfg_group_must_panel_config (*curr_grp
);
567 if (need_grp
!= NULL
)
568 mc_config_del_group (tmp_cfg
, need_grp
);
572 mc_config_save_file (tmp_cfg
, NULL
);
573 mc_config_deinit (tmp_cfg
);
576 /* --------------------------------------------------------------------------------------------- */
578 Create new mc_config object from specified ini-file or
579 append data to existing mc_config object from ini-file
583 load_setup_init_config_from_file (mc_config_t
** config
, const char *fname
, gboolean read_only
)
586 TODO: IMHO, in future, this function shall be placed in mcconfig module.
588 if (exist_file (fname
))
591 mc_config_read_file (*config
, fname
, read_only
, TRUE
);
593 *config
= mc_config_init (fname
, read_only
);
597 /* --------------------------------------------------------------------------------------------- */
605 /* Load boolean options */
606 for (i
= 0; bool_options
[i
].opt_name
!= NULL
; i
++)
607 *bool_options
[i
].opt_addr
=
608 mc_config_get_bool (mc_global
.main_config
, CONFIG_APP_SECTION
, bool_options
[i
].opt_name
,
609 *bool_options
[i
].opt_addr
);
611 /* Load integer options */
612 for (i
= 0; int_options
[i
].opt_name
!= NULL
; i
++)
613 *int_options
[i
].opt_addr
=
614 mc_config_get_int (mc_global
.main_config
, CONFIG_APP_SECTION
, int_options
[i
].opt_name
,
615 *int_options
[i
].opt_addr
);
617 /* Load string options */
618 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
619 *str_options
[i
].opt_addr
=
620 mc_config_get_string (mc_global
.main_config
, CONFIG_APP_SECTION
,
621 str_options
[i
].opt_name
, str_options
[i
].opt_defval
);
623 /* Overwrite some options */
624 #ifdef USE_INTERNAL_EDIT
625 if (option_word_wrap_line_length
<= 0)
626 option_word_wrap_line_length
= DEFAULT_WRAP_LINE_LENGTH
;
628 /* Reset forced in case of build without internal editor */
629 use_internal_edit
= FALSE
;
630 #endif /* USE_INTERNAL_EDIT */
632 if (option_tab_spacing
<= 0)
633 option_tab_spacing
= DEFAULT_TAB_SPACING
;
635 kt
= getenv ("KEYBOARD_KEY_TIMEOUT_US");
636 if (kt
!= NULL
&& kt
[0] != '\0')
637 old_esc_mode_timeout
= atoi (kt
);
640 /* --------------------------------------------------------------------------------------------- */
642 static panel_view_mode_t
643 setup__load_panel_state (const char *section
)
647 panel_view_mode_t mode
= view_listing
;
649 /* Load the display mode */
650 buffer
= mc_config_get_string (mc_global
.panels_config
, section
, "display", "listing");
652 for (i
= 0; panel_types
[i
].opt_name
!= NULL
; i
++)
653 if (g_ascii_strcasecmp (panel_types
[i
].opt_name
, buffer
) == 0)
655 mode
= panel_types
[i
].opt_type
;
664 /* --------------------------------------------------------------------------------------------- */
671 int first_panel_size
;
674 panels_layout
.horizontal_split
= mc_config_get_int (mc_global
.main_config
, CONFIG_APP_SECTION
,
675 "horizontal_split", 0);
676 equal_split
= mc_config_get_int (mc_global
.main_config
, "Layout", "equal_split", 1);
677 first_panel_size
= mc_config_get_int (mc_global
.main_config
, "Layout", "first_panel_size", 1);
678 if (panels_layout
.horizontal_split
)
680 panels_layout
.horizontal_equal
= equal_split
;
681 panels_layout
.left_panel_size
= first_panel_size
;
685 panels_layout
.vertical_equal
= equal_split
;
686 panels_layout
.top_panel_size
= first_panel_size
;
689 /* actual options override legacy ones */
690 for (i
= 0; layout
[i
].opt_name
!= NULL
; i
++)
691 *layout
[i
].opt_addr
= mc_config_get_int (mc_global
.main_config
, CONFIG_LAYOUT_SECTION
,
692 layout
[i
].opt_name
, *layout
[i
].opt_addr
);
694 /* remove legacy options */
695 mc_config_del_key (mc_global
.main_config
, CONFIG_APP_SECTION
, "horizontal_split");
696 mc_config_del_key (mc_global
.main_config
, "Layout", "equal_split");
697 mc_config_del_key (mc_global
.main_config
, "Layout", "first_panel_size");
699 startup_left_mode
= setup__load_panel_state ("New Left Panel");
700 startup_right_mode
= setup__load_panel_state ("New Right Panel");
702 /* At least one of the panels is a listing panel */
703 if (startup_left_mode
!= view_listing
&& startup_right_mode
!= view_listing
)
704 startup_left_mode
= view_listing
;
706 boot_current_is_left
=
707 mc_config_get_bool (mc_global
.panels_config
, "Dirs", "current_is_left", TRUE
);
710 /* --------------------------------------------------------------------------------------------- */
713 load_keys_from_section (const char *terminal
, mc_config_t
* cfg
)
716 gchar
**profile_keys
, **keys
;
717 char *valcopy
, *value
;
720 if (terminal
== NULL
)
723 section_name
= g_strconcat ("terminal:", terminal
, (char *) NULL
);
724 keys
= mc_config_get_keys (cfg
, section_name
, NULL
);
726 for (profile_keys
= keys
; *profile_keys
!= NULL
; profile_keys
++)
728 /* copy=other causes all keys from [terminal:other] to be loaded. */
729 if (g_ascii_strcasecmp (*profile_keys
, "copy") == 0)
731 valcopy
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
732 load_keys_from_section (valcopy
, cfg
);
737 key_code
= lookup_key (*profile_keys
, NULL
);
742 values
= mc_config_get_string_list (cfg
, section_name
, *profile_keys
, NULL
);
747 for (curr_values
= values
; *curr_values
!= NULL
; curr_values
++)
749 valcopy
= convert_controls (*curr_values
);
750 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
758 value
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
759 valcopy
= convert_controls (value
);
760 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
767 g_free (section_name
);
770 /* --------------------------------------------------------------------------------------------- */
773 load_keymap_from_section (const char *section_name
, GArray
* keymap
, mc_config_t
* cfg
)
775 gchar
**profile_keys
, **keys
;
777 if (section_name
== NULL
)
780 keys
= mc_config_get_keys (cfg
, section_name
, NULL
);
782 for (profile_keys
= keys
; *profile_keys
!= NULL
; profile_keys
++)
786 values
= mc_config_get_string_list (cfg
, section_name
, *profile_keys
, NULL
);
791 action
= keybind_lookup_action (*profile_keys
);
796 for (curr_values
= values
; *curr_values
!= NULL
; curr_values
++)
797 keybind_cmd_bind (keymap
, *curr_values
, action
);
807 /* --------------------------------------------------------------------------------------------- */
810 load_setup_get_keymap_profile_config (gboolean load_from_file
)
813 TODO: IMHO, in future, this function shall be placed in mcconfig module.
815 mc_config_t
*keymap_config
;
816 char *share_keymap
, *sysconfig_keymap
;
817 char *fname
, *fname2
;
819 /* 0) Create default keymap */
820 keymap_config
= create_default_keymap ();
822 return keymap_config
;
824 /* load and merge global keymaps */
826 /* 1) /usr/share/mc (mc_global.share_data_dir) */
827 share_keymap
= g_build_filename (mc_global
.share_data_dir
, GLOBAL_KEYMAP_FILE
, (char *) NULL
);
828 load_setup_init_config_from_file (&keymap_config
, share_keymap
, TRUE
);
830 /* 2) /etc/mc (mc_global.sysconfig_dir) */
832 g_build_filename (mc_global
.sysconfig_dir
, GLOBAL_KEYMAP_FILE
, (char *) NULL
);
833 load_setup_init_config_from_file (&keymap_config
, sysconfig_keymap
, TRUE
);
835 /* then load and merge one of user-defined keymap */
837 /* 3) --keymap=<keymap> */
838 fname
= load_setup_get_full_config_name (NULL
, mc_args__keymap_file
);
839 if (fname
!= NULL
&& strcmp (fname
, sysconfig_keymap
) != 0 && strcmp (fname
, share_keymap
) != 0)
841 load_setup_init_config_from_file (&keymap_config
, fname
, TRUE
);
846 /* 4) getenv("MC_KEYMAP") */
847 fname
= load_setup_get_full_config_name (NULL
, g_getenv ("MC_KEYMAP"));
848 if (fname
!= NULL
&& strcmp (fname
, sysconfig_keymap
) != 0 && strcmp (fname
, share_keymap
) != 0)
850 load_setup_init_config_from_file (&keymap_config
, fname
, TRUE
);
855 /* 5) main config; [Midnight Commander] -> keymap */
856 fname2
= mc_config_get_string (mc_global
.main_config
, CONFIG_APP_SECTION
, "keymap", NULL
);
857 if (fname2
!= NULL
&& *fname2
!= '\0')
858 fname
= load_setup_get_full_config_name (NULL
, fname2
);
860 if (fname
!= NULL
&& strcmp (fname
, sysconfig_keymap
) != 0 && strcmp (fname
, share_keymap
) != 0)
862 load_setup_init_config_from_file (&keymap_config
, fname
, TRUE
);
867 /* 6) ${XDG_CONFIG_HOME}/mc/mc.keymap */
868 fname
= mc_config_get_full_path (GLOBAL_KEYMAP_FILE
);
869 load_setup_init_config_from_file (&keymap_config
, fname
, TRUE
);
873 g_free (sysconfig_keymap
);
874 g_free (share_keymap
);
876 return keymap_config
;
879 /* --------------------------------------------------------------------------------------------- */
882 panel_save_type (const char *section
, panel_view_mode_t type
)
886 for (i
= 0; panel_types
[i
].opt_name
!= NULL
; i
++)
887 if (panel_types
[i
].opt_type
== type
)
889 mc_config_set_string (mc_global
.panels_config
, section
, "display",
890 panel_types
[i
].opt_name
);
895 /* --------------------------------------------------------------------------------------------- */
898 * Load panels options from [Panels] section.
901 panels_load_options (void)
903 if (mc_config_has_group (mc_global
.main_config
, CONFIG_PANELS_SECTION
))
908 for (i
= 0; panels_ini_options
[i
].opt_name
!= NULL
; i
++)
909 *panels_ini_options
[i
].opt_addr
=
910 mc_config_get_bool (mc_global
.main_config
, CONFIG_PANELS_SECTION
,
911 panels_ini_options
[i
].opt_name
,
912 *panels_ini_options
[i
].opt_addr
);
914 qmode
= mc_config_get_int (mc_global
.main_config
, CONFIG_PANELS_SECTION
,
915 "quick_search_mode", (int) panels_options
.qsearch_mode
);
917 panels_options
.qsearch_mode
= QSEARCH_CASE_INSENSITIVE
;
918 else if (qmode
>= QSEARCH_NUM
)
919 panels_options
.qsearch_mode
= QSEARCH_PANEL_CASE
;
921 panels_options
.qsearch_mode
= (qsearch_mode_t
) qmode
;
923 panels_options
.select_flags
=
924 mc_config_get_int (mc_global
.main_config
, CONFIG_PANELS_SECTION
, "select_flags",
925 (int) panels_options
.select_flags
);
929 /* --------------------------------------------------------------------------------------------- */
932 * Save panels options in [Panels] section.
935 panels_save_options (void)
939 for (i
= 0; panels_ini_options
[i
].opt_name
!= NULL
; i
++)
940 mc_config_set_bool (mc_global
.main_config
, CONFIG_PANELS_SECTION
,
941 panels_ini_options
[i
].opt_name
, *panels_ini_options
[i
].opt_addr
);
943 mc_config_set_int (mc_global
.main_config
, CONFIG_PANELS_SECTION
,
944 "quick_search_mode", (int) panels_options
.qsearch_mode
);
945 mc_config_set_int (mc_global
.main_config
, CONFIG_PANELS_SECTION
,
946 "select_flags", (int) panels_options
.select_flags
);
949 /* --------------------------------------------------------------------------------------------- */
956 /* Save boolean options */
957 for (i
= 0; bool_options
[i
].opt_name
!= NULL
; i
++)
958 mc_config_set_bool (mc_global
.main_config
, CONFIG_APP_SECTION
, bool_options
[i
].opt_name
,
959 *bool_options
[i
].opt_addr
);
961 /* Save integer options */
962 for (i
= 0; int_options
[i
].opt_name
!= NULL
; i
++)
963 mc_config_set_int (mc_global
.main_config
, CONFIG_APP_SECTION
, int_options
[i
].opt_name
,
964 *int_options
[i
].opt_addr
);
966 /* Save string options */
967 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
968 mc_config_set_string (mc_global
.main_config
, CONFIG_APP_SECTION
, str_options
[i
].opt_name
,
969 *str_options
[i
].opt_addr
);
972 /* --------------------------------------------------------------------------------------------- */
979 /* Save integer options */
980 for (i
= 0; layout
[i
].opt_name
!= NULL
; i
++)
981 mc_config_set_int (mc_global
.main_config
, CONFIG_LAYOUT_SECTION
, layout
[i
].opt_name
,
982 *layout
[i
].opt_addr
);
985 /* --------------------------------------------------------------------------------------------- */
987 /* save panels.ini */
989 save_panel_types (void)
991 panel_view_mode_t type
;
993 if (mc_global
.mc_run_mode
!= MC_RUN_FULL
)
996 type
= get_display_type (0);
997 panel_save_type ("New Left Panel", type
);
998 if (type
== view_listing
)
999 panel_save_setup (left_panel
, left_panel
->panel_name
);
1000 type
= get_display_type (1);
1001 panel_save_type ("New Right Panel", type
);
1002 if (type
== view_listing
)
1003 panel_save_setup (right_panel
, right_panel
->panel_name
);
1008 dirs
= get_panel_dir_for (other_panel
);
1009 mc_config_set_string (mc_global
.panels_config
, "Dirs", "other_dir", dirs
);
1013 if (current_panel
!= NULL
)
1014 mc_config_set_bool (mc_global
.panels_config
, "Dirs", "current_is_left",
1015 get_current_index () == 0);
1017 if (mc_global
.panels_config
->ini_path
== NULL
)
1018 mc_global
.panels_config
->ini_path
= g_strdup (panels_profile_name
);
1020 mc_config_del_group (mc_global
.panels_config
, "Temporal:New Left Panel");
1021 mc_config_del_group (mc_global
.panels_config
, "Temporal:New Right Panel");
1023 mc_config_save_file (mc_global
.panels_config
, NULL
);
1026 /* --------------------------------------------------------------------------------------------- */
1027 /*** public functions ****************************************************************************/
1028 /* --------------------------------------------------------------------------------------------- */
1033 if (profile_name
== NULL
)
1037 profile
= mc_config_get_full_path (MC_CONFIG_FILE
);
1038 if (!exist_file (profile
))
1042 inifile
= mc_build_filename (mc_global
.sysconfig_dir
, "mc.ini", (char *) NULL
);
1043 if (exist_file (inifile
))
1051 inifile
= mc_build_filename (mc_global
.share_data_dir
, "mc.ini", (char *) NULL
);
1052 if (!exist_file (inifile
))
1062 profile_name
= profile
;
1065 return profile_name
;
1068 /* --------------------------------------------------------------------------------------------- */
1073 const char *profile
;
1077 const char *cbuffer
;
1079 load_codepages_list ();
1080 #endif /* HAVE_CHARSET */
1082 profile
= setup_init ();
1084 /* mc.lib is common for all users, but has priority lower than
1085 ${XDG_CONFIG_HOME}/mc/ini. FIXME: it's only used for keys and treestore now */
1086 global_profile_name
=
1087 g_build_filename (mc_global
.sysconfig_dir
, MC_GLOBAL_CONFIG_FILE
, (char *) NULL
);
1088 if (!exist_file (global_profile_name
))
1090 g_free (global_profile_name
);
1091 global_profile_name
=
1092 g_build_filename (mc_global
.share_data_dir
, MC_GLOBAL_CONFIG_FILE
, (char *) NULL
);
1095 panels_profile_name
= mc_config_get_full_path (MC_PANELS_FILE
);
1097 mc_global
.main_config
= mc_config_init (profile
, FALSE
);
1099 if (!exist_file (panels_profile_name
))
1100 setup__move_panels_config_into_separate_file (profile
);
1102 mc_global
.panels_config
= mc_config_init (panels_profile_name
, FALSE
);
1106 panels_load_options ();
1109 /* Load time formats */
1110 user_recent_timeformat
=
1111 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "timeformat_recent",
1113 user_old_timeformat
=
1114 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "timeformat_old",
1117 #ifdef ENABLE_VFS_FTP
1119 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "ftp_proxy_host", "gate");
1120 ftpfs_init_passwd ();
1121 #endif /* ENABLE_VFS_FTP */
1123 /* The default color and the terminal dependent color */
1124 mc_global
.tty
.setup_color_string
=
1125 mc_config_get_string (mc_global
.main_config
, "Colors", "base_color", "");
1126 mc_global
.tty
.term_color_string
=
1127 mc_config_get_string (mc_global
.main_config
, "Colors", getenv ("TERM"), "");
1128 mc_global
.tty
.color_terminal_string
=
1129 mc_config_get_string (mc_global
.main_config
, "Colors", "color_terminals", "");
1131 /* Load the directory history */
1132 /* directory_history_load (); */
1133 /* Remove the temporal entries */
1136 if (codepages
->len
> 1)
1139 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "display_codepage",
1141 if (buffer
[0] != '\0')
1143 mc_global
.display_codepage
= get_codepage_index (buffer
);
1144 cp_display
= get_codepage_id (mc_global
.display_codepage
);
1148 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "source_codepage",
1150 if (buffer
[0] != '\0')
1152 default_source_codepage
= get_codepage_index (buffer
);
1153 mc_global
.source_codepage
= default_source_codepage
; /* May be source_codepage doesn't need this */
1154 cp_source
= get_codepage_id (mc_global
.source_codepage
);
1159 autodetect_codeset
=
1160 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "autodetect_codeset", "");
1161 if ((autodetect_codeset
[0] != '\0') && (strcmp (autodetect_codeset
, "off") != 0))
1162 is_autodetect_codeset_enabled
= TRUE
;
1164 g_free (init_translation_table (mc_global
.source_codepage
, mc_global
.display_codepage
));
1165 cbuffer
= get_codepage_id (mc_global
.display_codepage
);
1166 if (cbuffer
!= NULL
)
1167 mc_global
.utf8_display
= str_isutf8 (cbuffer
);
1168 #endif /* HAVE_CHARSET */
1172 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "spell_language", "en");
1173 #endif /* HAVE_ASPELL */
1175 clipboard_store_path
=
1176 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "clipboard_store", "");
1177 clipboard_paste_path
=
1178 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "clipboard_paste", "");
1181 /* --------------------------------------------------------------------------------------------- */
1184 save_setup (gboolean save_options
, gboolean save_panel_options
)
1186 gboolean ret
= TRUE
;
1192 if (save_panel_options
)
1193 save_panel_types ();
1201 panels_save_options ();
1203 /* directory_history_save (); */
1205 #ifdef ENABLE_VFS_FTP
1206 mc_config_set_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "ftpfs_password",
1207 ftpfs_anonymous_passwd
);
1208 if (ftpfs_proxy_host
)
1209 mc_config_set_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "ftp_proxy_host",
1211 #endif /* ENABLE_VFS_FTP */
1214 mc_config_set_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "display_codepage",
1215 get_codepage_id (mc_global
.display_codepage
));
1216 mc_config_set_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "source_codepage",
1217 get_codepage_id (default_source_codepage
));
1218 mc_config_set_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "autodetect_codeset",
1219 autodetect_codeset
);
1220 #endif /* HAVE_CHARSET */
1223 mc_config_set_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "spell_language",
1225 #endif /* HAVE_ASPELL */
1227 mc_config_set_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "clipboard_store",
1228 clipboard_store_path
);
1229 mc_config_set_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "clipboard_paste",
1230 clipboard_paste_path
);
1232 tmp_profile
= mc_config_get_full_path (MC_CONFIG_FILE
);
1233 ret
= mc_config_save_to_file (mc_global
.main_config
, tmp_profile
, NULL
);
1234 g_free (tmp_profile
);
1242 /* --------------------------------------------------------------------------------------------- */
1249 g_free (clipboard_store_path
);
1250 g_free (clipboard_paste_path
);
1251 g_free (global_profile_name
);
1252 g_free (mc_global
.tty
.color_terminal_string
);
1253 g_free (mc_global
.tty
.term_color_string
);
1254 g_free (mc_global
.tty
.setup_color_string
);
1255 g_free (profile_name
);
1256 g_free (panels_profile_name
);
1257 mc_config_deinit (mc_global
.main_config
);
1258 mc_config_deinit (mc_global
.panels_config
);
1260 g_free (user_recent_timeformat
);
1261 g_free (user_old_timeformat
);
1263 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
1264 g_free (*str_options
[i
].opt_addr
);
1268 /* directory_history_free (); */
1271 g_free (autodetect_codeset
);
1272 free_codepages_list ();
1276 g_free (spell_language
);
1277 #endif /* HAVE_ASPELL */
1281 /* --------------------------------------------------------------------------------------------- */
1284 setup_save_config_show_error (const char *filename
, GError
** mcerror
)
1286 if (mcerror
!= NULL
&& *mcerror
!= NULL
)
1288 message (D_ERROR
, MSG_ERROR
, _("Cannot save file %s:\n%s"), filename
, (*mcerror
)->message
);
1289 g_error_free (*mcerror
);
1295 /* --------------------------------------------------------------------------------------------- */
1298 load_key_defs (void)
1301 * Load keys from mc.lib before ${XDG_CONFIG_HOME}/mc/ini, so that the user
1302 * definitions override global settings.
1304 mc_config_t
*mc_global_config
;
1306 mc_global_config
= mc_config_init (global_profile_name
, FALSE
);
1307 if (mc_global_config
!= NULL
)
1309 load_keys_from_section ("general", mc_global_config
);
1310 load_keys_from_section (getenv ("TERM"), mc_global_config
);
1311 mc_config_deinit (mc_global_config
);
1314 load_keys_from_section ("general", mc_global
.main_config
);
1315 load_keys_from_section (getenv ("TERM"), mc_global
.main_config
);
1318 /* --------------------------------------------------------------------------------------------- */
1320 #ifdef ENABLE_VFS_FTP
1322 load_anon_passwd (void)
1327 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "ftpfs_password", "");
1329 if ((buffer
!= NULL
) && (buffer
[0] != '\0'))
1335 #endif /* ENABLE_VFS_FTP */
1337 /* --------------------------------------------------------------------------------------------- */
1340 load_keymap_defs (gboolean load_from_file
)
1343 * Load keymap from GLOBAL_KEYMAP_FILE before ${XDG_CONFIG_HOME}/mc/mc.keymap, so that the user
1344 * definitions override global settings.
1346 mc_config_t
*mc_global_keymap
;
1348 mc_global_keymap
= load_setup_get_keymap_profile_config (load_from_file
);
1350 if (mc_global_keymap
!= NULL
)
1352 main_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1353 load_keymap_from_section (KEYMAP_SECTION_MAIN
, main_keymap
, mc_global_keymap
);
1354 main_x_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1355 load_keymap_from_section (KEYMAP_SECTION_MAIN_EXT
, main_x_keymap
, mc_global_keymap
);
1357 panel_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1358 load_keymap_from_section (KEYMAP_SECTION_PANEL
, panel_keymap
, mc_global_keymap
);
1360 dialog_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1361 load_keymap_from_section (KEYMAP_SECTION_DIALOG
, dialog_keymap
, mc_global_keymap
);
1363 input_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1364 load_keymap_from_section (KEYMAP_SECTION_INPUT
, input_keymap
, mc_global_keymap
);
1366 listbox_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1367 load_keymap_from_section (KEYMAP_SECTION_LISTBOX
, listbox_keymap
, mc_global_keymap
);
1369 tree_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1370 load_keymap_from_section (KEYMAP_SECTION_TREE
, tree_keymap
, mc_global_keymap
);
1372 help_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1373 load_keymap_from_section (KEYMAP_SECTION_HELP
, help_keymap
, mc_global_keymap
);
1375 #ifdef USE_INTERNAL_EDIT
1376 editor_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1377 load_keymap_from_section (KEYMAP_SECTION_EDITOR
, editor_keymap
, mc_global_keymap
);
1378 editor_x_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1379 load_keymap_from_section (KEYMAP_SECTION_EDITOR_EXT
, editor_x_keymap
, mc_global_keymap
);
1382 viewer_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1383 load_keymap_from_section (KEYMAP_SECTION_VIEWER
, viewer_keymap
, mc_global_keymap
);
1384 viewer_hex_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1385 load_keymap_from_section (KEYMAP_SECTION_VIEWER_HEX
, viewer_hex_keymap
, mc_global_keymap
);
1387 #ifdef USE_DIFF_VIEW
1388 diff_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1389 load_keymap_from_section (KEYMAP_SECTION_DIFFVIEWER
, diff_keymap
, mc_global_keymap
);
1392 mc_config_deinit (mc_global_keymap
);
1395 main_map
= (global_keymap_t
*) main_keymap
->data
;
1396 main_x_map
= (global_keymap_t
*) main_x_keymap
->data
;
1397 panel_map
= (global_keymap_t
*) panel_keymap
->data
;
1398 dialog_map
= (global_keymap_t
*) dialog_keymap
->data
;
1399 input_map
= (global_keymap_t
*) input_keymap
->data
;
1400 listbox_map
= (global_keymap_t
*) listbox_keymap
->data
;
1401 tree_map
= (global_keymap_t
*) tree_keymap
->data
;
1402 help_map
= (global_keymap_t
*) help_keymap
->data
;
1403 #ifdef USE_INTERNAL_EDIT
1404 editor_map
= (global_keymap_t
*) editor_keymap
->data
;
1405 editor_x_map
= (global_keymap_t
*) editor_x_keymap
->data
;
1407 viewer_map
= (global_keymap_t
*) viewer_keymap
->data
;
1408 viewer_hex_map
= (global_keymap_t
*) viewer_hex_keymap
->data
;
1409 #ifdef USE_DIFF_VIEW
1410 diff_map
= (global_keymap_t
*) diff_keymap
->data
;
1414 /* --------------------------------------------------------------------------------------------- */
1417 free_keymap_defs (void)
1419 if (main_keymap
!= NULL
)
1420 g_array_free (main_keymap
, TRUE
);
1421 if (main_x_keymap
!= NULL
)
1422 g_array_free (main_x_keymap
, TRUE
);
1423 if (panel_keymap
!= NULL
)
1424 g_array_free (panel_keymap
, TRUE
);
1425 if (dialog_keymap
!= NULL
)
1426 g_array_free (dialog_keymap
, TRUE
);
1427 if (input_keymap
!= NULL
)
1428 g_array_free (input_keymap
, TRUE
);
1429 if (listbox_keymap
!= NULL
)
1430 g_array_free (listbox_keymap
, TRUE
);
1431 if (tree_keymap
!= NULL
)
1432 g_array_free (tree_keymap
, TRUE
);
1433 if (help_keymap
!= NULL
)
1434 g_array_free (help_keymap
, TRUE
);
1435 #ifdef USE_INTERNAL_EDIT
1436 if (editor_keymap
!= NULL
)
1437 g_array_free (editor_keymap
, TRUE
);
1438 if (editor_x_keymap
!= NULL
)
1439 g_array_free (editor_x_keymap
, TRUE
);
1441 if (viewer_keymap
!= NULL
)
1442 g_array_free (viewer_keymap
, TRUE
);
1443 if (viewer_hex_keymap
!= NULL
)
1444 g_array_free (viewer_hex_keymap
, TRUE
);
1445 #ifdef USE_DIFF_VIEW
1446 if (diff_keymap
!= NULL
)
1447 g_array_free (diff_keymap
, TRUE
);
1451 /* --------------------------------------------------------------------------------------------- */
1454 panel_load_setup (WPanel
* panel
, const char *section
)
1457 char *buffer
, buffer2
[BUF_TINY
];
1459 panel
->sort_info
.reverse
= mc_config_get_int (mc_global
.panels_config
, section
, "reverse", 0);
1460 panel
->sort_info
.case_sensitive
=
1461 mc_config_get_int (mc_global
.panels_config
, section
, "case_sensitive",
1462 OS_SORT_CASE_SENSITIVE_DEFAULT
);
1463 panel
->sort_info
.exec_first
=
1464 mc_config_get_int (mc_global
.panels_config
, section
, "exec_first", 0);
1466 /* Load sort order */
1467 buffer
= mc_config_get_string (mc_global
.panels_config
, section
, "sort_order", "name");
1468 panel
->sort_field
= panel_get_field_by_id (buffer
);
1469 if (panel
->sort_field
== NULL
)
1470 panel
->sort_field
= panel_get_field_by_id ("name");
1474 /* Load the listing mode */
1475 buffer
= mc_config_get_string (mc_global
.panels_config
, section
, "list_mode", "full");
1476 panel
->list_type
= list_full
;
1477 for (i
= 0; list_types
[i
].key
!= NULL
; i
++)
1478 if (g_ascii_strcasecmp (list_types
[i
].key
, buffer
) == 0)
1480 panel
->list_type
= list_types
[i
].list_type
;
1485 panel
->brief_cols
= mc_config_get_int (mc_global
.panels_config
, section
, "brief_cols", 2);
1488 g_free (panel
->user_format
);
1489 panel
->user_format
=
1490 mc_config_get_string (mc_global
.panels_config
, section
, "user_format", DEFAULT_USER_FORMAT
);
1492 for (i
= 0; i
< LIST_TYPES
; i
++)
1494 g_free (panel
->user_status_format
[i
]);
1495 g_snprintf (buffer2
, sizeof (buffer2
), "user_status%lld", (long long) i
);
1496 panel
->user_status_format
[i
] =
1497 mc_config_get_string (mc_global
.panels_config
, section
, buffer2
, DEFAULT_USER_FORMAT
);
1500 panel
->user_mini_status
=
1501 mc_config_get_bool (mc_global
.panels_config
, section
, "user_mini_status", FALSE
);
1504 /* --------------------------------------------------------------------------------------------- */
1507 panel_save_setup (WPanel
* panel
, const char *section
)
1509 char buffer
[BUF_TINY
];
1512 mc_config_set_int (mc_global
.panels_config
, section
, "reverse", panel
->sort_info
.reverse
);
1513 mc_config_set_int (mc_global
.panels_config
, section
, "case_sensitive",
1514 panel
->sort_info
.case_sensitive
);
1515 mc_config_set_int (mc_global
.panels_config
, section
, "exec_first", panel
->sort_info
.exec_first
);
1517 mc_config_set_string (mc_global
.panels_config
, section
, "sort_order", panel
->sort_field
->id
);
1519 for (i
= 0; list_types
[i
].key
!= NULL
; i
++)
1520 if (list_types
[i
].list_type
== (int) panel
->list_type
)
1522 mc_config_set_string (mc_global
.panels_config
, section
, "list_mode", list_types
[i
].key
);
1526 mc_config_set_int (mc_global
.panels_config
, section
, "brief_cols", panel
->brief_cols
);
1528 mc_config_set_string (mc_global
.panels_config
, section
, "user_format", panel
->user_format
);
1530 for (i
= 0; i
< LIST_TYPES
; i
++)
1532 g_snprintf (buffer
, sizeof (buffer
), "user_status%lld", (long long) i
);
1533 mc_config_set_string (mc_global
.panels_config
, section
, buffer
,
1534 panel
->user_status_format
[i
]);
1537 mc_config_set_bool (mc_global
.panels_config
, section
, "user_mini_status",
1538 panel
->user_mini_status
);
1541 /* --------------------------------------------------------------------------------------------- */