Example #1
0
File: actions.c Project: ab/pwman
int 
action_input_dialog(InputField *fields, int num_fields, char *title)
{
	int ch, i;
	char *ret;
	WINDOW *dialog_win;
	char msg[] = "(press 'q' to return to list)";
	char msg2[80];
	/*
	 * initialize the info window
	 */
	if(title){
		disp_h = ((num_fields+2) * 2) + 3;
	} else {
		disp_h = ((num_fields+1) * 2) + 3;
	}
	
	dialog_win = newwin(disp_h, disp_w, (LINES - disp_h)/2, (COLS - disp_w)/2);
	keypad(dialog_win, TRUE);

	action_input_dialog_draw_items(dialog_win, fields, num_fields, title, msg);
	/*
	 * actions loop
	 */
	while((ch = wgetch(dialog_win)) != 'q'){
		if(!options->readonly) {
			if( (ch >= '1') && (ch <= NUM_TO_CHAR(num_fields)) ){
				i = CHAR_TO_NUM(ch);
				if(fields[i].autogen != NULL){
					fields[i].value = (char*)ui_statusline_ask_str_with_autogen(
								fields[i].name, (char*)fields[i].value, 
								fields[i].max_length, fields[i].autogen, 0x07); 
				} else if(fields[i].type == STRING){
					fields[i].value = (char*)ui_statusline_ask_str(fields[i].name, 
								(char*)fields[i].value, fields[i].max_length);
				} else if(fields[i].type == INT){
					ui_statusline_ask_num(fields[i].name, (int*)fields[i].value);
				} else if(fields[i].type == INFORMATION){
					// Easy, do nothing!
				}
				action_input_dialog_draw_items(dialog_win, fields, num_fields, title, msg);
			} else if(ch == 'l'){
				delwin(dialog_win);
				action_list_launch();
				break;
			}	
		} else {
			statusline_readonly();
		}
	}
	/*
	 * clean up
	 */
	delwin(dialog_win);
	uilist_refresh();
}
Example #2
0
File: ui.c Project: unixwitch/pwman
int
ui_run()
{
int		ch;
int		load_worked = 0;

#ifdef DEBUG
int		debug_i = 0;

#endif

	time_base = time(NULL);

	while (1) {
		can_resize = TRUE;
		if (should_resize) {
			ui_resize();
		}
		ch = getch();
		ui_statusline_clear();
		can_resize = FALSE;

		if ((time_base < (time(NULL) - (options->passphrase_timeout * 60)))
		    && options->passphrase_timeout != 0 && tolower(ch) != 'q') {
			folder_write_file();
			folder_free_all();

			ui_statusline_msg("Passphrase has timed out and you must enter it again.");
			getch();

			load_worked = folder_read_file();
			if (load_worked != 0) {
				ui_statusline_msg("Error - unable to re-load the password file!");
				break;
			}
			if (search_results != NULL)
				search_remove();

			time_base = time(NULL);
			continue;
		}
		switch (ch) {
		case 'Q':
		case 'q':
			if (search_results != NULL)
				search_remove();
			else if (action_list_at_top_level())
				return 0;
			break;

		case '?':
			ui_display_help();
			break;

		case KEY_PPAGE:
			uilist_page_up();
			break;

		case KEY_NPAGE:
			uilist_page_down();
			break;

		case KEY_UP:
		case 'k':
			uilist_up();
			break;

		case KEY_DOWN:
		case 'j':
			uilist_down();
			break;

		case 'A':
			if (!options->readonly)
				action_list_add_sublist();
			else
				statusline_readonly();
			break;

		case 'U':
			action_list_up_one_level();
			break;

		case 'r':
			if (!options->readonly) {
				action_list_rename();
				folder_write_file();
			} else {
				statusline_readonly();
			}
			break;

		case 'a':
			if (!options->readonly) {
				action_list_add_pw();
				folder_write_file();
			} else {
				statusline_readonly();
			}
			break;

		case 'e':
		case ' ':
		case 13:	/* return/enter key */
			action_list_select_item();
			break;

		case 'x':
			action_list_mark();
			break;

		case 'B':
			action_list_copy_username();
			break;

		case 'C':
			action_list_copy_pw();
			break;

		case 'd':
		case 0x14A:	/* DEL key */
			if (!options->readonly)
				action_list_delete_item();
			else 
				statusline_readonly();
			break;

		case 'm':
			if (!options->readonly)
				action_list_move_item();
			else
				statusline_readonly();
			break;

		case 'o':
			action_edit_options();
			break;

		case 0x17:	/* control-w */
			if (!options->readonly)
				folder_write_file();
			else
				statusline_readonly();
			break;

		case 0x12:	/* control-r */
			action_list_read_file();
			break;

		case 0x07:	/* control-g */
			pwgen_indep();
			break;

		case 0x06:	/* control-f */
			gnupg_forget_passphrase();
			break;

		case 0x0C:	/* control-l */
			ui_refresh_windows();
			break;

		case '/':
		case 'F':
			search_get();
			break;

		case 'f':
			filter_get();
			break;

		case 'E':
			action_list_export();
			break;

		case 'I':
			if (!options->readonly) {
				folder_import_passwd();
				uilist_refresh();
			} else {
				statusline_readonly();
			}
			break;

		case 'L':
			action_list_locate();
			break;

		case 'l':
			action_list_launch();
			break;

		case 0x0B:	/* control-k (up) */
		case '[':
			action_list_move_item_up();
			break;

		case 0x0A:	/* control-j (down) */
		case ']':
			action_list_move_item_down();
			break;

#ifdef DEBUG
		case '$':
			debug_i++;
			snprintf(msg, 80, "Name %d", debug_i);

			folder_add(current_pw_sublist, msg, "myhost", "myuser", "mypasswd", "mylaucnh");
			uilist_refresh();
			break;
#endif

		default:
			break;
		}
	}
	return 0;
}