Ticket #2316: code cleanup before 4.7.4 release.
[pantumic.git] / src / boxes.c
blob884d4e57dd4bad34b284454b2dc64888399919d9
1 /* Some misc dialog boxes for the program.
3 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 2005, 2006, 2009 Free Software Foundation, Inc.
6 Authors: 1994, 1995 Miguel de Icaza
7 1995 Jakub Jelinek
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program 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, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
23 /** \file boxes.c
24 * \brief Source: Some misc dialog boxes for the program
27 #include <config.h>
29 #include <ctype.h>
30 #include <signal.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
37 #include "lib/global.h"
39 #include "lib/tty/tty.h"
40 #include "lib/tty/key.h" /* XCTRL and ALT macros */
41 #include "lib/skin.h" /* INPUT_COLOR */
42 #include "lib/mcconfig.h" /* Load/save user formats */
43 #include "lib/strutil.h"
45 #include "lib/vfs/mc-vfs/vfs.h"
46 #ifdef ENABLE_VFS_FTP
47 #include "lib/vfs/mc-vfs/ftpfs.h"
48 #endif /* ENABLE_VFS_FTP */
49 #ifdef ENABLE_VFS_SMB
50 #include "lib/vfs/mc-vfs/smbfs.h"
51 #endif /* ENABLE_VFS_SMB */
53 #include "dialog.h" /* The nice dialog manager */
54 #include "widget.h" /* The widgets for the nice dialog manager */
55 #include "wtools.h"
56 #include "setup.h" /* For profile_name */
57 #include "command.h" /* For cmdline */
58 #include "dir.h"
59 #include "panel.h" /* LIST_TYPES */
60 #include "main.h" /* For the confirm_* variables */
61 #include "tree.h"
62 #include "layout.h" /* for get_nth_panel_name proto */
63 #include "background.h" /* task_list */
65 #ifdef HAVE_CHARSET
66 #include "charsets.h"
67 #include "selcodepage.h"
68 #endif
70 #include "boxes.h"
72 static WRadio *display_radio;
73 static WInput *display_user_format;
74 static WInput *display_mini_status;
75 static WCheck *display_check_status;
76 static char **displays_status;
77 static int display_user_hotkey = 'u';
79 static cb_ret_t
80 display_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
82 switch (msg)
84 case DLG_KEY:
85 if (parm == '\n')
87 if (dlg_widget_active (display_radio))
89 assign_text (display_mini_status, displays_status[display_radio->sel]);
90 dlg_stop (h);
91 return MSG_HANDLED;
94 if (dlg_widget_active (display_user_format))
96 h->ret_value = B_USER + 6;
97 dlg_stop (h);
98 return MSG_HANDLED;
101 if (dlg_widget_active (display_mini_status))
103 h->ret_value = B_USER + 7;
104 dlg_stop (h);
105 return MSG_HANDLED;
109 if (g_ascii_tolower (parm) == display_user_hotkey)
111 display_radio->pos = display_radio->sel = 3;
112 dlg_select_widget (display_radio); /* force redraw */
113 h->callback (h, (Widget *) display_radio, DLG_ACTION, 0, NULL);
114 return MSG_HANDLED;
116 return MSG_NOT_HANDLED;
118 case DLG_ACTION:
119 if (sender == (Widget *) display_radio)
121 if (!(display_check_status->state & C_BOOL))
122 assign_text (display_mini_status, displays_status[display_radio->sel]);
123 update_input (display_mini_status, 0);
124 update_input (display_user_format, 0);
125 widget_disable (display_user_format->widget, display_radio->sel != 3);
126 return MSG_HANDLED;
129 if (sender == (Widget *) display_check_status)
131 if (display_check_status->state & C_BOOL)
133 widget_disable (display_mini_status->widget, FALSE);
134 assign_text (display_mini_status, displays_status[3]);
136 else
138 widget_disable (display_mini_status->widget, TRUE);
139 assign_text (display_mini_status, displays_status[display_radio->sel]);
141 update_input (display_mini_status, 0);
142 return MSG_HANDLED;
145 return MSG_NOT_HANDLED;
147 default:
148 return default_dlg_callback (h, sender, msg, parm, data);
152 static Dlg_head *
153 display_init (int radio_sel, char *init_text, int _check_status, char **_status)
155 int dlg_width = 48, dlg_height = 15;
156 Dlg_head *dd;
158 const int input_colors[3] =
160 INPUT_COLOR,
161 INPUT_UNCHANGED_COLOR,
162 INPUT_MARK_COLOR
165 /* Controls whether the array strings have been translated */
166 const char *displays[LIST_TYPES] = {
167 N_("&Full file list"),
168 N_("&Brief file list"),
169 N_("&Long file list"),
170 N_("&User defined:")
173 /* Index in displays[] for "user defined" */
174 const int user_type_idx = 3;
176 const char *display_title = N_("Listing mode");
177 const char *user_mini_status = N_("User &mini status");
178 const char *ok_name = N_("&OK");
179 const char *cancel_name = N_("&Cancel");
181 WButton *ok_button, *cancel_button;
184 int i, maxlen = 0;
185 const char *cp;
186 int ok_len, cancel_len, b_len, gap;
188 #ifdef ENABLE_NLS
189 display_title = _(display_title);
190 user_mini_status = _(user_mini_status);
191 ok_name = _(ok_name);
192 cancel_name = _(cancel_name);
194 for (i = 0; i < LIST_TYPES; i++)
195 displays[i] = _(displays[i]);
196 #endif
198 /* get hotkey of user-defined format string */
199 cp = strchr (displays[user_type_idx], '&');
200 if (cp != NULL && *++cp != '\0')
201 display_user_hotkey = g_ascii_tolower (*cp);
203 /* xpos will be fixed later */
204 ok_button = button_new (dlg_height - 3, 0, B_ENTER, DEFPUSH_BUTTON, ok_name, 0);
205 ok_len = button_get_len (ok_button);
206 cancel_button = button_new (dlg_height - 3, 0, B_CANCEL, NORMAL_BUTTON, cancel_name, 0);
207 cancel_len = button_get_len (cancel_button);
208 b_len = ok_len + cancel_len + 2;
210 dlg_width = max (dlg_width, str_term_width1 (display_title) + 10);
211 /* calculate max width of radiobutons */
212 for (i = 0; i < LIST_TYPES; i++)
213 maxlen = max (maxlen, str_term_width1 (displays[i]));
214 dlg_width = max (dlg_width, maxlen);
215 dlg_width = max (dlg_width, str_term_width1 (user_mini_status) + 13);
217 /* buttons */
218 dlg_width = max (dlg_width, b_len + 6);
219 gap = (dlg_width - 6 - b_len) / 3;
220 ok_button->widget.x = 3 + gap;
221 cancel_button->widget.x = ok_button->widget.x + ok_len + gap + 2;
224 displays_status = _status;
226 dd = create_dlg (TRUE, 0, 0, dlg_height, dlg_width, dialog_colors,
227 display_callback, "[Listing Mode...]", display_title,
228 DLG_CENTER | DLG_REVERSE);
230 add_widget (dd, cancel_button);
231 add_widget (dd, ok_button);
233 display_mini_status = input_new (10, 8, (int *) input_colors, dlg_width - 12, _status[radio_sel],
234 "mini-input", INPUT_COMPLETE_DEFAULT);
235 add_widget (dd, display_mini_status);
237 display_check_status = check_new (9, 4, _check_status, user_mini_status);
238 add_widget (dd, display_check_status);
240 display_user_format = input_new (7, 8, (int *) input_colors, dlg_width - 12, init_text,
241 "user-fmt-input", INPUT_COMPLETE_DEFAULT);
242 add_widget (dd, display_user_format);
244 display_radio = radio_new (3, 4, LIST_TYPES, displays);
245 display_radio->sel = display_radio->pos = radio_sel;
246 add_widget (dd, display_radio);
248 return dd;
251 /* return list type */
253 display_box (WPanel * panel, char **userp, char **minip, int *use_msformat, int num)
255 int result = -1;
256 Dlg_head *dd;
257 char *section = NULL;
258 size_t i;
260 if (panel == NULL)
262 const char *p = get_nth_panel_name (num);
263 panel = g_new (WPanel, 1);
264 panel->list_type = list_full;
265 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
266 panel->user_mini_status = 0;
267 for (i = 0; i < LIST_TYPES; i++)
268 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
269 section = g_strconcat ("Temporal:", p, (char *) NULL);
270 if (!mc_config_has_group (mc_main_config, section))
272 g_free (section);
273 section = g_strdup (p);
275 panel_load_setup (panel, section);
276 g_free (section);
279 dd = display_init (panel->list_type, panel->user_format,
280 panel->user_mini_status, panel->user_status_format);
282 if (run_dlg (dd) != B_CANCEL)
284 result = display_radio->sel;
285 *userp = g_strdup (display_user_format->buffer);
286 *minip = g_strdup (display_mini_status->buffer);
287 *use_msformat = display_check_status->state & C_BOOL;
290 if (section != NULL)
292 g_free (panel->user_format);
293 for (i = 0; i < LIST_TYPES; i++)
294 g_free (panel->user_status_format[i]);
295 g_free (panel);
298 destroy_dlg (dd);
300 return result;
303 const panel_field_t *
304 sort_box (const panel_field_t * sort_format, int *reverse, int *case_sensitive, int *exec_first)
306 int dlg_width = 40, dlg_height = 7;
308 const char **sort_orders_names;
309 gsize sort_names_num;
311 int sort_idx = 0;
313 const panel_field_t *result = sort_format;
315 sort_orders_names = panel_get_sortable_fields (&sort_names_num);
316 dlg_height += sort_names_num;
319 int max_radio = 0, max_check = 0;
320 int ok_len, cancel_len;
321 gsize i;
323 QuickWidget quick_widgets[] = {
324 /* 0 */
325 QUICK_BUTTON (0, dlg_width, dlg_height - 3, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
326 /* 1 */
327 QUICK_BUTTON (0, dlg_width, dlg_height - 3, dlg_height, N_("&OK"), B_ENTER, NULL),
328 /* 2 */
329 QUICK_CHECKBOX (0, dlg_width, 5, dlg_height, N_("&Reverse"), reverse),
330 /* 3 */
331 QUICK_CHECKBOX (0, dlg_width, 4, dlg_height, N_("Case sensi&tive"), case_sensitive),
332 /* 4 */
333 QUICK_CHECKBOX (0, dlg_width, 3, dlg_height, N_("Executable &first"), exec_first),
334 /* 5 */
335 QUICK_RADIO (4, dlg_width, 3, dlg_height, 0,
336 NULL, &sort_idx),
337 QUICK_END
340 QuickDialog quick_dlg = {
341 dlg_width, dlg_height, -1, -1,
342 N_("Sort order"), "[Sort Order...]",
343 quick_widgets, NULL, TRUE
346 quick_widgets[5].u.radio.items = sort_orders_names;
347 quick_widgets[5].u.radio.count = sort_names_num;
349 for (i = 0; i < sort_names_num; i++)
350 if (strcmp (sort_orders_names[i], _(sort_format->title_hotkey)) == 0)
352 sort_idx = i;
353 break;
356 #ifdef ENABLE_NLS
357 quick_dlg.title = _(quick_dlg.title);
358 /* buttons */
359 for (i = 0; i < 2; i++)
360 quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
361 /* checkboxes */
362 for (i = 2; i < 5; i++)
363 quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
364 #endif /* ENABLE_NlS */
366 /* buttons */
367 cancel_len = str_term_width1 (quick_widgets[0].u.button.text) + 4;
368 ok_len = str_term_width1 (quick_widgets[1].u.button.text) + 6;
369 /* checkboxes */
370 for (i = 2; i < 5; i++)
371 max_check = max (max_check, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4);
372 /* radiobuttons */
373 for (i = 0; i < sort_names_num; i++)
374 max_radio = max (max_radio, str_term_width1 (sort_orders_names[i]) + 4);
376 /* dialog width */
377 dlg_width = max (dlg_width, str_term_width1 (quick_dlg.title) + 8);
378 dlg_width = max (dlg_width, ok_len + cancel_len + 8);
379 dlg_width = max (dlg_width, 2 * max (max_radio, max_check) + 8);
381 /* fix widget and dialog parameters */
382 /* dialog */
383 quick_dlg.xlen = dlg_width;
384 /* widgets */
385 for (i = 0; (size_t) i < sizeof (quick_widgets) / sizeof (quick_widgets[0]) - 1; i++)
386 quick_widgets[i].x_divisions = dlg_width;
387 /* buttons */
388 quick_widgets[0].relative_x = dlg_width * 2 / 3 - cancel_len / 2;
389 quick_widgets[1].relative_x = dlg_width / 3 - ok_len / 2;
390 /* checkboxes */
391 for (i = 2; i < 5; i++)
392 quick_widgets[i].relative_x = dlg_width / 2 + 2;
394 if (quick_dialog (&quick_dlg) != B_CANCEL)
395 result = panel_get_field_by_title_hotkey (sort_orders_names[sort_idx]);
397 if (result == NULL)
398 result = sort_format;
400 g_strfreev ((gchar **) sort_orders_names);
401 return result;
405 void
406 confirm_box (void)
408 const char *title = _("Confirmation");
410 QuickWidget conf_widgets[] = {
411 /* 0 */ QUICK_BUTTON (29, 46, 10, 13, N_("&Cancel"), B_CANCEL, NULL),
412 /* 1 */ QUICK_BUTTON (12, 46, 10, 13, N_("&OK"), B_ENTER, NULL),
413 /* TRANSLATORS: no need to translate 'Confirmation', it's just a context prefix */
414 /* 2 */ QUICK_CHECKBOX (3, 46, 8, 13, N_("Confirmation|&History cleanup"),
415 &confirm_history_cleanup),
416 /* 3 */ QUICK_CHECKBOX (3, 46, 7, 13, N_("Confirmation|Di&rectory hotlist delete"),
417 &confirm_directory_hotlist_delete),
418 /* 4 */ QUICK_CHECKBOX (3, 46, 6, 13, N_("Confirmation|E&xit"), &confirm_exit),
419 /* 5 */ QUICK_CHECKBOX (3, 46, 5, 13, N_("Confirmation|&Execute"), &confirm_execute),
420 /* 6 */ QUICK_CHECKBOX (3, 46, 4, 13, N_("Confirmation|O&verwrite"), &confirm_overwrite),
421 /* 7 */ QUICK_CHECKBOX (3, 46, 3, 13, N_("Confirmation|&Delete"), &confirm_delete),
422 QUICK_END
425 const size_t w_num = sizeof (conf_widgets) / sizeof (conf_widgets[0]) - 1;
427 /* dialog sizes */
428 int dlg_width = 46;
429 int dlg_height = w_num + 5;
431 size_t i;
432 int maxlen = 0;
433 int cancel_len, ok_len, blen;
435 #ifdef ENABLE_NLS
436 title = _(title);
438 for (i = 0; i < 2; i++)
439 conf_widgets[i].u.button.text = _(conf_widgets[i].u.button.text);
440 #endif /* ENABLE_NLS */
442 for (i = 2; i < w_num; i++)
443 conf_widgets[i].u.checkbox.text = Q_ (conf_widgets[i].u.checkbox.text);
445 /* maximum length of checkboxes */
446 for (i = 2; i < w_num; i++)
447 maxlen = max (maxlen, str_term_width1 (conf_widgets[i].u.checkbox.text) + 4);
449 /* length of buttons */
450 cancel_len = str_term_width1 (conf_widgets[0].u.button.text) + 3;
451 ok_len = str_term_width1 (conf_widgets[1].u.button.text) + 5; /* default button */
453 blen = cancel_len + ok_len + 2;
455 dlg_width = max (maxlen, blen) + 6;
456 dlg_width = max (dlg_width, str_term_width1 (title) + 4);
458 /* correct widget parameters */
459 for (i = 0; i < w_num; i++)
461 conf_widgets[i].x_divisions = dlg_width;
462 conf_widgets[i].y_divisions = dlg_height;
465 conf_widgets[1].relative_x = dlg_width / 2 - blen / 2;
466 conf_widgets[0].relative_x = conf_widgets[1].relative_x + ok_len + 2;
469 QuickDialog confirmation = {
470 dlg_width, dlg_height, -1, -1, title,
471 "[Confirmation]", conf_widgets, NULL, TRUE
474 (void) quick_dialog (&confirmation);
479 #ifndef HAVE_CHARSET
480 void
481 display_bits_box (void) /* AB:FIXME: test dialog */
483 /* dialog sizes */
484 const int DISPY = 13;
485 const int DISPX = 46;
487 int new_meta = 0;
488 int current_mode;
490 const char *display_bits_str[] = {
491 N_("UTF-8 output"),
492 N_("Full 8 bits output"),
493 N_("ISO 8859-1"),
494 N_("7 bits")
497 QuickWidget display_widgets[] = {
498 /* 0 */ QUICK_BUTTON (15, DISPX, DISPY - 3, DISPY, N_("&Cancel"), B_CANCEL, NULL),
499 /* 1 */ QUICK_BUTTON (29, DISPX, DISPY - 3, DISPY, N_("&OK"), B_ENTER, NULL),
500 /* 2 */ QUICK_CHECKBOX (3, DISPX, 8, DISPY, N_("F&ull 8 bits input"), &new_meta),
501 /* 3 */ QUICK_RADIO (3, DISPX, 3, DISPY, 4, display_bits_str, &current_mode),
502 QUICK_END
505 QuickDialog display_bits = {
506 DISPX, DISPY, -1, -1, _("Display bits"),
507 "[Display bits]", display_widgets, NULL, TRUE
510 int i;
511 int l1, maxlen = 0;
512 int ok_len, cancel_len;
514 #ifdef ENABLE_NLS
515 static gboolean i18n_flag = FALSE;
517 if (!i18n_flag)
519 for (i = 0; i < 3; i++)
521 display_bits_str[i] = _(display_bits_str[i]);
524 display_widgets[0].u.button.text = _(display_widgets[0].u.button.text);
525 display_widgets[1].u.button.text = _(display_widgets[1].u.button.text);
526 display_widgets[2].u.checkbox.text = _(display_widgets[2].u.checkbox.text);
528 i18n_flag = TRUE;
530 #endif /* ENABLE_NLS */
532 /* radiobuttons */
533 for (i = 0; i < 3; i++)
534 maxlen = max (maxlen, str_term_width1 (display_bits_str[i]));
536 /* buttons */
537 cancel_len = str_term_width1 (display_widgets[0].u.button.text) + 2;
538 ok_len = str_term_width1 (display_widgets[1].u.button.text) + 4; /* default button */
540 l1 = max (cancel_len, ok_len);
542 display_bits.xlen = max (maxlen, l1) + 20;
544 for (i = 0; i < 4; i++)
545 display_widgets[i].x_divisions = display_bits.xlen;
547 display_widgets[0].relative_x = display_bits.xlen * 2 / 3 - cancel_len / 2;
548 display_widgets[1].relative_x = display_bits.xlen / 3 - ok_len / 2;
550 if (full_eight_bits)
551 current_mode = 0;
552 else if (eight_bit_clean)
553 current_mode = 1;
554 else
555 current_mode = 2;
557 new_meta = !use_8th_bit_as_meta;
559 if (quick_dialog (&display_bits) != B_CANCEL)
561 eight_bit_clean = current_mode < 3;
562 full_eight_bits = current_mode < 2;
563 #ifndef HAVE_SLANG
564 meta (stdscr, eight_bit_clean);
565 #else
566 SLsmg_Display_Eight_Bit = full_eight_bits ? 128 : 160;
567 #endif
568 use_8th_bit_as_meta = !new_meta;
572 #else /* HAVE_CHARSET */
574 static int new_display_codepage;
576 static WLabel *cplabel;
577 static WCheck *inpcheck;
579 static int
580 sel_charset_button (WButton *button, int action)
582 int new_dcp;
584 (void) button;
585 (void) action;
587 new_dcp = select_charset (-1, -1, new_display_codepage, TRUE);
589 if (new_dcp != SELECT_CHARSET_CANCEL)
591 const char *cpname;
592 char buf[BUF_TINY];
594 new_display_codepage = new_dcp;
595 cpname = (new_display_codepage == SELECT_CHARSET_OTHER_8BIT) ?
596 _("Other 8 bit") : codepages[new_display_codepage].name;
597 if (cpname != NULL)
598 utf8_display = str_isutf8 (cpname);
599 /* avoid strange bug with label repainting */
600 g_snprintf (buf, sizeof (buf), "%-27s", cpname);
601 label_set_text (cplabel, buf);
604 return 0;
607 static Dlg_head *
608 init_disp_bits_box (void)
610 /* dialog sizes */
611 const int DISPY = 11;
612 const int DISPX = 46;
614 const char *cpname;
615 Dlg_head *dbits_dlg;
617 do_refresh ();
619 dbits_dlg =
620 create_dlg (TRUE, 0, 0, DISPY, DISPX, dialog_colors, NULL,
621 "[Display bits]", _("Display bits"), DLG_CENTER | DLG_REVERSE);
623 add_widget (dbits_dlg, label_new (3, 4, _("Input / display codepage:")));
625 cpname = (new_display_codepage < 0) ? _("Other 8 bit") : codepages[new_display_codepage].name;
626 cplabel = label_new (4, 4, cpname);
627 add_widget (dbits_dlg, cplabel);
629 add_widget (dbits_dlg,
630 button_new (DISPY - 3, DISPX / 2 + 3, B_CANCEL, NORMAL_BUTTON, _("&Cancel"), 0));
631 add_widget (dbits_dlg, button_new (DISPY - 3, 7, B_ENTER, NORMAL_BUTTON, _("&OK"), 0));
633 inpcheck = check_new (6, 4, !use_8th_bit_as_meta, _("F&ull 8 bits input"));
634 add_widget (dbits_dlg, inpcheck);
636 cpname = _("&Select");
637 add_widget (dbits_dlg,
638 button_new (4, DISPX - 7 - str_term_width1 (cpname), B_USER,
639 NORMAL_BUTTON, cpname, sel_charset_button));
641 return dbits_dlg;
644 void
645 display_bits_box (void)
647 Dlg_head *dbits_dlg;
648 new_display_codepage = display_codepage;
650 application_keypad_mode ();
651 dbits_dlg = init_disp_bits_box ();
653 run_dlg (dbits_dlg);
655 if (dbits_dlg->ret_value == B_ENTER)
657 char *errmsg;
659 display_codepage = new_display_codepage;
660 errmsg = init_translation_table (source_codepage, display_codepage);
661 if (errmsg != NULL)
663 message (D_ERROR, MSG_ERROR, "%s", errmsg);
664 g_free (errmsg);
666 #ifdef HAVE_SLANG
667 tty_display_8bit (display_codepage != 0 && display_codepage != 1);
668 #else
669 tty_display_8bit (display_codepage != 0);
670 #endif
671 use_8th_bit_as_meta = !(inpcheck->state & C_BOOL);
673 destroy_dlg (dbits_dlg);
674 repaint_screen ();
677 #endif /* HAVE_CHARSET */
679 static cb_ret_t
680 tree_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
682 switch (msg)
684 case DLG_POST_KEY:
685 /* The enter key will be processed by the tree widget */
686 if (parm == '\n')
688 h->ret_value = B_ENTER;
689 dlg_stop (h);
691 return MSG_HANDLED;
693 case DLG_ACTION:
694 /* command from buttonbar */
695 return send_message ((Widget *) find_tree (h), WIDGET_COMMAND, parm);
697 default:
698 return default_dlg_callback (h, sender, msg, parm, data);
702 /* Show tree in a box, not on a panel */
703 char *
704 tree_box (const char *current_dir)
706 WTree *mytree;
707 Dlg_head *dlg;
708 char *val = NULL;
709 WButtonBar *bar;
711 (void) current_dir;
713 /* Create the components */
714 dlg = create_dlg (TRUE, 0, 0, LINES - 9, COLS - 20, dialog_colors,
715 tree_callback, "[Directory Tree]",
716 _("Directory tree"), DLG_CENTER | DLG_REVERSE);
718 mytree = tree_new (2, 2, dlg->lines - 6, dlg->cols - 5, FALSE);
719 add_widget (dlg, mytree);
720 add_widget (dlg, hline_new (dlg->lines - 4, 1, -1));
721 bar = buttonbar_new (TRUE);
722 add_widget (dlg, bar);
723 /* restore ButtonBar coordinates after add_widget() */
724 ((Widget *) bar)->x = 0;
725 ((Widget *) bar)->y = LINES - 1;
727 if (run_dlg (dlg) == B_ENTER)
728 val = g_strdup (tree_selected_name (mytree));
730 destroy_dlg (dlg);
731 return val;
734 #ifdef ENABLE_VFS
736 static char *ret_timeout;
738 #ifdef ENABLE_VFS_FTP
739 static char *ret_ftp_proxy;
740 static char *ret_passwd;
741 static char *ret_directory_timeout;
743 static cb_ret_t
744 confvfs_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
746 switch (msg)
748 case DLG_ACTION:
749 if (sender->id == 6)
751 /* message from "Always use ftp proxy" checkbutton */
752 const gboolean not_use = !(((WCheck *) sender)->state & C_BOOL);
753 Widget *w;
755 /* input */
756 w = dlg_find_by_id (h, sender->id - 1);
757 widget_disable (*w, not_use);
758 send_message (w, WIDGET_DRAW, 0);
760 return MSG_HANDLED;
762 return MSG_NOT_HANDLED;
764 default:
765 return default_dlg_callback (h, sender, msg, parm, data);
768 #endif /* ENABLE_VFS_FTP */
770 void
771 configure_vfs (void)
773 #define VFSX 56
775 #ifdef ENABLE_VFS_FTP
776 #define VFSY 17
777 #else
778 #define VFSY 8
779 #endif /* ENABLE_VFS_FTP */
781 char buffer2[BUF_TINY];
782 #ifdef ENABLE_VFS_FTP
783 char buffer3[BUF_TINY];
784 #endif
786 QuickWidget confvfs_widgets[] = {
787 /* 0 */ QUICK_BUTTON (30, VFSX, VFSY - 3, VFSY, N_("&Cancel"), B_CANCEL, NULL),
788 /* 1 */ QUICK_BUTTON (12, VFSX, VFSY - 3, VFSY, N_("&OK"), B_ENTER, NULL),
789 #ifdef ENABLE_VFS_FTP
790 /* 2 */ QUICK_CHECKBOX (4, VFSX, 12, VFSY, N_("Use passive mode over pro&xy"),
791 &ftpfs_use_passive_connections_over_proxy),
792 /* 3 */ QUICK_CHECKBOX (4, VFSX, 11, VFSY, N_("Use &passive mode"),
793 &ftpfs_use_passive_connections),
794 /* 4 */ QUICK_CHECKBOX (4, VFSX, 10, VFSY, N_("&Use ~/.netrc"), &ftpfs_use_netrc),
795 /* 5 */ QUICK_INPUT (4, VFSX, 9, VFSY, ftpfs_proxy_host, 48, 0, "input-ftp-proxy",
796 &ret_ftp_proxy),
797 /* 6 */ QUICK_CHECKBOX (4, VFSX, 8, VFSY, N_("&Always use ftp proxy"),
798 &ftpfs_always_use_proxy),
799 /* 7 */ QUICK_LABEL (49, VFSX, 7, VFSY, N_("sec")),
800 /* 8 */ QUICK_INPUT (38, VFSX, 7, VFSY, buffer3, 10, 0, "input-timeout",
801 &ret_directory_timeout),
802 /* 9 */ QUICK_LABEL (4, VFSX, 7, VFSY, N_("ftpfs directory cache timeout:")),
803 /* 10 */ QUICK_INPUT (4, VFSX, 6, VFSY, ftpfs_anonymous_passwd, 48, 0, "input-passwd",
804 &ret_passwd),
805 /* 11 */ QUICK_LABEL (4, VFSX, 5, VFSY, N_("ftp anonymous password:")),
806 #endif /* ENABLE_VFS_FTP */
807 /* 12 */ QUICK_LABEL (49, VFSX, 3, VFSY, N_("sec")),
808 /* 13 */ QUICK_INPUT (38, VFSX, 3, VFSY, buffer2, 10, 0, "input-timo-vfs", &ret_timeout),
809 /* 14 */ QUICK_LABEL (4, VFSX, 3, VFSY, N_("Timeout for freeing VFSs:")),
810 QUICK_END
813 QuickDialog confvfs_dlg = {
814 VFSX, VFSY, -1, -1, N_("Virtual File System Setting"),
815 "[Virtual FS]", confvfs_widgets,
816 #ifdef ENABLE_VFS_FTP
817 confvfs_callback,
818 #else
819 NULL,
820 #endif
821 FALSE
824 #ifdef ENABLE_VFS_FTP
825 g_snprintf (buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
827 if (!ftpfs_always_use_proxy)
828 confvfs_widgets[5].options = W_DISABLED;
829 #endif
831 g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
833 if (quick_dialog (&confvfs_dlg) != B_CANCEL)
835 vfs_timeout = atoi (ret_timeout);
836 g_free (ret_timeout);
838 if (vfs_timeout < 0 || vfs_timeout > 10000)
839 vfs_timeout = 10;
840 #ifdef ENABLE_VFS_FTP
841 g_free (ftpfs_anonymous_passwd);
842 ftpfs_anonymous_passwd = ret_passwd;
843 g_free (ftpfs_proxy_host);
844 ftpfs_proxy_host = ret_ftp_proxy;
845 ftpfs_directory_timeout = atoi (ret_directory_timeout);
846 g_free (ret_directory_timeout);
847 #endif
850 #undef VFSX
851 #undef VFSY
854 #endif /* ENABLE_VFS */
856 char *
857 cd_dialog (void)
859 const char *label = N_("cd");
860 const int ylen = 5;
861 const int xlen = 57;
863 int len;
865 #ifdef ENABLE_NLS
866 label = _(label);
867 #endif
869 len = str_term_width1 (label);
872 char *my_str;
874 QuickWidget quick_widgets[] = {
875 /* 0 */ QUICK_INPUT (4 + len, xlen, 2, ylen, "", xlen - 7 - len, 2, "input", &my_str),
876 /* 1 */ QUICK_LABEL (3, xlen, 2, ylen, label),
877 QUICK_END
880 QuickDialog Quick_input = {
881 xlen, ylen, 2, LINES - 2 - ylen, _("Quick cd"),
882 "[Quick cd]", quick_widgets, NULL, TRUE
885 return (quick_dialog (&Quick_input) != B_CANCEL) ? my_str : NULL;
889 void
890 symlink_dialog (const char *existing, const char *new, char **ret_existing, char **ret_new)
892 QuickWidget quick_widgets[] = {
893 /* 0 */ QUICK_BUTTON (50, 80, 6, 8, N_("&Cancel"), B_CANCEL, NULL),
894 /* 1 */ QUICK_BUTTON (16, 80, 6, 8, N_("&OK"), B_ENTER, NULL),
895 /* 2 */ QUICK_INPUT (4, 80, 5, 8, new, 58, 0, "input-1", ret_new),
896 /* 3 */ QUICK_LABEL (4, 80, 4, 8, N_("Symbolic link filename:")),
897 /* 4 */ QUICK_INPUT (4, 80, 3, 8, existing, 58, 0, "input-2", ret_existing),
898 /* 5 */ QUICK_LABEL (4, 80, 2, 8,
899 N_("Existing filename (filename symlink will point to):")),
900 QUICK_END
903 QuickDialog Quick_input = {
904 64, 12, -1, -1, N_("Symbolic link"),
905 "[File Menu]", quick_widgets, NULL, FALSE
908 if (quick_dialog (&Quick_input) == B_CANCEL)
910 *ret_new = NULL;
911 *ret_existing = NULL;
915 #ifdef WITH_BACKGROUND
916 #define B_STOP (B_USER+1)
917 #define B_RESUME (B_USER+2)
918 #define B_KILL (B_USER+3)
920 static int JOBS_X = 60;
921 #define JOBS_Y 15
922 static WListbox *bg_list;
923 static Dlg_head *jobs_dlg;
925 static void
926 jobs_fill_listbox (void)
928 static const char *state_str[2];
929 TaskList *tl = task_list;
931 if (!state_str[0])
933 state_str[0] = _("Running");
934 state_str[1] = _("Stopped");
937 while (tl)
939 char *s;
941 s = g_strconcat (state_str[tl->state], " ", tl->info, (char *) NULL);
942 listbox_add_item (bg_list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
943 g_free (s);
944 tl = tl->next;
948 static int
949 task_cb (WButton *button, int action)
951 TaskList *tl;
952 int sig = 0;
954 (void) button;
956 if (bg_list->list == NULL)
957 return 0;
959 /* Get this instance information */
960 listbox_get_current (bg_list, NULL, (void **) &tl);
962 # ifdef SIGTSTP
963 if (action == B_STOP)
965 sig = SIGSTOP;
966 tl->state = Task_Stopped;
968 else if (action == B_RESUME)
970 sig = SIGCONT;
971 tl->state = Task_Running;
973 else
974 # endif
975 if (action == B_KILL)
977 sig = SIGKILL;
980 if (sig == SIGKILL)
981 unregister_task_running (tl->pid, tl->fd);
983 kill (tl->pid, sig);
984 listbox_remove_list (bg_list);
985 jobs_fill_listbox ();
987 /* This can be optimized to just redraw this widget :-) */
988 dlg_redraw (jobs_dlg);
990 return 0;
993 static struct
995 const char *name;
996 int xpos;
997 int value;
998 bcback callback;
1000 job_buttons[] =
1002 /* *INDENT-OFF* */
1003 { N_("&Stop"), 3, B_STOP, task_cb },
1004 { N_("&Resume"), 12, B_RESUME, task_cb },
1005 { N_("&Kill"), 23, B_KILL, task_cb },
1006 { N_("&OK"), 35, B_CANCEL, NULL }
1007 /* *INDENT-ON* */
1010 void
1011 jobs_cmd (void)
1013 register int i;
1014 int n_buttons = sizeof (job_buttons) / sizeof (job_buttons[0]);
1016 #ifdef ENABLE_NLS
1017 static int i18n_flag = 0;
1018 if (!i18n_flag)
1020 int startx = job_buttons[0].xpos;
1021 int len;
1023 for (i = 0; i < n_buttons; i++)
1025 job_buttons[i].name = _(job_buttons[i].name);
1027 len = str_term_width1 (job_buttons[i].name) + 4;
1028 JOBS_X = max (JOBS_X, startx + len + 3);
1030 job_buttons[i].xpos = startx;
1031 startx += len;
1034 /* Last button - Ok a.k.a. Cancel :) */
1035 job_buttons[n_buttons - 1].xpos =
1036 JOBS_X - str_term_width1 (job_buttons[n_buttons - 1].name) - 7;
1038 i18n_flag = 1;
1040 #endif /* ENABLE_NLS */
1042 jobs_dlg = create_dlg (TRUE, 0, 0, JOBS_Y, JOBS_X, dialog_colors, NULL,
1043 "[Background jobs]", _("Background Jobs"), DLG_CENTER | DLG_REVERSE);
1045 bg_list = listbox_new (2, 3, JOBS_Y - 9, JOBS_X - 7, FALSE, NULL);
1046 add_widget (jobs_dlg, bg_list);
1048 i = n_buttons;
1049 while (i--)
1051 add_widget (jobs_dlg, button_new (JOBS_Y - 4,
1052 job_buttons[i].xpos, job_buttons[i].value,
1053 NORMAL_BUTTON, job_buttons[i].name,
1054 job_buttons[i].callback));
1057 /* Insert all of task information in the list */
1058 jobs_fill_listbox ();
1059 run_dlg (jobs_dlg);
1061 destroy_dlg (jobs_dlg);
1063 #endif /* WITH_BACKGROUND */
1065 #ifdef ENABLE_VFS_SMB
1066 struct smb_authinfo *
1067 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain, const char *user)
1069 static int dialog_x = 44;
1070 int b0 = 3, dialog_y = 12;
1071 static const char *lc_labs[] = { N_("Domain:"), N_("Username:"), N_("Password:") };
1072 static const char *buts[] = { N_("&OK"), N_("&Cancel") };
1073 static int ilen = 30, istart = 14;
1074 static int b2 = 30;
1075 char *title;
1076 WInput *in_password;
1077 WInput *in_user;
1078 WInput *in_domain;
1079 Dlg_head *auth_dlg;
1080 struct smb_authinfo *return_value = NULL;
1082 const int input_colors[3] =
1084 INPUT_COLOR,
1085 INPUT_UNCHANGED_COLOR,
1086 INPUT_MARK_COLOR
1089 #ifdef ENABLE_NLS
1090 static int i18n_flag = 0;
1092 if (!i18n_flag)
1094 register int i = sizeof (lc_labs) / sizeof (lc_labs[0]);
1095 int l1, maxlen = 0;
1097 while (i--)
1099 l1 = str_term_width1 (lc_labs[i] = _(lc_labs[i]));
1100 if (l1 > maxlen)
1101 maxlen = l1;
1103 i = maxlen + ilen + 7;
1104 if (i > dialog_x)
1105 dialog_x = i;
1107 for (i = sizeof (buts) / sizeof (buts[0]), l1 = 0; i--;)
1109 l1 += str_term_width1 (buts[i] = _(buts[i]));
1111 l1 += 15;
1112 if (l1 > dialog_x)
1113 dialog_x = l1;
1115 ilen = dialog_x - 7 - maxlen; /* for the case of very long buttons :) */
1116 istart = dialog_x - 3 - ilen;
1118 b2 = dialog_x - (str_term_width1 (buts[1]) + 6);
1120 i18n_flag = 1;
1123 #endif /* ENABLE_NLS */
1125 if (!domain)
1126 domain = "";
1127 if (!user)
1128 user = "";
1130 title = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
1132 auth_dlg = create_dlg (TRUE, 0, 0, dialog_y, dialog_x, dialog_colors, NULL,
1133 "[Smb Authinfo]", title, DLG_CENTER | DLG_REVERSE);
1135 g_free (title);
1137 in_user = input_new (5, istart, (int *) input_colors, ilen, user, "auth_name", INPUT_COMPLETE_DEFAULT);
1138 add_widget (auth_dlg, in_user);
1140 in_domain = input_new (3, istart, (int *) input_colors, ilen, domain, "auth_domain", INPUT_COMPLETE_DEFAULT);
1142 add_widget (auth_dlg, in_domain);
1143 add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON, buts[1], 0));
1144 add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON, buts[0], 0));
1146 in_password = input_new (7, istart, (int *) input_colors, ilen, "", "auth_password", INPUT_COMPLETE_DEFAULT);
1148 in_password->completion_flags = 0;
1149 in_password->is_password = 1;
1150 add_widget (auth_dlg, in_password);
1152 add_widget (auth_dlg, label_new (7, 3, lc_labs[2]));
1153 add_widget (auth_dlg, label_new (5, 3, lc_labs[1]));
1154 add_widget (auth_dlg, label_new (3, 3, lc_labs[0]));
1156 if (run_dlg (auth_dlg) != B_CANCEL)
1157 return_value = vfs_smb_authinfo_new (host, share, in_domain->buffer, in_user->buffer,
1158 in_password->buffer);
1160 destroy_dlg (auth_dlg);
1162 return return_value;
1164 #endif /* ENABLE_VFS_SMB */