Some WIDGET-related stuff moved to lib/widget directory
[midnight-commander/osp/cernimil.git] / src / boxes.c
blobb41c2162efc343dc3412aca2d2b9ff280d5d4552
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 "lib/widget/dialog.h" /* The nice dialog manager */
54 #include "lib/widget/widget.h" /* The widgets for the nice dialog manager */
55 #include "lib/widget/wtools.h"
57 #include "setup.h" /* For profile_name */
58 #include "command.h" /* For cmdline */
59 #include "dir.h"
60 #include "panel.h" /* LIST_TYPES */
61 #include "main.h" /* For the confirm_* variables */
62 #include "tree.h"
63 #include "layout.h" /* for get_nth_panel_name proto */
64 #include "background.h" /* task_list */
66 #ifdef HAVE_CHARSET
67 #include "charsets.h"
68 #include "selcodepage.h"
69 #endif
71 #include "boxes.h"
73 /*** global variables ****************************************************************************/
75 /*** file scope macro definitions ****************************************************************/
77 #ifdef ENABLE_VFS
78 #define VFSX 56
80 #ifdef ENABLE_VFS_FTP
81 #define VFSY 17
82 #else
83 #define VFSY 8
84 #endif /* ENABLE_VFS_FTP */
85 #endif /* ENABLE_VFS */
87 #ifdef WITH_BACKGROUND
88 #define B_STOP (B_USER+1)
89 #define B_RESUME (B_USER+2)
90 #define B_KILL (B_USER+3)
91 #define JOBS_Y 15
92 #endif /* WITH_BACKGROUND */
94 /*** file scope type declarations ****************************************************************/
96 /*** file scope variables ************************************************************************/
98 static WRadio *display_radio;
99 static WInput *display_user_format;
100 static WInput *display_mini_status;
101 static WCheck *display_check_status;
102 static char **displays_status;
103 static int display_user_hotkey = 'u';
105 #ifdef HAVE_CHARSET
106 static int new_display_codepage;
107 static WLabel *cplabel;
108 static WCheck *inpcheck;
109 #endif /* HAVE_CHARSET */
111 #ifdef ENABLE_VFS
112 static char *ret_timeout;
113 #ifdef ENABLE_VFS_FTP
114 static char *ret_ftp_proxy;
115 static char *ret_passwd;
116 static char *ret_directory_timeout;
117 #endif /* ENABLE_VFS_FTP */
118 #endif /* ENABLE_VFS */
120 #ifdef WITH_BACKGROUND
121 static int JOBS_X = 60;
122 static WListbox *bg_list;
123 static Dlg_head *jobs_dlg;
125 static int task_cb (WButton * button, int action);
127 static struct
129 const char *name;
130 int xpos;
131 int value;
132 bcback callback;
134 job_buttons[] =
136 /* *INDENT-OFF* */
137 { N_("&Stop"), 3, B_STOP, task_cb },
138 { N_("&Resume"), 12, B_RESUME, task_cb },
139 { N_("&Kill"), 23, B_KILL, task_cb },
140 { N_("&OK"), 35, B_CANCEL, NULL }
141 /* *INDENT-ON* */
144 #endif /* WITH_BACKGROUND */
146 /*** file scope functions ************************************************************************/
147 /* --------------------------------------------------------------------------------------------- */
149 static cb_ret_t
150 display_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
152 switch (msg)
154 case DLG_KEY:
155 if (parm == '\n')
157 if (dlg_widget_active (display_radio))
159 assign_text (display_mini_status, displays_status[display_radio->sel]);
160 dlg_stop (h);
161 return MSG_HANDLED;
164 if (dlg_widget_active (display_user_format))
166 h->ret_value = B_USER + 6;
167 dlg_stop (h);
168 return MSG_HANDLED;
171 if (dlg_widget_active (display_mini_status))
173 h->ret_value = B_USER + 7;
174 dlg_stop (h);
175 return MSG_HANDLED;
179 if ((g_ascii_tolower (parm) == display_user_hotkey)
180 && dlg_widget_active (display_user_format) && dlg_widget_active (display_mini_status))
182 display_radio->pos = display_radio->sel = 3;
183 dlg_select_widget (display_radio); /* force redraw */
184 h->callback (h, (Widget *) display_radio, DLG_ACTION, 0, NULL);
185 return MSG_HANDLED;
187 return MSG_NOT_HANDLED;
189 case DLG_ACTION:
190 if (sender == (Widget *) display_radio)
192 if (!(display_check_status->state & C_BOOL))
193 assign_text (display_mini_status, displays_status[display_radio->sel]);
194 update_input (display_mini_status, 0);
195 update_input (display_user_format, 0);
196 widget_disable (display_user_format->widget, display_radio->sel != 3);
197 return MSG_HANDLED;
200 if (sender == (Widget *) display_check_status)
202 if (display_check_status->state & C_BOOL)
204 widget_disable (display_mini_status->widget, FALSE);
205 assign_text (display_mini_status, displays_status[3]);
207 else
209 widget_disable (display_mini_status->widget, TRUE);
210 assign_text (display_mini_status, displays_status[display_radio->sel]);
212 update_input (display_mini_status, 0);
213 return MSG_HANDLED;
216 return MSG_NOT_HANDLED;
218 default:
219 return default_dlg_callback (h, sender, msg, parm, data);
223 /* --------------------------------------------------------------------------------------------- */
225 static Dlg_head *
226 display_init (int radio_sel, char *init_text, int _check_status, char **_status)
228 int dlg_width = 48, dlg_height = 15;
229 Dlg_head *dd;
231 /* Controls whether the array strings have been translated */
232 const char *displays[LIST_TYPES] = {
233 N_("&Full file list"),
234 N_("&Brief file list"),
235 N_("&Long file list"),
236 N_("&User defined:")
239 /* Index in displays[] for "user defined" */
240 const int user_type_idx = 3;
242 const char *display_title = N_("Listing mode");
243 const char *user_mini_status = N_("User &mini status");
244 const char *ok_name = N_("&OK");
245 const char *cancel_name = N_("&Cancel");
247 WButton *ok_button, *cancel_button;
250 int i, maxlen = 0;
251 const char *cp;
252 int ok_len, cancel_len, b_len, gap;
254 #ifdef ENABLE_NLS
255 display_title = _(display_title);
256 user_mini_status = _(user_mini_status);
257 ok_name = _(ok_name);
258 cancel_name = _(cancel_name);
260 for (i = 0; i < LIST_TYPES; i++)
261 displays[i] = _(displays[i]);
262 #endif
264 /* get hotkey of user-defined format string */
265 cp = strchr (displays[user_type_idx], '&');
266 if (cp != NULL && *++cp != '\0')
267 display_user_hotkey = g_ascii_tolower (*cp);
269 /* xpos will be fixed later */
270 ok_button = button_new (dlg_height - 3, 0, B_ENTER, DEFPUSH_BUTTON, ok_name, 0);
271 ok_len = button_get_len (ok_button);
272 cancel_button = button_new (dlg_height - 3, 0, B_CANCEL, NORMAL_BUTTON, cancel_name, 0);
273 cancel_len = button_get_len (cancel_button);
274 b_len = ok_len + cancel_len + 2;
276 dlg_width = max (dlg_width, str_term_width1 (display_title) + 10);
277 /* calculate max width of radiobutons */
278 for (i = 0; i < LIST_TYPES; i++)
279 maxlen = max (maxlen, str_term_width1 (displays[i]));
280 dlg_width = max (dlg_width, maxlen);
281 dlg_width = max (dlg_width, str_term_width1 (user_mini_status) + 13);
283 /* buttons */
284 dlg_width = max (dlg_width, b_len + 6);
285 gap = (dlg_width - 6 - b_len) / 3;
286 ok_button->widget.x = 3 + gap;
287 cancel_button->widget.x = ok_button->widget.x + ok_len + gap + 2;
290 displays_status = _status;
292 dd = create_dlg (TRUE, 0, 0, dlg_height, dlg_width, dialog_colors,
293 display_callback, "[Listing Mode...]", display_title,
294 DLG_CENTER | DLG_REVERSE);
296 add_widget (dd, cancel_button);
297 add_widget (dd, ok_button);
299 display_mini_status =
300 input_new (10, 8, input_get_default_colors (), dlg_width - 12, _status[radio_sel],
301 "mini-input", INPUT_COMPLETE_DEFAULT);
302 add_widget (dd, display_mini_status);
304 display_check_status = check_new (9, 4, _check_status, user_mini_status);
305 add_widget (dd, display_check_status);
307 display_user_format = input_new (7, 8, input_get_default_colors (), dlg_width - 12, init_text,
308 "user-fmt-input", INPUT_COMPLETE_DEFAULT);
309 add_widget (dd, display_user_format);
311 display_radio = radio_new (3, 4, LIST_TYPES, displays);
312 display_radio->sel = display_radio->pos = radio_sel;
313 add_widget (dd, display_radio);
315 return dd;
318 /* --------------------------------------------------------------------------------------------- */
319 #ifdef HAVE_CHARSET
321 static int
322 sel_charset_button (WButton * button, int action)
324 int new_dcp;
326 (void) button;
327 (void) action;
329 new_dcp = select_charset (-1, -1, new_display_codepage, TRUE);
331 if (new_dcp != SELECT_CHARSET_CANCEL)
333 const char *cpname;
334 char buf[BUF_TINY];
336 new_display_codepage = new_dcp;
337 cpname = (new_display_codepage == SELECT_CHARSET_OTHER_8BIT) ?
338 _("Other 8 bit") :
339 ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name;
340 if (cpname != NULL)
341 utf8_display = str_isutf8 (cpname);
342 /* avoid strange bug with label repainting */
343 g_snprintf (buf, sizeof (buf), "%-27s", cpname);
344 label_set_text (cplabel, buf);
347 return 0;
350 /* --------------------------------------------------------------------------------------------- */
352 static Dlg_head *
353 init_disp_bits_box (void)
355 /* dialog sizes */
356 const int DISPY = 11;
357 const int DISPX = 46;
359 const char *cpname;
360 Dlg_head *dbits_dlg;
362 do_refresh ();
364 dbits_dlg =
365 create_dlg (TRUE, 0, 0, DISPY, DISPX, dialog_colors, NULL,
366 "[Display bits]", _("Display bits"), DLG_CENTER | DLG_REVERSE);
368 add_widget (dbits_dlg, label_new (3, 4, _("Input / display codepage:")));
370 cpname = (new_display_codepage < 0) ? _("Other 8 bit")
371 : ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name;
372 cplabel = label_new (4, 4, cpname);
373 add_widget (dbits_dlg, cplabel);
375 add_widget (dbits_dlg,
376 button_new (DISPY - 3, DISPX / 2 + 3, B_CANCEL, NORMAL_BUTTON, _("&Cancel"), 0));
377 add_widget (dbits_dlg, button_new (DISPY - 3, 7, B_ENTER, NORMAL_BUTTON, _("&OK"), 0));
379 inpcheck = check_new (6, 4, !use_8th_bit_as_meta, _("F&ull 8 bits input"));
380 add_widget (dbits_dlg, inpcheck);
382 cpname = _("&Select");
383 add_widget (dbits_dlg,
384 button_new (4, DISPX - 7 - str_term_width1 (cpname), B_USER,
385 NORMAL_BUTTON, cpname, sel_charset_button));
387 return dbits_dlg;
389 #endif /* HAVE_CHARSET */
391 /* --------------------------------------------------------------------------------------------- */
393 static cb_ret_t
394 tree_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
396 switch (msg)
398 case DLG_POST_KEY:
399 /* The enter key will be processed by the tree widget */
400 if (parm == '\n')
402 h->ret_value = B_ENTER;
403 dlg_stop (h);
405 return MSG_HANDLED;
407 case DLG_ACTION:
408 /* command from buttonbar */
409 return send_message ((Widget *) find_tree (h), WIDGET_COMMAND, parm);
411 default:
412 return default_dlg_callback (h, sender, msg, parm, data);
416 /* --------------------------------------------------------------------------------------------- */
418 #ifdef ENABLE_VFS
419 #ifdef ENABLE_VFS_FTP
421 static cb_ret_t
422 confvfs_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
424 switch (msg)
426 case DLG_ACTION:
427 if (sender->id == 6)
429 /* message from "Always use ftp proxy" checkbutton */
430 const gboolean not_use = !(((WCheck *) sender)->state & C_BOOL);
431 Widget *w;
433 /* input */
434 w = dlg_find_by_id (h, sender->id - 1);
435 widget_disable (*w, not_use);
436 send_message (w, WIDGET_DRAW, 0);
438 return MSG_HANDLED;
440 return MSG_NOT_HANDLED;
442 default:
443 return default_dlg_callback (h, sender, msg, parm, data);
446 #endif /* ENABLE_VFS_FTP */
447 #endif /* ENABLE_VFS */
449 #ifdef WITH_BACKGROUND
450 static void
451 jobs_fill_listbox (void)
453 static const char *state_str[2];
454 TaskList *tl = task_list;
456 if (!state_str[0])
458 state_str[0] = _("Running");
459 state_str[1] = _("Stopped");
462 while (tl)
464 char *s;
466 s = g_strconcat (state_str[tl->state], " ", tl->info, (char *) NULL);
467 listbox_add_item (bg_list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
468 g_free (s);
469 tl = tl->next;
473 /* --------------------------------------------------------------------------------------------- */
475 static int
476 task_cb (WButton * button, int action)
478 TaskList *tl;
479 int sig = 0;
481 (void) button;
483 if (bg_list->list == NULL)
484 return 0;
486 /* Get this instance information */
487 listbox_get_current (bg_list, NULL, (void **) &tl);
489 #ifdef SIGTSTP
490 if (action == B_STOP)
492 sig = SIGSTOP;
493 tl->state = Task_Stopped;
495 else if (action == B_RESUME)
497 sig = SIGCONT;
498 tl->state = Task_Running;
500 else
501 #endif
502 if (action == B_KILL)
504 sig = SIGKILL;
507 if (sig == SIGKILL)
508 unregister_task_running (tl->pid, tl->fd);
510 kill (tl->pid, sig);
511 listbox_remove_list (bg_list);
512 jobs_fill_listbox ();
514 /* This can be optimized to just redraw this widget :-) */
515 dlg_redraw (jobs_dlg);
517 return 0;
519 #endif /* WITH_BACKGROUND */
521 /* --------------------------------------------------------------------------------------------- */
522 /*** public functions ****************************************************************************/
523 /* --------------------------------------------------------------------------------------------- */
525 /* return list type */
527 display_box (WPanel * panel, char **userp, char **minip, int *use_msformat, int num)
529 int result = -1;
530 Dlg_head *dd;
531 char *section = NULL;
532 size_t i;
534 if (panel == NULL)
536 const char *p = get_nth_panel_name (num);
537 panel = g_new (WPanel, 1);
538 panel->list_type = list_full;
539 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
540 panel->user_mini_status = 0;
541 for (i = 0; i < LIST_TYPES; i++)
542 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
543 section = g_strconcat ("Temporal:", p, (char *) NULL);
544 if (!mc_config_has_group (mc_main_config, section))
546 g_free (section);
547 section = g_strdup (p);
549 panel_load_setup (panel, section);
550 g_free (section);
553 dd = display_init (panel->list_type, panel->user_format,
554 panel->user_mini_status, panel->user_status_format);
556 if (run_dlg (dd) != B_CANCEL)
558 result = display_radio->sel;
559 *userp = g_strdup (display_user_format->buffer);
560 *minip = g_strdup (display_mini_status->buffer);
561 *use_msformat = display_check_status->state & C_BOOL;
564 if (section != NULL)
566 g_free (panel->user_format);
567 for (i = 0; i < LIST_TYPES; i++)
568 g_free (panel->user_status_format[i]);
569 g_free (panel);
572 destroy_dlg (dd);
574 return result;
577 /* --------------------------------------------------------------------------------------------- */
579 const panel_field_t *
580 sort_box (const panel_field_t * sort_format, int *reverse, int *case_sensitive, int *exec_first)
582 int dlg_width = 40, dlg_height = 7;
584 const char **sort_orders_names;
585 gsize sort_names_num;
587 int sort_idx = 0;
589 const panel_field_t *result = sort_format;
591 sort_orders_names = panel_get_sortable_fields (&sort_names_num);
592 dlg_height += sort_names_num;
595 int max_radio = 0, max_check = 0;
596 int ok_len, cancel_len;
597 gsize i;
599 QuickWidget quick_widgets[] = {
600 /* 0 */
601 QUICK_BUTTON (0, dlg_width, dlg_height - 3, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
602 /* 1 */
603 QUICK_BUTTON (0, dlg_width, dlg_height - 3, dlg_height, N_("&OK"), B_ENTER, NULL),
604 /* 2 */
605 QUICK_CHECKBOX (0, dlg_width, 5, dlg_height, N_("&Reverse"), reverse),
606 /* 3 */
607 QUICK_CHECKBOX (0, dlg_width, 4, dlg_height, N_("Case sensi&tive"), case_sensitive),
608 /* 4 */
609 QUICK_CHECKBOX (0, dlg_width, 3, dlg_height, N_("Executable &first"), exec_first),
610 /* 5 */
611 QUICK_RADIO (4, dlg_width, 3, dlg_height, 0,
612 NULL, &sort_idx),
613 QUICK_END
616 QuickDialog quick_dlg = {
617 dlg_width, dlg_height, -1, -1,
618 N_("Sort order"), "[Sort Order...]",
619 quick_widgets, NULL, TRUE
622 quick_widgets[5].u.radio.items = sort_orders_names;
623 quick_widgets[5].u.radio.count = sort_names_num;
625 for (i = 0; i < sort_names_num; i++)
626 if (strcmp (sort_orders_names[i], _(sort_format->title_hotkey)) == 0)
628 sort_idx = i;
629 break;
632 #ifdef ENABLE_NLS
633 quick_dlg.title = _(quick_dlg.title);
634 /* buttons */
635 for (i = 0; i < 2; i++)
636 quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
637 /* checkboxes */
638 for (i = 2; i < 5; i++)
639 quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
640 #endif /* ENABLE_NlS */
642 /* buttons */
643 cancel_len = str_term_width1 (quick_widgets[0].u.button.text) + 4;
644 ok_len = str_term_width1 (quick_widgets[1].u.button.text) + 6;
645 /* checkboxes */
646 for (i = 2; i < 5; i++)
647 max_check = max (max_check, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4);
648 /* radiobuttons */
649 for (i = 0; i < sort_names_num; i++)
650 max_radio = max (max_radio, str_term_width1 (sort_orders_names[i]) + 4);
652 /* dialog width */
653 dlg_width = max (dlg_width, str_term_width1 (quick_dlg.title) + 8);
654 dlg_width = max (dlg_width, ok_len + cancel_len + 8);
655 dlg_width = max (dlg_width, 2 * max (max_radio, max_check) + 8);
657 /* fix widget and dialog parameters */
658 /* dialog */
659 quick_dlg.xlen = dlg_width;
660 /* widgets */
661 for (i = 0; (size_t) i < sizeof (quick_widgets) / sizeof (quick_widgets[0]) - 1; i++)
662 quick_widgets[i].x_divisions = dlg_width;
663 /* buttons */
664 quick_widgets[0].relative_x = dlg_width * 2 / 3 - cancel_len / 2;
665 quick_widgets[1].relative_x = dlg_width / 3 - ok_len / 2;
666 /* checkboxes */
667 for (i = 2; i < 5; i++)
668 quick_widgets[i].relative_x = dlg_width / 2 + 2;
670 if (quick_dialog (&quick_dlg) != B_CANCEL)
671 result = panel_get_field_by_title_hotkey (sort_orders_names[sort_idx]);
673 if (result == NULL)
674 result = sort_format;
676 g_strfreev ((gchar **) sort_orders_names);
677 return result;
680 /* --------------------------------------------------------------------------------------------- */
682 void
683 confirm_box (void)
685 const char *title = _("Confirmation");
687 QuickWidget conf_widgets[] = {
688 /* 0 */ QUICK_BUTTON (29, 46, 10, 13, N_("&Cancel"), B_CANCEL, NULL),
689 /* 1 */ QUICK_BUTTON (12, 46, 10, 13, N_("&OK"), B_ENTER, NULL),
690 /* TRANSLATORS: no need to translate 'Confirmation', it's just a context prefix */
691 /* 2 */ QUICK_CHECKBOX (3, 46, 8, 13, N_("Confirmation|&History cleanup"),
692 &confirm_history_cleanup),
693 /* 3 */ QUICK_CHECKBOX (3, 46, 7, 13, N_("Confirmation|Di&rectory hotlist delete"),
694 &confirm_directory_hotlist_delete),
695 /* 4 */ QUICK_CHECKBOX (3, 46, 6, 13, N_("Confirmation|E&xit"), &confirm_exit),
696 /* 5 */ QUICK_CHECKBOX (3, 46, 5, 13, N_("Confirmation|&Execute"), &confirm_execute),
697 /* 6 */ QUICK_CHECKBOX (3, 46, 4, 13, N_("Confirmation|O&verwrite"), &confirm_overwrite),
698 /* 7 */ QUICK_CHECKBOX (3, 46, 3, 13, N_("Confirmation|&Delete"), &confirm_delete),
699 QUICK_END
702 const size_t w_num = sizeof (conf_widgets) / sizeof (conf_widgets[0]) - 1;
704 /* dialog sizes */
705 int dlg_width = 46;
706 int dlg_height = w_num + 5;
708 size_t i;
709 int maxlen = 0;
710 int cancel_len, ok_len, blen;
712 #ifdef ENABLE_NLS
713 title = _(title);
715 for (i = 0; i < 2; i++)
716 conf_widgets[i].u.button.text = _(conf_widgets[i].u.button.text);
717 #endif /* ENABLE_NLS */
719 for (i = 2; i < w_num; i++)
720 conf_widgets[i].u.checkbox.text = Q_ (conf_widgets[i].u.checkbox.text);
722 /* maximum length of checkboxes */
723 for (i = 2; i < w_num; i++)
724 maxlen = max (maxlen, str_term_width1 (conf_widgets[i].u.checkbox.text) + 4);
726 /* length of buttons */
727 cancel_len = str_term_width1 (conf_widgets[0].u.button.text) + 3;
728 ok_len = str_term_width1 (conf_widgets[1].u.button.text) + 5; /* default button */
730 blen = cancel_len + ok_len + 2;
732 dlg_width = max (maxlen, blen) + 6;
733 dlg_width = max (dlg_width, str_term_width1 (title) + 4);
735 /* correct widget parameters */
736 for (i = 0; i < w_num; i++)
738 conf_widgets[i].x_divisions = dlg_width;
739 conf_widgets[i].y_divisions = dlg_height;
742 conf_widgets[1].relative_x = dlg_width / 2 - blen / 2;
743 conf_widgets[0].relative_x = conf_widgets[1].relative_x + ok_len + 2;
746 QuickDialog confirmation = {
747 dlg_width, dlg_height, -1, -1, title,
748 "[Confirmation]", conf_widgets, NULL, TRUE
751 (void) quick_dialog (&confirmation);
755 /* --------------------------------------------------------------------------------------------- */
757 #ifndef HAVE_CHARSET
758 void
759 display_bits_box (void) /* AB:FIXME: test dialog */
761 /* dialog sizes */
762 const int DISPY = 13;
763 const int DISPX = 46;
765 int new_meta = 0;
766 int current_mode;
768 const char *display_bits_str[] = {
769 N_("UTF-8 output"),
770 N_("Full 8 bits output"),
771 N_("ISO 8859-1"),
772 N_("7 bits")
775 QuickWidget display_widgets[] = {
776 /* 0 */ QUICK_BUTTON (15, DISPX, DISPY - 3, DISPY, N_("&Cancel"), B_CANCEL, NULL),
777 /* 1 */ QUICK_BUTTON (29, DISPX, DISPY - 3, DISPY, N_("&OK"), B_ENTER, NULL),
778 /* 2 */ QUICK_CHECKBOX (3, DISPX, 8, DISPY, N_("F&ull 8 bits input"), &new_meta),
779 /* 3 */ QUICK_RADIO (3, DISPX, 3, DISPY, 4, display_bits_str, &current_mode),
780 QUICK_END
783 QuickDialog display_bits = {
784 DISPX, DISPY, -1, -1, _("Display bits"),
785 "[Display bits]", display_widgets, NULL, TRUE
788 int i;
789 int l1, maxlen = 0;
790 int ok_len, cancel_len;
792 #ifdef ENABLE_NLS
793 static gboolean i18n_flag = FALSE;
795 if (!i18n_flag)
797 for (i = 0; i < 3; i++)
799 display_bits_str[i] = _(display_bits_str[i]);
802 display_widgets[0].u.button.text = _(display_widgets[0].u.button.text);
803 display_widgets[1].u.button.text = _(display_widgets[1].u.button.text);
804 display_widgets[2].u.checkbox.text = _(display_widgets[2].u.checkbox.text);
806 i18n_flag = TRUE;
808 #endif /* ENABLE_NLS */
810 /* radiobuttons */
811 for (i = 0; i < 3; i++)
812 maxlen = max (maxlen, str_term_width1 (display_bits_str[i]));
814 /* buttons */
815 cancel_len = str_term_width1 (display_widgets[0].u.button.text) + 2;
816 ok_len = str_term_width1 (display_widgets[1].u.button.text) + 4; /* default button */
818 l1 = max (cancel_len, ok_len);
820 display_bits.xlen = max (maxlen, l1) + 20;
822 for (i = 0; i < 4; i++)
823 display_widgets[i].x_divisions = display_bits.xlen;
825 display_widgets[0].relative_x = display_bits.xlen * 2 / 3 - cancel_len / 2;
826 display_widgets[1].relative_x = display_bits.xlen / 3 - ok_len / 2;
828 if (full_eight_bits)
829 current_mode = 0;
830 else if (eight_bit_clean)
831 current_mode = 1;
832 else
833 current_mode = 2;
835 new_meta = !use_8th_bit_as_meta;
837 if (quick_dialog (&display_bits) != B_CANCEL)
839 eight_bit_clean = current_mode < 3;
840 full_eight_bits = current_mode < 2;
841 #ifndef HAVE_SLANG
842 meta (stdscr, eight_bit_clean);
843 #else
844 SLsmg_Display_Eight_Bit = full_eight_bits ? 128 : 160;
845 #endif
846 use_8th_bit_as_meta = !new_meta;
850 /* --------------------------------------------------------------------------------------------- */
851 #else /* HAVE_CHARSET */
853 void
854 display_bits_box (void)
856 Dlg_head *dbits_dlg;
857 new_display_codepage = display_codepage;
859 application_keypad_mode ();
860 dbits_dlg = init_disp_bits_box ();
862 run_dlg (dbits_dlg);
864 if (dbits_dlg->ret_value == B_ENTER)
866 char *errmsg;
868 display_codepage = new_display_codepage;
869 errmsg = init_translation_table (source_codepage, display_codepage);
870 if (errmsg != NULL)
872 message (D_ERROR, MSG_ERROR, "%s", errmsg);
873 g_free (errmsg);
875 #ifdef HAVE_SLANG
876 tty_display_8bit (display_codepage != 0 && display_codepage != 1);
877 #else
878 tty_display_8bit (display_codepage != 0);
879 #endif
880 use_8th_bit_as_meta = !(inpcheck->state & C_BOOL);
882 destroy_dlg (dbits_dlg);
883 repaint_screen ();
885 #endif /* HAVE_CHARSET */
887 /* --------------------------------------------------------------------------------------------- */
888 /** Show tree in a box, not on a panel */
890 char *
891 tree_box (const char *current_dir)
893 WTree *mytree;
894 Dlg_head *dlg;
895 char *val = NULL;
896 WButtonBar *bar;
898 (void) current_dir;
900 /* Create the components */
901 dlg = create_dlg (TRUE, 0, 0, LINES - 9, COLS - 20, dialog_colors,
902 tree_callback, "[Directory Tree]",
903 _("Directory tree"), DLG_CENTER | DLG_REVERSE);
905 mytree = tree_new (2, 2, dlg->lines - 6, dlg->cols - 5, FALSE);
906 add_widget (dlg, mytree);
907 add_widget (dlg, hline_new (dlg->lines - 4, 1, -1));
908 bar = buttonbar_new (TRUE);
909 add_widget (dlg, bar);
910 /* restore ButtonBar coordinates after add_widget() */
911 ((Widget *) bar)->x = 0;
912 ((Widget *) bar)->y = LINES - 1;
914 if (run_dlg (dlg) == B_ENTER)
915 val = g_strdup (tree_selected_name (mytree));
917 destroy_dlg (dlg);
918 return val;
921 /* --------------------------------------------------------------------------------------------- */
923 #ifdef ENABLE_VFS
924 void
925 configure_vfs (void)
927 char buffer2[BUF_TINY];
928 #ifdef ENABLE_VFS_FTP
929 char buffer3[BUF_TINY];
930 #endif
932 QuickWidget confvfs_widgets[] = {
933 /* 0 */ QUICK_BUTTON (30, VFSX, VFSY - 3, VFSY, N_("&Cancel"), B_CANCEL, NULL),
934 /* 1 */ QUICK_BUTTON (12, VFSX, VFSY - 3, VFSY, N_("&OK"), B_ENTER, NULL),
935 #ifdef ENABLE_VFS_FTP
936 /* 2 */ QUICK_CHECKBOX (4, VFSX, 12, VFSY, N_("Use passive mode over pro&xy"),
937 &ftpfs_use_passive_connections_over_proxy),
938 /* 3 */ QUICK_CHECKBOX (4, VFSX, 11, VFSY, N_("Use &passive mode"),
939 &ftpfs_use_passive_connections),
940 /* 4 */ QUICK_CHECKBOX (4, VFSX, 10, VFSY, N_("&Use ~/.netrc"), &ftpfs_use_netrc),
941 /* 5 */ QUICK_INPUT (4, VFSX, 9, VFSY, ftpfs_proxy_host, 48, 0, "input-ftp-proxy",
942 &ret_ftp_proxy),
943 /* 6 */ QUICK_CHECKBOX (4, VFSX, 8, VFSY, N_("&Always use ftp proxy"),
944 &ftpfs_always_use_proxy),
945 /* 7 */ QUICK_LABEL (49, VFSX, 7, VFSY, N_("sec")),
946 /* 8 */ QUICK_INPUT (38, VFSX, 7, VFSY, buffer3, 10, 0, "input-timeout",
947 &ret_directory_timeout),
948 /* 9 */ QUICK_LABEL (4, VFSX, 7, VFSY, N_("ftpfs directory cache timeout:")),
949 /* 10 */ QUICK_INPUT (4, VFSX, 6, VFSY, ftpfs_anonymous_passwd, 48, 0, "input-passwd",
950 &ret_passwd),
951 /* 11 */ QUICK_LABEL (4, VFSX, 5, VFSY, N_("ftp anonymous password:")),
952 #endif /* ENABLE_VFS_FTP */
953 /* 12 */ QUICK_LABEL (49, VFSX, 3, VFSY, N_("sec")),
954 /* 13 */ QUICK_INPUT (38, VFSX, 3, VFSY, buffer2, 10, 0, "input-timo-vfs", &ret_timeout),
955 /* 14 */ QUICK_LABEL (4, VFSX, 3, VFSY, N_("Timeout for freeing VFSs:")),
956 QUICK_END
959 QuickDialog confvfs_dlg = {
960 VFSX, VFSY, -1, -1, N_("Virtual File System Setting"),
961 "[Virtual FS]", confvfs_widgets,
962 #ifdef ENABLE_VFS_FTP
963 confvfs_callback,
964 #else
965 NULL,
966 #endif
967 FALSE
970 #ifdef ENABLE_VFS_FTP
971 g_snprintf (buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
973 if (!ftpfs_always_use_proxy)
974 confvfs_widgets[5].options = W_DISABLED;
975 #endif
977 g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
979 if (quick_dialog (&confvfs_dlg) != B_CANCEL)
981 vfs_timeout = atoi (ret_timeout);
982 g_free (ret_timeout);
984 if (vfs_timeout < 0 || vfs_timeout > 10000)
985 vfs_timeout = 10;
986 #ifdef ENABLE_VFS_FTP
987 g_free (ftpfs_anonymous_passwd);
988 ftpfs_anonymous_passwd = ret_passwd;
989 g_free (ftpfs_proxy_host);
990 ftpfs_proxy_host = ret_ftp_proxy;
991 ftpfs_directory_timeout = atoi (ret_directory_timeout);
992 g_free (ret_directory_timeout);
993 #endif
996 #undef VFSX
997 #undef VFSY
1000 #endif /* ENABLE_VFS */
1002 /* --------------------------------------------------------------------------------------------- */
1004 char *
1005 cd_dialog (void)
1007 const char *label = N_("cd");
1008 const int ylen = 5;
1009 const int xlen = 57;
1011 int len;
1013 #ifdef ENABLE_NLS
1014 label = _(label);
1015 #endif
1017 len = str_term_width1 (label);
1020 char *my_str;
1022 QuickWidget quick_widgets[] = {
1023 /* 0 */ QUICK_INPUT (4 + len, xlen, 2, ylen, "", xlen - 7 - len, 2, "input", &my_str),
1024 /* 1 */ QUICK_LABEL (3, xlen, 2, ylen, label),
1025 QUICK_END
1028 QuickDialog Quick_input = {
1029 xlen, ylen, 2, LINES - 2 - ylen, _("Quick cd"),
1030 "[Quick cd]", quick_widgets, NULL, TRUE
1033 return (quick_dialog (&Quick_input) != B_CANCEL) ? my_str : NULL;
1037 /* --------------------------------------------------------------------------------------------- */
1039 void
1040 symlink_dialog (const char *existing, const char *new, char **ret_existing, char **ret_new)
1042 QuickWidget quick_widgets[] = {
1043 /* 0 */ QUICK_BUTTON (50, 80, 6, 8, N_("&Cancel"), B_CANCEL, NULL),
1044 /* 1 */ QUICK_BUTTON (16, 80, 6, 8, N_("&OK"), B_ENTER, NULL),
1045 /* 2 */ QUICK_INPUT (4, 80, 5, 8, new, 58, 0, "input-1", ret_new),
1046 /* 3 */ QUICK_LABEL (4, 80, 4, 8, N_("Symbolic link filename:")),
1047 /* 4 */ QUICK_INPUT (4, 80, 3, 8, existing, 58, 0, "input-2", ret_existing),
1048 /* 5 */ QUICK_LABEL (4, 80, 2, 8,
1049 N_("Existing filename (filename symlink will point to):")),
1050 QUICK_END
1053 QuickDialog Quick_input = {
1054 64, 12, -1, -1, N_("Symbolic link"),
1055 "[File Menu]", quick_widgets, NULL, FALSE
1058 if (quick_dialog (&Quick_input) == B_CANCEL)
1060 *ret_new = NULL;
1061 *ret_existing = NULL;
1065 /* --------------------------------------------------------------------------------------------- */
1067 #ifdef WITH_BACKGROUND
1068 void
1069 jobs_cmd (void)
1071 register int i;
1072 int n_buttons = sizeof (job_buttons) / sizeof (job_buttons[0]);
1074 #ifdef ENABLE_NLS
1075 static int i18n_flag = 0;
1076 if (!i18n_flag)
1078 int startx = job_buttons[0].xpos;
1079 int len;
1081 for (i = 0; i < n_buttons; i++)
1083 job_buttons[i].name = _(job_buttons[i].name);
1085 len = str_term_width1 (job_buttons[i].name) + 4;
1086 JOBS_X = max (JOBS_X, startx + len + 3);
1088 job_buttons[i].xpos = startx;
1089 startx += len;
1092 /* Last button - Ok a.k.a. Cancel :) */
1093 job_buttons[n_buttons - 1].xpos =
1094 JOBS_X - str_term_width1 (job_buttons[n_buttons - 1].name) - 7;
1096 i18n_flag = 1;
1098 #endif /* ENABLE_NLS */
1100 jobs_dlg = create_dlg (TRUE, 0, 0, JOBS_Y, JOBS_X, dialog_colors, NULL,
1101 "[Background jobs]", _("Background Jobs"), DLG_CENTER | DLG_REVERSE);
1103 bg_list = listbox_new (2, 3, JOBS_Y - 9, JOBS_X - 7, FALSE, NULL);
1104 add_widget (jobs_dlg, bg_list);
1106 i = n_buttons;
1107 while (i--)
1109 add_widget (jobs_dlg, button_new (JOBS_Y - 4,
1110 job_buttons[i].xpos, job_buttons[i].value,
1111 NORMAL_BUTTON, job_buttons[i].name,
1112 job_buttons[i].callback));
1115 /* Insert all of task information in the list */
1116 jobs_fill_listbox ();
1117 run_dlg (jobs_dlg);
1119 destroy_dlg (jobs_dlg);
1121 #endif /* WITH_BACKGROUND */
1123 /* --------------------------------------------------------------------------------------------- */
1125 #ifdef ENABLE_VFS_SMB
1126 struct smb_authinfo *
1127 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain, const char *user)
1129 static int dialog_x = 44;
1130 int b0 = 3, dialog_y = 12;
1131 static const char *lc_labs[] = { N_("Domain:"), N_("Username:"), N_("Password:") };
1132 static const char *buts[] = { N_("&OK"), N_("&Cancel") };
1133 static int ilen = 30, istart = 14;
1134 static int b2 = 30;
1135 char *title;
1136 WInput *in_password;
1137 WInput *in_user;
1138 WInput *in_domain;
1139 Dlg_head *auth_dlg;
1140 struct smb_authinfo *return_value = NULL;
1142 const int input_colors[3] = {
1143 INPUT_COLOR,
1144 INPUT_UNCHANGED_COLOR,
1145 INPUT_MARK_COLOR
1148 #ifdef ENABLE_NLS
1149 static int i18n_flag = 0;
1151 if (!i18n_flag)
1153 register int i = sizeof (lc_labs) / sizeof (lc_labs[0]);
1154 int l1, maxlen = 0;
1156 while (i--)
1158 l1 = str_term_width1 (lc_labs[i] = _(lc_labs[i]));
1159 if (l1 > maxlen)
1160 maxlen = l1;
1162 i = maxlen + ilen + 7;
1163 if (i > dialog_x)
1164 dialog_x = i;
1166 for (i = sizeof (buts) / sizeof (buts[0]), l1 = 0; i--;)
1168 l1 += str_term_width1 (buts[i] = _(buts[i]));
1170 l1 += 15;
1171 if (l1 > dialog_x)
1172 dialog_x = l1;
1174 ilen = dialog_x - 7 - maxlen; /* for the case of very long buttons :) */
1175 istart = dialog_x - 3 - ilen;
1177 b2 = dialog_x - (str_term_width1 (buts[1]) + 6);
1179 i18n_flag = 1;
1182 #endif /* ENABLE_NLS */
1184 if (!domain)
1185 domain = "";
1186 if (!user)
1187 user = "";
1189 title = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
1191 auth_dlg = create_dlg (TRUE, 0, 0, dialog_y, dialog_x, dialog_colors, NULL,
1192 "[Smb Authinfo]", title, DLG_CENTER | DLG_REVERSE);
1194 g_free (title);
1196 in_user =
1197 input_new (5, istart, input_get_default_colors (), ilen, user, "auth_name",
1198 INPUT_COMPLETE_DEFAULT);
1199 add_widget (auth_dlg, in_user);
1201 in_domain =
1202 input_new (3, istart, input_get_default_colors (), ilen, domain, "auth_domain",
1203 INPUT_COMPLETE_DEFAULT);
1205 add_widget (auth_dlg, in_domain);
1206 add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON, buts[1], 0));
1207 add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON, buts[0], 0));
1209 in_password =
1210 input_new (7, istart, input_get_default_colors (), ilen, "", "auth_password",
1211 INPUT_COMPLETE_DEFAULT);
1213 in_password->completion_flags = 0;
1214 in_password->is_password = 1;
1215 add_widget (auth_dlg, in_password);
1217 add_widget (auth_dlg, label_new (7, 3, lc_labs[2]));
1218 add_widget (auth_dlg, label_new (5, 3, lc_labs[1]));
1219 add_widget (auth_dlg, label_new (3, 3, lc_labs[0]));
1221 if (run_dlg (auth_dlg) != B_CANCEL)
1222 return_value = vfs_smb_authinfo_new (host, share, in_domain->buffer, in_user->buffer,
1223 in_password->buffer);
1225 destroy_dlg (auth_dlg);
1227 return return_value;
1229 #endif /* ENABLE_VFS_SMB */
1231 /* --------------------------------------------------------------------------------------------- */