struct smb_authinfo * vfs_smb_get_authinfo (const char *host, const char *share, const char *domain, const char *user) { char *label; struct smb_authinfo *return_value = NULL; if (domain == NULL) domain = ""; if (user == NULL) user = ""; label = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share); { char *ret_domain, *ret_user, *ret_password; quick_widget_t quick_widgets[] = { /* *INDENT-OFF* */ QUICK_LABEL (label, NULL), QUICK_SEPARATOR (TRUE), QUICK_START_COLUMNS, QUICK_LABEL (N_("Domain:"), NULL), QUICK_SEPARATOR (FALSE), QUICK_LABEL (N_("Username:"******"Password:"******"auth_domain", &ret_domain, NULL, FALSE, FALSE, INPUT_COMPLETE_HOSTNAMES), QUICK_SEPARATOR (FALSE), QUICK_INPUT (user, "auth_name", &ret_user, NULL, FALSE, FALSE, INPUT_COMPLETE_USERNAMES), QUICK_SEPARATOR (FALSE), QUICK_INPUT ("", "auth_password", &ret_password, NULL, TRUE, FALSE, INPUT_COMPLETE_NONE), QUICK_STOP_COLUMNS, QUICK_BUTTONS_OK_CANCEL, QUICK_END /* *INDENT-ON* */ }; quick_dialog_t qdlg = { -1, -1, 40, N_("SMB authentication"), "[Smb Authinfo]", quick_widgets, NULL, NULL }; if (quick_dialog (&qdlg) != B_CANCEL) { return_value = vfs_smb_authinfo_new (host, share, ret_domain, ret_user, ret_password); g_free (ret_domain); g_free (ret_user); g_free (ret_password); } } g_free (label); return return_value; }
void editcmd_dialog_replace_show (WEdit * edit, const char *search_default, const char *replace_default, /*@out@ */ char **search_text, /*@out@ */ char **replace_text) { if (*search_default == '\0') search_default = INPUT_LAST_TEXT; { size_t num_of_types; gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types); int REPLACE_DLG_HEIGHT = REPLACE_DLG_MIN_HEIGHT + num_of_types - REPLACE_DLG_HEIGHT_SUPPLY; QuickWidget quick_widgets[] = { /* 0 */ QUICK_BUTTON (6, 10, 13, REPLACE_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL), /* 1 */ QUICK_BUTTON (2, 10, 13, REPLACE_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL), #ifdef HAVE_CHARSET /* 2 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 11, REPLACE_DLG_HEIGHT, N_("All charsets"), &edit->all_codepages), #endif /* 3 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 10, REPLACE_DLG_HEIGHT, N_("&Whole words"), &edit->whole_words), /* 4 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 9, REPLACE_DLG_HEIGHT, N_("In se&lection"), &edit->only_in_selection), /* 5 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 8, REPLACE_DLG_HEIGHT, N_("&Backwards"), &edit->replace_backwards), /* 6 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 7, REPLACE_DLG_HEIGHT, N_("case &Sensitive"), &edit->replace_case), /* 7 */ QUICK_RADIO (3, REPLACE_DLG_WIDTH, 7, REPLACE_DLG_HEIGHT, num_of_types, (const char **) list_of_types, (int *) &edit->search_type), /* 8 */ QUICK_LABEL (2, REPLACE_DLG_WIDTH, 4, REPLACE_DLG_HEIGHT, N_(" Enter replacement string:")), /* 9 */ QUICK_INPUT (3, REPLACE_DLG_WIDTH, 5, REPLACE_DLG_HEIGHT, replace_default, REPLACE_DLG_WIDTH - 6, 0, "replace", replace_text), /* 10 */ QUICK_LABEL (2, REPLACE_DLG_WIDTH, 2, REPLACE_DLG_HEIGHT, N_(" Enter search string:")), /* 11 */ QUICK_INPUT (3, REPLACE_DLG_WIDTH, 3, REPLACE_DLG_HEIGHT, search_default, REPLACE_DLG_WIDTH - 6, 0, MC_HISTORY_SHARED_SEARCH, search_text), QUICK_END }; QuickDialog Quick_input = { REPLACE_DLG_WIDTH, REPLACE_DLG_HEIGHT, -1, -1, N_(" Replace "), "[Input Line Keys]", quick_widgets, FALSE }; if (quick_dialog (&Quick_input) != B_CANCEL) { edit->replace_mode = 0; } else { *replace_text = NULL; *search_text = NULL; } g_strfreev (list_of_types); } }
char * cd_dialog (void) { const char *label = N_("cd"); const int ylen = 5; const int xlen = 57; int len; #ifdef ENABLE_NLS label = _(label); #endif len = str_term_width1 (label); { char *my_str; QuickWidget quick_widgets[] = { /* 0 */ QUICK_INPUT (4 + len, xlen, 2, ylen, "", xlen - 7 - len, 2, "input", &my_str), /* 1 */ QUICK_LABEL (3, xlen, 2, ylen, label), QUICK_END }; QuickDialog Quick_input = { xlen, ylen, 2, LINES - 2 - ylen, _("Quick cd"), "[Quick cd]", quick_widgets, NULL, TRUE }; return (quick_dialog (&Quick_input) != B_CANCEL) ? my_str : NULL; } }
gboolean mcview_dialog_goto (WView * view, off_t * offset) { typedef enum { MC_VIEW_GOTO_LINENUM = 0, MC_VIEW_GOTO_PERCENT = 1, MC_VIEW_GOTO_OFFSET_DEC = 2, MC_VIEW_GOTO_OFFSET_HEX = 3 } mcview_goto_type_t; const char *mc_view_goto_str[] = { N_("&Line number"), N_("Pe&rcents"), N_("&Decimal offset"), N_("He&xadecimal offset") }; static mcview_goto_type_t current_goto_type = MC_VIEW_GOTO_LINENUM; size_t num_of_types; char *exp = NULL; int qd_result; gboolean res; num_of_types = G_N_ELEMENTS (mc_view_goto_str); #ifdef ENABLE_NLS { size_t i; for (i = 0; i < num_of_types; i++) mc_view_goto_str[i] = _(mc_view_goto_str[i]); } #endif { quick_widget_t quick_widgets[] = { /* *INDENT-OFF* */ QUICK_INPUT (INPUT_LAST_TEXT, MC_HISTORY_VIEW_GOTO, &exp, NULL, FALSE, FALSE, INPUT_COMPLETE_NONE), QUICK_RADIO (num_of_types, (const char **) mc_view_goto_str, (int *) ¤t_goto_type, NULL), QUICK_BUTTONS_OK_CANCEL, QUICK_END /* *INDENT-ON* */ }; quick_dialog_t qdlg = { -1, -1, 40, N_("Goto"), "[Input Line Keys]", quick_widgets, NULL, NULL }; /* run dialog */ qd_result = quick_dialog (&qdlg); } *offset = -1; /* check input line value */ res = (qd_result != B_CANCEL && exp != NULL && exp[0] != '\0'); if (res) { int base = (current_goto_type == MC_VIEW_GOTO_OFFSET_HEX) ? 16 : 10; off_t addr; char *error; addr = (off_t) g_ascii_strtoll (exp, &error, base); if ((*error == '\0') && (addr >= 0)) { switch (current_goto_type) { case MC_VIEW_GOTO_LINENUM: /* Line number entered by user is 1-based. */ if (addr > 0) addr--; mcview_coord_to_offset (view, offset, addr, 0); *offset = mcview_bol (view, *offset, 0); break; case MC_VIEW_GOTO_PERCENT: if (addr > 100) addr = 100; /* read all data from pipe to get real size */ if (view->growbuf_in_use) mcview_growbuf_read_all_data (view); *offset = addr * mcview_get_filesize (view) / 100; if (!view->mode_flags.hex) *offset = mcview_bol (view, *offset, 0); break; case MC_VIEW_GOTO_OFFSET_DEC: case MC_VIEW_GOTO_OFFSET_HEX: if (!view->mode_flags.hex) { if (view->growbuf_in_use) mcview_growbuf_read_until (view, addr); *offset = mcview_bol (view, addr, 0); } else { /* read all data from pipe to get real size */ if (view->growbuf_in_use) mcview_growbuf_read_all_data (view); *offset = addr; addr = mcview_get_filesize (view); if (*offset > addr) *offset = addr; } break; default: *offset = 0; break; } } } g_free (exp); return res; }
char * file_mask_dialog (FileOpContext * ctx, FileOperation operation, gboolean only_one, const char *format, const void *text, const char *def_text, gboolean * do_bg) { const size_t FMDY = 13; const size_t FMDX = 68; size_t fmd_xlen; /* buttons */ const size_t gap = 1; size_t b0_len, b2_len; size_t b1_len = 0; int source_easy_patterns = easy_patterns; size_t i, len; char fmd_buf[BUF_MEDIUM]; char *source_mask, *orig_mask, *dest_dir, *tmp; char *def_text_secure; int val; QuickWidget fmd_widgets[] = { /* 0 */ QUICK_BUTTON (42, 64, 10, FMDY, N_("&Cancel"), B_CANCEL, NULL), #ifdef WITH_BACKGROUND /* 1 */ QUICK_BUTTON (25, 64, 10, FMDY, N_("&Background"), B_USER, NULL), #define OFFSET 0 #else #define OFFSET 1 #endif /* WITH_BACKGROUND */ /* 2 - OFFSET */ QUICK_BUTTON (14, FMDX, 10, FMDY, N_("&OK"), B_ENTER, NULL), /* 3 - OFFSET */ QUICK_CHECKBOX (42, FMDX, 8, FMDY, N_("&Stable Symlinks"), &ctx->stable_symlinks), /* 4 - OFFSET */ QUICK_CHECKBOX (31, FMDX, 7, FMDY, N_("Di&ve into subdir if exists"), &ctx->dive_into_subdirs), /* 5 - OFFSET */ QUICK_CHECKBOX (3, FMDX, 8, FMDY, N_("Preserve &attributes"), &ctx->op_preserve), /* 6 - OFFSET */ QUICK_CHECKBOX (3, FMDX, 7, FMDY, N_("Follow &links"), &ctx->follow_links), /* 7 - OFFSET */ QUICK_INPUT (3, FMDX, 6, FMDY, "", 58, 0, "input2", &dest_dir), /* 8 - OFFSET */ QUICK_LABEL (3, FMDX, 5, FMDY, N_("to:")), /* 9 - OFFSET */ QUICK_CHECKBOX (37, FMDX, 4, FMDY, N_("&Using shell patterns"), &source_easy_patterns), /* 10 - OFFSET */ QUICK_INPUT (3, FMDX, 3, FMDY, easy_patterns ? "*" : "^(.*)$", 58, 0, "input-def", &source_mask), /* 11 - OFFSET */ QUICK_LABEL (3, FMDX, 2, FMDY, fmd_buf), QUICK_END }; g_return_val_if_fail (ctx != NULL, NULL); #ifdef ENABLE_NLS /* buttons */ for (i = 0; i <= 2 - OFFSET; i++) fmd_widgets[i].u.button.text = _(fmd_widgets[i].u.button.text); /* checkboxes */ for (i = 3 - OFFSET; i <= 9 - OFFSET; i++) if (i != 7 - OFFSET) fmd_widgets[i].u.checkbox.text = _(fmd_widgets[i].u.checkbox.text); #endif /* !ENABLE_NLS */ fmd_xlen = max (FMDX, (size_t) COLS * 2 / 3); len = str_term_width1 (fmd_widgets[6 - OFFSET].u.checkbox.text) + str_term_width1 (fmd_widgets[4 - OFFSET].u.checkbox.text) + 15; fmd_xlen = max (fmd_xlen, len); len = str_term_width1 (fmd_widgets[5 - OFFSET].u.checkbox.text) + str_term_width1 (fmd_widgets[3 - OFFSET].u.checkbox.text) + 15; fmd_xlen = max (fmd_xlen, len); /* buttons */ b2_len = str_term_width1 (fmd_widgets[2 - OFFSET].u.button.text) + 6 + gap; /* OK */ #ifdef WITH_BACKGROUND b1_len = str_term_width1 (fmd_widgets[1].u.button.text) + 4 + gap; /* Background */ #endif b0_len = str_term_width1 (fmd_widgets[0].u.button.text) + 4; /* Cancel */ len = b0_len + b1_len + b2_len; fmd_xlen = min (max (fmd_xlen, len + 6), (size_t) COLS); if (only_one) { int flen; flen = str_term_width1 (format); i = fmd_xlen - flen - 4; /* FIXME */ g_snprintf (fmd_buf, sizeof (fmd_buf), format, str_trunc ((const char *) text, i)); } else { g_snprintf (fmd_buf, sizeof (fmd_buf), format, *(const int *) text); fmd_xlen = max (fmd_xlen, (size_t) str_term_width1 (fmd_buf) + 6); } for (i = sizeof (fmd_widgets) / sizeof (fmd_widgets[0]); i > 0;) fmd_widgets[--i].x_divisions = fmd_xlen; i = (fmd_xlen - len) / 2; /* OK button */ fmd_widgets[2 - OFFSET].relative_x = i; i += b2_len; #ifdef WITH_BACKGROUND /* Background button */ fmd_widgets[1].relative_x = i; i += b1_len; #endif /* Cancel button */ fmd_widgets[0].relative_x = i; #define chkbox_xpos(i) \ fmd_widgets [i].relative_x = fmd_xlen - str_term_width1 (fmd_widgets [i].u.checkbox.text) - 6 chkbox_xpos (3 - OFFSET); chkbox_xpos (4 - OFFSET); chkbox_xpos (9 - OFFSET); #undef chkbox_xpos /* inputs */ fmd_widgets[7 - OFFSET].u.input.len = fmd_widgets[10 - OFFSET].u.input.len = fmd_xlen - 6; /* unselect checkbox if target filesystem don't support attributes */ ctx->op_preserve = filegui__check_attrs_on_fs (def_text); /* filter out a possible password from def_text */ tmp = strip_password (g_strdup (def_text), 1); if (source_easy_patterns) def_text_secure = strutils_glob_escape (tmp); else def_text_secure = strutils_regex_escape (tmp); g_free (tmp); /* destination */ fmd_widgets[7 - OFFSET].u.input.text = def_text_secure; ctx->stable_symlinks = FALSE; *do_bg = FALSE; { struct stat buf; QuickDialog Quick_input = { fmd_xlen, FMDY, -1, -1, op_names[operation], "[Mask Copy/Rename]", fmd_widgets, NULL, TRUE }; ask_file_mask: val = quick_dialog_skip (&Quick_input, 4); if (val == B_CANCEL) { g_free (def_text_secure); return NULL; } if (ctx->follow_links) ctx->stat_func = mc_stat; else ctx->stat_func = mc_lstat; if (ctx->op_preserve) { ctx->preserve = TRUE; ctx->umask_kill = 0777777; ctx->preserve_uidgid = (geteuid () == 0); } else { int i2; ctx->preserve = ctx->preserve_uidgid = FALSE; i2 = umask (0); umask (i2); ctx->umask_kill = i2 ^ 0777777; } if ((dest_dir == NULL) || (*dest_dir == '\0')) { g_free (def_text_secure); g_free (source_mask); return dest_dir; } ctx->search_handle = mc_search_new (source_mask, -1); if (ctx->search_handle == NULL) { message (D_ERROR, MSG_ERROR, _("Invalid source pattern `%s'"), source_mask); g_free (dest_dir); g_free (source_mask); goto ask_file_mask; } g_free (def_text_secure); g_free (source_mask); ctx->search_handle->is_case_sensitive = TRUE; if (source_easy_patterns) ctx->search_handle->search_type = MC_SEARCH_T_GLOB; else ctx->search_handle->search_type = MC_SEARCH_T_REGEX; tmp = dest_dir; dest_dir = tilde_expand (tmp); g_free (tmp); ctx->dest_mask = strrchr (dest_dir, PATH_SEP); if (ctx->dest_mask == NULL) ctx->dest_mask = dest_dir; else ctx->dest_mask++; orig_mask = ctx->dest_mask; if (!*ctx->dest_mask || (!ctx->dive_into_subdirs && !is_wildcarded (ctx->dest_mask) && (!only_one || (!mc_stat (dest_dir, &buf) && S_ISDIR (buf.st_mode)))) || (ctx->dive_into_subdirs && ((!only_one && !is_wildcarded (ctx->dest_mask)) || (only_one && !mc_stat (dest_dir, &buf) && S_ISDIR (buf.st_mode))))) ctx->dest_mask = g_strdup ("\\0"); else { ctx->dest_mask = g_strdup (ctx->dest_mask); *orig_mask = '\0'; } if (!*dest_dir) { g_free (dest_dir); dest_dir = g_strdup ("./"); } if (val == B_USER) *do_bg = TRUE; } return dest_dir; }
void configure_vfs (void) { char buffer2[BUF_TINY]; #ifdef ENABLE_VFS_FTP char buffer3[BUF_TINY]; #endif QuickWidget confvfs_widgets[] = { /* 0 */ QUICK_BUTTON (30, VFSX, VFSY - 3, VFSY, N_("&Cancel"), B_CANCEL, NULL), /* 1 */ QUICK_BUTTON (12, VFSX, VFSY - 3, VFSY, N_("&OK"), B_ENTER, NULL), #ifdef ENABLE_VFS_FTP /* 2 */ QUICK_CHECKBOX (4, VFSX, 12, VFSY, N_("Use passive mode over pro&xy"), &ftpfs_use_passive_connections_over_proxy), /* 3 */ QUICK_CHECKBOX (4, VFSX, 11, VFSY, N_("Use &passive mode"), &ftpfs_use_passive_connections), /* 4 */ QUICK_CHECKBOX (4, VFSX, 10, VFSY, N_("&Use ~/.netrc"), &ftpfs_use_netrc), /* 5 */ QUICK_INPUT (4, VFSX, 9, VFSY, ftpfs_proxy_host, 48, 0, "input-ftp-proxy", &ret_ftp_proxy), /* 6 */ QUICK_CHECKBOX (4, VFSX, 8, VFSY, N_("&Always use ftp proxy"), &ftpfs_always_use_proxy), /* 7 */ QUICK_LABEL (49, VFSX, 7, VFSY, N_("sec")), /* 8 */ QUICK_INPUT (38, VFSX, 7, VFSY, buffer3, 10, 0, "input-timeout", &ret_directory_timeout), /* 9 */ QUICK_LABEL (4, VFSX, 7, VFSY, N_("ftpfs directory cache timeout:")), /* 10 */ QUICK_INPUT (4, VFSX, 6, VFSY, ftpfs_anonymous_passwd, 48, 0, "input-passwd", &ret_passwd), /* 11 */ QUICK_LABEL (4, VFSX, 5, VFSY, N_("ftp anonymous password:"******"sec")), /* 13 */ QUICK_INPUT (38, VFSX, 3, VFSY, buffer2, 10, 0, "input-timo-vfs", &ret_timeout), /* 14 */ QUICK_LABEL (4, VFSX, 3, VFSY, N_("Timeout for freeing VFSs:")), QUICK_END }; QuickDialog confvfs_dlg = { VFSX, VFSY, -1, -1, N_("Virtual File System Setting"), "[Virtual FS]", confvfs_widgets, #ifdef ENABLE_VFS_FTP confvfs_callback, #else NULL, #endif FALSE }; #ifdef ENABLE_VFS_FTP g_snprintf (buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout); if (!ftpfs_always_use_proxy) confvfs_widgets[5].options = W_DISABLED; #endif g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout); if (quick_dialog (&confvfs_dlg) != B_CANCEL) { vfs_timeout = atoi (ret_timeout); g_free (ret_timeout); if (vfs_timeout < 0 || vfs_timeout > 10000) vfs_timeout = 10; #ifdef ENABLE_VFS_FTP g_free (ftpfs_anonymous_passwd); ftpfs_anonymous_passwd = ret_passwd; g_free (ftpfs_proxy_host); ftpfs_proxy_host = ret_ftp_proxy; ftpfs_directory_timeout = atoi (ret_directory_timeout); g_free (ret_directory_timeout); #endif } #undef VFSX #undef VFSY }
/** * Show dialog, not background safe. * * If the arguments "header" and "text" should be translated, * that MUST be done by the caller of fg_input_dialog_help(). * * The argument "history_name" holds the name of a section * in the history file. Data entered in the input field of * the dialog box will be stored there. * */ static char * fg_input_dialog_help (const char *header, const char *text, const char *help, const char *history_name, const char *def_text, gboolean strip_password) { char *my_str; int flags = (strip_password) ? 4 : 0; QuickWidget quick_widgets[] = { /* 0 */ QUICK_BUTTON (6, 64, 1, 0, N_("&Cancel"), B_CANCEL, NULL), /* 1 */ QUICK_BUTTON (3, 64, 1, 0, N_("&OK"), B_ENTER, NULL), /* 2 */ QUICK_INPUT (3, 64, 0, 0, def_text, 58, flags, NULL, &my_str), /* 3 */ QUICK_LABEL (3, 64, 2, 0, ""), QUICK_END }; int b0_len, b1_len, b_len, gap; char histname[64] = "inp|"; int lines, cols; int len; int i; char *p_text; int ret; /* buttons */ #ifdef ENABLE_NLS quick_widgets[0].u.button.text = _(quick_widgets[0].u.button.text); quick_widgets[1].u.button.text = _(quick_widgets[1].u.button.text); #endif /* ENABLE_NLS */ b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3; b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 5; /* default button */ b_len = b0_len + b1_len + 2; /* including gap */ /* input line */ if (history_name != NULL && *history_name != '\0') { g_strlcpy (histname + 3, history_name, sizeof (histname) - 3); quick_widgets[2].u.input.histname = histname; } /* The special value of def_text is used to identify password boxes and hide characters with "*". Don't save passwords in history! */ if (def_text == INPUT_PASSWORD) { quick_widgets[2].u.input.flags = 1; histname[3] = '\0'; quick_widgets[2].u.input.text = ""; } /* text */ p_text = g_strstrip (g_strdup (text)); str_msg_term_size (p_text, &lines, &cols); quick_widgets[3].u.label.text = p_text; /* dialog width */ len = str_term_width1 (header); len = max (max (len, cols) + 4, 64); len = min (max (len, b_len + 6), COLS); /* button locations */ gap = (len - 8 - b_len) / 3; quick_widgets[1].relative_x = 3 + gap; quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + gap + 2; { QuickDialog Quick_input = { len, lines + 6, -1, -1, header, help, quick_widgets, NULL, TRUE }; for (i = 0; i < 4; i++) { quick_widgets[i].x_divisions = Quick_input.xlen; quick_widgets[i].y_divisions = Quick_input.ylen; } for (i = 0; i < 3; i++) quick_widgets[i].relative_y += 2 + lines; /* input line length */ quick_widgets[2].u.input.len = Quick_input.xlen - 6; ret = quick_dialog (&Quick_input); } g_free (p_text); return (ret != B_CANCEL) ? my_str : NULL; }
gboolean mcview_dialog_search (mcview_t * view) { int SEARCH_DLG_MIN_HEIGHT = 12; int SEARCH_DLG_HEIGHT_SUPPLY = 3; int SEARCH_DLG_WIDTH = 58; char *exp = NULL; int qd_result; size_t num_of_types; gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types); int SEARCH_DLG_HEIGHT = SEARCH_DLG_MIN_HEIGHT + num_of_types - SEARCH_DLG_HEIGHT_SUPPLY; QuickWidget quick_widgets[] = { QUICK_BUTTON (6, 10, SEARCH_DLG_HEIGHT - 3, SEARCH_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL), QUICK_BUTTON (2, 10, SEARCH_DLG_HEIGHT - 3, SEARCH_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL), #ifdef HAVE_CHARSET QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 8, SEARCH_DLG_HEIGHT, N_("&All charsets"), &mcview_search_options.all_codepages), #endif QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 7, SEARCH_DLG_HEIGHT, N_("&Whole words"), &mcview_search_options.whole_words), QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT, N_("&Backwards"), &mcview_search_options.backwards), QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, N_("Cas&e sensitive"), &mcview_search_options.case_sens), QUICK_RADIO (3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, num_of_types, (const char **) list_of_types, (int *) &mcview_search_options.type), QUICK_INPUT (3, SEARCH_DLG_WIDTH, 3, SEARCH_DLG_HEIGHT, INPUT_LAST_TEXT, SEARCH_DLG_WIDTH - 6, 0, MC_HISTORY_SHARED_SEARCH, &exp), QUICK_LABEL (3, SEARCH_DLG_WIDTH, 2, SEARCH_DLG_HEIGHT, N_("Enter search string:")), QUICK_END }; QuickDialog Quick_input = { SEARCH_DLG_WIDTH, SEARCH_DLG_HEIGHT, -1, -1, N_("Search"), "[Input Line Keys]", quick_widgets, NULL, NULL, FALSE }; qd_result = quick_dialog (&Quick_input); g_strfreev (list_of_types); if ((qd_result == B_CANCEL) || (exp == NULL) || (exp[0] == '\0')) { g_free (exp); return FALSE; } #ifdef HAVE_CHARSET { GString *tmp = str_convert_to_input (exp); if (tmp) { g_free (exp); exp = g_string_free (tmp, FALSE); } } #endif g_free (view->last_search_string); view->last_search_string = exp; mcview_nroff_seq_free (&view->search_nroff_seq); mc_search_free (view->search); view->search = mc_search_new (view->last_search_string, -1); view->search_nroff_seq = mcview_nroff_seq_new (view); if (view->search != NULL) { view->search->search_type = mcview_search_options.type; view->search->is_all_charsets = mcview_search_options.all_codepages; view->search->is_case_sensitive = mcview_search_options.case_sens; view->search->whole_words = mcview_search_options.whole_words; view->search->search_fn = mcview_search_cmd_callback; view->search->update_fn = mcview_search_update_cmd_callback; } return (view->search != NULL); }
gboolean mcview_dialog_goto (mcview_t * view, off_t * offset) { typedef enum { MC_VIEW_GOTO_LINENUM = 0, MC_VIEW_GOTO_PERCENT = 1, MC_VIEW_GOTO_OFFSET_DEC = 2, MC_VIEW_GOTO_OFFSET_HEX = 3 } mcview_goto_type_t; const char *mc_view_goto_str[] = { N_("&Line number (decimal)"), N_("Pe&rcents"), N_("&Decimal offset"), N_("He&xadecimal offset") }; const int goto_dlg_height = 12; int goto_dlg_width = 40; static mcview_goto_type_t current_goto_type = MC_VIEW_GOTO_LINENUM; size_t i; size_t num_of_types = sizeof (mc_view_goto_str) / sizeof (mc_view_goto_str[0]); char *exp = NULL; int qd_result; gboolean res = FALSE; QuickWidget quick_widgets[] = { QUICK_BUTTON (6, 10, goto_dlg_height - 3, goto_dlg_height, N_("&Cancel"), B_CANCEL, NULL), QUICK_BUTTON (2, 10, goto_dlg_height - 3, goto_dlg_height, N_("&OK"), B_ENTER, NULL), QUICK_RADIO (3, goto_dlg_width, 4, goto_dlg_height, num_of_types, (const char **) mc_view_goto_str, (int *) ¤t_goto_type), QUICK_INPUT (3, goto_dlg_width, 2, goto_dlg_height, INPUT_LAST_TEXT, goto_dlg_width - 6, 0, MC_HISTORY_VIEW_GOTO, &exp), QUICK_END }; QuickDialog Quick_input = { goto_dlg_width, goto_dlg_height, -1, -1, N_("Goto"), "[Input Line Keys]", quick_widgets, NULL, NULL, FALSE }; #ifdef ENABLE_NLS for (i = 0; i < num_of_types; i++) mc_view_goto_str[i] = _(mc_view_goto_str[i]); quick_widgets[0].u.button.text = _(quick_widgets[0].u.button.text); quick_widgets[1].u.button.text = _(quick_widgets[1].u.button.text); #endif /* calculate widget coordinates */ { int b0_len, b1_len, len; const int button_gap = 2; /* preliminary dialog width */ goto_dlg_width = max (goto_dlg_width, str_term_width1 (Quick_input.title) + 4); /* length of radiobuttons */ for (i = 0; i < num_of_types; i++) goto_dlg_width = max (goto_dlg_width, str_term_width1 (mc_view_goto_str[i]) + 10); /* length of buttons */ b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3; b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 5; /* default button */ len = b0_len + b1_len + button_gap * 2; /* dialog width */ Quick_input.xlen = max (goto_dlg_width, len + 6); /* correct widget coordinates */ for (i = sizeof (quick_widgets) / sizeof (quick_widgets[0]); i > 0; i--) quick_widgets[i - 1].x_divisions = Quick_input.xlen; /* input length */ quick_widgets[3].u.input.len = Quick_input.xlen - 6; /* button positions */ quick_widgets[1].relative_x = Quick_input.xlen / 2 - len / 2; quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + button_gap; } /* run dialog */ qd_result = quick_dialog (&Quick_input); *offset = -1; /* check input line value */ if ((qd_result != B_CANCEL) && (exp != NULL) && (exp[0] != '\0')) { int base = (current_goto_type == MC_VIEW_GOTO_OFFSET_HEX) ? 16 : 10; off_t addr; char *error; res = TRUE; addr = strtoll (exp, &error, base); if ((*error == '\0') && (addr >= 0)) { switch (current_goto_type) { case MC_VIEW_GOTO_LINENUM: mcview_coord_to_offset (view, offset, addr, 0); *offset = mcview_bol (view, *offset, 0); break; case MC_VIEW_GOTO_PERCENT: if (addr > 100) addr = 100; *offset = addr * mcview_get_filesize (view) / 100; if (!view->hex_mode) *offset = mcview_bol (view, *offset, 0); break; case MC_VIEW_GOTO_OFFSET_DEC: case MC_VIEW_GOTO_OFFSET_HEX: *offset = addr; if (!view->hex_mode) *offset = mcview_bol (view, *offset, 0); else { addr = mcview_get_filesize (view); if (*offset > addr) *offset = addr; } break; default: *offset = 0; break; } } } g_free (exp); return res; }
/* return list type */ int panel_listing_box (WPanel * panel, int num, char **userp, char **minip, int *use_msformat, int *brief_cols) { int result = -1; char *section = NULL; if (panel == NULL) { const char *p; size_t i; p = get_nth_panel_name (num); panel = g_new (WPanel, 1); panel->list_type = list_full; panel->user_format = g_strdup (DEFAULT_USER_FORMAT); panel->user_mini_status = 0; for (i = 0; i < LIST_TYPES; i++) panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT); section = g_strconcat ("Temporal:", p, (char *) NULL); if (!mc_config_has_group (mc_main_config, section)) { g_free (section); section = g_strdup (p); } panel_load_setup (panel, section); g_free (section); } { int mini_user_status; char panel_brief_cols_in[BUF_TINY]; char *panel_brief_cols_out = NULL; char *panel_user_format = NULL; char *mini_user_format = NULL; const char *cp; /* Controls whether the array strings have been translated */ const char *list_types[LIST_TYPES] = { N_("&Full file list"), N_("&Brief file list:"), N_("&Long file list"), N_("&User defined:") }; quick_widget_t quick_widgets[] = { /* *INDENT-OFF* */ QUICK_START_COLUMNS, QUICK_RADIO (LIST_TYPES, list_types, &result, &panel_listing_types_id), QUICK_NEXT_COLUMN, QUICK_SEPARATOR (FALSE), QUICK_LABELED_INPUT (_ ("columns"), input_label_right, panel_brief_cols_in, "panel-brief-cols-input", &panel_brief_cols_out, &panel_brief_cols_id, FALSE, FALSE, INPUT_COMPLETE_NONE), QUICK_STOP_COLUMNS, QUICK_INPUT (panel->user_format, "user-fmt-input", &panel_user_format, &panel_user_format_id, FALSE, FALSE, INPUT_COMPLETE_NONE), QUICK_SEPARATOR (TRUE), QUICK_CHECKBOX (N_("User &mini status"), &mini_user_status, &mini_user_status_id), QUICK_INPUT (panel->user_status_format[panel->list_type], "mini_input", &mini_user_format, &mini_user_format_id, FALSE, FALSE, INPUT_COMPLETE_NONE), QUICK_BUTTONS_OK_CANCEL, QUICK_END /* *INDENT-ON* */ }; quick_dialog_t qdlg = { -1, -1, 48, N_("Listing mode"), "[Listing Mode...]", quick_widgets, panel_listing_callback, NULL }; /* get hotkey of user-defined format string */ cp = strchr (_(list_types[panel_listing_user_idx]), '&'); if (cp != NULL && *++cp != '\0') listing_user_hotkey = g_ascii_tolower (*cp); mini_user_status = panel->user_mini_status; result = panel->list_type; status_format = panel->user_status_format; g_snprintf (panel_brief_cols_in, sizeof (panel_brief_cols_in), "%d", panel->brief_cols); if ((int) panel->list_type != panel_listing_brief_idx) quick_widgets[4].options = W_DISABLED; if ((int) panel->list_type != panel_listing_user_idx) quick_widgets[6].options = W_DISABLED; if (!mini_user_status) quick_widgets[9].options = W_DISABLED; if (quick_dialog (&qdlg) == B_CANCEL) result = -1; else { int cols; char *error = NULL; *userp = panel_user_format; *minip = mini_user_format; *use_msformat = mini_user_status; cols = strtol (panel_brief_cols_out, &error, 10); if (*error == '\0') *brief_cols = cols; else *brief_cols = panel->brief_cols; g_free (panel_brief_cols_out); } } if (section != NULL) { int i; g_free (panel->user_format); for (i = 0; i < LIST_TYPES; i++) g_free (panel->user_status_format[i]); g_free (panel); } return result; }
void configure_vfs (void) { char buffer2[BUF_TINY]; #ifdef ENABLE_VFS_FTP char buffer3[BUF_TINY]; g_snprintf (buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout); #endif g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout); { char *ret_timeout; #ifdef ENABLE_VFS_FTP char *ret_passwd; char *ret_ftp_proxy; char *ret_directory_timeout; #endif /* ENABLE_VFS_FTP */ quick_widget_t quick_widgets[] = { /* *INDENT-OFF* */ QUICK_LABELED_INPUT (N_("Timeout for freeing VFSs (sec):"), input_label_left, buffer2, "input-timo-vfs", &ret_timeout, NULL, FALSE, FALSE, INPUT_COMPLETE_NONE), #ifdef ENABLE_VFS_FTP QUICK_SEPARATOR (TRUE), QUICK_LABELED_INPUT (N_("FTP anonymous password:"******"input-passwd", &ret_passwd, NULL, FALSE, FALSE, INPUT_COMPLETE_NONE), QUICK_LABELED_INPUT (N_("FTP directory cache timeout (sec):"), input_label_left, buffer3, "input-timeout", &ret_directory_timeout, NULL, FALSE, FALSE, INPUT_COMPLETE_NONE), QUICK_CHECKBOX (N_("&Always use ftp proxy:"), &ftpfs_always_use_proxy, &ftpfs_always_use_proxy_id), QUICK_INPUT (ftpfs_proxy_host, "input-ftp-proxy", &ret_ftp_proxy, &ftpfs_proxy_host_id, FALSE, FALSE, INPUT_COMPLETE_HOSTNAMES), QUICK_CHECKBOX (N_("&Use ~/.netrc"), &ftpfs_use_netrc, NULL), QUICK_CHECKBOX (N_("Use &passive mode"), &ftpfs_use_passive_connections, NULL), QUICK_CHECKBOX (N_("Use passive mode over pro&xy"), &ftpfs_use_passive_connections_over_proxy, NULL), #endif /* ENABLE_VFS_FTP */ QUICK_BUTTONS_OK_CANCEL, QUICK_END /* *INDENT-ON* */ }; quick_dialog_t qdlg = { -1, -1, 56, N_("Virtual File System Setting"), "[Virtual FS]", quick_widgets, #ifdef ENABLE_VFS_FTP confvfs_callback, #else NULL, #endif NULL, }; #ifdef ENABLE_VFS_FTP if (!ftpfs_always_use_proxy) quick_widgets[5].options = W_DISABLED; #endif if (quick_dialog (&qdlg) != B_CANCEL) { /* cppcheck-suppress uninitvar */ vfs_timeout = atoi (ret_timeout); g_free (ret_timeout); if (vfs_timeout < 0 || vfs_timeout > 10000) vfs_timeout = 10; #ifdef ENABLE_VFS_FTP g_free (ftpfs_anonymous_passwd); /* cppcheck-suppress uninitvar */ ftpfs_anonymous_passwd = ret_passwd; g_free (ftpfs_proxy_host); /* cppcheck-suppress uninitvar */ ftpfs_proxy_host = ret_ftp_proxy; /* cppcheck-suppress uninitvar */ ftpfs_directory_timeout = atoi (ret_directory_timeout); g_free (ret_directory_timeout); #endif } } }
void configure_box (void) { int dlg_width = 60; int dlg_height = 21; char time_out[BUF_TINY] = ""; char *time_out_new; const char *pause_options[] = { N_("&Never"), N_("On dum&b terminals"), N_("Alwa&ys") }; int pause_options_num = G_N_ELEMENTS (pause_options); QuickWidget quick_widgets[] = { /* buttons */ QUICK_BUTTON (38, dlg_width, dlg_height - 3, dlg_height, N_("&Cancel"), B_CANCEL, NULL), QUICK_BUTTON (14, dlg_width, dlg_height - 3, dlg_height, N_("&OK"), B_ENTER, NULL), /* other options */ QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 12, dlg_height, N_("A&uto save setup"), &auto_save_setup), QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 11, dlg_height, N_("Sa&fe delete"), &safe_delete), QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 10, dlg_height, N_("Cd follows lin&ks"), &mc_global.vfs.cd_symlinks), QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 9, dlg_height, N_("Rotating d&ash"), &nice_rotating_dash), QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 8, dlg_height, N_("Co&mplete: show all"), &mc_global.widget.show_all_if_ambiguous), QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 7, dlg_height, N_("Shell &patterns"), &easy_patterns), QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 6, dlg_height, N_("&Drop down menus"), &drop_menus), QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 5, dlg_height, N_("Auto m&enus"), &auto_menu), QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 4, dlg_height, N_("Use internal vie&w"), &use_internal_view), QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 3, dlg_height, N_("Use internal edi&t"), &use_internal_edit), QUICK_GROUPBOX (dlg_width / 2, dlg_width, 2, dlg_height, dlg_width / 2 - 4, 16, N_("Other options")), /* pause options */ QUICK_RADIO (5, dlg_width, 14, dlg_height, pause_options_num, pause_options, &pause_after_run), QUICK_GROUPBOX (3, dlg_width, 13, dlg_height, dlg_width / 2 - 4, 5, N_("Pause after run")), /* Esc key mode */ QUICK_INPUT (10, dlg_width, 11, dlg_height, (const char *) time_out, 8, 0, MC_HISTORY_ESC_TIMEOUT, &time_out_new), QUICK_LABEL (5, dlg_width, 11, dlg_height, N_("Timeout:")), QUICK_CHECKBOX (5, dlg_width, 10, dlg_height, N_("S&ingle press"), &old_esc_mode), QUICK_GROUPBOX (3, dlg_width, 9, dlg_height, dlg_width / 2 - 4, 4, N_("Esc key mode")), /* file operation options */ QUICK_CHECKBOX (5, dlg_width, 7, dlg_height, N_("Preallocate &space"), &mc_global.vfs.preallocate_space), QUICK_CHECKBOX (5, dlg_width, 6, dlg_height, N_("Mkdi&r autoname"), &auto_fill_mkdir_name), QUICK_CHECKBOX (5, dlg_width, 5, dlg_height, N_("Classic pro&gressbar"), &classic_progressbar), QUICK_CHECKBOX (5, dlg_width, 4, dlg_height, N_("Compute tota&ls"), &file_op_compute_totals), QUICK_CHECKBOX (5, dlg_width, 3, dlg_height, N_("&Verbose operation"), &verbose), QUICK_GROUPBOX (3, dlg_width, 2, dlg_height, dlg_width / 2 - 4, 7, N_("File operation options")), QUICK_END }; const size_t qw_num = G_N_ELEMENTS (quick_widgets) - 1; QuickDialog Quick_input = { dlg_width, dlg_height, -1, -1, N_("Configure options"), "[Configuration]", quick_widgets, configure_callback, TRUE }; int b0_len, b1_len; int b_len, c_len, g_len, l_len; size_t i; #ifdef ENABLE_NLS for (i = 0; i < qw_num; i++) switch (i) { case 0: case 1: /* buttons */ quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text); break; case 12: case 14: case 18: case 24: /* groupboxes */ quick_widgets[i].u.groupbox.title = _(quick_widgets[i].u.groupbox.title); break; case 13: { /* radio button */ size_t j; for (j = 0; j < (size_t) pause_options_num; j++) pause_options[j] = _(pause_options[j]); } break; case 15: /* input line */ break; case 16: /* label */ quick_widgets[i].u.label.text = _(quick_widgets[i].u.label.text); break; default: /* checkboxes */ quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text); break; } Quick_input.title = _(Quick_input.title); #endif /* ENABLE_NLS */ /* calculate widget and dialog widths */ /* dialog title */ dlg_width = max (dlg_width, str_term_width1 (Quick_input.title) + 4); /* buttons */ b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3; b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 5; b_len = b0_len + b1_len + 1; /* checkboxes within groupboxes */ c_len = 0; for (i = 2; i < 24; i++) if ((i < 12) || (i == 17) || (i > 18)) c_len = max (c_len, str_term_width1 (quick_widgets[i].u.checkbox.text) + 3); /* radiobuttons */ for (i = 0; i < (size_t) pause_options_num; i++) c_len = max (c_len, str_term_width1 (pause_options[i]) + 3); /* label + input */ l_len = str_term_width1 (quick_widgets[16].u.label.text); c_len = max (c_len, l_len + 1 + 8); /* groupboxes */ g_len = max (c_len + 2, str_term_width1 (quick_widgets[24].u.groupbox.title) + 4); g_len = max (g_len, str_term_width1 (quick_widgets[18].u.groupbox.title) + 4); g_len = max (g_len, str_term_width1 (quick_widgets[14].u.groupbox.title) + 4); g_len = max (g_len, str_term_width1 (quick_widgets[12].u.groupbox.title) + 4); /* dialog width */ Quick_input.xlen = max (dlg_width, g_len * 2 + 9); Quick_input.xlen = max (Quick_input.xlen, b_len + 2); if ((Quick_input.xlen & 1) != 0) Quick_input.xlen++; /* fix widget parameters */ for (i = 0; i < qw_num; i++) quick_widgets[i].x_divisions = Quick_input.xlen; /* groupboxes */ quick_widgets[14].u.groupbox.width = quick_widgets[18].u.groupbox.width = quick_widgets[24].u.groupbox.width = Quick_input.xlen / 2 - 4; quick_widgets[12].u.groupbox.width = Quick_input.xlen / 2 - 3; /* input */ quick_widgets[15].relative_x = quick_widgets[16].relative_x + l_len + 1; quick_widgets[15].u.input.len = quick_widgets[18].u.groupbox.width - l_len - 4; /* right column */ quick_widgets[12].relative_x = Quick_input.xlen / 2; for (i = 2; i < 12; i++) quick_widgets[i].relative_x = quick_widgets[12].relative_x + 2; /* buttons */ quick_widgets[1].relative_x = (Quick_input.xlen - b_len) / 3; quick_widgets[0].relative_x = 2 * quick_widgets[1].relative_x + b1_len + 1; g_snprintf (time_out, sizeof (time_out), "%d", old_esc_mode_timeout); if (!old_esc_mode) quick_widgets[15].options = quick_widgets[16].options = W_DISABLED; #ifndef HAVE_POSIX_FALLOCATE mc_global.vfs.preallocate_space = FALSE; quick_widgets[19].options = W_DISABLED; #endif if (quick_dialog (&Quick_input) == B_ENTER) old_esc_mode_timeout = atoi (time_out_new); g_free (time_out_new); }
void editcmd_dialog_search_show (WEdit * edit, char **search_text) { if (*search_text == '\0') *search_text = INPUT_LAST_TEXT; { size_t num_of_types; gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types); int SEARCH_DLG_HEIGHT = SEARCH_DLG_MIN_HEIGHT + num_of_types - SEARCH_DLG_HEIGHT_SUPPLY; size_t i; int dialog_result; QuickWidget quick_widgets[] = { /* 0 */ QUICK_BUTTON (6, 10, 11, SEARCH_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL), /* 1 */ QUICK_BUTTON (4, 10, 11, SEARCH_DLG_HEIGHT, N_("&Find all"), B_USER, NULL), /* 2 */ QUICK_BUTTON (2, 10, 11, SEARCH_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL), #ifdef HAVE_CHARSET /* 3 */ QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 9, SEARCH_DLG_HEIGHT, N_("All charsets"), &edit->all_codepages), #endif /* 4 */ QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 8, SEARCH_DLG_HEIGHT, N_("&Whole words"), &edit->whole_words), /* 5 */ QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 7, SEARCH_DLG_HEIGHT, N_("In se&lection"), &edit->only_in_selection), /* 6 */ QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT, N_("&Backwards"), &edit->replace_backwards), /* 7 */ QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, N_("case &Sensitive"), &edit->replace_case), /* 8 */ QUICK_RADIO ( 3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, num_of_types, (const char **) list_of_types, (int *) &edit->search_type), /* 9 */ QUICK_INPUT (3, SEARCH_DLG_WIDTH, 3, SEARCH_DLG_HEIGHT, *search_text, SEARCH_DLG_WIDTH - 6, 0, MC_HISTORY_SHARED_SEARCH, search_text), /* 10 */ QUICK_LABEL (2, SEARCH_DLG_WIDTH, 2, SEARCH_DLG_HEIGHT, N_(" Enter search string:")), QUICK_END }; #ifdef HAVE_CHARSET size_t last_checkbox = 7; #else size_t last_checkbox = 6; #endif QuickDialog Quick_input = { SEARCH_DLG_WIDTH, SEARCH_DLG_HEIGHT, -1, -1, N_("Search"), "[Input Line Keys]", quick_widgets, TRUE }; #ifdef ENABLE_NLS char **list_of_types_nls; /* header title */ Quick_input.title = _(Quick_input.title); /* buttons */ for (i = 0; i < 3; i++) quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text); /* checkboxes */ for (i = 3; i <= last_checkbox; i++) quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text); /* label */ quick_widgets[10].u.label.text = _(quick_widgets[10].u.label.text); /* radiobuttons */ /* create copy of radio items to avoid memory leak */ list_of_types_nls = g_new0 (char *, num_of_types + 1); for (i = 0; i < num_of_types; i++) list_of_types_nls[i] = g_strdup (_(list_of_types[i])); g_strfreev (list_of_types); list_of_types = list_of_types_nls; quick_widgets[last_checkbox + 1].u.radio.items = (const char **) list_of_types; #endif /* calculate widget coordinates */ { int len = 0; int dlg_width; gchar **radio = list_of_types; int b0_len, b1_len, b2_len; const int button_gap = 2; /* length of radiobuttons */ while (*radio != NULL) { len = max (len, str_term_width1 (*radio)); radio++; } /* length of checkboxes */ for (i = 3; i <= last_checkbox; i++) len = max (len, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4); /* preliminary dialog width */ dlg_width = max (len * 2, str_term_width1 (Quick_input.title)) + 4; /* length of buttons */ b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3; b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 3; b2_len = str_term_width1 (quick_widgets[2].u.button.text) + 5; /* default button */ len = b0_len + b1_len + b2_len + button_gap * 2; /* dialog width */ Quick_input.xlen = max (SEARCH_DLG_WIDTH, max (dlg_width, len + 6)); /* correct widget coordinates */ for (i = 0; i < sizeof (quick_widgets)/sizeof (quick_widgets[0]); i++) quick_widgets[i].x_divisions = Quick_input.xlen; /* checkbox positions */ for (i = 3; i <= last_checkbox; i++) quick_widgets[i].relative_x = Quick_input.xlen/2 + 2; /* input length */ quick_widgets[last_checkbox + 2].u.input.len = Quick_input.xlen - 6; /* button positions */ quick_widgets[2].relative_x = Quick_input.xlen/2 - len/2; quick_widgets[1].relative_x = quick_widgets[2].relative_x + b2_len + button_gap; quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + button_gap; } dialog_result = quick_dialog (&Quick_input); g_strfreev (list_of_types); if (dialog_result == B_CANCEL) *search_text = NULL; else if (dialog_result == B_USER) search_create_bookmark = 1; } }
static void select_unselect_cmd (const char *title, const char *history_name, gboolean do_select) { /* dialog sizes */ const int DX = 50; const int DY = 7; int files_only = (select_flags & SELECT_FILES_ONLY) != 0; int case_sens = (select_flags & SELECT_MATCH_CASE) != 0; int shell_patterns = (select_flags & SELECT_SHELL_PATTERNS) != 0; char *reg_exp; mc_search_t *search; int i; QuickWidget quick_widgets[] = { QUICK_CHECKBOX (3, DX, DY - 3, DY, N_("&Using shell patterns"), &shell_patterns), QUICK_CHECKBOX (DX / 2 + 1, DX, DY - 4, DY, N_("&Case sensitive"), &case_sens), QUICK_CHECKBOX (3, DX, DY - 4, DY, N_("&Files only"), &files_only), QUICK_INPUT (3, DX, DY - 5, DY, INPUT_LAST_TEXT, DX - 6, 0, history_name, ®_exp), QUICK_END }; QuickDialog quick_dlg = { DX, DY, -1, -1, title, "[Select/Unselect Files]", quick_widgets, NULL, FALSE }; if (quick_dialog (&quick_dlg) == B_CANCEL) return; if (!reg_exp) return; if (!*reg_exp) { g_free (reg_exp); return; } search = mc_search_new (reg_exp, -1); search->search_type = (shell_patterns != 0) ? MC_SEARCH_T_GLOB : MC_SEARCH_T_REGEX; search->is_entire_line = TRUE; search->is_case_sensitive = case_sens != 0; for (i = 0; i < current_panel->count; i++) { if (strcmp (current_panel->dir.list[i].fname, "..") == 0) continue; if (S_ISDIR (current_panel->dir.list[i].st.st_mode) && files_only != 0) continue; if (mc_search_run (search, current_panel->dir.list[i].fname, 0, current_panel->dir.list[i].fnamelen, NULL)) do_file_mark (current_panel, i, do_select); } mc_search_free (search); g_free (reg_exp); /* result flags */ select_flags = 0; if (case_sens != 0) select_flags |= SELECT_MATCH_CASE; if (files_only != 0) select_flags |= SELECT_FILES_ONLY; if (shell_patterns != 0) select_flags |= SELECT_SHELL_PATTERNS; }