Add useful macros for widget type cast.
[midnight-commander.git] / src / filemanager / boxes.c
blob290fde515c1ae6982fbfbb028dccd021e0b9183a
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 #endif /* ENABLE_BACKGROUND */
91 /*** file scope type declarations ****************************************************************/
93 /*** file scope variables ************************************************************************/
95 /* Index in list_types[] for "user defined" */
96 static const int panel_listing_user_idx = 3;
98 static char **status_format;
99 static int listing_user_hotkey = 'u';
100 static unsigned long panel_listing_types_id, panel_user_format_id;
101 static unsigned long mini_user_status_id, mini_user_format_id;
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 WListbox *bg_list = NULL;
114 #endif /* ENABLE_BACKGROUND */
116 /* --------------------------------------------------------------------------------------------- */
117 /*** file scope functions ************************************************************************/
118 /* --------------------------------------------------------------------------------------------- */
120 static cb_ret_t
121 panel_listing_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
123 WDialog *h = DIALOG (w);
125 switch (msg)
127 case MSG_KEY:
128 if (parm == '\n')
130 Widget *wi;
132 wi = dlg_find_by_id (h, panel_listing_types_id);
133 if (dlg_widget_active (wi))
135 WInput *in;
137 in = INPUT (dlg_find_by_id (h, mini_user_format_id));
138 input_assign_text (in, status_format[RADIO (wi)->sel]);
139 dlg_stop (h);
140 return MSG_HANDLED;
143 wi = dlg_find_by_id (h, panel_user_format_id);
144 if (dlg_widget_active (wi))
146 h->ret_value = B_USER + 6;
147 dlg_stop (h);
148 return MSG_HANDLED;
151 wi = dlg_find_by_id (h, mini_user_format_id);
152 if (dlg_widget_active (wi))
154 h->ret_value = B_USER + 7;
155 dlg_stop (h);
156 return MSG_HANDLED;
160 if (g_ascii_tolower (parm) == listing_user_hotkey)
162 Widget *wi;
164 wi = dlg_find_by_id (h, panel_user_format_id);
165 if (dlg_widget_active (wi))
167 wi = dlg_find_by_id (h, mini_user_format_id);
168 if (dlg_widget_active (wi))
170 WRadio *r;
172 r = RADIO (dlg_find_by_id (h, panel_listing_types_id));
173 r->pos = r->sel = panel_listing_user_idx;
174 dlg_select_widget (WIDGET (r)); /* force redraw */
175 send_message (h, r, MSG_ACTION, 0, NULL);
176 return MSG_HANDLED;
180 return MSG_NOT_HANDLED;
182 case MSG_ACTION:
183 if (sender != NULL && sender->id == panel_listing_types_id)
185 WCheck *ch;
186 WInput *in1, *in2;
188 in1 = INPUT (dlg_find_by_id (h, panel_user_format_id));
189 ch = CHECK (dlg_find_by_id (h, mini_user_status_id));
190 in2 = INPUT (dlg_find_by_id (h, mini_user_format_id));
192 if (!(ch->state & C_BOOL))
193 input_assign_text (in2, status_format[RADIO (sender)->sel]);
194 input_update (in2, FALSE);
195 input_update (in1, FALSE);
196 widget_disable (WIDGET (in1), RADIO (sender)->sel != panel_listing_user_idx);
197 return MSG_HANDLED;
200 if (sender != NULL && sender->id == mini_user_status_id)
202 WInput *in;
204 in = INPUT (dlg_find_by_id (h, mini_user_format_id));
206 if (CHECK (sender)->state & C_BOOL)
208 widget_disable (WIDGET (in), FALSE);
209 input_assign_text (in, status_format[3]);
211 else
213 WRadio *r;
215 r = RADIO (dlg_find_by_id (h, panel_listing_types_id));
216 widget_disable (WIDGET (in), TRUE);
217 input_assign_text (in, status_format[r->sel]);
219 /* input_update (in, FALSE); */
220 return MSG_HANDLED;
223 return MSG_NOT_HANDLED;
225 default:
226 return dlg_default_callback (w, sender, msg, parm, data);
230 /* --------------------------------------------------------------------------------------------- */
232 #ifdef HAVE_CHARSET
233 static int
234 sel_charset_button (WButton * button, int action)
236 int new_dcp;
238 (void) action;
240 new_dcp = select_charset (-1, -1, new_display_codepage, TRUE);
242 if (new_dcp != SELECT_CHARSET_CANCEL)
244 const char *cpname;
245 char buf[BUF_TINY];
246 Widget *w;
248 new_display_codepage = new_dcp;
249 cpname = (new_display_codepage == SELECT_CHARSET_OTHER_8BIT) ?
250 _("Other 8 bit") :
251 ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name;
252 if (cpname != NULL)
253 mc_global.utf8_display = str_isutf8 (cpname);
254 /* avoid strange bug with label repainting */
255 g_snprintf (buf, sizeof (buf), "%-27s", cpname);
256 w = dlg_find_by_id (WIDGET (button)->owner, disp_bits_name_id);
257 label_set_text (LABEL (w), buf);
260 return 0;
262 #endif /* HAVE_CHARSET */
264 /* --------------------------------------------------------------------------------------------- */
266 static cb_ret_t
267 tree_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
269 WDialog *h = DIALOG (w);
271 switch (msg)
273 case MSG_POST_KEY:
274 /* The enter key will be processed by the tree widget */
275 if (parm == '\n')
277 h->ret_value = B_ENTER;
278 dlg_stop (h);
280 return MSG_HANDLED;
282 case MSG_RESIZE:
284 Widget *bar;
286 /* simply call dlg_set_size() with new size */
287 dlg_set_size (h, LINES - 9, COLS - 20);
288 bar = WIDGET (find_buttonbar (h));
289 bar->x = 0;
290 bar->y = LINES - 1;
291 return MSG_HANDLED;
294 case MSG_ACTION:
295 return send_message (find_tree (h), NULL, MSG_ACTION, parm, NULL);
297 default:
298 return dlg_default_callback (w, sender, msg, parm, data);
302 /* --------------------------------------------------------------------------------------------- */
304 #if defined(ENABLE_VFS) && defined (ENABLE_VFS_FTP)
305 static cb_ret_t
306 confvfs_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
308 switch (msg)
310 case MSG_ACTION:
311 /* message from "Always use ftp proxy" checkbutton */
312 if (sender != NULL && sender->id == ftpfs_always_use_proxy_id)
314 const gboolean not_use = !(CHECK (sender)->state & C_BOOL);
315 Widget *wi;
317 /* input */
318 wi = dlg_find_by_id (DIALOG (w), ftpfs_proxy_host_id);
319 widget_disable (wi, not_use);
320 return MSG_HANDLED;
322 return MSG_NOT_HANDLED;
324 default:
325 return dlg_default_callback (w, sender, msg, parm, data);
328 #endif /* ENABLE_VFS && ENABLE_VFS_FTP */
330 /* --------------------------------------------------------------------------------------------- */
332 #ifdef ENABLE_BACKGROUND
333 static void
334 jobs_fill_listbox (WListbox * list)
336 static const char *state_str[2] = { "", "" };
337 TaskList *tl;
339 if (state_str[0] == '\0')
341 state_str[0] = _("Running");
342 state_str[1] = _("Stopped");
345 for (tl = task_list; tl != NULL; tl = tl->next)
347 char *s;
349 s = g_strconcat (state_str[tl->state], " ", tl->info, (char *) NULL);
350 listbox_add_item (list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
351 g_free (s);
355 /* --------------------------------------------------------------------------------------------- */
357 static int
358 task_cb (WButton * button, int action)
360 TaskList *tl;
361 int sig = 0;
363 (void) button;
365 if (bg_list->list == NULL)
366 return 0;
368 /* Get this instance information */
369 listbox_get_current (bg_list, NULL, (void **) &tl);
371 #ifdef SIGTSTP
372 if (action == B_STOP)
374 sig = SIGSTOP;
375 tl->state = Task_Stopped;
377 else if (action == B_RESUME)
379 sig = SIGCONT;
380 tl->state = Task_Running;
382 else
383 #endif
384 if (action == B_KILL)
385 sig = SIGKILL;
387 if (sig == SIGKILL)
388 unregister_task_running (tl->pid, tl->fd);
390 kill (tl->pid, sig);
391 listbox_remove_list (bg_list);
392 jobs_fill_listbox (bg_list);
394 /* This can be optimized to just redraw this widget :-) */
395 dlg_redraw (WIDGET (button)->owner);
397 return 0;
399 #endif /* ENABLE_BACKGROUND */
401 /* --------------------------------------------------------------------------------------------- */
402 /*** public functions ****************************************************************************/
403 /* --------------------------------------------------------------------------------------------- */
405 /* return list type */
407 panel_listing_box (WPanel * panel, char **userp, char **minip, int *use_msformat, int num)
409 int result = -1;
410 char *section = NULL;
412 if (panel == NULL)
414 const char *p;
415 size_t i;
417 p = get_nth_panel_name (num);
418 panel = g_new (WPanel, 1);
419 panel->list_type = list_full;
420 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
421 panel->user_mini_status = 0;
422 for (i = 0; i < LIST_TYPES; i++)
423 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
424 section = g_strconcat ("Temporal:", p, (char *) NULL);
425 if (!mc_config_has_group (mc_main_config, section))
427 g_free (section);
428 section = g_strdup (p);
430 panel_load_setup (panel, section);
431 g_free (section);
435 int mini_user_status;
436 char *panel_user_format;
437 char *mini_user_format;
438 const char *cp;
440 /* Controls whether the array strings have been translated */
441 const char *list_types[LIST_TYPES] = {
442 N_("&Full file list"),
443 N_("&Brief file list"),
444 N_("&Long file list"),
445 N_("&User defined:")
448 quick_widget_t quick_widgets[] = {
449 /* *INDENT-OFF* */
450 QUICK_RADIO (LIST_TYPES, list_types, &result, &panel_listing_types_id),
451 QUICK_INPUT (panel->user_format, INPUT_COMPLETE_DEFAULT, "user-fmt-input",
452 &panel_user_format, &panel_user_format_id),
453 QUICK_SEPARATOR (TRUE),
454 QUICK_CHECKBOX (N_("User &mini status"), &mini_user_status, &mini_user_status_id),
455 QUICK_INPUT (panel->user_status_format[panel->list_type], INPUT_COMPLETE_DEFAULT,
456 "mini_input", &mini_user_format, &mini_user_format_id),
457 QUICK_BUTTONS_OK_CANCEL,
458 QUICK_END
459 /* *INDENT-ON* */
462 quick_dialog_t qdlg = {
463 -1, -1, 48,
464 N_("Listing mode"), "[Listing Mode...]",
465 quick_widgets, panel_listing_callback, NULL
468 /* get hotkey of user-defined format string */
469 cp = strchr (_(list_types[panel_listing_user_idx]), '&');
470 if (cp != NULL && *++cp != '\0')
471 listing_user_hotkey = g_ascii_tolower (*cp);
473 mini_user_status = panel->user_mini_status;
474 result = panel->list_type;
475 status_format = panel->user_status_format;
477 if (panel->list_type != panel_listing_user_idx)
478 quick_widgets[1].options = W_DISABLED;
480 if (!mini_user_status)
481 quick_widgets[4].options = W_DISABLED;
483 if (quick_dialog (&qdlg) == B_CANCEL)
484 result = -1;
485 else
487 *userp = panel_user_format;
488 *minip = mini_user_format;
489 *use_msformat = mini_user_status;
493 if (section != NULL)
495 int i;
497 g_free (panel->user_format);
498 for (i = 0; i < LIST_TYPES; i++)
499 g_free (panel->user_status_format[i]);
500 g_free (panel);
503 return result;
506 /* --------------------------------------------------------------------------------------------- */
508 const panel_field_t *
509 sort_box (panel_sort_info_t * info)
511 const char **sort_orders_names;
512 gsize sort_names_num, i;
513 int sort_idx = 0;
514 const panel_field_t *result = info->sort_field;
516 sort_orders_names = panel_get_sortable_fields (&sort_names_num);
518 for (i = 0; i < sort_names_num; i++)
519 if (strcmp (sort_orders_names[i], _(info->sort_field->title_hotkey)) == 0)
521 sort_idx = i;
522 break;
526 quick_widget_t quick_widgets[] = {
527 /* *INDENT-OFF* */
528 QUICK_START_COLUMNS,
529 QUICK_RADIO (sort_names_num, sort_orders_names, &sort_idx, NULL),
530 QUICK_NEXT_COLUMN,
531 QUICK_CHECKBOX (N_("Executable &first"), &info->exec_first, NULL),
532 QUICK_CHECKBOX (N_("Cas&e sensitive"), &info->case_sensitive, NULL),
533 QUICK_CHECKBOX (N_("&Reverse"), &info->reverse, NULL),
534 QUICK_STOP_COLUMNS,
535 QUICK_BUTTONS_OK_CANCEL,
536 QUICK_END
537 /* *INDENT-ON* */
540 quick_dialog_t qdlg = {
541 -1, -1, 40,
542 N_("Sort order"), "[Sort Order...]",
543 quick_widgets, NULL, NULL
546 if (quick_dialog (&qdlg) != B_CANCEL)
547 result = panel_get_field_by_title_hotkey (sort_orders_names[sort_idx]);
549 if (result == NULL)
550 result = info->sort_field;
553 g_strfreev ((gchar **) sort_orders_names);
555 return result;
558 /* --------------------------------------------------------------------------------------------- */
560 void
561 confirm_box (void)
563 quick_widget_t quick_widgets[] = {
564 /* *INDENT-OFF* */
565 /* TRANSLATORS: no need to translate 'Confirmation', it's just a context prefix */
566 QUICK_CHECKBOX (N_("Confirmation|&Delete"), &confirm_delete, NULL),
567 QUICK_CHECKBOX (N_("Confirmation|O&verwrite"), &confirm_overwrite, NULL),
568 QUICK_CHECKBOX (N_("Confirmation|&Execute"), &confirm_execute, NULL),
569 QUICK_CHECKBOX (N_("Confirmation|E&xit"), &confirm_exit, NULL),
570 QUICK_CHECKBOX (N_("Confirmation|Di&rectory hotlist delete"),
571 &confirm_directory_hotlist_delete, NULL),
572 QUICK_CHECKBOX (N_("Confirmation|&History cleanup"),
573 &mc_global.widget.confirm_history_cleanup, NULL),
574 QUICK_BUTTONS_OK_CANCEL,
575 QUICK_END
576 /* *INDENT-ON* */
579 quick_dialog_t qdlg = {
580 -1, -1, 46,
581 N_("Confirmation"), "[Confirmation]",
582 quick_widgets, NULL, NULL
585 (void) quick_dialog (&qdlg);
588 /* --------------------------------------------------------------------------------------------- */
590 #ifndef HAVE_CHARSET
591 void
592 display_bits_box (void)
594 int new_meta;
595 int current_mode;
597 const char *display_bits_str[] = {
598 N_("&UTF-8 output"),
599 N_("&Full 8 bits output"),
600 N_("&ISO 8859-1"),
601 N_("7 &bits")
604 quick_widget_t quick_widgets[] = {
605 /* *INDENT-OFF* */
606 QUICK_RADIO (4, display_bits_str, &current_mode, NULL),
607 QUICK_SEPARATOR (TRUE),
608 QUICK_CHECKBOX (N_("F&ull 8 bits input"), &new_meta, NULL),
609 QUICK_BUTTONS_OK_CANCEL,
610 QUICK_END
611 /* *INDENT-ON* */
614 quick_dialog_t qdlg = {
615 -1, -1, 46,
616 _("Display bits"), "[Display bits]",
617 quick_widgets, NULL, NULL
620 if (mc_global.full_eight_bits)
621 current_mode = 0;
622 else if (mc_global.eight_bit_clean)
623 current_mode = 1;
624 else
625 current_mode = 2;
627 new_meta = !use_8th_bit_as_meta;
629 if (quick_dialog (&qdlg) != B_CANCEL)
631 mc_global.eight_bit_clean = current_mode < 3;
632 mc_global.full_eight_bits = current_mode < 2;
633 #ifndef HAVE_SLANG
634 meta (stdscr, mc_global.eight_bit_clean);
635 #else
636 SLsmg_Display_Eight_Bit = mc_global.full_eight_bits ? 128 : 160;
637 #endif
638 use_8th_bit_as_meta = !new_meta;
642 /* --------------------------------------------------------------------------------------------- */
643 #else /* HAVE_CHARSET */
645 void
646 display_bits_box (void)
648 const char *cpname;
650 cpname = (new_display_codepage < 0) ? _("Other 8 bit")
651 : ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name;
653 new_display_codepage = mc_global.display_codepage;
656 int new_meta;
658 quick_widget_t quick_widgets[] = {
659 /* *INDENT-OFF* */
660 QUICK_START_COLUMNS,
661 QUICK_LABEL (N_("Input / display codepage:"), NULL),
662 QUICK_NEXT_COLUMN,
663 QUICK_STOP_COLUMNS,
664 QUICK_START_COLUMNS,
665 QUICK_LABEL (cpname, &disp_bits_name_id),
666 QUICK_NEXT_COLUMN,
667 QUICK_BUTTON (N_("&Select"), B_USER, sel_charset_button, NULL),
668 QUICK_STOP_COLUMNS,
669 QUICK_SEPARATOR (TRUE),
670 QUICK_CHECKBOX (N_("F&ull 8 bits input"), &new_meta, NULL),
671 QUICK_BUTTONS_OK_CANCEL,
672 QUICK_END
673 /* *INDENT-ON* */
676 quick_dialog_t qdlg = {
677 -1, -1, 46,
678 N_("Display bits"), "[Display bits]",
679 quick_widgets, NULL, NULL
682 new_meta = !use_8th_bit_as_meta;
683 application_keypad_mode ();
685 if (quick_dialog (&qdlg) == B_ENTER)
687 char *errmsg;
689 mc_global.display_codepage = new_display_codepage;
691 errmsg = init_translation_table (mc_global.source_codepage, mc_global.display_codepage);
692 if (errmsg != NULL)
694 message (D_ERROR, MSG_ERROR, "%s", errmsg);
695 g_free (errmsg);
698 #ifdef HAVE_SLANG
699 tty_display_8bit (mc_global.display_codepage != 0 && mc_global.display_codepage != 1);
700 #else
701 tty_display_8bit (mc_global.display_codepage != 0);
702 #endif
703 use_8th_bit_as_meta = !new_meta;
705 repaint_screen ();
709 #endif /* HAVE_CHARSET */
711 /* --------------------------------------------------------------------------------------------- */
712 /** Show tree in a box, not on a panel */
714 char *
715 tree_box (const char *current_dir)
717 WTree *mytree;
718 WDialog *dlg;
719 Widget *wd;
720 char *val = NULL;
721 WButtonBar *bar;
723 (void) current_dir;
725 /* Create the components */
726 dlg = create_dlg (TRUE, 0, 0, LINES - 9, COLS - 20, dialog_colors, tree_callback, NULL,
727 "[Directory Tree]", _("Directory tree"), DLG_CENTER);
728 wd = WIDGET (dlg);
730 mytree = tree_new (2, 2, wd->lines - 6, wd->cols - 5, FALSE);
731 add_widget_autopos (dlg, mytree, WPOS_KEEP_ALL, NULL);
732 add_widget_autopos (dlg, hline_new (wd->lines - 4, 1, -1), WPOS_KEEP_BOTTOM, NULL);
733 bar = buttonbar_new (TRUE);
734 add_widget (dlg, bar);
735 /* restore ButtonBar coordinates after add_widget() */
736 WIDGET (bar)->x = 0;
737 WIDGET (bar)->y = LINES - 1;
739 if (run_dlg (dlg) == B_ENTER)
740 val = vfs_path_to_str (tree_selected_name (mytree));
742 destroy_dlg (dlg);
743 return val;
746 /* --------------------------------------------------------------------------------------------- */
748 #ifdef ENABLE_VFS
749 void
750 configure_vfs (void)
752 char buffer2[BUF_TINY];
753 #ifdef ENABLE_VFS_FTP
754 char buffer3[BUF_TINY];
756 g_snprintf (buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
757 #endif
759 g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
762 char *ret_timeout;
763 #ifdef ENABLE_VFS_FTP
764 char *ret_passwd;
765 char *ret_ftp_proxy;
766 char *ret_directory_timeout;
767 #endif /* ENABLE_VFS_FTP */
769 quick_widget_t quick_widgets[] = {
770 /* *INDENT-OFF* */
771 QUICK_LABELED_INPUT (N_("Timeout for freeing VFSs (sec):"), input_label_left,
772 buffer2, 0, "input-timo-vfs", &ret_timeout, NULL),
773 #ifdef ENABLE_VFS_FTP
774 QUICK_SEPARATOR (TRUE),
775 QUICK_LABELED_INPUT (N_("FTP anonymous password:"), input_label_left,
776 ftpfs_anonymous_passwd, 0, "input-passwd", &ret_passwd, NULL),
777 QUICK_LABELED_INPUT (N_("FTP directory cache timeout (sec):"), input_label_left,
778 buffer3, 0, "input-timeout", &ret_directory_timeout, NULL),
779 QUICK_CHECKBOX (N_("&Always use ftp proxy:"), &ftpfs_always_use_proxy,
780 &ftpfs_always_use_proxy_id),
781 QUICK_INPUT (ftpfs_proxy_host, 0, "input-ftp-proxy", &ret_ftp_proxy,
782 &ftpfs_proxy_host_id),
783 QUICK_CHECKBOX (N_("&Use ~/.netrc"), &ftpfs_use_netrc, NULL),
784 QUICK_CHECKBOX (N_("Use &passive mode"), &ftpfs_use_passive_connections, NULL),
785 QUICK_CHECKBOX (N_("Use passive mode over pro&xy"),
786 &ftpfs_use_passive_connections_over_proxy, NULL),
787 #endif /* ENABLE_VFS_FTP */
788 QUICK_BUTTONS_OK_CANCEL,
789 QUICK_END
790 /* *INDENT-ON* */
793 quick_dialog_t qdlg = {
794 -1, -1, 56,
795 N_("Virtual File System Setting"), "[Virtual FS]",
796 quick_widgets,
797 #ifdef ENABLE_VFS_FTP
798 confvfs_callback,
799 #else
800 NULL,
801 #endif
802 NULL,
805 #ifdef ENABLE_VFS_FTP
806 if (!ftpfs_always_use_proxy)
807 quick_widgets[5].options = W_DISABLED;
808 #endif
810 if (quick_dialog (&qdlg) != B_CANCEL)
812 vfs_timeout = atoi (ret_timeout);
813 g_free (ret_timeout);
815 if (vfs_timeout < 0 || vfs_timeout > 10000)
816 vfs_timeout = 10;
817 #ifdef ENABLE_VFS_FTP
818 g_free (ftpfs_anonymous_passwd);
819 ftpfs_anonymous_passwd = ret_passwd;
820 g_free (ftpfs_proxy_host);
821 ftpfs_proxy_host = ret_ftp_proxy;
822 ftpfs_directory_timeout = atoi (ret_directory_timeout);
823 g_free (ret_directory_timeout);
824 #endif
829 #endif /* ENABLE_VFS */
831 /* --------------------------------------------------------------------------------------------- */
833 char *
834 cd_dialog (void)
836 const Widget *w = WIDGET (current_panel);
837 char *my_str;
839 quick_widget_t quick_widgets[] = {
840 QUICK_LABELED_INPUT (N_("cd"), input_label_left, "", 2, "input", &my_str, NULL),
841 QUICK_END
844 quick_dialog_t qdlg = {
845 w->y + w->lines - 6, w->x, w->cols,
846 N_("Quick cd"), "[Quick cd]",
847 quick_widgets, NULL, NULL
850 return (quick_dialog (&qdlg) != B_CANCEL) ? my_str : NULL;
853 /* --------------------------------------------------------------------------------------------- */
855 void
856 symlink_dialog (const vfs_path_t * existing_vpath, const vfs_path_t * new_vpath,
857 char **ret_existing, char **ret_new)
859 char *existing;
860 char *new;
862 existing = vfs_path_to_str (existing_vpath);
863 new = vfs_path_to_str (new_vpath);
866 quick_widget_t quick_widgets[] = {
867 /* *INDENT-OFF* */
868 QUICK_LABELED_INPUT (N_("Existing filename (filename symlink will point to):"),
869 input_label_above,
870 existing, 0, "input-2", ret_existing, NULL),
871 QUICK_SEPARATOR (FALSE),
872 QUICK_LABELED_INPUT (N_("Symbolic link filename:"), input_label_above,
873 new, 0, "input-1", ret_new, NULL),
874 QUICK_BUTTONS_OK_CANCEL,
875 QUICK_END
876 /* *INDENT-ON* */
879 quick_dialog_t qdlg = {
880 -1, -1, 64,
881 N_("Symbolic link"), "[File Menu]",
882 quick_widgets, NULL, NULL
885 if (quick_dialog (&qdlg) == B_CANCEL)
887 *ret_new = NULL;
888 *ret_existing = NULL;
892 g_free (existing);
893 g_free (new);
896 /* --------------------------------------------------------------------------------------------- */
898 #ifdef ENABLE_BACKGROUND
899 void
900 jobs_cmd (void)
902 struct
904 const char *name;
905 int flags;
906 int value;
907 int len;
908 bcback_fn callback;
910 job_but[] =
912 /* *INDENT-OFF* */
913 { N_("&Stop"), NORMAL_BUTTON, B_STOP, 0, task_cb },
914 { N_("&Resume"), NORMAL_BUTTON, B_RESUME, 0, task_cb },
915 { N_("&Kill"), NORMAL_BUTTON, B_KILL, 0, task_cb },
916 { N_("&OK"), DEFPUSH_BUTTON, B_CANCEL, 0, NULL }
917 /* *INDENT-ON* */
920 size_t i;
921 const size_t n_but = G_N_ELEMENTS (job_but);
923 WDialog *jobs_dlg;
924 int cols = 60;
925 int lines = 15;
926 int x = 0;
928 for (i = 0; i < n_but; i++)
930 #ifdef ENABLE_NLS
931 job_but[i].name = _(job_but[i].name);
932 #endif /* ENABLE_NLS */
934 job_but[i].len = str_term_width1 (job_but[i].name) + 3;
935 if (job_but[i].flags == DEFPUSH_BUTTON)
936 job_but[i].len += 2;
937 x += job_but[i].len;
940 x += (int) n_but - 1;
941 cols = max (cols, x + 6);
943 jobs_dlg = create_dlg (TRUE, 0, 0, lines, cols, dialog_colors, NULL, NULL,
944 "[Background jobs]", _("Background jobs"), DLG_CENTER);
946 bg_list = listbox_new (2, 2, lines - 6, cols - 6, FALSE, NULL);
947 jobs_fill_listbox (bg_list);
948 add_widget (jobs_dlg, bg_list);
950 add_widget (jobs_dlg, hline_new (lines - 4, -1, -1));
952 x = (cols - x) / 2;
953 for (i = 0; i < n_but; i++)
955 add_widget (jobs_dlg,
956 button_new (lines - 3, x, job_but[i].value, job_but[i].flags, job_but[i].name,
957 job_but[i].callback));
958 x += job_but[i].len + 1;
961 (void) run_dlg (jobs_dlg);
962 destroy_dlg (jobs_dlg);
964 #endif /* ENABLE_BACKGROUND */
966 /* --------------------------------------------------------------------------------------------- */
968 #ifdef ENABLE_VFS_SMB
969 struct smb_authinfo *
970 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain, const char *user)
972 char *label;
973 struct smb_authinfo *return_value = NULL;
975 if (domain == NULL)
976 domain = "";
977 if (user == NULL)
978 user = "";
980 label = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
983 char *ret_domain, *ret_user, *ret_password;
985 quick_widget_t quick_widgets[] = {
986 /* *INDENT-OFF* */
987 QUICK_LABEL (label, NULL),
988 QUICK_SEPARATOR (TRUE),
989 QUICK_START_COLUMNS,
990 QUICK_LABEL (N_("Domain:"), NULL),
991 QUICK_SEPARATOR (FALSE),
992 QUICK_LABEL (N_("Username:"), NULL),
993 QUICK_SEPARATOR (FALSE),
994 QUICK_LABEL (N_("Password:"), NULL),
995 QUICK_NEXT_COLUMN,
996 QUICK_INPUT (domain, 0, "auth_domain", &ret_domain, NULL),
997 QUICK_SEPARATOR (FALSE),
998 QUICK_INPUT (user, 0, "auth_name", &ret_user, NULL),
999 QUICK_SEPARATOR (FALSE),
1000 QUICK_INPUT ("", 1, "auth_password", &ret_password, NULL),
1001 QUICK_STOP_COLUMNS,
1002 QUICK_BUTTONS_OK_CANCEL,
1003 QUICK_END
1004 /* *INDENT-ON* */
1007 quick_dialog_t qdlg = {
1008 -1, -1, 40,
1009 N_("SMB authentication"), "[Smb Authinfo]",
1010 quick_widgets, NULL, NULL
1013 if (quick_dialog (&qdlg) != B_CANCEL)
1015 return_value = vfs_smb_authinfo_new (host, share, ret_domain, ret_user, ret_password);
1017 g_free (ret_domain);
1018 g_free (ret_user);
1019 g_free (ret_password);
1023 g_free (label);
1025 return return_value;
1027 #endif /* ENABLE_VFS_SMB */
1029 /* --------------------------------------------------------------------------------------------- */