Drop old QuickWidget engine.
[midnight-commander.git] / src / filemanager / boxes.c
blob92f98b301227485c3cb1fbf5a793c6dba59c065b
1 /*
2 Some misc dialog boxes for the program.
4 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5 2005, 2006, 2009, 2010, 2011, 2012
6 The Free Software Foundation, Inc.
8 Written by:
9 Miguel de Icaza, 1994, 1995
10 Jakub Jelinek, 1995
11 Andrew Borodin <aborodin@vmail.ru>, 2009, 2010, 2011, 2012
13 This file is part of the Midnight Commander.
15 The Midnight Commander is free software: you can redistribute it
16 and/or modify it under the terms of the GNU General Public License as
17 published by the Free Software Foundation, either version 3 of the License,
18 or (at your option) any later version.
20 The Midnight Commander is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 /** \file boxes.c
30 * \brief Source: Some misc dialog boxes for the program
33 #include <config.h>
35 #include <ctype.h>
36 #include <signal.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <sys/types.h>
41 #include <sys/stat.h>
43 #include "lib/global.h"
45 #include "lib/tty/tty.h"
46 #include "lib/tty/key.h" /* XCTRL and ALT macros */
47 #include "lib/skin.h" /* INPUT_COLOR */
48 #include "lib/mcconfig.h" /* Load/save user formats */
49 #include "lib/strutil.h"
51 #include "lib/vfs/vfs.h"
52 #ifdef ENABLE_VFS_FTP
53 #include "src/vfs/ftpfs/ftpfs.h"
54 #endif /* ENABLE_VFS_FTP */
55 #ifdef ENABLE_VFS_SMB
56 #include "src/vfs/smbfs/smbfs.h"
57 #endif /* ENABLE_VFS_SMB */
59 #include "lib/util.h" /* Q_() */
60 #include "lib/widget.h"
62 #include "src/setup.h" /* For profile_name */
63 #ifdef ENABLE_BACKGROUND
64 #include "src/background.h" /* task_list */
65 #endif
67 #ifdef HAVE_CHARSET
68 #include "lib/charsets.h"
69 #include "src/selcodepage.h"
70 #endif
72 #include "command.h" /* For cmdline */
73 #include "dir.h"
74 #include "panel.h" /* LIST_TYPES */
75 #include "tree.h"
76 #include "layout.h" /* for get_nth_panel_name proto */
77 #include "midnight.h" /* current_panel */
79 #include "boxes.h"
81 /*** global variables ****************************************************************************/
83 /*** file scope macro definitions ****************************************************************/
85 #ifdef ENABLE_BACKGROUND
86 #define B_STOP (B_USER+1)
87 #define B_RESUME (B_USER+2)
88 #define B_KILL (B_USER+3)
89 #define JOBS_Y 15
90 #endif /* ENABLE_BACKGROUND */
92 /*** file scope type declarations ****************************************************************/
94 /*** file scope variables ************************************************************************/
96 static WRadio *display_radio;
97 static WInput *display_user_format;
98 static WInput *display_mini_status;
99 static WCheck *display_check_status;
100 static char **displays_status;
101 static int display_user_hotkey = 'u';
103 #ifdef HAVE_CHARSET
104 static int new_display_codepage;
105 static unsigned long disp_bits_name_id;
106 #endif /* HAVE_CHARSET */
108 #if defined(ENABLE_VFS) && defined(ENABLE_VFS_FTP)
109 static unsigned long ftpfs_always_use_proxy_id, ftpfs_proxy_host_id;
110 #endif /* ENABLE_VFS && ENABLE_VFS_FTP */
112 #ifdef ENABLE_BACKGROUND
113 static int JOBS_X = 60;
114 static WListbox *bg_list;
115 static Dlg_head *jobs_dlg;
117 static int task_cb (WButton * button, int action);
119 static struct
121 const char *name;
122 int xpos;
123 int value;
124 bcback_fn callback;
126 job_buttons[] =
128 /* *INDENT-OFF* */
129 { N_("&Stop"), 3, B_STOP, task_cb },
130 { N_("&Resume"), 12, B_RESUME, task_cb },
131 { N_("&Kill"), 23, B_KILL, task_cb },
132 { N_("&OK"), 35, B_CANCEL, NULL }
133 /* *INDENT-ON* */
136 #endif /* ENABLE_BACKGROUND */
138 /*** file scope functions ************************************************************************/
139 /* --------------------------------------------------------------------------------------------- */
141 static cb_ret_t
142 display_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
144 switch (msg)
146 case DLG_KEY:
147 if (parm == '\n')
149 if (dlg_widget_active (display_radio))
151 input_assign_text (display_mini_status, displays_status[display_radio->sel]);
152 dlg_stop (h);
153 return MSG_HANDLED;
156 if (dlg_widget_active (display_user_format))
158 h->ret_value = B_USER + 6;
159 dlg_stop (h);
160 return MSG_HANDLED;
163 if (dlg_widget_active (display_mini_status))
165 h->ret_value = B_USER + 7;
166 dlg_stop (h);
167 return MSG_HANDLED;
171 if ((g_ascii_tolower (parm) == display_user_hotkey)
172 && dlg_widget_active (display_user_format) && dlg_widget_active (display_mini_status))
174 display_radio->pos = display_radio->sel = 3;
175 dlg_select_widget (display_radio); /* force redraw */
176 h->callback (h, WIDGET (display_radio), DLG_ACTION, 0, NULL);
177 return MSG_HANDLED;
179 return MSG_NOT_HANDLED;
181 case DLG_ACTION:
182 if (sender == WIDGET (display_radio))
184 if (!(display_check_status->state & C_BOOL))
185 input_assign_text (display_mini_status, displays_status[display_radio->sel]);
186 input_update (display_mini_status, FALSE);
187 input_update (display_user_format, FALSE);
188 widget_disable (WIDGET (display_user_format), display_radio->sel != 3);
189 return MSG_HANDLED;
192 if (sender == WIDGET (display_check_status))
194 if (display_check_status->state & C_BOOL)
196 widget_disable (WIDGET (display_mini_status), FALSE);
197 input_assign_text (display_mini_status, displays_status[3]);
199 else
201 widget_disable (WIDGET (display_mini_status), TRUE);
202 input_assign_text (display_mini_status, displays_status[display_radio->sel]);
204 input_update (display_mini_status, FALSE);
205 return MSG_HANDLED;
208 return MSG_NOT_HANDLED;
210 default:
211 return default_dlg_callback (h, sender, msg, parm, data);
215 /* --------------------------------------------------------------------------------------------- */
217 static Dlg_head *
218 display_init (int radio_sel, char *init_text, int _check_status, char **_status)
220 int dlg_width = 48, dlg_height = 15;
221 Dlg_head *dd;
223 /* Controls whether the array strings have been translated */
224 const char *displays[LIST_TYPES] = {
225 N_("&Full file list"),
226 N_("&Brief file list"),
227 N_("&Long file list"),
228 N_("&User defined:")
231 /* Index in displays[] for "user defined" */
232 const int user_type_idx = 3;
234 const char *display_title = N_("Listing mode");
235 const char *user_mini_status = N_("User &mini status");
236 const char *ok_name = N_("&OK");
237 const char *cancel_name = N_("&Cancel");
239 WButton *ok_button, *cancel_button;
242 int i, maxlen = 0;
243 const char *cp;
244 int ok_len, cancel_len, b_len, gap;
246 #ifdef ENABLE_NLS
247 display_title = _(display_title);
248 user_mini_status = _(user_mini_status);
249 ok_name = _(ok_name);
250 cancel_name = _(cancel_name);
252 for (i = 0; i < LIST_TYPES; i++)
253 displays[i] = _(displays[i]);
254 #endif
256 /* get hotkey of user-defined format string */
257 cp = strchr (displays[user_type_idx], '&');
258 if (cp != NULL && *++cp != '\0')
259 display_user_hotkey = g_ascii_tolower (*cp);
261 /* xpos will be fixed later */
262 ok_button = button_new (dlg_height - 3, 0, B_ENTER, DEFPUSH_BUTTON, ok_name, 0);
263 ok_len = button_get_len (ok_button);
264 cancel_button = button_new (dlg_height - 3, 0, B_CANCEL, NORMAL_BUTTON, cancel_name, 0);
265 cancel_len = button_get_len (cancel_button);
266 b_len = ok_len + cancel_len + 2;
268 dlg_width = max (dlg_width, str_term_width1 (display_title) + 10);
269 /* calculate max width of radiobutons */
270 for (i = 0; i < LIST_TYPES; i++)
271 maxlen = max (maxlen, str_term_width1 (displays[i]));
272 dlg_width = max (dlg_width, maxlen);
273 dlg_width = max (dlg_width, str_term_width1 (user_mini_status) + 13);
275 /* buttons */
276 dlg_width = max (dlg_width, b_len + 6);
277 gap = (dlg_width - 6 - b_len) / 3;
278 WIDGET (ok_button)->x = 3 + gap;
279 WIDGET (cancel_button)->x = WIDGET (ok_button)->x + ok_len + gap + 2;
282 displays_status = _status;
284 dd = create_dlg (TRUE, 0, 0, dlg_height, dlg_width, dialog_colors,
285 display_callback, NULL, "[Listing Mode...]", display_title,
286 DLG_CENTER | DLG_REVERSE);
288 add_widget (dd, cancel_button);
289 add_widget (dd, ok_button);
291 display_mini_status =
292 input_new (10, 8, input_get_default_colors (), dlg_width - 12, _status[radio_sel],
293 "mini-input", INPUT_COMPLETE_DEFAULT);
294 add_widget (dd, display_mini_status);
296 display_check_status = check_new (9, 4, _check_status, user_mini_status);
297 add_widget (dd, display_check_status);
299 display_user_format = input_new (7, 8, input_get_default_colors (), dlg_width - 12, init_text,
300 "user-fmt-input", INPUT_COMPLETE_DEFAULT);
301 add_widget (dd, display_user_format);
303 display_radio = radio_new (3, 4, LIST_TYPES, displays);
304 display_radio->sel = display_radio->pos = radio_sel;
305 add_widget (dd, display_radio);
307 return dd;
310 /* --------------------------------------------------------------------------------------------- */
312 #ifdef HAVE_CHARSET
313 static int
314 sel_charset_button (WButton * button, int action)
316 int new_dcp;
318 (void) action;
320 new_dcp = select_charset (-1, -1, new_display_codepage, TRUE);
322 if (new_dcp != SELECT_CHARSET_CANCEL)
324 const char *cpname;
325 char buf[BUF_TINY];
326 Widget *w;
328 new_display_codepage = new_dcp;
329 cpname = (new_display_codepage == SELECT_CHARSET_OTHER_8BIT) ?
330 _("Other 8 bit") :
331 ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name;
332 if (cpname != NULL)
333 mc_global.utf8_display = str_isutf8 (cpname);
334 /* avoid strange bug with label repainting */
335 g_snprintf (buf, sizeof (buf), "%-27s", cpname);
336 w = dlg_find_by_id (WIDGET (button)->owner, disp_bits_name_id);
337 label_set_text ((WLabel *) w, buf);
340 return 0;
342 #endif /* HAVE_CHARSET */
344 /* --------------------------------------------------------------------------------------------- */
346 static cb_ret_t
347 tree_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
349 switch (msg)
351 case DLG_POST_KEY:
352 /* The enter key will be processed by the tree widget */
353 if (parm == '\n')
355 h->ret_value = B_ENTER;
356 dlg_stop (h);
358 return MSG_HANDLED;
360 case DLG_ACTION:
361 return send_message (WIDGET (find_tree (h)), NULL, WIDGET_COMMAND, parm, NULL);
363 default:
364 return default_dlg_callback (h, sender, msg, parm, data);
368 /* --------------------------------------------------------------------------------------------- */
370 #if defined(ENABLE_VFS) && defined (ENABLE_VFS_FTP)
371 static cb_ret_t
372 confvfs_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
374 switch (msg)
376 case DLG_ACTION:
377 /* message from "Always use ftp proxy" checkbutton */
378 if (sender != NULL && sender->id == ftpfs_always_use_proxy_id)
380 const gboolean not_use = !(((WCheck *) sender)->state & C_BOOL);
381 Widget *w;
383 /* input */
384 w = dlg_find_by_id (h, ftpfs_proxy_host_id);
385 widget_disable (w, not_use);
386 return MSG_HANDLED;
388 return MSG_NOT_HANDLED;
390 default:
391 return default_dlg_callback (h, sender, msg, parm, data);
394 #endif /* ENABLE_VFS && ENABLE_VFS_FTP */
396 /* --------------------------------------------------------------------------------------------- */
398 #ifdef ENABLE_BACKGROUND
399 static void
400 jobs_fill_listbox (void)
402 static const char *state_str[2];
403 TaskList *tl = task_list;
405 if (!state_str[0])
407 state_str[0] = _("Running");
408 state_str[1] = _("Stopped");
411 while (tl)
413 char *s;
415 s = g_strconcat (state_str[tl->state], " ", tl->info, (char *) NULL);
416 listbox_add_item (bg_list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
417 g_free (s);
418 tl = tl->next;
422 /* --------------------------------------------------------------------------------------------- */
424 static int
425 task_cb (WButton * button, int action)
427 TaskList *tl;
428 int sig = 0;
430 (void) button;
432 if (bg_list->list == NULL)
433 return 0;
435 /* Get this instance information */
436 listbox_get_current (bg_list, NULL, (void **) &tl);
438 #ifdef SIGTSTP
439 if (action == B_STOP)
441 sig = SIGSTOP;
442 tl->state = Task_Stopped;
444 else if (action == B_RESUME)
446 sig = SIGCONT;
447 tl->state = Task_Running;
449 else
450 #endif
451 if (action == B_KILL)
453 sig = SIGKILL;
456 if (sig == SIGKILL)
457 unregister_task_running (tl->pid, tl->fd);
459 kill (tl->pid, sig);
460 listbox_remove_list (bg_list);
461 jobs_fill_listbox ();
463 /* This can be optimized to just redraw this widget :-) */
464 dlg_redraw (jobs_dlg);
466 return 0;
468 #endif /* ENABLE_BACKGROUND */
470 /* --------------------------------------------------------------------------------------------- */
471 /*** public functions ****************************************************************************/
472 /* --------------------------------------------------------------------------------------------- */
474 /* return list type */
476 display_box (WPanel * panel, char **userp, char **minip, int *use_msformat, int num)
478 int result = -1;
479 Dlg_head *dd;
480 char *section = NULL;
481 size_t i;
483 if (panel == NULL)
485 const char *p = get_nth_panel_name (num);
486 panel = g_new (WPanel, 1);
487 panel->list_type = list_full;
488 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
489 panel->user_mini_status = 0;
490 for (i = 0; i < LIST_TYPES; i++)
491 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
492 section = g_strconcat ("Temporal:", p, (char *) NULL);
493 if (!mc_config_has_group (mc_main_config, section))
495 g_free (section);
496 section = g_strdup (p);
498 panel_load_setup (panel, section);
499 g_free (section);
502 dd = display_init (panel->list_type, panel->user_format,
503 panel->user_mini_status, panel->user_status_format);
505 if (run_dlg (dd) != B_CANCEL)
507 result = display_radio->sel;
508 *userp = g_strdup (display_user_format->buffer);
509 *minip = g_strdup (display_mini_status->buffer);
510 *use_msformat = display_check_status->state & C_BOOL;
513 if (section != NULL)
515 g_free (panel->user_format);
516 for (i = 0; i < LIST_TYPES; i++)
517 g_free (panel->user_status_format[i]);
518 g_free (panel);
521 destroy_dlg (dd);
523 return result;
526 /* --------------------------------------------------------------------------------------------- */
528 const panel_field_t *
529 sort_box (panel_sort_info_t * info)
531 const char **sort_orders_names;
532 gsize sort_names_num, i;
533 int sort_idx = 0;
534 const panel_field_t *result = info->sort_field;
536 sort_orders_names = panel_get_sortable_fields (&sort_names_num);
538 for (i = 0; i < sort_names_num; i++)
539 if (strcmp (sort_orders_names[i], _(info->sort_field->title_hotkey)) == 0)
541 sort_idx = i;
542 break;
546 quick_widget_t quick_widgets[] = {
547 /* *INDENT-OFF* */
548 QUICK_START_COLUMNS,
549 QUICK_RADIO (sort_names_num, sort_orders_names, &sort_idx, NULL),
550 QUICK_NEXT_COLUMN,
551 QUICK_CHECKBOX (N_("Executable &first"), &info->exec_first, NULL),
552 QUICK_CHECKBOX (N_("Case sensi&tive"), &info->case_sensitive, NULL),
553 QUICK_CHECKBOX (N_("&Reverse"), &info->reverse, NULL),
554 QUICK_STOP_COLUMNS,
555 QUICK_START_BUTTONS (TRUE, TRUE),
556 QUICK_BUTTON (N_("&OK"), B_ENTER, NULL, NULL),
557 QUICK_BUTTON (N_("&Cancel"), B_CANCEL, NULL, NULL),
558 QUICK_END
559 /* *INDENT-ON* */
562 quick_dialog_t qdlg = {
563 -1, -1, 40,
564 N_("Sort order"), "[Sort Order...]",
565 quick_widgets, NULL, NULL
568 if (quick_dialog (&qdlg) != B_CANCEL)
569 result = panel_get_field_by_title_hotkey (sort_orders_names[sort_idx]);
571 if (result == NULL)
572 result = info->sort_field;
575 g_strfreev ((gchar **) sort_orders_names);
577 return result;
580 /* --------------------------------------------------------------------------------------------- */
582 void
583 confirm_box (void)
585 quick_widget_t quick_widgets[] = {
586 /* *INDENT-OFF* */
587 /* TRANSLATORS: no need to translate 'Confirmation', it's just a context prefix */
588 QUICK_CHECKBOX (N_("Confirmation|&Delete"), &confirm_delete, NULL),
589 QUICK_CHECKBOX (N_("Confirmation|O&verwrite"), &confirm_overwrite, NULL),
590 QUICK_CHECKBOX (N_("Confirmation|&Execute"), &confirm_execute, NULL),
591 QUICK_CHECKBOX (N_("Confirmation|E&xit"), &confirm_exit, NULL),
592 QUICK_CHECKBOX (N_("Confirmation|Di&rectory hotlist delete"),
593 &confirm_directory_hotlist_delete, NULL),
594 QUICK_CHECKBOX (N_("Confirmation|&History cleanup"),
595 &mc_global.widget.confirm_history_cleanup, NULL),
596 QUICK_START_BUTTONS (TRUE, TRUE),
597 QUICK_BUTTON (N_("&OK"), B_ENTER, NULL, NULL),
598 QUICK_BUTTON (N_("&Cancel"), B_CANCEL, NULL, NULL),
599 QUICK_END
600 /* *INDENT-ON* */
603 quick_dialog_t qdlg = {
604 -1, -1, 46,
605 N_("Confirmation"), "[Confirmation]",
606 quick_widgets, NULL, NULL
609 (void) quick_dialog (&qdlg);
612 /* --------------------------------------------------------------------------------------------- */
614 #ifndef HAVE_CHARSET
615 void
616 display_bits_box (void)
618 int new_meta;
619 int current_mode;
621 const char *display_bits_str[] = {
622 N_("&UTF-8 output"),
623 N_("&Full 8 bits output"),
624 N_("&ISO 8859-1"),
625 N_("7 &bits")
628 quick_widget_t quick_widgets[] = {
629 /* *INDENT-OFF* */
630 QUICK_RADIO (4, display_bits_str, &current_mode, NULL),
631 QUICK_SEPARATOR (TRUE),
632 QUICK_CHECKBOX (N_("F&ull 8 bits input"), &new_meta, NULL),
633 QUICK_START_BUTTONS (TRUE, TRUE),
634 QUICK_BUTTON (N_("&OK"), B_ENTER, NULL, NULL),
635 QUICK_BUTTON (N_("&Cancel"), B_CANCEL, NULL, NULL),
636 QUICK_END
637 /* *INDENT-ON* */
640 quick_dialog_t qdlg = {
641 -1, -1, 46,
642 _("Display bits"), "[Display bits]",
643 quick_widgets, NULL, NULL
646 if (mc_global.full_eight_bits)
647 current_mode = 0;
648 else if (mc_global.eight_bit_clean)
649 current_mode = 1;
650 else
651 current_mode = 2;
653 new_meta = !use_8th_bit_as_meta;
655 if (quick_dialog (&qdlg) != B_CANCEL)
657 mc_global.eight_bit_clean = current_mode < 3;
658 mc_global.full_eight_bits = current_mode < 2;
659 #ifndef HAVE_SLANG
660 meta (stdscr, mc_global.eight_bit_clean);
661 #else
662 SLsmg_Display_Eight_Bit = mc_global.full_eight_bits ? 128 : 160;
663 #endif
664 use_8th_bit_as_meta = !new_meta;
668 /* --------------------------------------------------------------------------------------------- */
669 #else /* HAVE_CHARSET */
671 void
672 display_bits_box (void)
674 const char *cpname;
676 cpname = (new_display_codepage < 0) ? _("Other 8 bit")
677 : ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name;
679 new_display_codepage = mc_global.display_codepage;
682 int new_meta;
684 quick_widget_t quick_widgets[] = {
685 /* *INDENT-OFF* */
686 QUICK_START_COLUMNS,
687 QUICK_LABEL (N_("Input / display codepage:"), NULL),
688 QUICK_NEXT_COLUMN,
689 QUICK_STOP_COLUMNS,
690 QUICK_START_COLUMNS,
691 QUICK_LABEL (cpname, &disp_bits_name_id),
692 QUICK_NEXT_COLUMN,
693 QUICK_BUTTON (N_("&Select"), B_USER, sel_charset_button, NULL),
694 QUICK_STOP_COLUMNS,
695 QUICK_SEPARATOR (TRUE),
696 QUICK_CHECKBOX (N_("F&ull 8 bits input"), &new_meta, NULL),
697 QUICK_START_BUTTONS (TRUE, TRUE),
698 QUICK_BUTTON (N_("&OK"), B_ENTER, NULL, NULL),
699 QUICK_BUTTON (N_("&Cancel"), B_CANCEL, NULL, NULL),
700 QUICK_END
701 /* *INDENT-ON* */
704 quick_dialog_t qdlg = {
705 -1, -1, 46,
706 N_("Display bits"), "[Display bits]",
707 quick_widgets, NULL, NULL
710 new_meta = !use_8th_bit_as_meta;
711 application_keypad_mode ();
713 if (quick_dialog (&qdlg) == B_ENTER)
715 char *errmsg;
717 mc_global.display_codepage = new_display_codepage;
719 errmsg = init_translation_table (mc_global.source_codepage, mc_global.display_codepage);
720 if (errmsg != NULL)
722 message (D_ERROR, MSG_ERROR, "%s", errmsg);
723 g_free (errmsg);
726 #ifdef HAVE_SLANG
727 tty_display_8bit (mc_global.display_codepage != 0 && mc_global.display_codepage != 1);
728 #else
729 tty_display_8bit (mc_global.display_codepage != 0);
730 #endif
731 use_8th_bit_as_meta = !new_meta;
733 repaint_screen ();
737 #endif /* HAVE_CHARSET */
739 /* --------------------------------------------------------------------------------------------- */
740 /** Show tree in a box, not on a panel */
742 char *
743 tree_box (const char *current_dir)
745 WTree *mytree;
746 Dlg_head *dlg;
747 Widget *wd;
748 char *val = NULL;
749 WButtonBar *bar;
751 (void) current_dir;
753 /* Create the components */
754 dlg = create_dlg (TRUE, 0, 0, LINES - 9, COLS - 20, dialog_colors,
755 tree_callback, NULL, "[Directory Tree]",
756 _("Directory tree"), DLG_CENTER | DLG_REVERSE);
757 wd = WIDGET (dlg);
759 mytree = tree_new (2, 2, wd->lines - 6, wd->cols - 5, FALSE);
760 add_widget (dlg, mytree);
761 add_widget (dlg, hline_new (wd->lines - 4, 1, -1));
762 bar = buttonbar_new (TRUE);
763 add_widget (dlg, bar);
764 /* restore ButtonBar coordinates after add_widget() */
765 WIDGET (bar)->x = 0;
766 WIDGET (bar)->y = LINES - 1;
768 if (run_dlg (dlg) == B_ENTER)
769 val = vfs_path_to_str (tree_selected_name (mytree));
771 destroy_dlg (dlg);
772 return val;
775 /* --------------------------------------------------------------------------------------------- */
777 #ifdef ENABLE_VFS
778 void
779 configure_vfs (void)
781 char buffer2[BUF_TINY];
782 #ifdef ENABLE_VFS_FTP
783 char buffer3[BUF_TINY];
785 g_snprintf (buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
786 #endif
788 g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
791 char *ret_timeout;
792 #ifdef ENABLE_VFS_FTP
793 char *ret_passwd;
794 char *ret_ftp_proxy;
795 char *ret_directory_timeout;
796 #endif /* ENABLE_VFS_FTP */
798 quick_widget_t quick_widgets[] = {
799 /* *INDENT-OFF* */
800 QUICK_LABELED_INPUT (N_("Timeout for freeing VFSs (sec):"), input_label_left,
801 buffer2, 0, "input-timo-vfs", &ret_timeout, NULL),
802 #ifdef ENABLE_VFS_FTP
803 QUICK_SEPARATOR (TRUE),
804 QUICK_LABELED_INPUT (N_("FTP anonymous password:"), input_label_left,
805 ftpfs_anonymous_passwd, 0, "input-passwd", &ret_passwd, NULL),
806 QUICK_LABELED_INPUT (N_("FTP directory cache timeout (sec):"), input_label_left,
807 buffer3, 0, "input-timeout", &ret_directory_timeout, NULL),
808 QUICK_CHECKBOX (N_("&Always use ftp proxy:"), &ftpfs_always_use_proxy,
809 &ftpfs_always_use_proxy_id),
810 QUICK_INPUT (ftpfs_proxy_host, 0, "input-ftp-proxy", &ret_ftp_proxy,
811 &ftpfs_proxy_host_id),
812 QUICK_CHECKBOX (N_("&Use ~/.netrc"), &ftpfs_use_netrc, NULL),
813 QUICK_CHECKBOX (N_("Use &passive mode"), &ftpfs_use_passive_connections, NULL),
814 QUICK_CHECKBOX (N_("Use passive mode over pro&xy"),
815 &ftpfs_use_passive_connections_over_proxy, NULL),
816 #endif /* ENABLE_VFS_FTP */
817 QUICK_START_BUTTONS (TRUE, TRUE),
818 QUICK_BUTTON (N_("&OK"), B_ENTER, NULL, NULL),
819 QUICK_BUTTON (N_("&Cancel"), B_CANCEL, NULL, NULL),
820 QUICK_END
821 /* *INDENT-ON* */
824 quick_dialog_t qdlg = {
825 -1, -1, 56,
826 N_("Virtual File System Setting"), "[Virtual FS]",
827 quick_widgets,
828 #ifdef ENABLE_VFS_FTP
829 confvfs_callback,
830 #else
831 NULL,
832 #endif
833 NULL,
836 #ifdef ENABLE_VFS_FTP
837 if (!ftpfs_always_use_proxy)
838 quick_widgets[5].options = W_DISABLED;
839 #endif
841 if (quick_dialog (&qdlg) != B_CANCEL)
843 vfs_timeout = atoi (ret_timeout);
844 g_free (ret_timeout);
846 if (vfs_timeout < 0 || vfs_timeout > 10000)
847 vfs_timeout = 10;
848 #ifdef ENABLE_VFS_FTP
849 g_free (ftpfs_anonymous_passwd);
850 ftpfs_anonymous_passwd = ret_passwd;
851 g_free (ftpfs_proxy_host);
852 ftpfs_proxy_host = ret_ftp_proxy;
853 ftpfs_directory_timeout = atoi (ret_directory_timeout);
854 g_free (ret_directory_timeout);
855 #endif
860 #endif /* ENABLE_VFS */
862 /* --------------------------------------------------------------------------------------------- */
864 char *
865 cd_dialog (void)
867 const Widget *w = WIDGET (current_panel);
868 char *my_str;
870 quick_widget_t quick_widgets[] = {
871 QUICK_LABELED_INPUT (N_("cd"), input_label_left, "", 2, "input", &my_str, NULL),
872 QUICK_END
875 quick_dialog_t qdlg = {
876 w->y + w->lines - 6, w->x, w->cols,
877 N_("Quick cd"), "[Quick cd]",
878 quick_widgets, NULL, NULL
881 return (quick_dialog (&qdlg) != B_CANCEL) ? my_str : NULL;
884 /* --------------------------------------------------------------------------------------------- */
886 void
887 symlink_dialog (const vfs_path_t * existing_vpath, const vfs_path_t * new_vpath,
888 char **ret_existing, char **ret_new)
890 char *existing;
891 char *new;
893 existing = vfs_path_to_str (existing_vpath);
894 new = vfs_path_to_str (new_vpath);
897 quick_widget_t quick_widgets[] = {
898 /* *INDENT-OFF* */
899 QUICK_LABELED_INPUT (N_("Existing filename (filename symlink will point to):"),
900 input_label_above,
901 existing, 0, "input-2", ret_existing, NULL),
902 QUICK_SEPARATOR (FALSE),
903 QUICK_LABELED_INPUT (N_("Symbolic link filename:"), input_label_above,
904 new, 0, "input-1", ret_new, NULL),
905 QUICK_START_BUTTONS (TRUE, TRUE),
906 QUICK_BUTTON (N_("&OK"), B_ENTER, NULL, NULL),
907 QUICK_BUTTON (N_("&Cancel"), B_CANCEL, NULL, NULL),
908 QUICK_END
909 /* *INDENT-ON* */
912 quick_dialog_t qdlg = {
913 -1, -1, 64,
914 N_("Symbolic link"), "[File Menu]",
915 quick_widgets, NULL, NULL
918 if (quick_dialog (&qdlg) == B_CANCEL)
920 *ret_new = NULL;
921 *ret_existing = NULL;
925 g_free (existing);
926 g_free (new);
929 /* --------------------------------------------------------------------------------------------- */
931 #ifdef ENABLE_BACKGROUND
932 void
933 jobs_cmd (void)
935 register int i;
936 int n_buttons = sizeof (job_buttons) / sizeof (job_buttons[0]);
938 #ifdef ENABLE_NLS
939 static int i18n_flag = 0;
940 if (!i18n_flag)
942 int startx = job_buttons[0].xpos;
943 int len;
945 for (i = 0; i < n_buttons; i++)
947 job_buttons[i].name = _(job_buttons[i].name);
949 len = str_term_width1 (job_buttons[i].name) + 4;
950 JOBS_X = max (JOBS_X, startx + len + 3);
952 job_buttons[i].xpos = startx;
953 startx += len;
956 /* Last button - Ok a.k.a. Cancel :) */
957 job_buttons[n_buttons - 1].xpos =
958 JOBS_X - str_term_width1 (job_buttons[n_buttons - 1].name) - 7;
960 i18n_flag = 1;
962 #endif /* ENABLE_NLS */
964 jobs_dlg = create_dlg (TRUE, 0, 0, JOBS_Y, JOBS_X, dialog_colors, NULL, NULL,
965 "[Background jobs]", _("Background Jobs"), DLG_CENTER | DLG_REVERSE);
967 bg_list = listbox_new (2, 3, JOBS_Y - 9, JOBS_X - 7, FALSE, NULL);
968 add_widget (jobs_dlg, bg_list);
970 i = n_buttons;
971 while (i--)
973 add_widget (jobs_dlg, button_new (JOBS_Y - 4,
974 job_buttons[i].xpos, job_buttons[i].value,
975 NORMAL_BUTTON, job_buttons[i].name,
976 job_buttons[i].callback));
979 /* Insert all of task information in the list */
980 jobs_fill_listbox ();
981 run_dlg (jobs_dlg);
983 destroy_dlg (jobs_dlg);
985 #endif /* ENABLE_BACKGROUND */
987 /* --------------------------------------------------------------------------------------------- */
989 #ifdef ENABLE_VFS_SMB
990 struct smb_authinfo *
991 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain, const char *user)
993 static int dialog_x = 44;
994 int b0 = 3, dialog_y = 12;
995 static const char *lc_labs[] = { N_("Domain:"), N_("Username:"), N_("Password:") };
996 static const char *buts[] = { N_("&OK"), N_("&Cancel") };
997 static int ilen = 30, istart = 14;
998 static int b2 = 30;
999 char *title;
1000 WInput *in_password;
1001 WInput *in_user;
1002 WInput *in_domain;
1003 Dlg_head *auth_dlg;
1004 struct smb_authinfo *return_value = NULL;
1006 #ifdef ENABLE_NLS
1007 static int i18n_flag = 0;
1009 if (!i18n_flag)
1011 register int i = sizeof (lc_labs) / sizeof (lc_labs[0]);
1012 int l1, maxlen = 0;
1014 while (i--)
1016 l1 = str_term_width1 (lc_labs[i] = _(lc_labs[i]));
1017 if (l1 > maxlen)
1018 maxlen = l1;
1020 i = maxlen + ilen + 7;
1021 if (i > dialog_x)
1022 dialog_x = i;
1024 for (i = sizeof (buts) / sizeof (buts[0]), l1 = 0; i--;)
1026 l1 += str_term_width1 (buts[i] = _(buts[i]));
1028 l1 += 15;
1029 if (l1 > dialog_x)
1030 dialog_x = l1;
1032 ilen = dialog_x - 7 - maxlen; /* for the case of very long buttons :) */
1033 istart = dialog_x - 3 - ilen;
1035 b2 = dialog_x - (str_term_width1 (buts[1]) + 6);
1037 i18n_flag = 1;
1040 #endif /* ENABLE_NLS */
1042 if (!domain)
1043 domain = "";
1044 if (!user)
1045 user = "";
1047 title = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
1049 auth_dlg = create_dlg (TRUE, 0, 0, dialog_y, dialog_x, dialog_colors, NULL, NULL,
1050 "[Smb Authinfo]", title, DLG_CENTER | DLG_REVERSE);
1052 g_free (title);
1054 in_user =
1055 input_new (5, istart, input_get_default_colors (), ilen, user, "auth_name",
1056 INPUT_COMPLETE_DEFAULT);
1057 add_widget (auth_dlg, in_user);
1059 in_domain =
1060 input_new (3, istart, input_get_default_colors (), ilen, domain, "auth_domain",
1061 INPUT_COMPLETE_DEFAULT);
1063 add_widget (auth_dlg, in_domain);
1064 add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON, buts[1], 0));
1065 add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON, buts[0], 0));
1067 in_password =
1068 input_new (7, istart, input_get_default_colors (), ilen, "", "auth_password",
1069 INPUT_COMPLETE_DEFAULT);
1071 in_password->completion_flags = 0;
1072 in_password->is_password = 1;
1073 add_widget (auth_dlg, in_password);
1075 add_widget (auth_dlg, label_new (7, 3, lc_labs[2]));
1076 add_widget (auth_dlg, label_new (5, 3, lc_labs[1]));
1077 add_widget (auth_dlg, label_new (3, 3, lc_labs[0]));
1079 if (run_dlg (auth_dlg) != B_CANCEL)
1080 return_value = vfs_smb_authinfo_new (host, share, in_domain->buffer, in_user->buffer,
1081 in_password->buffer);
1083 destroy_dlg (auth_dlg);
1085 return return_value;
1087 #endif /* ENABLE_VFS_SMB */
1089 /* --------------------------------------------------------------------------------------------- */