char * listbox_add_item (WListbox * l, listbox_append_t pos, int hotkey, const char *text, void *data, gboolean free_data) { WLEntry *entry; if (l == NULL) return NULL; if (!l->allow_duplicates && (listbox_search_text (l, text) >= 0)) return NULL; entry = g_new (WLEntry, 1); entry->text = g_strdup (text); entry->data = data; entry->free_data = free_data; entry->hotkey = hotkey; listbox_append_item (l, entry, pos); return entry->text; }
static void do_enter_key (WDialog * h, int f_pos) { WListbox *chl_list; struct passwd *chl_pass; struct group *chl_grp; int fe; gboolean chl_end, is_owner; do { int result; WDialog *chl_dlg; const char *title; int lxx, lyy, b_pos; is_owner = (f_pos == 3); title = is_owner ? _("owner") : _("group"); lxx = (COLS - 74) / 2 + (is_owner ? 35 : 53); lyy = (LINES - 13) / 2; chl_end = FALSE; chl_dlg = dlg_create (TRUE, lyy, lxx, 13, 17, WPOS_KEEP_DEFAULT, TRUE, dialog_colors, chl_callback, NULL, "[Advanced Chown]", title); /* get new listboxes */ chl_list = listbox_new (1, 1, 11, 15, FALSE, NULL); listbox_add_item (chl_list, LISTBOX_APPEND_AT_END, 0, "<Unknown>", NULL, FALSE); if (is_owner) { /* get and put user names in the listbox */ setpwent (); while ((chl_pass = getpwent ()) != NULL) listbox_add_item (chl_list, LISTBOX_APPEND_SORTED, 0, chl_pass->pw_name, NULL, FALSE); endpwent (); fe = listbox_search_text (chl_list, get_owner (sf_stat->st_uid)); } else { /* get and put group names in the listbox */ setgrent (); while ((chl_grp = getgrent ()) != NULL) listbox_add_item (chl_list, LISTBOX_APPEND_SORTED, 0, chl_grp->gr_name, NULL, FALSE); endgrent (); fe = listbox_search_text (chl_list, get_group (sf_stat->st_gid)); } listbox_select_entry (chl_list, fe); b_pos = chl_list->pos; add_widget (chl_dlg, chl_list); result = dlg_run (chl_dlg); if (result != B_CANCEL) { if (b_pos != chl_list->pos) { gboolean ok = FALSE; char *text; listbox_get_current (chl_list, &text, NULL); if (is_owner) { chl_pass = getpwnam (text); if (chl_pass != NULL) { ok = TRUE; sf_stat->st_uid = chl_pass->pw_uid; } } else { chl_grp = getgrnam (text); if (chl_grp != NULL) { sf_stat->st_gid = chl_grp->gr_gid; ok = TRUE; } } if (ok) { ch_flags[f_pos + 6] = '+'; update_ownership (); } dlg_focus (h); if (ok) print_flags (); } if (result == KEY_LEFT) { if (!is_owner) chl_end = TRUE; dlg_one_up (ch_dlg); f_pos--; } else if (result == KEY_RIGHT) { if (is_owner) chl_end = TRUE; dlg_one_down (ch_dlg); f_pos++; } } /* Here we used to redraw the window */ dlg_destroy (chl_dlg); } while (chl_end); }
void chown_cmd (void) { char *fname; struct stat sf_stat; uid_t new_user; gid_t new_group; char buffer[BUF_TINY]; chown_i18n (); do { /* do while any files remaining */ vfs_path_t *vpath; WDialog *ch_dlg; ch_dlg = init_chown (); new_user = new_group = -1; if (current_panel->marked) fname = next_file (); /* next marked file */ else fname = selection (current_panel)->fname; /* single file */ vpath = vfs_path_from_str (fname); if (mc_stat (vpath, &sf_stat) != 0) { /* get status of file */ dlg_destroy (ch_dlg); vfs_path_free (vpath); break; } vfs_path_free (vpath); /* select in listboxes */ listbox_select_entry (l_user, listbox_search_text (l_user, get_owner (sf_stat.st_uid))); listbox_select_entry (l_group, listbox_search_text (l_group, get_group (sf_stat.st_gid))); chown_label (0, str_trunc (fname, GW - 4)); chown_label (1, str_trunc (get_owner (sf_stat.st_uid), GW - 4)); chown_label (2, str_trunc (get_group (sf_stat.st_gid), GW - 4)); size_trunc_len (buffer, GW - 4, sf_stat.st_size, 0, panels_options.kilobyte_si); chown_label (3, buffer); chown_label (4, string_perm (sf_stat.st_mode)); switch (dlg_run (ch_dlg)) { case B_CANCEL: end_chown = 1; break; case B_SETUSR: { struct passwd *user; char *text; listbox_get_current (l_user, &text, NULL); user = getpwnam (text); if (user) { new_user = user->pw_uid; apply_chowns (new_user, new_group); } break; } case B_SETGRP: { struct group *grp; char *text; listbox_get_current (l_group, &text, NULL); grp = getgrnam (text); if (grp) { new_group = grp->gr_gid; apply_chowns (new_user, new_group); } break; } case B_SETALL: case B_ENTER: { struct group *grp; struct passwd *user; char *text; listbox_get_current (l_group, &text, NULL); grp = getgrnam (text); if (grp) new_group = grp->gr_gid; listbox_get_current (l_user, &text, NULL); user = getpwnam (text); if (user) new_user = user->pw_uid; if (ch_dlg->ret_value == B_ENTER) { vfs_path_t *fname_vpath; fname_vpath = vfs_path_from_str (fname); need_update = 1; if (mc_chown (fname_vpath, new_user, new_group) == -1) message (D_ERROR, MSG_ERROR, _("Cannot chown \"%s\"\n%s"), fname, unix_error_string (errno)); vfs_path_free (fname_vpath); } else apply_chowns (new_user, new_group); break; } } /* switch */ if (current_panel->marked && ch_dlg->ret_value != B_CANCEL) { do_file_mark (current_panel, current_file, 0); need_update = 1; } dlg_destroy (ch_dlg); } while (current_panel->marked && !end_chown); chown_done (); }
static void init_panelize (void) { struct { int ret_cmd; button_flags_t flags; const char *text; } panelize_but[] = { /* *INDENT-OFF* */ { B_ENTER, DEFPUSH_BUTTON, N_("Pane&lize") }, { B_REMOVE, NORMAL_BUTTON, N_("&Remove") }, { B_ADD, NORMAL_BUTTON, N_("&Add new") }, { B_CANCEL, NORMAL_BUTTON, N_("&Cancel") } /* *INDENT-ON* */ }; size_t i; int blen; int panelize_cols; struct panelize *current; int x, y; last_listitem = 0; do_refresh (); i = G_N_ELEMENTS (panelize_but); blen = i - 1; /* gaps between buttons */ while (i-- != 0) { #ifdef ENABLE_NLS panelize_but[i].text = _(panelize_but[i].text); #endif blen += str_term_width1 (panelize_but[i].text) + 3 + 1; if (panelize_but[i].flags == DEFPUSH_BUTTON) blen += 2; } panelize_cols = COLS - 6; panelize_cols = max (panelize_cols, blen + 4); panelize_dlg = dlg_create (TRUE, 0, 0, 20, panelize_cols, dialog_colors, panelize_callback, NULL, "[External panelize]", _("External panelize"), DLG_CENTER); /* add listbox to the dialogs */ y = UY; add_widget (panelize_dlg, groupbox_new (y++, UX, 12, panelize_cols - UX * 2, "")); l_panelize = listbox_new (y, UX + 1, 10, panelize_cols - UX * 2 - 2, FALSE, NULL); for (current = panelize; current != NULL; current = current->next) listbox_add_item (l_panelize, LISTBOX_APPEND_AT_END, 0, current->label, current); listbox_select_entry (l_panelize, listbox_search_text (l_panelize, _("Other command"))); add_widget (panelize_dlg, l_panelize); y += WIDGET (l_panelize)->lines + 1; add_widget (panelize_dlg, label_new (y++, UX, _("Command"))); pname = input_new (y++, UX, input_colors, panelize_cols - UX * 2, "", "in", INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_HOSTNAMES | INPUT_COMPLETE_COMMANDS | INPUT_COMPLETE_VARIABLES | INPUT_COMPLETE_USERNAMES | INPUT_COMPLETE_CD | INPUT_COMPLETE_SHELL_ESC); add_widget (panelize_dlg, pname); add_widget (panelize_dlg, hline_new (y++, -1, -1)); x = (panelize_cols - blen) / 2; for (i = 0; i < G_N_ELEMENTS (panelize_but); i++) { WButton *b; b = button_new (y, x, panelize_but[i].ret_cmd, panelize_but[i].flags, panelize_but[i].text, NULL); add_widget (panelize_dlg, b); x += button_get_len (b) + 1; } dlg_select_widget (l_panelize); }
static void init_panelize (void) { int i, panelize_cols = COLS - 6; struct panelize *current = panelize; #ifdef ENABLE_NLS static int i18n_flag = 0; static int maxlen = 0; if (!i18n_flag) { i = sizeof (panelize_but) / sizeof (panelize_but[0]); while (i--) { panelize_but[i].text = _(panelize_but[i].text); maxlen += str_term_width1 (panelize_but[i].text) + 5; } maxlen += 10; i18n_flag = 1; } panelize_cols = max (panelize_cols, maxlen); panelize_but[2].x = panelize_but[3].x + str_term_width1 (panelize_but[3].text) + 7; panelize_but[1].x = panelize_but[2].x + str_term_width1 (panelize_but[2].text) + 5; panelize_but[0].x = panelize_cols - str_term_width1 (panelize_but[0].text) - 8 - BX; #endif /* ENABLE_NLS */ last_listitem = 0; do_refresh (); panelize_dlg = create_dlg (TRUE, 0, 0, 22, panelize_cols, dialog_colors, panelize_callback, "[External panelize]", _("External panelize"), DLG_CENTER | DLG_REVERSE); for (i = 0; i < BUTTONS; i++) add_widget (panelize_dlg, button_new (BY + panelize_but[i].y, BX + panelize_but[i].x, panelize_but[i].ret_cmd, panelize_but[i].flags, panelize_but[i].text, 0)); pname = input_new (UY + 14, UX, input_get_default_colors (), panelize_dlg->cols - 10, "", "in", INPUT_COMPLETE_DEFAULT); add_widget (panelize_dlg, pname); add_widget (panelize_dlg, label_new (UY + 13, UX, _("Command"))); /* get new listbox */ l_panelize = listbox_new (UY + 1, UX + 1, 10, panelize_dlg->cols - 12, FALSE, NULL); while (current) { listbox_add_item (l_panelize, LISTBOX_APPEND_AT_END, 0, current->label, current); current = current->next; } /* add listbox to the dialogs */ add_widget (panelize_dlg, l_panelize); listbox_select_entry (l_panelize, listbox_search_text (l_panelize, _("Other command"))); }
void chown_cmd (void) { char *fname; struct stat sf_stat; WLEntry *fe; Dlg_head *ch_dlg; uid_t new_user; gid_t new_group; char buffer [BUF_TINY]; do { /* do while any files remaining */ ch_dlg = init_chown (); new_user = new_group = -1; if (current_panel->marked) fname = next_file (); /* next marked file */ else fname = selection (current_panel)->fname; /* single file */ if (mc_stat (fname, &sf_stat) != 0) { /* get status of file */ destroy_dlg (ch_dlg); break; } /* select in listboxes */ fe = listbox_search_text (l_user, get_owner(sf_stat.st_uid)); if (fe) listbox_select_entry (l_user, fe); fe = listbox_search_text (l_group, get_group(sf_stat.st_gid)); if (fe) listbox_select_entry (l_group, fe); chown_label (0, name_trunc (fname, 15)); chown_label (1, name_trunc (get_owner (sf_stat.st_uid), 15)); chown_label (2, name_trunc (get_group (sf_stat.st_gid), 15)); size_trunc_len (buffer, 15, sf_stat.st_size, 0); chown_label (3, buffer); chown_label (4, string_perm (sf_stat.st_mode)); run_dlg (ch_dlg); switch (ch_dlg->ret_value) { case B_CANCEL: end_chown = 1; break; case B_SETUSR: { struct passwd *user; user = getpwnam (l_user->current->text); if (user){ new_user = user->pw_uid; apply_chowns (new_user, new_group); } break; } case B_SETGRP: { struct group *grp; grp = getgrnam (l_group->current->text); if (grp){ new_group = grp->gr_gid; apply_chowns (new_user, new_group); } break; } case B_SETALL: case B_ENTER: { struct group *grp; struct passwd *user; grp = getgrnam (l_group->current->text); if (grp) new_group = grp->gr_gid; user = getpwnam (l_user->current->text); if (user) new_user = user->pw_uid; if (ch_dlg->ret_value==B_ENTER) { need_update = 1; if (mc_chown (fname, new_user, new_group) == -1) message (1, MSG_ERROR, _(" Cannot chown \"%s\" \n %s "), fname, unix_error_string (errno)); } else apply_chowns (new_user, new_group); break; } } if (current_panel->marked && ch_dlg->ret_value != B_CANCEL){ do_file_mark (current_panel, current_file, 0); need_update = 1; } destroy_dlg (ch_dlg); } while (current_panel->marked && !end_chown); chown_done (); }
void chown_cmd (void) { char *fname; struct stat sf_stat; WLEntry *fe; uid_t new_user; gid_t new_group; char buffer [15]; #if 0 /* Please no */ if (!vfs_current_is_local ()) { if (vfs_current_is_extfs ()) { message (1, _(" Oops... "), _(" I can't run the Chown command on an extfs ")); return; } else if (vfs_current_is_tarfs ()) { message (1, _(" Oops... "), _(" I can't run the Chown command on a tarfs ")); return; } } #endif do { /* do while any files remaining */ init_chown (); new_user = new_group = -1; if (cpanel->marked) fname = next_file (); /* next marked file */ else fname = selection (cpanel)->fname; /* single file */ if (!stat_file (fname, &sf_stat)){ /* get status of file */ destroy_dlg (ch_dlg); break; } /* select in listboxes */ fe = listbox_search_text (l_user, get_owner(sf_stat.st_uid)); if (fe) listbox_select_entry (l_user, fe); fe = listbox_search_text (l_group, get_group(sf_stat.st_gid)); if (fe) listbox_select_entry (l_group, fe); chown_label (0, name_trunc (fname, 15)); chown_label (1, name_trunc (get_owner (sf_stat.st_uid), 15)); chown_label (2, name_trunc (get_group (sf_stat.st_gid), 15)); sprintf (buffer, "%d", c_fsize); chown_label (3, buffer); chown_label (4, string_perm (sf_stat.st_mode)); run_dlg (ch_dlg); switch (ch_dlg->ret_value) { case B_CANCEL: end_chown = 1; break; case B_SETUSR: { struct passwd *user; user = getpwnam (l_user->current->text); if (user){ new_user = user->pw_uid; apply_chowns (new_user, new_group); } break; } case B_SETGRP: { struct group *grp; grp = getgrnam (l_group->current->text); if (grp){ new_group = grp->gr_gid; apply_chowns (new_user, new_group); } break; } case B_SETALL: case B_ENTER: { struct group *grp; struct passwd *user; grp = getgrnam (l_group->current->text); if (grp) new_group = grp->gr_gid; user = getpwnam (l_user->current->text); if (user) new_user = user->pw_uid; if (ch_dlg->ret_value==B_ENTER) { need_update = 1; if (mc_chown (fname, new_user, new_group) == -1) message (1, MSG_ERROR, _(" Couldn't chown \"%s\" \n %s "), fname, unix_error_string (errno)); } else apply_chowns (new_user, new_group); break; } } if (cpanel->marked && ch_dlg->ret_value != B_CANCEL){ do_file_mark (cpanel, current_file, 0); need_update = 1; } destroy_dlg (ch_dlg); } while (cpanel->marked && !end_chown); chown_done (); }
static void do_enter_key (Dlg_head * h, int f_pos) { Dlg_head *chl_dlg; WListbox *chl_list; struct passwd *chl_pass; struct group *chl_grp; WLEntry *fe; int lxx, lyy, chl_end, b_pos; int is_owner; const char *title; do { is_owner = (f_pos == 3); title = is_owner ? _("owner") : _("group"); lxx = (COLS - 74) / 2 + (is_owner ? 35 : 53); lyy = (LINES - 13) / 2; chl_end = 0; chl_dlg = create_dlg (lyy, lxx, 13, 17, dialog_colors, chl_callback, "[Advanced Chown]", title, DLG_COMPACT | DLG_REVERSE); /* get new listboxes */ chl_list = listbox_new (1, 1, 11, 15, NULL); listbox_add_item (chl_list, LISTBOX_APPEND_AT_END, 0, "<Unknown>", NULL); if (is_owner) { /* get and put user names in the listbox */ setpwent (); while ((chl_pass = getpwent ())) { listbox_add_item (chl_list, LISTBOX_APPEND_SORTED, 0, chl_pass->pw_name, NULL); } endpwent (); fe = listbox_search_text (chl_list, get_owner (sf_stat->st_uid)); } else { /* get and put group names in the listbox */ setgrent (); while ((chl_grp = getgrent ())) { listbox_add_item (chl_list, LISTBOX_APPEND_SORTED, 0, chl_grp->gr_name, NULL); } endgrent (); fe = listbox_search_text (chl_list, get_group (sf_stat->st_gid)); } if (fe) listbox_select_entry (chl_list, fe); b_pos = chl_list->pos; add_widget (chl_dlg, chl_list); run_dlg (chl_dlg); if (b_pos != chl_list->pos) { int ok = 0; if (is_owner) { chl_pass = getpwnam (chl_list->current->text); if (chl_pass) { ok = 1; sf_stat->st_uid = chl_pass->pw_uid; } } else { chl_grp = getgrnam (chl_list->current->text); if (chl_grp) { sf_stat->st_gid = chl_grp->gr_gid; ok = 1; } } if (ok) { ch_flags[f_pos + 6] = '+'; update_ownership (); } dlg_focus (h); if (ok) print_flags (); } if (chl_dlg->ret_value == KEY_LEFT) { if (!is_owner) chl_end = 1; dlg_one_up (ch_dlg); f_pos--; } else if (chl_dlg->ret_value == KEY_RIGHT) { if (is_owner) chl_end = 1; dlg_one_down (ch_dlg); f_pos++; } /* Here we used to redraw the window */ destroy_dlg (chl_dlg); } while (chl_end); }