Revert "Ticket #1605: Incorrect parsing FTP-string"
[midnight-commander.git] / src / option.c
blob724864225f6874048bd7015df05718dec12dc5fa
1 /* Configure box module for the Midnight Commander
2 Copyright (C) 1994, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
3 2007, 2009 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 /** \file option.c
21 * \brief Source: configure box module
24 #include <config.h>
26 #include <stdio.h>
27 #include <string.h>
29 #include <sys/types.h>
30 #include <sys/stat.h>
31 #include <unistd.h>
33 #include "global.h"
35 #include "../src/tty/tty.h"
37 #include "dialog.h"
38 #include "widget.h"
39 #include "setup.h" /* For save_setup() */
40 #include "main.h"
41 #include "../src/mcconfig/mcconfig.h" /* For mc_config_save_file */
42 #include "strutil.h"
43 #include "panel.h" /* Needed for the externs */
44 #include "file.h" /* safe_delete */
45 #include "layout.h" /* For nice_rotating_dash */
46 #include "option.h"
48 static Dlg_head *conf_dlg;
50 #define TOGGLE_VARIABLE 0
52 static int first_width, second_width;
54 static struct {
55 const char *text;
56 int *variable;
57 void (*toggle_function)(void);
58 WCheck *widget;
59 } check_options [] = {
60 /* other options */
61 {N_("safe de&Lete"), &safe_delete, TOGGLE_VARIABLE, 0 },
62 {N_("cd follows lin&Ks"), &cd_symlinks, TOGGLE_VARIABLE, 0 },
63 {N_("L&ynx-like motion"), &navigate_with_arrows,TOGGLE_VARIABLE, 0 },
64 {N_("rotatin&G dash"), &nice_rotating_dash,TOGGLE_VARIABLE, 0 },
65 {N_("co&Mplete: show all"),&show_all_if_ambiguous,TOGGLE_VARIABLE, 0 },
66 {N_("&Use internal view"), &use_internal_view, TOGGLE_VARIABLE, 0 },
67 {N_("use internal ed&It"), &use_internal_edit, TOGGLE_VARIABLE, 0 },
68 {N_("auto m&Enus"), &auto_menu, TOGGLE_VARIABLE, 0 },
69 {N_("&Auto save setup"), &auto_save_setup, TOGGLE_VARIABLE, 0 },
70 {N_("shell &Patterns"), &easy_patterns, TOGGLE_VARIABLE, 0 },
71 {N_("Compute &Totals"), &file_op_compute_totals, TOGGLE_VARIABLE, 0 },
72 {N_("&Verbose operation"), &verbose, TOGGLE_VARIABLE, 0 },
73 {N_("Mkdir autoname"), &auto_fill_mkdir_name, TOGGLE_VARIABLE, 0 },
74 /* panel options */
75 {N_("&Fast dir reload"), &fast_reload, toggle_fast_reload, 0 },
76 {N_("mi&X all files"), &mix_all_files, toggle_mix_all_files, 0 },
77 {N_("&Drop down menus"), &drop_menus, TOGGLE_VARIABLE, 0 },
78 {N_("ma&Rk moves down"), &mark_moves_down, TOGGLE_VARIABLE, 0 },
79 {N_("show &Hidden files"), &show_dot_files, toggle_show_hidden, 0 },
80 {N_("show &Backup files"), &show_backups, toggle_show_backup, 0 },
81 {N_("Use SI si&ze units"), &kilobyte_si, toggle_kilobyte_si, 0 },
82 { 0, 0, 0, 0 }
85 /* Make sure this corresponds to the check_options structure */
86 #define OTHER_OPTIONS 13
87 #define PANEL_OPTIONS 7
89 static WRadio *pause_radio;
91 static const char *pause_options [3] = {
92 N_("&Never"),
93 N_("on dumb &Terminals"),
94 N_("Alwa&ys") };
96 #define PAUSE_OPTIONS (sizeof(pause_options) / sizeof(pause_options[0]))
98 /* Heights of the panes */
99 #define PY 3
100 #define OY PY
101 /* Align bottoms of "pause after run" and "other options" */
102 #define RY (OTHER_OPTIONS - PAUSE_OPTIONS + OY)
103 #define DLG_Y (OTHER_OPTIONS + 9)
104 #define BY (DLG_Y - 3)
106 /* Horizontal dimensions */
107 #define X_MARGIN 3
108 #define X_PANE_GAP 1
109 #define PX X_MARGIN
110 #define RX X_MARGIN
111 #define OX (first_width + X_MARGIN + X_PANE_GAP)
113 /* Create the "Configure options" dialog */
114 static void
115 init_configure (void)
117 int i;
118 static int i18n_config_flag = 0;
119 static int b1, b2, b3;
120 const char *ok_button = _("&OK");
121 const char *cancel_button = _("&Cancel");
122 const char *save_button = _("&Save");
123 static const char *title1, *title2, *title3;
125 if (!i18n_config_flag) {
126 register int l1;
128 /* Similar code is in layout.c (init_layout()) */
130 title1 = _(" Panel options ");
131 title2 = _(" Pause after run... ");
132 title3 = _(" Other options ");
134 first_width = str_term_width1 (title1) + 1;
135 second_width = str_term_width1 (title3) + 1;
137 for (i = 0; check_options[i].text; i++) {
138 check_options[i].text = _(check_options[i].text);
139 l1 = str_term_width1 (check_options[i].text) + 7;
140 if (i >= OTHER_OPTIONS) {
141 if (l1 > first_width)
142 first_width = l1;
143 } else {
144 if (l1 > second_width)
145 second_width = l1;
149 i = PAUSE_OPTIONS;
150 while (i--) {
151 pause_options[i] = _(pause_options[i]);
152 l1 = str_term_width1 (pause_options[i]) + 7;
153 if (l1 > first_width)
154 first_width = l1;
157 l1 = str_term_width1 (title2) + 1;
158 if (l1 > first_width)
159 first_width = l1;
161 l1 = 11 + str_term_width1 (ok_button)
162 + str_term_width1 (save_button)
163 + str_term_width1 (cancel_button);
165 i = (first_width + second_width - l1) / 4;
166 b1 = 5 + i;
167 b2 = b1 + str_term_width1 (ok_button) + i + 6;
168 b3 = b2 + str_term_width1 (save_button) + i + 4;
170 i18n_config_flag = 1;
173 conf_dlg =
174 create_dlg (0, 0, DLG_Y,
175 first_width + second_width + 2 * X_MARGIN + X_PANE_GAP,
176 dialog_colors, NULL, "[Configuration]",
177 _("Configure options"), DLG_CENTER | DLG_REVERSE);
179 add_widget (conf_dlg,
180 groupbox_new (PY, PX, PANEL_OPTIONS + 2, first_width, title1));
182 add_widget (conf_dlg,
183 groupbox_new (RY, RX, PAUSE_OPTIONS + 2, first_width, title2));
185 add_widget (conf_dlg,
186 groupbox_new (OY, OX, OTHER_OPTIONS + 2, second_width, title3));
188 add_widget (conf_dlg,
189 button_new (BY, b3, B_CANCEL, NORMAL_BUTTON,
190 cancel_button, 0));
192 add_widget (conf_dlg,
193 button_new (BY, b2, B_EXIT, NORMAL_BUTTON,
194 save_button, 0));
196 add_widget (conf_dlg,
197 button_new (BY, b1, B_ENTER, DEFPUSH_BUTTON,
198 ok_button, 0));
200 #define XTRACT(i) *check_options[i].variable, check_options[i].text
202 /* Add checkboxes for "other options" */
203 for (i = 0; i < OTHER_OPTIONS; i++) {
204 check_options[i].widget =
205 check_new (OY + (OTHER_OPTIONS - i), OX + 2, XTRACT (i));
206 add_widget (conf_dlg, check_options[i].widget);
209 pause_radio =
210 radio_new (RY + 1, RX + 2, 3, pause_options);
211 pause_radio->sel = pause_after_run;
212 add_widget (conf_dlg, pause_radio);
214 /* Add checkboxes for "panel options" */
215 for (i = 0; i < PANEL_OPTIONS; i++) {
216 check_options[i + OTHER_OPTIONS].widget =
217 check_new (PY + (PANEL_OPTIONS - i), PX + 2,
218 XTRACT (i + OTHER_OPTIONS));
219 add_widget (conf_dlg, check_options[i + OTHER_OPTIONS].widget);
224 void configure_box (void)
226 int result, i;
228 init_configure ();
229 run_dlg (conf_dlg);
231 result = conf_dlg->ret_value;
232 if (result == B_ENTER || result == B_EXIT){
233 for (i = 0; check_options [i].text; i++)
234 if (check_options [i].widget->state & C_CHANGE){
235 if (check_options [i].toggle_function)
236 (*check_options [i].toggle_function)();
237 else
238 *check_options [i].variable =
239 !(*check_options [i].variable);
241 pause_after_run = pause_radio->sel;
244 /* If they pressed the save button */
245 if (result == B_EXIT){
246 save_configure ();
247 mc_config_save_file (mc_main_config, NULL);
250 destroy_dlg (conf_dlg);