mc/src/setup.c

734 lines
21 KiB
C
Raw Normal View History

1998-02-27 07:54:42 +03:00
/* Setup loading/saving.
Copyright (C) 1994 Miguel de Icaza
1998-02-27 07:54:42 +03:00
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
1998-02-27 07:54:42 +03:00
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
1998-02-27 07:54:42 +03:00
#include <config.h>
#include <sys/types.h> /* Needed to include local .h files */
#include <sys/stat.h>
#include <sys/param.h>
#include <string.h>
#include "tty.h"
#include <stdio.h>
#include "global.h"
#include "dir.h"
1998-02-27 07:54:42 +03:00
#include "panel.h"
#include "main.h"
#include "tree.h"
#include "profile.h"
1998-12-03 00:27:27 +03:00
#define WANT_WIDGETS
1998-02-27 07:54:42 +03:00
#include "setup.h"
#include "mouse.h" /* To make view.h happy */
#include "view.h" /* For the externs */
#include "key.h" /* For the externs */
#include "hotlist.h" /* load/save/done hotlist */
#include "panelize.h" /* load/save/done panelize */
#include "layout.h"
#include "menu.h" /* menubar_visible declaration */
#include "win.h" /* lookup_key */
#include "cmd.h"
#include "file.h"
#include "x.h"
1998-02-27 07:54:42 +03:00
#ifdef HAVE_GNOME
# include "gdesktop.h"
#endif
#ifndef PORT_LIST_MODE_NAME
# define PORT_LIST_MODE_NAME "list_mode"
#endif
#ifndef PORT_LIST_MODE_DEFAULT
# define PORT_LIST_MODE_DEFAULT "full"
#endif
#ifdef HAVE_CHARSET
#include "dialog.h"
#include "charsets.h"
#endif
1998-02-27 07:54:42 +03:00
#include "../vfs/vfs.h"
#ifdef USE_NETCODE
# include "../vfs/ftpfs.h"
#endif
#ifdef HAVE_GNOME
extern int tree_panel_visible;
extern int we_can_afford_the_speed;
int use_magic = 0;
#endif
1998-02-27 07:54:42 +03:00
/* "$Id$" */
#ifdef USE_VFS
extern int vfs_timeout;
extern int tar_gzipped_memlimit;
#endif
extern char *find_ignore_dirs;
extern int num_history_items_recorded;
char *profile_name;
char setup_color_string [4096];
char term_color_string [4096];
char color_terminal_string [512];
#define load_int(a,b,c) GetPrivateProfileInt(a,b,c,profile_name)
#define load_string(a,b,c,d,e) GetPrivateProfileString(a,b,c,d,e,profile_name)
#define save_string WritePrivateProfileString
int startup_left_mode;
int startup_right_mode;
/* Ugly hack to allow panel_save_setup to work as a place holder for */
/* default panel values */
int saving_setup;
2000-02-02 19:57:51 +03:00
static const struct {
1998-02-27 07:54:42 +03:00
char *key;
sortfn *sort_type;
} sort_names [] = {
{ "name", (sortfn *) sort_name },
{ "extension", (sortfn *) sort_ext },
{ "time", (sortfn *) sort_time },
{ "atime", (sortfn *) sort_atime },
{ "ctime", (sortfn *) sort_ctime },
{ "size", (sortfn *) sort_size },
{ "inode", (sortfn *) sort_inode },
{ "unsorted", (sortfn *) unsorted },
{ 0, 0 }
};
2000-02-02 19:57:51 +03:00
static const struct {
1998-02-27 07:54:42 +03:00
char *key;
int list_type;
} list_types [] = {
{ "full", list_full },
1998-02-27 07:54:42 +03:00
{ "brief", list_brief },
{ "long", list_long },
{ "user", list_user },
{ "icons", list_icons },
1998-02-27 07:54:42 +03:00
{ 0, 0 }
};
2000-02-02 19:57:51 +03:00
static const struct {
1998-02-27 07:54:42 +03:00
char *opt_name;
int opt_type;
} panel_types [] = {
{ "listing", view_listing },
{ "quickview", view_quick },
{ "info", view_info },
{ "tree", view_tree },
{ 0, 0 }
};
2000-02-02 19:57:51 +03:00
static const struct {
1998-02-27 07:54:42 +03:00
char *opt_name;
int *opt_addr;
} layout [] = {
#ifndef HAVE_GNOME
{ "equal_split", &equal_split },
{ "first_panel_size", &first_panel_size },
{ "message_visible", &message_visible },
{ "keybar_visible", &keybar_visible },
{ "xterm_hintbar", &xterm_hintbar },
{ "output_lines", &output_lines },
#endif
{ "menubar_visible", &menubar_visible },
{ "command_prompt", &command_prompt },
{ "show_mini_info", &show_mini_info },
{ "permission_mode", &permission_mode },
{ "filetype_mode", &filetype_mode },
{ 0, 0 }
};
Sun May 10 13:21:45 1998 Norbert Warmuth <k3190@fh-sw.de> * edit/syntax.c: Disable debug messages on stderr. * edit/edit.h: Added missing _() Sun May 10 14:51:03 1998 Norbert Warmuth <k3190@fh-sw.de> * ftpfs.c (__ftpfs_chdir): CWD command wasn't sent at all. This optimation is wrong because for directories containing spaces we have to "CWD <pathname>" and "LIST -la" instead of "LIST -la <pathname>". I implemented a different optimation. Now ftpfs_chdir only stores the new working directory and sets a flag. __ftpfs_chdir is called when we really want to change the directory on the ftp server. (resolve_symlink): Log the directory listing to the logfile. * ftpfs.h (struct ftpfs_connection): Added a (per connection) cwd_defered flag. Sun May 10 13:27:50 1998 Norbert Warmuth <k3190@fh-sw.de> * widget.c (handle_char): Don't try to to delete default text in input widget more than once. Right after MC's start copy_filename (ESC Enter) failed because a flag wasn't cleared while characters were stuffed into the commandline (Andrej reported this bug). * main.c (copy_readlink): usr mc_readlink instead of readlink * file.c: Changed default for the copy/move option "dive into subdir if exists" to off (note: this was only possible after the change in setup.c). (copy_dir_dir): Activated the previously uncommented code which implements "Dive into subdirs". Even when there's no case where we actually would like that behaviour it is a documented feature. Though I don't wanted to change the default behavour. Hence the option change. (file_mask_defaults): set dive_into_subdirs (file_mask_dialog): Fix for debian Bug #20727: Move operation with "[ ] Dive into subdir if exists" and destination filename not wildcarded. If destination is an existing directory then files will be moved into this directory. If destination is not an existing directory then src file will be renamed (one file selected) or an error will be displayed (more than one file selected). (file_mask_dialog): made the option "Using shell patterns" local to the current copy/move operation, i.e. this option is always initialized with the global options's value. Previously it affected the global Options/Configuration/shell Patterns. Another possiblilty would be to make the global option a default option on startup and keep changes in the copy/move dialog (without saving these changes with save setup). * setup.c: Don't save and load options which can be changed outside the options menu. For example I don't like that preserve_uid_gid and dive_into_subdirs from the copy/move dialog are saved and restored (strange, what about the other options from this dialog?). It would be much cleaner to make these option read-only. This way one could edit ~/.mc/ini to provide default option setting on startup and "Save setup" wouldn't have side effects outside the option's menu. Sun May 10 13:24:20 1998 Norbert Warmuth <k3190@fh-sw.de> * doc/mc.1.in, doc/mc.sgml, mc.hlp: Updated to reflect new default for dive into subdirs.
1998-05-10 17:41:43 +04:00
#undef SAVE_CHANGES_OUTSIDE_OPTIONS_MENU
#ifdef SAVE_CHANGES_OUTSIDE_OPTIONS_MENU
1998-02-27 07:54:42 +03:00
extern int preserve_uidgid;
Sun May 10 13:21:45 1998 Norbert Warmuth <k3190@fh-sw.de> * edit/syntax.c: Disable debug messages on stderr. * edit/edit.h: Added missing _() Sun May 10 14:51:03 1998 Norbert Warmuth <k3190@fh-sw.de> * ftpfs.c (__ftpfs_chdir): CWD command wasn't sent at all. This optimation is wrong because for directories containing spaces we have to "CWD <pathname>" and "LIST -la" instead of "LIST -la <pathname>". I implemented a different optimation. Now ftpfs_chdir only stores the new working directory and sets a flag. __ftpfs_chdir is called when we really want to change the directory on the ftp server. (resolve_symlink): Log the directory listing to the logfile. * ftpfs.h (struct ftpfs_connection): Added a (per connection) cwd_defered flag. Sun May 10 13:27:50 1998 Norbert Warmuth <k3190@fh-sw.de> * widget.c (handle_char): Don't try to to delete default text in input widget more than once. Right after MC's start copy_filename (ESC Enter) failed because a flag wasn't cleared while characters were stuffed into the commandline (Andrej reported this bug). * main.c (copy_readlink): usr mc_readlink instead of readlink * file.c: Changed default for the copy/move option "dive into subdir if exists" to off (note: this was only possible after the change in setup.c). (copy_dir_dir): Activated the previously uncommented code which implements "Dive into subdirs". Even when there's no case where we actually would like that behaviour it is a documented feature. Though I don't wanted to change the default behavour. Hence the option change. (file_mask_defaults): set dive_into_subdirs (file_mask_dialog): Fix for debian Bug #20727: Move operation with "[ ] Dive into subdir if exists" and destination filename not wildcarded. If destination is an existing directory then files will be moved into this directory. If destination is not an existing directory then src file will be renamed (one file selected) or an error will be displayed (more than one file selected). (file_mask_dialog): made the option "Using shell patterns" local to the current copy/move operation, i.e. this option is always initialized with the global options's value. Previously it affected the global Options/Configuration/shell Patterns. Another possiblilty would be to make the global option a default option on startup and keep changes in the copy/move dialog (without saving these changes with save setup). * setup.c: Don't save and load options which can be changed outside the options menu. For example I don't like that preserve_uid_gid and dive_into_subdirs from the copy/move dialog are saved and restored (strange, what about the other options from this dialog?). It would be much cleaner to make these option read-only. This way one could edit ~/.mc/ini to provide default option setting on startup and "Save setup" wouldn't have side effects outside the option's menu. Sun May 10 13:24:20 1998 Norbert Warmuth <k3190@fh-sw.de> * doc/mc.1.in, doc/mc.sgml, mc.hlp: Updated to reflect new default for dive into subdirs.
1998-05-10 17:41:43 +04:00
#endif
1998-02-27 07:54:42 +03:00
2000-02-02 19:57:51 +03:00
static const struct {
1998-02-27 07:54:42 +03:00
char *opt_name;
int *opt_addr;
} options [] = {
{ "show_backups", &show_backups },
#ifdef HAVE_GNOME
{ "gnome_show_dot_files", &show_dot_files },
#else
1998-02-27 07:54:42 +03:00
{ "show_dot_files", &show_dot_files },
#endif
1998-02-27 07:54:42 +03:00
{ "verbose", &verbose },
{ "mark_moves_down", &mark_moves_down },
{ "pause_after_run", &pause_after_run },
{ "shell_patterns", &easy_patterns },
{ "auto_save_setup", &auto_save_setup },
{ "align_extensions", &align_extensions },
{ "auto_menu", &auto_menu },
{ "use_internal_view", &use_internal_view },
{ "use_internal_edit", &use_internal_edit },
{ "clear_before_exec", &clear_before_exec },
{ "mix_all_files", &mix_all_files },
{ "fast_reload", &fast_reload },
{ "fast_reload_msg_shown", &fast_reload_w },
{ "confirm_delete", &confirm_delete },
{ "confirm_overwrite", &confirm_overwrite },
{ "confirm_execute", &confirm_execute },
{ "confirm_exit", &confirm_exit },
{ "safe_delete", &know_not_what_am_i_doing },
#ifndef HAVE_X
1998-02-27 07:54:42 +03:00
{ "mouse_repeat_rate", &mou_auto_repeat },
{ "double_click_speed", &double_click_speed },
#ifndef HAVE_CHARSET
1998-02-27 07:54:42 +03:00
{ "eight_bit_clean", &eight_bit_clean },
{ "full_eight_bits", &full_eight_bits },
#endif
1998-02-27 07:54:42 +03:00
{ "use_8th_bit_as_meta", &use_8th_bit_as_meta },
#endif
1998-02-27 07:54:42 +03:00
{ "confirm_view_dir", &confirm_view_dir },
{ "mouse_move_pages", &mouse_move_pages },
{ "mouse_move_pages_viewer", &mouse_move_pages_viewer },
{ "fast_refresh", &fast_refresh },
{ "navigate_with_arrows", &navigate_with_arrows },
{ "advanced_chown", &advanced_chfns },
{ "drop_menus", &drop_menus },
{ "wrap_mode", &global_wrap_mode},
#ifndef HAVE_X
1998-02-27 07:54:42 +03:00
{ "old_esc_mode", &old_esc_mode },
{ "cd_symlinks", &cd_symlinks },
#endif
1998-02-27 07:54:42 +03:00
{ "show_all_if_ambiguous", &show_all_if_ambiguous },
{ "have_fast_cpu", &have_fast_cpu },
{ "iconify_on_exec", &iconify_on_exec },
{ "torben_fj_mode", &torben_fj_mode },
{ "use_file_to_guess_type", &use_file_to_check_type },
{ "alternate_plus_minus", &alternate_plus_minus },
{ "only_leading_plus_minus", &only_leading_plus_minus },
{ "show_output_starts_shell", &output_starts_shell },
{ "panel_scroll_pages", &panel_scroll_pages },
{ "xtree_mode", &xtree_mode },
{ "num_history_items_recorded", &num_history_items_recorded },
{ "file_op_compute_totals", &file_op_compute_totals },
#ifdef HAVE_GNOME
{ "use_magic", &use_magic },
#endif
Sun May 10 13:21:45 1998 Norbert Warmuth <k3190@fh-sw.de> * edit/syntax.c: Disable debug messages on stderr. * edit/edit.h: Added missing _() Sun May 10 14:51:03 1998 Norbert Warmuth <k3190@fh-sw.de> * ftpfs.c (__ftpfs_chdir): CWD command wasn't sent at all. This optimation is wrong because for directories containing spaces we have to "CWD <pathname>" and "LIST -la" instead of "LIST -la <pathname>". I implemented a different optimation. Now ftpfs_chdir only stores the new working directory and sets a flag. __ftpfs_chdir is called when we really want to change the directory on the ftp server. (resolve_symlink): Log the directory listing to the logfile. * ftpfs.h (struct ftpfs_connection): Added a (per connection) cwd_defered flag. Sun May 10 13:27:50 1998 Norbert Warmuth <k3190@fh-sw.de> * widget.c (handle_char): Don't try to to delete default text in input widget more than once. Right after MC's start copy_filename (ESC Enter) failed because a flag wasn't cleared while characters were stuffed into the commandline (Andrej reported this bug). * main.c (copy_readlink): usr mc_readlink instead of readlink * file.c: Changed default for the copy/move option "dive into subdir if exists" to off (note: this was only possible after the change in setup.c). (copy_dir_dir): Activated the previously uncommented code which implements "Dive into subdirs". Even when there's no case where we actually would like that behaviour it is a documented feature. Though I don't wanted to change the default behavour. Hence the option change. (file_mask_defaults): set dive_into_subdirs (file_mask_dialog): Fix for debian Bug #20727: Move operation with "[ ] Dive into subdir if exists" and destination filename not wildcarded. If destination is an existing directory then files will be moved into this directory. If destination is not an existing directory then src file will be renamed (one file selected) or an error will be displayed (more than one file selected). (file_mask_dialog): made the option "Using shell patterns" local to the current copy/move operation, i.e. this option is always initialized with the global options's value. Previously it affected the global Options/Configuration/shell Patterns. Another possiblilty would be to make the global option a default option on startup and keep changes in the copy/move dialog (without saving these changes with save setup). * setup.c: Don't save and load options which can be changed outside the options menu. For example I don't like that preserve_uid_gid and dive_into_subdirs from the copy/move dialog are saved and restored (strange, what about the other options from this dialog?). It would be much cleaner to make these option read-only. This way one could edit ~/.mc/ini to provide default option setting on startup and "Save setup" wouldn't have side effects outside the option's menu. Sun May 10 13:24:20 1998 Norbert Warmuth <k3190@fh-sw.de> * doc/mc.1.in, doc/mc.sgml, mc.hlp: Updated to reflect new default for dive into subdirs.
1998-05-10 17:41:43 +04:00
#ifdef SAVE_CHANGES_OUTSIDE_OPTIONS_MENU
{ "dive_into_subdirs", &dive_into_subdirs },
{ "preserve_uidgid", &preserve_uidgid },
/* What about the other two options in the copy dialog
(follow links, stable symlinks) -Norbert */
{ "tree_navigation_flag", &tree_navigation_flag },
#endif
#ifdef USE_VFS
1998-02-27 07:54:42 +03:00
{ "vfs_timeout", &vfs_timeout },
#ifdef USE_NETCODE
{ "ftpfs_directory_timeout", &ftpfs_directory_timeout },
{ "use_netrc", &use_netrc },
{ "ftpfs_retry_seconds", &ftpfs_retry_seconds },
{ "ftpfs_always_use_proxy", &ftpfs_always_use_proxy },
{ "ftpfs_use_passive_connections", &ftpfs_use_passive_connections },
{ "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options },
Rerun configure when you have problems with missing slang.h. Sun Jan 31 20:04:13 1999 Norbert Warmuth <nwarmuth@privat.circular.de> * vfs/vfs.c (vfs_strip_suffix_from_filename): Whoever replaces every occurance of 0 with NULL should stop this stupidy. And replacing '\0' with NULL is plain wrong!!. Reverted this replacement. * vfs/ftpfs.c (load_no_proxy_list): ditto Fri Jan 29 22:55:56 1999 Norbert Warmuth <nwarmuth@privat.circular.de> * slang/slang.h: renamed to slang-mc.h * slang/Makefile.in: delete slang.h on "make clean" * configure.in: link slang/slang-mc.h to slang/slang.h when the included slang is used. Problem was that MC's slang.h was used when we compiled with an already installed SLang and the systems header file were included with <slang/slang.h>. Unfortunatly I can't use AC_LINK_FILES to make the links because if we needn't make any links AC_LINK_FILES makes a link from srcdir to top_builddir (builddir != srcdir). Temporary add $LGPM to $LIBS when checking for the resizeterm and keyok functions (ncurses might be linked against GPM). Substitude PACKAGE (intl/Makefile makes use of it) Sun Jan 31 19:42:47 1999 Norbert Warmuth <nwarmuth@privat.circular.de> * gnome/Makefile.in (install_mx): make it work with srcdir != builddir (gmc.gnorba is located in $srcdir) * src/hotlist.c (add_new_entry_input, add_new_group_input): Make the quick_widget arrays static and various changes needed because they are now static. add_widgets_i18n recalculates button positions which get lost when the quick_widget arrays are non static. * src/screen.c (to_buffer): nul terminate string when using strncpy * src/setup.c: Save and restore new option ftpfs_first_cd_then_ls. Sun Jan 31 19:57:24 1999 Norbert Warmuth <nwarmuth@privat.circular.de> * vfs/ftpfs.c (insert_dot): New function. Insert a "." into the linked list. Stat'ing the root directory of a ftpfs fails if the dot is missing. (retrieve_dir): insert "." into the linked list if the ftp server haven't send it. Sun Jan 31 19:50:24 1999 Norbert Warmuth <nwarmuth@privat.circular.de> * The following changes make ftpfs work with a remote AmiTCP server are the result of somehow longish EMail debugging session. I don't know any public server of this kind but I was told the combination Unix/Amiga boxes are often used in intranets. * vfs/ftpfs.c (translate_path): New function. Translate a Unix path, i.e. MC's internal path representation (e.g. /somedir/somefile) to a path valid for the remote server. Every path transfered to the remote server has to be mangled by this function right prior to sending it. Currently only Amiga ftp servers are handled in a special manner. * vfs/ftpfs.c (various places): use translate_path * vfs/ftpfs.c (login_server): Assume we have to mangle pathnames if the greatings string from the server contains the word Amiga. If this assumption is wrong I have to find another way to turn on path translation. * vfs/ftpfs.c (ftpfs_get_current_directory): Prepend a leading slash if it is missing. MC needs it as seperator between hostname and path in its internal url representation.
1999-01-31 23:28:13 +03:00
{ "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls },
1998-02-27 07:54:42 +03:00
#endif
#endif
#ifdef USE_INTERNAL_EDIT
{ "editor_word_wrap_line_length", &option_word_wrap_line_length },
{ "editor_key_emulation", &edit_key_emulation },
{ "editor_tab_spacing", &option_tab_spacing },
{ "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces },
{ "editor_return_does_auto_indent", &option_return_does_auto_indent },
{ "editor_backspace_through_tabs", &option_backspace_through_tabs },
{ "editor_fake_half_tabs", &option_fake_half_tabs },
{ "editor_option_save_mode", &option_save_mode },
{ "editor_option_backup_ext_int", &option_backup_ext_int },
{ "editor_option_auto_para_formatting", &option_auto_para_formatting },
{ "editor_option_typewriter_wrap", &option_typewriter_wrap },
{ "editor_edit_confirm_save", &edit_confirm_save },
{ "editor_syntax_highlighting", &option_syntax_highlighting },
1998-02-27 07:54:42 +03:00
#endif
1999-01-17 07:17:20 +03:00
#ifdef HAVE_GNOME
{ "desktop_use_shaped_icons", &desktop_use_shaped_icons },
1999-08-24 03:16:08 +04:00
{ "desktop_use_shaped_text", &desktop_use_shaped_text },
{ "desktop_auto_placement", &desktop_auto_placement },
{ "desktop_snap_icons", &desktop_snap_icons },
{ "desktop_arr_r2l", &desktop_arr_r2l },
{ "desktop_arr_b2t", &desktop_arr_b2t },
{ "desktop_arr_rows", &desktop_arr_rows },
1999-01-17 07:17:20 +03:00
{ "tree_panel_visible", &tree_panel_visible },
{ "we_can_afford_the_speed", &we_can_afford_the_speed },
/* Keep the following in sync with panel.h */
{ "column_width_brief_icon", &default_column_width[0] },
{ "column_width_brief_filename", &default_column_width[1] },
{ "column_width_detailed_icon", &default_column_width[2] },
{ "column_width_detailed_filename", &default_column_width[3] },
{ "column_width_detailed_size", &default_column_width[4] },
{ "column_width_detailed_mtime", &default_column_width[5] },
{ "column_width_custom_0", &default_column_width[6] },
{ "column_width_custom_1", &default_column_width[7] },
{ "column_width_custom_2", &default_column_width[8] },
{ "column_width_custom_3", &default_column_width[9] },
{ "column_width_custom_4", &default_column_width[10] },
{ "column_width_custom_5", &default_column_width[11] },
{ "column_width_custom_6", &default_column_width[12] },
{ "column_width_custom_7", &default_column_width[13] },
{ "column_width_custom_8", &default_column_width[14] },
{ "column_width_custom_9", &default_column_width[15] },
{ "column_width_custom_10", &default_column_width[16] },
{ "column_width_custom_11", &default_column_width[17] },
{ "column_width_custom_12", &default_column_width[18] },
{ "column_width_custom_13", &default_column_width[19] },
{ "column_width_custom_14", &default_column_width[20] },
1999-01-17 07:17:20 +03:00
#else
1998-02-27 07:54:42 +03:00
{ "nice_rotating_dash", &nice_rotating_dash },
1999-01-17 07:17:20 +03:00
{ "horizontal_split", &horizontal_split },
1998-02-27 07:54:42 +03:00
#endif
{ 0, 0 }
};
1998-12-03 00:27:27 +03:00
void
panel_save_setup (WPanel *panel, char *section)
1998-02-27 07:54:42 +03:00
{
char buffer [BUF_TINY];
1998-02-27 07:54:42 +03:00
int i;
g_snprintf (buffer, sizeof (buffer), "%d", panel->reverse);
1998-02-27 07:54:42 +03:00
save_string (section, "reverse", buffer, profile_name);
g_snprintf (buffer, sizeof (buffer), "%d", panel->case_sensitive);
1998-02-27 07:54:42 +03:00
save_string (section, "case_sensitive", buffer, profile_name);
for (i = 0; sort_names [i].key; i++)
if (sort_names [i].sort_type == (sortfn *) panel->sort_type){
save_string (section, "sort_order",
sort_names [i].key, profile_name);
break;
}
for (i = 0; list_types [i].key; i++)
if (list_types [i].list_type == panel->list_type){
save_string (section, PORT_LIST_MODE_NAME, list_types [i].key, profile_name);
1998-02-27 07:54:42 +03:00
break;
}
1998-02-27 07:54:42 +03:00
save_string (section, "user_format",
panel->user_format, profile_name);
1998-02-27 07:54:42 +03:00
for (i = 0; i < LIST_TYPES; i++){
g_snprintf (buffer, sizeof (buffer), "user_status%d", i);
save_string (section, buffer,
1998-02-27 07:54:42 +03:00
panel->user_status_format [i], profile_name);
}
g_snprintf (buffer, sizeof (buffer), "%d", panel->user_mini_status);
1998-02-27 07:54:42 +03:00
save_string (section, "user_mini_status", buffer,
profile_name);
}
1998-12-03 00:27:27 +03:00
void
save_layout (void)
1998-02-27 07:54:42 +03:00
{
char *profile;
int i;
char buffer [BUF_TINY];
1998-02-27 07:54:42 +03:00
profile = concat_dir_and_file (home_dir, PROFILE_NAME);
/* Save integer options */
for (i = 0; layout [i].opt_name; i++){
g_snprintf (buffer, sizeof (buffer), "%d", *layout [i].opt_addr);
1998-02-27 07:54:42 +03:00
save_string ("Layout", layout [i].opt_name, buffer, profile);
}
g_free (profile);
1998-02-27 07:54:42 +03:00
}
1998-12-03 00:27:27 +03:00
void
save_configure (void)
1998-02-27 07:54:42 +03:00
{
char *profile;
int i;
profile = concat_dir_and_file (home_dir, PROFILE_NAME);
/* Save integer options */
for (i = 0; options [i].opt_name; i++)
set_int (profile, options [i].opt_name, *options [i].opt_addr);
#ifdef HAVE_GNOME
save_string (app_text, "default_user_format", default_user_format, profile_name);
#endif
g_free (profile);
1998-02-27 07:54:42 +03:00
}
#ifndef PORT_HAS_SAVE_PANEL_TYPES
1998-12-03 00:27:27 +03:00
static void
panel_save_type (char *section, int type)
1998-02-27 07:54:42 +03:00
{
int i;
1998-02-27 07:54:42 +03:00
for (i = 0; panel_types [i].opt_name; i++)
if (panel_types [i].opt_type == type){
save_string (section, "display", panel_types [i].opt_name,
profile_name);
break;
}
}
1998-12-03 00:27:27 +03:00
void
save_panel_types ()
1998-02-27 07:54:42 +03:00
{
int type;
type = get_display_type (0);
panel_save_type ("New Left Panel", type);
if (type == view_listing)
panel_save_setup (left_panel, left_panel->panel_name);
type = get_display_type (1);
panel_save_type ("New Right Panel", type);
if (type == view_listing)
panel_save_setup (right_panel, right_panel->panel_name);
}
#endif
1998-02-27 07:54:42 +03:00
1998-12-03 00:27:27 +03:00
void
save_setup (void)
1998-02-27 07:54:42 +03:00
{
char *profile;
1998-02-27 07:54:42 +03:00
saving_setup = 1;
profile = concat_dir_and_file (home_dir, PROFILE_NAME);
save_layout ();
save_configure ();
save_string ("Dirs", "other_dir",
get_other_type () == view_listing
? opanel->cwd : ".", profile);
1999-03-27 22:00:18 +03:00
if (get_current_panel () != NULL)
WritePrivateProfileString ("Dirs", "current_is_left",
get_current_index () == 0 ? "1" : "0", profile);
#ifndef HAVE_X
1998-02-27 07:54:42 +03:00
save_hotlist ();
#endif /* !HAVE_X */
1998-02-27 07:54:42 +03:00
save_panelize ();
save_panel_types ();
/* directory_history_save (); */
1998-02-27 07:54:42 +03:00
#ifdef USE_VFS
#ifdef USE_NETCODE
WritePrivateProfileString ("Misc", "ftpfs_password",
ftpfs_anonymous_passwd, profile);
if (ftpfs_proxy_host)
WritePrivateProfileString ("Misc", "ftp_proxy_host",
ftpfs_proxy_host, profile);
#endif
#endif
#ifdef HAVE_CHARSET
save_string( "Misc", "display_codepage",
get_codepage_id( display_codepage ), profile_name );
#endif
g_free (profile);
1998-02-27 07:54:42 +03:00
saving_setup = 0;
}
1998-12-03 00:27:27 +03:00
void
panel_load_setup (WPanel *panel, char *section)
1998-02-27 07:54:42 +03:00
{
int i;
char buffer [BUF_TINY];
1998-02-27 07:54:42 +03:00
panel->reverse = load_int (section, "reverse", 0);
panel->case_sensitive = load_int (section, "case_sensitive", OS_SORT_CASE_SENSITIVE_DEFAULT);
1998-02-27 07:54:42 +03:00
/* Load sort order */
load_string (section, "sort_order", "name", buffer, sizeof (buffer));
panel->sort_type = (sortfn *) sort_name;
for (i = 0; sort_names [i].key; i++)
if ( g_strcasecmp (sort_names [i].key, buffer) == 0){
1998-02-27 07:54:42 +03:00
panel->sort_type = sort_names [i].sort_type;
break;
}
/* Load the listing mode */
load_string (section, PORT_LIST_MODE_NAME, PORT_LIST_MODE_DEFAULT, buffer, sizeof (buffer));
1998-02-27 07:54:42 +03:00
panel->list_type = list_full;
for (i = 0; list_types [i].key; i++)
if ( g_strcasecmp (list_types [i].key, buffer) == 0){
1998-02-27 07:54:42 +03:00
panel->list_type = list_types [i].list_type;
break;
}
#ifndef PORT_HAS_ICON_VIEW
if (panel->list_type == list_icons)
panel->list_type = list_full;
#endif
1998-02-27 07:54:42 +03:00
/* User formats */
if (panel->user_format){
g_free (panel->user_format);
1998-02-27 07:54:42 +03:00
panel->user_format = 0;
}
panel->user_format = g_strdup (get_profile_string (section, "user_format",
1998-02-27 07:54:42 +03:00
DEFAULT_USER_FORMAT,
profile_name));
for (i = 0; i < LIST_TYPES; i++){
if (panel->user_status_format [i])
g_free (panel->user_status_format [i]);
g_snprintf (buffer, sizeof (buffer), "user_status%d", i);
1998-02-27 07:54:42 +03:00
panel->user_status_format [i] =
g_strdup (get_profile_string (section, buffer,
1998-02-27 07:54:42 +03:00
DEFAULT_USER_FORMAT, profile_name));
}
1998-02-27 07:54:42 +03:00
panel->user_mini_status =
load_int (section, "user_mini_status", 0);
}
1998-12-03 00:27:27 +03:00
static void
load_layout (char *profile_name)
1998-02-27 07:54:42 +03:00
{
int i;
1998-02-27 07:54:42 +03:00
for (i = 0; layout [i].opt_name; i++)
*layout [i].opt_addr =
load_int ("Layout", layout [i].opt_name,
*layout [i].opt_addr);
}
1998-12-03 00:27:27 +03:00
static int
load_mode (char *section)
1998-02-27 07:54:42 +03:00
{
char buffer [20];
int i;
1998-02-27 07:54:42 +03:00
int mode = view_listing;
1998-02-27 07:54:42 +03:00
/* Load the display mode */
load_string (section, "display", "listing", buffer, sizeof (buffer));
for (i = 0; panel_types [i].opt_name; i++)
if ( g_strcasecmp (panel_types [i].opt_name, buffer) == 0){
1998-02-27 07:54:42 +03:00
mode = panel_types [i].opt_type;
break;
}
return mode;
}
1998-12-03 00:27:27 +03:00
static char *
do_load_string (char *s, char *ss, char *def)
1998-02-27 07:54:42 +03:00
{
char *buffer = g_malloc (BUF_SMALL);
1998-02-27 07:54:42 +03:00
char *p;
load_string (s, ss, def, buffer, BUF_SMALL);
1998-02-27 07:54:42 +03:00
p = g_strdup (buffer);
g_free (buffer);
1998-02-27 07:54:42 +03:00
return p;
}
char *
setup_init (void)
1998-02-27 07:54:42 +03:00
{
char *profile;
char *inifile;
if (profile_name)
return profile_name;
profile = concat_dir_and_file (home_dir, PROFILE_NAME);
if (!exist_file (profile)){
inifile = concat_dir_and_file (mc_home, "mc.ini");
if (exist_file (inifile)){
g_free (profile);
profile = inifile;
} else
g_free (inifile);
1998-02-27 07:54:42 +03:00
}
1998-02-27 07:54:42 +03:00
profile_name = profile;
return profile;
}
void
load_setup (void)
{
char *profile;
int i;
profile = setup_init ();
1998-02-27 07:54:42 +03:00
/* Load integer boolean options */
for (i = 0; options [i].opt_name; i++)
*options [i].opt_addr =
get_int (profile, options [i].opt_name, *options [i].opt_addr);
#ifdef HAVE_GNOME
g_free (default_user_format);
default_user_format = do_load_string (app_text, "default_user_format", DEFAULT_USER_FORMAT);
#endif
1998-02-27 07:54:42 +03:00
load_layout (profile);
load_panelize ();
startup_left_mode = load_mode ("New Left Panel");
startup_right_mode = load_mode ("New Right Panel");
/* At least one of the panels is a listing panel */
if (startup_left_mode != view_listing && startup_right_mode!=view_listing)
startup_left_mode = view_listing;
1998-02-27 07:54:42 +03:00
if (!other_dir){
char *buffer;
buffer = (char*) g_malloc (MC_MAXPATHLEN);
1998-02-27 07:54:42 +03:00
load_string ("Dirs", "other_dir", ".", buffer,
MC_MAXPATHLEN);
if (vfs_file_is_local (buffer))
other_dir = buffer;
else
g_free (buffer);
1998-02-27 07:54:42 +03:00
}
#ifdef USE_NETCODE
ftpfs_proxy_host = do_load_string ("Misc", "ftp_proxy_host", "gate");
#endif
boot_current_is_left =
GetPrivateProfileInt ("Dirs", "current_is_left", 1, profile);
1998-02-27 07:54:42 +03:00
load_string ("Misc", "find_ignore_dirs", "", setup_color_string,
sizeof (setup_color_string));
if (setup_color_string [0])
find_ignore_dirs = g_strconcat (":", setup_color_string, ":", NULL);
1998-02-27 07:54:42 +03:00
/* The default color and the terminal dependent color */
load_string ("Colors", "base_color", "", setup_color_string,
sizeof (setup_color_string));
load_string ("Colors", getenv ("TERM"), "",
term_color_string, sizeof (term_color_string));
load_string ("Colors", "color_terminals", "",
color_terminal_string, sizeof (color_terminal_string));
/* Load the directory history */
/* directory_history_load (); */
1998-02-27 07:54:42 +03:00
/* Remove the temporal entries */
profile_clean_section ("Temporal:New Left Panel", profile_name);
profile_clean_section ("Temporal:New Right Panel", profile_name);
2000-02-02 19:57:51 +03:00
#ifdef USE_VFS
#ifdef USE_NETCODE
ftpfs_init_passwd ();
#endif
#endif
#ifdef HAVE_CHARSET
if ( load_codepages_list() <= 0 ) {
char errmsg[256];
sprintf( errmsg, _("Can't load %s"), CHARSETS_INDEX );
message( 1, MSG_ERROR, "%s", errmsg );
} else {
char cpname[128];
load_string( "Misc", "display_codepage", "",
cpname, sizeof(cpname) );
if ( cpname[0] != '\0' )
display_codepage = get_codepage_index( cpname );
}
init_printable_table( display_codepage );
{
char *errmsg = init_translation_table( source_codepage,
display_codepage );
if (errmsg)
message( 1, MSG_ERROR, "%s", errmsg );
}
#endif
1998-02-27 07:54:42 +03:00
}
#ifdef USE_VFS
#ifdef USE_NETCODE
1998-12-03 00:27:27 +03:00
char *
load_anon_passwd ()
1998-02-27 07:54:42 +03:00
{
char buffer [255];
load_string ("Misc", "ftpfs_password", "", buffer, sizeof (buffer));
if (buffer [0])
return g_strdup (buffer);
1998-02-27 07:54:42 +03:00
else
return 0;
}
#endif
#endif
void done_setup (void)
{
g_free (profile_name);
#ifndef HAVE_X
1998-02-27 07:54:42 +03:00
done_hotlist ();
#endif /* HAVE_X */
1998-02-27 07:54:42 +03:00
done_panelize ();
/* directory_history_free (); */
1998-02-27 07:54:42 +03:00
}
#ifndef HAVE_X
1998-12-03 00:27:27 +03:00
static void
load_keys_from_section (char *terminal, char *profile_name)
1998-02-27 07:54:42 +03:00
{
char *section_name;
void *profile_keys;
char *key, *value, *valcopy;
int key_code;
if (!terminal)
return;
section_name = g_strconcat ("terminal:", terminal, NULL);
1998-02-27 07:54:42 +03:00
profile_keys = profile_init_iterator (section_name, profile_name);
if (!profile_keys){
g_free (section_name);
1998-02-27 07:54:42 +03:00
return;
}
1998-02-27 07:54:42 +03:00
while (profile_keys){
profile_keys = profile_iterator_next (profile_keys, &key, &value);
key_code = lookup_key (key);
valcopy = convert_controls (value);
if (key_code)
define_sequence (key_code, valcopy, MCKEY_NOACTION);
g_free (valcopy);
1998-02-27 07:54:42 +03:00
}
g_free (section_name);
1998-02-27 07:54:42 +03:00
return;
}
void load_key_defs (void)
{
char *libfile = concat_dir_and_file (mc_home, "mc.lib");
load_keys_from_section (getenv ("TERM"), profile_name);
load_keys_from_section ("general", profile_name);
load_keys_from_section (getenv ("TERM"), libfile);
load_keys_from_section ("general", libfile);
/* We don't want a huge database loaded in core */
free_profile_name (libfile);
g_free (libfile);
1998-02-27 07:54:42 +03:00
}
#endif