AddProjectForm::AddProjectForm(int rows, int cols, Srv* srv, const char* projname, bool userexist) : NForm(rows,cols) { this->srv = srv; settitle(projname); this->projname = projname; this->userexist = userexist; Item* project = NULL; if (srv !=NULL) project = srv->findprojectbynamefromall(projname); int row = 0; //поля try { genfields(row,project); } catch(const char* err) { kLogPrintf("ERROR EXCAPTION %s\n",err); } //пересчитываем высоту формы, чтобы влезли все поля и центрируем int r,c =0; scale_form(frm, &r, &c); kLogPrintf("field_count=%d scale_form()->%d,%d\n", field_count(frm), r, c); resize(r+3,c+2); post_form(frm); this->refresh(); }
StateType DialogForm::show() { if (!m_pFields[0]) { return STATE_ERROR; } //Create form & window FIELD *pFields[m_curField]; for (int i = 0; i < m_numFields + 1; i++) { if (i < m_curField) { pFields[i] = m_pFields[i]; } else { pFields[i] = 0; } } m_pForm = new_form(pFields); int rows, cols; scale_form(m_pForm, &rows, &cols); m_rows = std::max(m_rows, rows); m_cols = std::max(m_cols, cols); delwin(m_pWindow); m_pWindow = newwin(m_rows + 6, m_cols + 4, (getmaxy(stdscr) - m_rows) / 2 - 3, (getmaxx(stdscr) - m_cols) / 2 - 2); set_form_win(m_pForm, m_pWindow); set_form_sub(m_pForm, derwin(m_pWindow, m_rows, m_cols, 2, 2)); post_form(m_pForm); curs_set(1); Panel::show(); curs_set(0); return getReturnState(); }
void InitResizeMOSAIC () { resizeWindow = CreateCenteredBoxedTitledWindow (RESIZE_height, RESIZE_width, "RESIZE"); resizePanel = new_panel (resizeWindow); mvwaddstr (resizeWindow, 1, 1, "New height"); mvwaddstr (resizeWindow, 2, 1, "New width"); /* MAKING OF FORM */ FIELD **fields = (FIELD **) malloc (3 * sizeof (FIELD *)); fields[0] = new_field (1, 3, 0, 0, 0, 0); set_field_back (fields[0], A_BOLD); field_opts_off (fields[0], O_PASSOK); set_field_just (fields[0], JUSTIFY_LEFT); set_field_type (fields[0], TYPE_INTEGER, 0, 1, 999); fields[1] = new_field (1, 3, 1, 0, 0, 0); set_field_back (fields[1], A_BOLD); field_opts_off (fields[1], O_PASSOK); set_field_just (fields[1], JUSTIFY_LEFT); set_field_type (fields[1], TYPE_INTEGER, 0, 1, 999); fields[2] = NULL; // the FORM itself, WINDOW and post it! resize_form = new_form (fields); // subwindow: inside the box WINDOW *subwindow = derwin (resizeWindow, 2, 3, 1, 12); set_form_win (resize_form, subwindow); set_form_sub (resize_form, subwindow); post_form (resize_form); touchwin (resizeWindow); }
bool InputForm::Init() { field = (FIELD **)calloc(choices*2+1, sizeof(FIELD *)); for (int i = 0; i < choices; ++i) { field[2*i] = new_field(1, 30, 4+i*2, 2, 02, 02); field[2*i+1] = new_field(1, 20, 4+i*2, 30, 02, 02); set_field_back(field[2*i+1], A_UNDERLINE); field_opts_off(field[2*i+1], O_AUTOSKIP); set_field_buffer(field[2*i], 0, itemNames[i].c_str()); set_field_back(field[2*i], O_EDIT); } field[choices*2] = NULL; form = new_form(field); scale_form(form, &formRows, &formCols); win = newwin(formRows+8, formCols+20, LINES/2-formRows/2 -6, COLS/2-10-formCols/2); keypad(win, TRUE); set_form_win(form, win); set_form_sub(form, derwin(win, formRows, formCols, 2, 2)); box(win, 0, 0); wattron(win, COLOR_PAIR(1)); mvwprintw(win, 0, formCols/2+8-title.size()/2, "%s", title.c_str()); wattroff(win, COLOR_PAIR(1)); post_form(form); panel = new_panel(win); switchOkCancle(); update_panels(); doupdate(); form_driver(form, REQ_NEXT_FIELD); return true; }
void create_device_name_form(void) { fields[0] = new_field(1, 32, 1, 1, 0, 0); if (!fields[0]) fatal_error("cannot create field"); field_opts_off(fields[0], O_ACTIVE); field_opts_off(fields[0], O_EDIT); set_field_fore(fields[0], attr_textbox); set_field_back(fields[0], attr_textbox); set_field_buffer(fields[0], 0, _("Device name:")); fields[1] = new_field(1, 32, 2, 1, 0, 0); if (!fields[1]) fatal_error("cannot create field"); field_opts_off(fields[1], O_AUTOSKIP); field_opts_off(fields[1], O_NULLOK); field_opts_off(fields[1], O_STATIC); set_field_fore(fields[1], attr_textfield); set_field_back(fields[1], attr_textfield); set_field_buffer(fields[1], 0, mixer_device_name); form = new_form(fields); if (!form) fatal_error("cannot create form"); if (!create()) return; post_form(form); }
void init_term_gui(void) { /* Fix ESC key */ set_escdelay(25); initscr(); start_color(); cbreak(); noecho(); if (can_change_color()) { init_color(XS_COLOR_BLUE, 43, 180, 349); init_color(XS_COLOR_RED, 886, 27, 124); init_pair(XS_COLOR_PAIR_1, COLOR_WHITE, XS_COLOR_RED); init_pair(XS_COLOR_PAIR_2, COLOR_WHITE, XS_COLOR_BLUE); } else{ init_pair(XS_COLOR_PAIR_1, COLOR_WHITE, COLOR_RED); init_pair(XS_COLOR_PAIR_2, COLOR_WHITE, COLOR_BLUE); } /* int max_rows; */ /* int max_cols; */ /* getmaxyx(stdscr, max_rows, max_cols); */ show_recent_apps(); prepare_for_new_results(False); mvprintw(0, 0, "$"); mvwprintw(window, MAX_Y - 2, 0, "Loading paths..."); refresh(); field[0] = new_field( 1, // columns 20, // width 0, // pos y 2, // pos x 0, 0 ); /* Hide cursor */ curs_set(0); set_field_fore(field[0], COLOR_PAIR(XS_COLOR_PAIR_2)); field[1] = NULL; form = new_form(field); post_form(form); wrefresh(window); }
int main() { FIELD *f1[2]; FORM *frm1; chtype ch; int error; HOOK fptr=getbuf; initscr(); f1[0]=new_field(24,80,0,0,1,1); assert(f1[0]!=NULL); f1[1]=NULL; frm1=new_form(f1); assert(frm1!=NULL); set_field_fore(f1[0],A_REVERSE); field_opts_off(f1[0],O_STATIC); //set_field_buffer(f1[0],0,"Sajid"); set_field_type(f1[0],TYPE_ALPHA,80); set_field_term(f1[0],fptr); post_form(frm1); wrefresh(stdscr); keypad(stdscr,TRUE); while((ch=getch())!=KEY_F(3)) { switch(ch) { case KEY_LEFT: error=form_driver(frm1,REQ_PREV_CHAR); if(error==E_REQUEST_DENIED) form_driver(frm1,REQ_SCR_BCHAR); break; case KEY_RIGHT: form_driver(frm1,REQ_NEXT_CHAR); break; default: form_driver(frm1,ch); break; } } unpost_form(frm1); free_form(frm1); free_field(f1[0]); getch(); printw(ptr); endwin(); }
void ListBox::createForm() { if (m_pForm != 0) { unpost_form(m_pForm); free_form(m_pForm); } m_pForm = new_form(m_pFields); int rows, cols; scale_form(m_pForm, &rows, &cols); set_form_win(m_pForm, m_pPanel->getWindow()); set_form_sub(m_pForm, derwin(m_pPanel->getWindow(), getHeight() - 2, getWidth() - 2, getY() + 1, getX() + 1)); post_form(m_pForm); form_driver(m_pForm, REQ_LAST_FIELD); if (isSelected()) { selectField(REQ_PREV_FIELD); } }
static void on_window_size_changed(void) { form_driver(form, REQ_VALIDATION); /* save field value */ unpost_form(form); if (!create()) return; /* * This call fails because ncurses does not allow changing options of * the current field, and we cannot change the current field because * there is only one. The only way to make this work would be to throw * away and recreate all fields. */ field_opts_off(fields[1], O_BLANK); post_form(form); }
void create_input_form() { delete_input_form(); keypad(input_window, TRUE); url_field[0] = new_field(1, input_cols - (FIELD_START + 1), 0, 0, 0, 0); url_field[1] = NULL; set_field_back(url_field[0], A_REVERSE); field_opts_off(url_field[0], O_AUTOSKIP); field_opts_off(url_field[0], O_STATIC); set_max_field(url_field[0], FIELD_BUF_SIZE); url_form = new_form(url_field); set_form_win(url_form, input_window); set_form_sub(url_form, derwin(input_window, 1, input_cols - (FIELD_START + 1), 0, FIELD_START)); post_form(url_form); wrefresh(input_window); }
static void brsh_init(void) { /* handle window resize */ signal(SIGWINCH, &resized_); /* initalize curses */ initscr(); cbreak(); noecho(); intrflush(stdscr, FALSE); keypad(stdscr, TRUE); /* enable cursor keys and others */ /* create the output window */ win_output = newwin(LINES - g_brsh_input_display_lines - 1, COLS, 0, 0); scrollok(win_output, TRUE); /* create the input field */ fld_input = new_field(g_brsh_input_display_lines, COLS, LINES - g_brsh_input_display_lines, 0, g_brsh_input_maximum_lines - g_brsh_input_display_lines, 1); static FIELD *fields[2] = { NULL, NULL }; /* not sure if it needs this to hang around or not, so we'll make it static anyway */ fields[0] = fld_input; frm_input = new_form(fields); post_form(frm_input); /* draw a line */ move(LINES - g_brsh_input_display_lines - 1, 0); for (int i = 0; i < COLS; i++) addch(ACS_HLINE); if (g_brsh_show_instructions) mvprintw(LINES - g_brsh_input_display_lines - 1, COLS - 15, " F1 = Help "); refresh(); move(LINES - g_brsh_input_display_lines, 0); /* post welcome banner */ brsh_print(BRSH_NAME " " BRSH_VERSION "\n"); }
AddProjectForm::AddProjectForm(int rows, int cols, Srv* srv, const char* projname, bool userexist) : NForm(rows,cols) { this->srv = srv; settitle(projname); this->projname = projname; this->userexist = userexist; Item* project = NULL; if (srv !=NULL) project = srv->findprojectbynamefromall(projname); int row = 1; //поля genfields(row,project); //пересчитываем высоту формы, чтобы влезли все поля и центрируем resize(row + 2,getwidth()); move(getmaxy(stdscr)/2-getheight()/2,getmaxx(stdscr)/2-getwidth()/2); set_form_fields(frm, fields); set_current_field(frm, fields[0]); //фокус на поле post_form(frm); this->refresh(); }
AddAccMgrForm::AddAccMgrForm(int rows, int cols, Srv* srv, const char* mgrname) : NForm(rows,cols) { this->srv = srv; settitle(mgrname); this->mgrname = mgrname; Item* account_manager = NULL; if (srv !=NULL) account_manager = srv->findaccountmanager(mgrname); //поля int row = 0; genfields(row,account_manager); //пересчитываем высоту формы, чтобы влезли все поля и центрируем int r,c =0; scale_form(frm, &r, &c); kLogPrintf("field_count=%d scale_form()->%d,%d\n", field_count(frm), r, c); resize(r+3,c+2); set_current_field(frm, fields[0]); //фокус на поле post_form(frm); this->refresh(); }
static void display_form(FORM * f) { WINDOW *w; int rows, cols; scale_form(f, &rows, &cols); /* * Put the form at the upper-left corner of the display, with just a box * around it. */ if ((w = newwin(rows + 2, cols + 4, 0, 0)) != (WINDOW *) 0) { set_form_win(f, w); set_form_sub(f, derwin(w, rows, cols, 1, 2)); box(w, 0, 0); keypad(w, TRUE); } if (post_form(f) != E_OK) wrefresh(w); }
/* * create the internal form */ static void wdg_input_form_create(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_input_handle, ww); int mrows, mcols; size_t c = wdg_get_ncols(wo); size_t x = wdg_get_begin_x(wo); size_t y = wdg_get_begin_y(wo); /* the form is already posted */ if (ww->form) return; /* create the form */ ww->form = new_form(ww->fields); /* get the geometry to make a window */ scale_form(ww->form, &mrows, &mcols); /* create the window for the form */ ww->fwin = newwin(mrows, MAX(mcols, (int)c - 4), y + 1, x + 2); /* set the color */ wbkgd(ww->fwin, COLOR_PAIR(wo->window_color)); keypad(ww->fwin, TRUE); /* associate with the form */ set_form_win(ww->form, ww->fwin); /* the subwin for the form */ set_form_sub(ww->form, derwin(ww->fwin, mrows + 1, mcols, 1, 1)); /* make the active field in reverse mode */ set_field_back(current_field(ww->form), A_REVERSE); /* display the form */ post_form(ww->form); wnoutrefresh(ww->fwin); }
void call_list_form_activate(PANEL *panel, int active) { call_list_info_t *info = call_list_info(panel); // Store form state info->form_active = active; if (active) { set_current_field(info->form, info->fields[FLD_LIST_FILTER]); // Show cursor curs_set(1); // Change current field background set_field_back(info->fields[FLD_LIST_FILTER], A_REVERSE); } else { set_current_field(info->form, NULL); // Hide cursor curs_set(0); // Change current field background set_field_back(info->fields[FLD_LIST_FILTER], A_NORMAL); } post_form(info->form); form_driver(info->form, REQ_END_LINE); }
void viewNewPlayer(FootBallGame::TeamNumber teamNumber) { const char *itemName; const ITEM *currentItem; const int window_nlines = 10, window_ncols = 90; char *choices[] = { "Add", "Cancel", }; for (;;) { // Create new window. WINDOW *window = newwin(window_nlines, window_ncols, headerWindow_begin_y + headerWindow_nlines + 1, 0); // Set new window options. keypad(window, TRUE); // Create the form fields FIELD *field[6]; for (unsigned i = 0; i < ARRAY_SIZE(field)-1; i++) field[i] = new_field(1, 26, i+2, 23, 0, 0); field[ARRAY_SIZE(field)-1] = NULL; // Set feild options for (unsigned i = 0; i < ARRAY_SIZE(field)-1; i++) { set_field_back(field[i], A_UNDERLINE); field_opts_off(field[i], O_AUTOSKIP); } // Set the field types set_field_type(field[0], TYPE_REGEXP, "^[A-Za-z ]*$"); set_field_type(field[1], TYPE_INTEGER, 0, 1, 999); set_field_type(field[2], TYPE_REGEXP, "^[A-Za-z ]*$"); set_field_type(field[3], TYPE_NUMERIC, 2, 1.00, 1500.00); set_field_type(field[4], TYPE_NUMERIC, 2, 1.00, 300.00); // Create the form FORM *form = new_form(field); set_form_win(form, window); set_form_sub(form, derwin(window, 10, 90, 0, 0)); // Setup the menu items int nChoices = ARRAY_SIZE(choices)+1; ITEM **items = new ITEM* [nChoices]; for (int i = 0; i < nChoices-1; i++) items[i] = new_item(choices[i], NULL); items[nChoices-1] = NULL; // Create the menu MENU *menu = new_menu(items); // Menu options set_menu_format(menu, 1, 2); set_menu_mark(menu, NULL); // Attach the menu to the window set_menu_win(menu, window); set_menu_sub(menu, derwin(window, 1, 20, 8, 17)); // Make window and menu visible; post_form(form); post_menu(menu); mvwprintw(window, 0, 10, "Player Properties: "); mvwprintw(window, 2, 10, "Name: "); mvwprintw(window, 3, 10, "Number: "); mvwprintw(window, 4, 10, "Position: "); mvwprintw(window, 5, 10, "weight (kg): "); mvwprintw(window, 6, 10, "height (cm): "); wrefresh(window); refresh(); // Start user interaction loop. int c; // The restart variable is used to tell the function to rebuild the // menu by starting at the top of the for(;;) loop above. bool restart = false; while (!restart && (c = wgetch(window))) { mvprintw(LINES-1, 0, " "); refresh(); switch(c) { case KEY_DOWN: case 0x09: // Go to next field form_driver(form, REQ_NEXT_FIELD); // GO to the end of the presend buffer // Leaves nicely at the last character form_driver(form, REQ_END_LINE); break; case KEY_UP: // Go to previous field form_driver(form, REQ_PREV_FIELD); form_driver(form, REQ_END_LINE); break; case 0x7F: form_driver(form, REQ_DEL_PREV); break; case KEY_LEFT: menu_driver(menu, REQ_LEFT_ITEM); break; case KEY_RIGHT: menu_driver(menu, REQ_RIGHT_ITEM); break; case 10: // When the user hits enter determine the currently selected // item and do nessary actions. currentItem = current_item(menu); itemName = item_name(currentItem); // Cancel if (strncmp(itemName, choices[1], strlen(choices[1])) == 0) { // Delete allocated data unpost_form(form); unpost_menu(menu); free_form(form); free_menu(menu); for (unsigned i = 0; i < ARRAY_SIZE(field)-1; i++) free_field(field[i]); for (int i = 0; i < nChoices; i++) free_item(items[i]); delete [] items; delwin(window); return; } else if (strncmp(itemName, choices[0], strlen(choices[0])) == 0) { form_driver(form, REQ_VALIDATION); bool invalid = false; for (unsigned i = 0; i < ARRAY_SIZE(field)-1; i++) if (field_status(field[i])==false) invalid = true;; if (invalid == false) { FootBallPlayer *player = new FootBallPlayer; player->setName(field_buffer(field[0], 0)); player->setNumber(atoi(field_buffer(field[1], 0))); player->setPosition(field_buffer(field[2], 0)); player->setWeight(strtof(field_buffer(field[3], 0), NULL)); player->setHeight(strtof(field_buffer(field[4], 0), NULL)); FootBallTeam *team = game.getFootBallTeam(teamNumber); if (team == NULL) { team = new FootBallTeam; game.setFootBallTeam(teamNumber, team); } team->addFootBallPlayer(player); // Delete allocated data unpost_form(form); unpost_menu(menu); free_form(form); free_menu(menu); for (unsigned i = 0; i < ARRAY_SIZE(field)-1; i++) free_field(field[i]); for (int i = 0; i < nChoices; i++) free_item(items[i]); delete [] items; delwin(window); return; } else { mvprintw(LINES-1, 0, "Fill out the form correctly!!"); refresh(); } } break; default: // If this is a normal character, it gets // printed form_driver(form, c); break; } } } }
void viewEditTeamProperties(FootBallGame::TeamNumber teamNumber) { const char *fieldBuffer; const ITEM *currentItem; const char *itemName; ITEM **items; const int window_nlines = 10, window_ncols = 90; char *choices[] = { "Ok", "Cancel", }; for(;;) { // Create new window. WINDOW *window = newwin(window_nlines, window_ncols, headerWindow_begin_y + headerWindow_nlines + 1, 0); // Set new window options. keypad(window, TRUE); // Team the team FootBallTeam *team = game.getFootBallTeam(teamNumber); // Create the form fields FIELD *field[2]; field[0] = new_field(1, 20, 2, 22, 0, 0); field[1] = NULL; // Set feild options set_field_back(field[0], A_UNDERLINE); field_opts_off(field[0], O_AUTOSKIP); set_field_type(field[0], TYPE_REGEXP, "^[A-Za-z ]*$"); if (team) { String teamName = team->getTeamName(); set_field_buffer(field[0], 0, teamName.c_str()); } // Create the form FORM *form = new_form(field); // Attach the form to the window set_form_win(form, window); set_form_sub(form, derwin(window, 4, 90, 0, 0)); // Setup the menu int nChoices = ARRAY_SIZE(choices)+1; items = new ITEM* [nChoices]; for (int i = 0; i < nChoices-1; i++) items[i] = new_item(choices[i], NULL); items[nChoices-1] = NULL; // Create the menu MENU *menu = new_menu(items); // Menu options set_menu_format(menu, 1, 2); set_menu_mark(menu, NULL); // Attach the menu to the window set_menu_win(menu, window); set_menu_sub(menu, derwin(window, 1, 20, 4, 17)); // Make window and menu visible; post_form(form); post_menu(menu); mvwprintw(window, 0, 10, "Team Properties: "); mvwprintw(window, 2, 10, "Team Name: "); wrefresh(window); refresh(); // Start user interaction loop. int c; // The restart variable is used to tell the function to rebuild the // menu by starting at the top of the for(;;) loop above. bool restart = false; while (!restart && (c = wgetch(window))) { switch(c) { case KEY_DOWN: case 0x09: // Go to next field form_driver(form, REQ_NEXT_FIELD); // GO to the end of the presend buffer // Leaves nicely at the last character form_driver(form, REQ_END_LINE); break; case KEY_UP: // Go to previous field form_driver(form, REQ_PREV_FIELD); form_driver(form, REQ_END_LINE); break; case 0x7F: form_driver(form, REQ_DEL_PREV); break; case KEY_LEFT: menu_driver(menu, REQ_LEFT_ITEM); break; case KEY_RIGHT: menu_driver(menu, REQ_RIGHT_ITEM); break; case 10: // Enter // When the user hits enter determine the currently selected // item and do nessary actions. currentItem = current_item(menu); itemName = item_name(currentItem); if (strcmp(itemName, choices[0]) == 0) { form_driver(form, REQ_VALIDATION); fieldBuffer = field_buffer(field[0], 0); if (fieldBuffer != NULL && strcmp(fieldBuffer, "") != 0) { if (team == NULL) { team = new FootBallTeam; game.setFootBallTeam(teamNumber, team); } team->setTeamName(fieldBuffer); } } // Delete allocated data delwin(window); unpost_form(form); free_form(form); unpost_menu(menu); free_menu(menu); for (unsigned i = 0; i < ARRAY_SIZE(field); i++) free_field(field[i]); for (int i = 0; i < nChoices-1; i++) free_item(items[i]); delete[] items; return; default: // If this is a normal character, it gets printed. form_driver(form, c); break; } } } }
void actions_dataentry_scr(const char *curr_path, const char *case_num) { const size_t n_fields = 4; const size_t starty = 6; const size_t startx = 25; FIELD *field[n_fields]; FORM *my_form; Action_t record; int width[] = { MAX_ACT_DATE - 1, MAX_ACT_TYPE, MAX_ACT_NOTE - 200 }; int height[] = { 1, 1, 4 }; for ( size_t i = 0; i < n_fields - 1; ++i ) field[i] = new_field(height[i], width[i], starty + i * 2, startx, 0, 0); field[n_fields - 1] = NULL; set_field_back( field[0], A_UNDERLINE ); field_opts_off( field[0], O_AUTOSKIP ); set_field_back( field[1], A_UNDERLINE ); field_opts_off( field[1], O_AUTOSKIP ); set_field_back( field[2], A_UNDERLINE ); field_opts_off( field[2], O_AUTOSKIP ); field_opts_off( field[2], O_STATIC ); set_max_field( field[2], MAX_ACT_NOTE ); my_form = new_form(field); post_form(my_form); refresh(); int note_count = MAX_ACT_NOTE; char note_msg[4]; char date_str[MAX_ACT_DATE]; get_curr_date( date_str ); mvprintw( 0, 0, curr_path ); mvprintw( 4, 10, "Case Number: %s", case_num ); mvprintw( 6, 10, "Entry Date: " ); mvprintw( 8, 10, "Type: " ); mvprintw( 10, 10, "Note: " ); mvprintw( 15, 77, "%d", note_count ); mvprintw( 16, 10, "(F2) = Add | (ESC) = Previous Screen" ); set_visible_fields( field, 1, 3 ); size_t actions_count = actions_list( case_num ); move( 6, 25 ); set_field_buffer( field[0], 0, date_str ); set_current_field( my_form, field[0] ); record.id = 0; int ch; do { ch = getch(); switch ( ch ) { case KEY_UP: form_driver(my_form, REQ_PREV_FIELD); form_driver(my_form, REQ_END_LINE); break; case KEY_LEFT: form_driver(my_form, REQ_LEFT_CHAR); break; case KEY_RIGHT: form_driver(my_form, REQ_RIGHT_CHAR); break; case KEY_BACKSPACE: { FIELD * curr_fld = current_field( my_form ); if ( curr_fld == field[2] ) { snprintf( note_msg, 4, "%d", ++note_count ); display_msg( 15, 77, my_form, curr_fld, note_msg ); } } form_driver(my_form, REQ_PREV_CHAR); form_driver(my_form, REQ_DEL_CHAR); break; case DEL: { FIELD * curr_fld = current_field( my_form ); if ( curr_fld == field[2] ) { snprintf( note_msg, 4, "%d", ++note_count ); display_msg( 15, 77, my_form, curr_fld, note_msg ); } } form_driver( my_form, REQ_DEL_CHAR ); break; case ENTER: form_driver( my_form, REQ_NEXT_FIELD ); form_driver( my_form, REQ_END_LINE ); break; case KEY_F(1): { FIELD * curr_fld = current_field( my_form ); if ( curr_fld == field[1] ) { if ( query_select_all_codes_from_action_types() ) { clear_line(18, 10); mvprintw( 18, 10, db_get_error_msg() ); } else { const Code_t const * code_ptr; size_t count = 0; mvprintw( 8, 75, "Type Options:" ); while ( ( code_ptr = get_code_from_result() ) != NULL ) mvprintw( 9 + count++, 81, "[%d] %s", code_ptr->code, code_ptr->desc ); free_code_result(); int row, col; get_cursor_pos( curr_fld, &row, &col ); move( row, col ); set_current_field( my_form, curr_fld ); } } } break; case KEY_F(2): { clear_line( 18, 10 ); strncpy( record.case_num, case_num, MAX_CANUM ); strncpy( record.entry_date, compress_str( field_buffer(field[0], 0) ), MAX_ACT_DATE ); record.type = atoi( compress_str( field_buffer(field[1], 0) ) ); strncpy( record.note, field_buffer(field[2], 0), MAX_ACT_NOTE ); if ( is_empty_str( record.note, MAX_ACT_NOTE ) ) { mvprintw( 18, 10, "[!] Action must at least have a note." ); move( 10, 25 ); set_current_field( my_form, field[2] ); break; } if ( query_add_action( &record ) ) { mvprintw( 18, 10, db_get_error_msg() ); } else { clear_fields( field, 0, 2 ); actions_count++; print_action( &record, actions_count ); note_count = MAX_ACT_NOTE; mvprintw( 15, 77, "%d", note_count ); } move( 6, 25 ); set_current_field( my_form, field[0] ); } break; default: { FIELD * curr_fld = current_field( my_form ); if ( ch == '\'' ) break; if ( curr_fld == field[1] ) { if ( !isdigit( ch ) ) break; } else if ( curr_fld == field[2] ) { snprintf( note_msg, 4, "%d", --note_count ); display_msg( 15, 77, my_form, curr_fld, note_msg ); } } form_driver( my_form, ch ); break; } } while ( ch != ESC ); unpost_form( my_form ); free_form( my_form ); for ( size_t i = 0; i < n_fields - 1; ++i ) free_field( field[i] ); return; }
void actions_menu(const char *curr_path) { const char *screen_title = "Actions"; FIELD *field[2]; FORM *my_form; initscr(); curs_set(1); cbreak(); clear(); noecho(); keypad(stdscr, TRUE); field[0] = new_field( 1, MAX_CANUM, 4, 25, 0, 0 ); field[1] = NULL; set_field_back(field[0], A_UNDERLINE); field_opts_off(field[0], O_AUTOSKIP); field_opts_on(field[0], O_BLANK); my_form = new_form(field); post_form(my_form); refresh(); mvprintw( 0, 0, menu_path( curr_path, screen_title ) ); mvprintw( 2, 10, "Enter case number then press (Enter) to start. | (F4) = Exit" ); mvprintw( 4, 10, "Case Num: " ); refresh(); move( 4, 25 ); set_current_field( my_form, field[0] ); int done = 0; int ch; do { ch = getch(); switch ( ch ) { case KEY_LEFT: form_driver(my_form, REQ_LEFT_CHAR); break; case KEY_RIGHT: form_driver(my_form, REQ_RIGHT_CHAR); break; case KEY_BACKSPACE: form_driver(my_form, REQ_PREV_CHAR); form_driver(my_form, REQ_DEL_CHAR); break; case DEL: form_driver( my_form, REQ_DEL_CHAR ); break; case ENTER: { size_t count = 0; char case_num[MAX_CANUM]; form_driver(my_form, REQ_NEXT_FIELD); strcpy(case_num, compress_str(field_buffer(field[0], 0) )); if ( query_select_count_from_case_for(case_num, &count) ) { clear_line(20, 10); mvprintw( 20, 10, db_get_error_msg() ); move( 4, 25 ); } else { if ( count ) { actions_dataentry_scr( menu_path( curr_path, screen_title ), case_num ); done = 1; break; } } } break; default: if ( ch == '\'' ) break; form_driver( my_form, ch ); break; } } while ( ( ch != KEY_F(4) ) && ( done != 1 ) ); unpost_form( my_form ); free_form( my_form ); free_field( field[0] ); endwin(); return; }
void summons_dataentry_scr(const char *curr_path, const char *case_num) { const size_t n_fields = 6; const size_t starty = 6; const size_t startx = 25; FIELD *field[n_fields]; FORM *my_form; Summon_t record; int width[] = { MAX_SUMM_NAME, MAX_SUMM_STATUS, MAX_SUMM_REASON, MAX_SUMM_CITY, MAX_SUMM_DATE }; for ( size_t i = 0; i < n_fields - 1; ++i ) field[i] = new_field(1, width[i], starty + i * 2, startx, 0, 0); field[n_fields - 1] = NULL; set_field_back( field[0], A_UNDERLINE ); field_opts_off( field[0], O_AUTOSKIP ); set_field_back( field[1], A_UNDERLINE ); field_opts_on( field[1], O_BLANK ); field_opts_off( field[1], O_AUTOSKIP ); set_field_back( field[2], A_UNDERLINE ); field_opts_off( field[2], O_AUTOSKIP ); field_opts_on( field[2], O_BLANK ); set_field_back( field[3], A_UNDERLINE ); field_opts_off( field[3], O_AUTOSKIP ); field_opts_on( field[3], O_BLANK ); set_field_back( field[4], A_UNDERLINE ); field_opts_off( field[4], O_AUTOSKIP ); my_form = new_form(field); post_form(my_form); refresh(); mvprintw( 0, 0, curr_path ); mvprintw( 4, 10, "Case Number: %s", case_num ); mvprintw( 6, 10, "Person: " ); mvprintw( 8, 10, "Status: " ); mvprintw( 10, 10, "Reason: " ); mvprintw( 12, 10, "City: " ); mvprintw( 14, 10, "Date Summoned: " ); mvprintw( 16, 10, "(F1) = Options | (F2) = Update | (F3) = Delete | (F5) = List | (ESC) = Main Menu" ); set_visible_fields( field, 1, 5 ); move( 6, 25 ); set_current_field( my_form, field[0] ); record.id = 0; int ch; do { ch = getch(); switch ( ch ) { case KEY_UP: form_driver(my_form, REQ_PREV_FIELD); form_driver(my_form, REQ_END_LINE); break; case KEY_LEFT: form_driver(my_form, REQ_LEFT_CHAR); break; case KEY_RIGHT: form_driver(my_form, REQ_RIGHT_CHAR); break; case KEY_BACKSPACE: form_driver(my_form, REQ_PREV_CHAR); form_driver(my_form, REQ_DEL_CHAR); break; case ENTER: form_driver( my_form, REQ_NEXT_FIELD ); if ( current_field( my_form ) == field[0] ) form_driver( my_form, REQ_END_LINE ); break; case KEY_F(1): clear_lines( 20, 40 ); { FIELD * curr_fld = current_field( my_form ); size_t error = 0; size_t in_target_fld = 0; char fld_name[7]; if ( curr_fld == field[1] ) { error = query_select_all_codes_from_summon_status(); in_target_fld = 1; strncpy( fld_name, "Status", 7 ); } else if ( curr_fld == field[2] ) { error = query_select_all_codes_from_summon_reasons(); in_target_fld = 1; strncpy( fld_name, "Reason", 7 ); } else if ( curr_fld == field[3] ) { if ( query_select_all_codes_from_city_rates() ) { clear_line(20, 10); mvprintw( 20, 10, db_get_error_msg() ); move( 12, 25 ); set_current_field( my_form, curr_fld ); } else { const SCode_t const * scode_ptr; size_t count = 0; size_t column = 10; mvprintw( 20, 5, "Cities:" ); while ( ( scode_ptr = get_scode_from_result() ) != NULL ) { mvprintw( 21 + count++, column, "[%s] %s", scode_ptr->code, scode_ptr->name ); if ( count == 30 ) { column += 20; count = 0; } } free_scode_result(); } } if ( !error && in_target_fld ) { const Code_t const * code_ptr; size_t count = 0; mvprintw( 20, 5, "%s Options:", fld_name ); while ( ( code_ptr = get_code_from_result() ) != NULL ) mvprintw( 21 + count++, 10, "[%d] %s", code_ptr->code, code_ptr->desc ); free_code_result(); } int row, col; get_cursor_pos( curr_fld, &row, &col ); move( row, col ); set_current_field( my_form, curr_fld ); } break; case KEY_F(2): clear_lines( 20, 40 ); char person_name[MAX_SUMM_NAME]; strncpy( person_name, field_buffer(field[0], 0), MAX_SUMM_NAME ); if ( is_empty_str( person_name, MAX_SUMM_NAME ) ) { mvprintw( 20, 10, "[!] Summon must at least have the person's name." ); move( 6, 25 ); set_current_field( my_form, field[0] ); break; } strncpy( record.case_num, case_num, MAX_CANUM ); strncpy( record.name, field_buffer(field[0], 0), MAX_SUMM_NAME ); record.status = atoi( compress_str( field_buffer(field[1], 0) ) ); record.reason = atoi( compress_str( field_buffer(field[2], 0) ) ); strncpy( record.city_code, compress_str( field_buffer(field[3], 0) ), MAX_SUMM_CITY ); strncpy( record.summon_date, compress_str( field_buffer(field[4], 0) ), MAX_SUMM_DATE ); if ( query_update_summon( &record ) ) { mvprintw( 20, 10, db_get_error_msg() ); move( 6, 25 ); set_current_field( my_form, field[0] ); } else { clear_fields( field, 0, 4 ); mvprintw( 20, 10, "[!] Summon has been updated." ); move( 6, 25 ); set_current_field( my_form, field[0] ); record.id = 0; } break; case KEY_F(3): clear_lines( 20, 40 ); if ( record.id > 0 ) { mvprintw( 20, 10, "[?] Delete summon '%u' ? [Y/n]", record.id ); int ch = toupper( getch() ); if ( ch == 'Y' ) { if ( query_delete_summon( record.id ) ) { mvprintw( 20, 10, db_get_error_msg() ); } else { clear_fields( field, 0, 4 ); mvprintw( 20, 10, "[!] Summon '%u' has been deleted.", record.id ); move( 6, 25 ); set_current_field( my_form, field[0] ); record.id = 0; } } } break; case KEY_F(5): clear_lines( 20, 40 ); if ( query_select_all_from_summons_for( case_num ) ) { mvprintw( 20, 10, db_get_error_msg() ); } else { Summon_t *summ_ptr; Summon_t *summons[MAX_SUMM_SET]; size_t count = 0; while ( ( summ_ptr = get_summon_from_result() ) != NULL ) { summons[count] = summ_ptr; count++; } if ( count ) { size_t selection; char code_buff[4]; summons_list_scr( summons, count, &selection ); if ( selection > 0 ) { summ_ptr = summons[selection - 1]; record.id = summ_ptr->id; set_field_buffer( field[0], 0, summ_ptr->name ); snprintf( code_buff, 4, "%d", summ_ptr->status ); set_field_buffer( field[1], 0, code_buff ); snprintf( code_buff, 4, "%d", summ_ptr->reason ); set_field_buffer( field[2], 0, code_buff ); set_field_buffer( field[3], 0, summ_ptr->city_code ); set_field_buffer( field[4], 0, summ_ptr->summon_date ); } free_summon_result(); } else { mvprintw( 20, 10, "[!] Case %s has no summons.", case_num ); } } set_current_field( my_form, field[0] ); move( 6, 25 ); break; default: { FIELD * curr_fld = current_field( my_form ); if ( ch == '\'' ) break; if ( curr_fld == field[1] || curr_fld == field[2] ) { if ( !isdigit( ch ) ) break; } else if ( curr_fld == field[3] ) { if ( !isalpha( ch ) ) break; else ch = toupper( ch ); } form_driver( my_form, ch ); break; } } } while ( ch != ESC ); unpost_form( my_form ); free_form( my_form ); for ( size_t i = 0; i < n_fields - 1; ++i ) free_field( field[i] ); return; }
void cases_menu(const char *curr_path) { const char *screen_title = "Cases"; const size_t n_fields = 7; const size_t starty = 4; const size_t startx = 25; FIELD *field[n_fields]; FORM *my_form; int width[] = { MAX_CANUM, MAX_CINUM, MAX_PHYADD, MAX_POSADD, MAX_STATUS, MAX_DELDATE }; initscr(); curs_set(1); cbreak(); clear(); noecho(); keypad(stdscr, TRUE); for (size_t i = 0; i < n_fields - 1; ++i) { field[i] = new_field(1, width[i], starty + i * 2, startx, 0, 0); } field[n_fields - 1] = NULL; set_field_back(field[0], A_UNDERLINE); field_opts_off(field[0], O_AUTOSKIP); field_opts_on(field[0], O_BLANK); set_field_back(field[1], A_UNDERLINE); field_opts_off(field[1], O_AUTOSKIP); set_field_back(field[2], A_UNDERLINE); field_opts_off(field[2], O_AUTOSKIP); set_field_back(field[3], A_UNDERLINE); field_opts_off(field[3], O_AUTOSKIP); set_field_back(field[4], A_UNDERLINE); field_opts_off(field[4], O_AUTOSKIP); set_field_back(field[5], A_UNDERLINE); field_opts_off(field[5], O_AUTOSKIP); my_form = new_form(field); post_form(my_form); refresh(); mvprintw(0, 0, menu_path(curr_path, screen_title)); mvprintw(4, 10, "Case Num: "); mvprintw(6, 10, "Civil Num: "); mvprintw(8, 10, "Physical Add: "); mvprintw(10, 10, "Postal Add: "); mvprintw(12, 10, "Status: "); mvprintw(14, 10, "Delivery Date: "); mvprintw(16, 10, "(F1) = Options | (F2) = Update | (F3) = Delete | (F4) = Exit"); move(4, 25); refresh(); int ch; do { ch = getch(); switch(ch) { case KEY_UP: form_driver(my_form, REQ_PREV_FIELD); form_driver(my_form, REQ_END_LINE); break; case KEY_LEFT: form_driver(my_form, REQ_LEFT_CHAR); break; case KEY_RIGHT: form_driver(my_form, REQ_RIGHT_CHAR); break; case ENTER: form_driver( my_form, REQ_NEXT_FIELD ); form_driver( my_form, REQ_END_LINE ); if (field_status(field[0])) { size_t count = 0; char case_num[MAX_CANUM]; clear_line( 20, 10 ); strcpy( case_num, compress_str(field_buffer(field[0], 0) ) ); if ( query_select_count_from_case_for(case_num, &count) ) { mvprintw( 20, 10, db_get_error_msg() ); move( 4, 25 ); } else { if ( count ) { //call routine to fill in fields Case_t record; if ( query_select_all_from_case_for(case_num, &record) ) { mvprintw( 20, 10, db_get_error_msg() ); move( 4, 25 ); } else { char status_buff[4]; set_field_buffer( field[1], 0, record.civil ); set_field_buffer( field[2], 0, record.physical_add ); set_field_buffer( field[3], 0, record.postal_add ); snprintf( status_buff, 4, "%d", record.status ); set_field_buffer( field[4], 0, status_buff ); set_field_buffer( field[5], 0, record.delivery_date ); } } else { clear_fields( field, 1, 5 ); mvprintw( 20, 10, "[!] Case %s does not exist.", case_num ); move( 6, 25 ); set_current_field( my_form, field[0] ); } } set_field_status( field[0], 0 ); } break; case KEY_BACKSPACE: form_driver(my_form, REQ_PREV_CHAR); form_driver(my_form, REQ_DEL_CHAR); break; case ESC: { FIELD * curr_field = current_field( my_form ); int row, col; get_cursor_pos( curr_field, &row, &col ); clear_lines( 20, 40 ); move( row, col ); set_current_field( my_form, curr_field ); } break; case KEY_F(1): if ( current_field( my_form ) == field[4] ) { clear_lines( 20, 30 ); if ( query_select_all_codes_from_case_status() ) { mvprintw( 20, 10, db_get_error_msg() ); } else { const Code_t const * code_ptr; size_t count = 0; mvprintw( 20, 5, "Status Options:" ); while ( ( code_ptr = get_code_from_result() ) != NULL ) { mvprintw( 21 + count, 10, "[%d] %s", code_ptr->code, code_ptr->desc ); count++; } free_code_result(); move( 12, 25 ); set_current_field( my_form, field[4] ); } } break; case KEY_F(2): { size_t count = 0; char case_num[MAX_CANUM]; clear_lines( 20, 30 ); strncpy( case_num, compress_str(field_buffer(field[0], 0) ), MAX_CANUM ); if ( query_select_count_from_case_for( case_num, &count ) ) { mvprintw( 20, 10, db_get_error_msg() ); } else { Case_t record; strncpy( record.number, compress_str(field_buffer(field[0], 0)), MAX_CANUM ); strncpy( record.civil, compress_str(field_buffer(field[1], 0)), MAX_CINUM ); strncpy( record.physical_add, field_buffer(field[2], 0), MAX_PHYADD ); strncpy( record.postal_add, field_buffer(field[3], 0), MAX_POSADD ); record.status = atoi( compress_str(field_buffer(field[4], 0)) ); strncpy( record.delivery_date, compress_str(field_buffer(field[5], 0)), MAX_DELDATE ); if ( count ) { // update existing record if ( query_update_case( &record ) == 0 ) { mvprintw( 20, 10, "[!] Case has been updated." ); } else { mvprintw( 20, 10, db_get_error_msg() ); } } else { // create new record if ( query_create_new_case( &record ) == 0 ) { mvprintw (20, 10, "[!] Case has been created successfully." ); } else { mvprintw( 20, 10, db_get_error_msg() ); } } } move(4, 25); set_current_field( my_form, field[0] ); } break; case KEY_F(3): { size_t count = 0; char case_num[MAX_CANUM]; clear_lines(20, 30); strncpy(case_num, compress_str(field_buffer(field[0], 0) ), MAX_CANUM); if ( strlen(case_num) ) { if ( query_select_count_from_case_for(case_num, &count) ) { mvprintw( 20, 10, db_get_error_msg() ); } else { if (count) { mvprintw(20, 10, "[?] Delete case '%s' ? [Y/n]", case_num); int ch = toupper(getch()); if (ch == 'Y') { if ( query_delete_case(case_num) ) { mvprintw( 20, 10, db_get_error_msg() ); } else { clear_fields(field, 0, 5); mvprintw(20, 10, "[!] Case '%s' has been deleted."); } } } else { mvprintw(20, 10, "[!] Case '%s' does not exist.", case_num); } } } else { mvprintw(20, 10, "[!] Must enter a valid Case Number to be deleted."); } } move(4, 25); set_current_field(my_form, field[0]); break; case DEL: form_driver(my_form, REQ_DEL_CHAR); break; default: { FIELD * curr_fld = current_field( my_form ); if ( ch == '\'' ) break; if ( curr_fld == field[4] ) { if ( !isdigit( ch ) ) break; } } form_driver(my_form, ch); break; } } while( ch != KEY_F(4) ); unpost_form(my_form); free_form(my_form); for (size_t i = 0; i < n_fields -1; ++i) { free_field(field[i]); } endwin(); return; }
int kullanici_onayla() { FIELD *field[3]; FORM *my_form; int ch; touchwin(ana_win); wrefresh(ana_win); init_pair(1, COLOR_WHITE, COLOR_BLUE); init_pair(2, COLOR_WHITE, COLOR_BLUE); /*calisma yili 4 karakter*/ field[0] = new_field(1, 10, 18, 42, 0, 0); /*firma 2 karakter*/ field[1] = new_field(1, 10, 20, 42, 0, 0); field[2] = NULL; set_field_fore(field[0], COLOR_PAIR(1)); set_field_fore(field[1], COLOR_PAIR(1)); /*geri plan rengi olsun*/ set_field_back(field[0], COLOR_PAIR(2)); set_field_back(field[1], COLOR_PAIR(2)); /* set_field_type(field[0], TYPE_INTEGER); set_field_type(field[1], TYPE_INTEGER); */ field_opts_off(field[0], O_AUTOSKIP); field_opts_off(field[1], O_AUTOSKIP); /*sifre alani olan ikinci field password biçiminde olmali/ field_opts_off(field[1], O_PUBLIC); /*geri plan rengi olmasin*/ /* set_field_back(field[0], A_UNDERLINE); set_field_back(field[1], A_UNDERLINE); */ my_form = new_form(field); post_form(my_form); refresh(); set_current_field(my_form, field[0]); mvprintw(18, 25, _("User name :") ); mvprintw(20, 25, _("Password :"******"This application under GPL license.") ); attroff(A_BLINK); attroff(A_BOLD); attron(A_BOLD); mvprintw(LINES-3, 5, _("F2-> Begin ESC-> Cancel") ); mvprintw(18, 5, _("F5-> Settings") ); attroff(A_BOLD); mvprintw(7,3, _(" Acik ")); mvprintw(8,3," _| _| _| "); mvprintw(9,3," _|_|_| _| _|_| _|_|_|_| _|_|_| _|_| _|_| "); mvprintw(10,3," _| _|_| _| _|_|_|_| _| _| _| _| _|_|_|_| "); mvprintw(11,3," _| _|_| _| _| _| _| _| _| _| "); mvprintw(12,3," _| _|_|_| _| _|_|_| _|_| _| _| _| _|_|_| "); refresh(); while((ch = getch()) ) { switch(ch) { case 8: /*KEY_BACKSPACE hatali kod vermekte 8 dogru olandir konsolda 8 xterm key_backspace*/ form_driver(my_form, REQ_PREV_CHAR); form_driver(my_form, REQ_DEL_CHAR); break; case KEY_BACKSPACE: form_driver(my_form, REQ_PREV_CHAR); form_driver(my_form, REQ_DEL_CHAR); break; case 9: /*TAB tusuna basýlmasý durumunda sonraki field konumlan*/ form_driver(my_form, REQ_NEXT_FIELD); form_driver(my_form, REQ_END_LINE); break; case 10: /*ENTER tuþuna basýlmasý durumunda sonraki feild gececek*/ form_driver(my_form, REQ_NEXT_FIELD); form_driver(my_form, REQ_END_LINE); break; case KEY_DC: /*del tusu*/ form_driver(my_form,REQ_DEL_CHAR); break; case KEY_HOME: form_driver(my_form,REQ_BEG_LINE); break; case KEY_END: form_driver(my_form,REQ_END_LINE); break; case KEY_DOWN: form_driver(my_form, REQ_NEXT_FIELD); form_driver(my_form, REQ_END_LINE); break; case KEY_UP: form_driver(my_form, REQ_PREV_FIELD); form_driver(my_form, REQ_END_LINE); break; case KEY_LEFT: form_driver(my_form,REQ_LEFT_CHAR); break; case KEY_RIGHT: form_driver(my_form,REQ_RIGHT_CHAR); break; case 27: /*esc durumunda*/ unpost_form(my_form); free_form(my_form); free_field(field[0]); free_field(field[1]); endwin(); exit(0); break; case KEY_F(5): /*ayarlara gecis*/ ayarlar(); unpost_form(my_form); free_form(my_form); free_field(field[0]); free_field(field[1]); endwin(); exit (0); break; case KEY_F(2): /*f2 durumunda*/ form_driver(my_form, REQ_PREV_FIELD); strcpy(query, "select kullanici, sifre, haklar from kullanicilar"); if ( pgsql_sorgula(query) ==1 ) { mesaj(sql_sorgulama_hatasi); return 1;} for (i=0;i<pgsql_row_miktar;i++) { sprintf(kullanici,"%s", pgsql_kayit_field() ); sprintf(sifre,"%s", pgsql_kayit_field() ); sprintf(haklar,"%s", pgsql_kayit_field() ); if ( strcmp(g_strstrip(field_buffer(field[0],0)), kullanici) ==NULL ) { if ( (sifre_kripto_coz( g_strstrip(field_buffer(field[1],0)) , sifre) == 0) || (strcmp(g_strstrip(field_buffer(field[1],0)), sifre) == NULL ) ) { //kullanýcý root ise haklar full olmalý //databaseden degistirme ihtimali olabilir if ( strstr( kullanici, "root") ) {sprintf(haklar,"%s", "1111111111111111111111111111111111111111111111111111111111111111");} beep(); unpost_form(my_form); free_form(my_form); free_field(field[0]); free_field(field[1]); touchwin(ana_win); wrefresh(ana_win); return; } else { set_field_buffer(field[0],0," "); set_field_buffer(field[1],0," "); refresh(); //beep sesi beep(); } } } break; default: form_driver(my_form, ch); break; } } return 0; /*son*/ }
char *input_box(size_t length, const char *title, const char *description) { WINDOW *ib_win = NULL; PANEL *my_panels[1]; FIELD **fields; FORM *my_form = NULL; int height, width, startx, starty, max_height, max_width, ch = 0, rows, cols, quit = 0, i; char *result_ptr = NULL, *temp_ptr = NULL; /* create a buffer with the size of 'length' */ if (!(temp_ptr = malloc(length))) { vrmr_error(-1, VR_ERR, gettext("malloc failed: %s"), strerror(errno)); return (NULL); } // set the window size getmaxyx(stdscr, max_height, max_width); height = 8; if (length < 16) { width = 37; // minimum TODO: why 37? } else if ((int)length + 8 > max_width) { free(temp_ptr); return NULL; } else { width = (int)length + 8; if ((int)StrLen(title) + 8 > width) width = (int)StrLen(title) + 8; if ((int)StrLen(description) + 8 > width) width = (int)StrLen(description) + 8; } // print on the centre of the screen starty = (max_height - height) / 2; startx = (max_width - width) / 2; // create window ib_win = create_newwin( height, width, starty, startx, title, vccnf.color_win); my_panels[0] = new_panel(ib_win); fields = (FIELD **)calloc(1 + 1, sizeof(FIELD *)); fields[0] = new_field_wrap( 1, (int)length - 1, 3, (int)(((width - length) / 2) - 2), 0, 0); set_field_back(fields[0], vccnf.color_win_rev); field_opts_off(fields[0], O_AUTOSKIP); set_field_status(fields[0], FALSE); my_form = new_form(fields); scale_form(my_form, &rows, &cols); keypad(ib_win, TRUE); set_form_win(my_form, ib_win); set_form_sub(my_form, derwin(ib_win, rows, cols, 1, 2)); post_form(my_form); mvwprintw(ib_win, 2, 4, "%s", description); mvwprintw(ib_win, 6, 4, gettext("Note: whitespaces not allowed.")); update_panels(); doupdate(); while (quit == 0) { ch = wgetch(ib_win); switch (ch) { case 27: case KEY_F(10): case 10: // enter // Go to next field form_driver_wrap(my_form, REQ_NEXT_FIELD); form_driver_wrap(my_form, REQ_END_LINE); quit = 1; break; case KEY_BACKSPACE: case 127: form_driver_wrap(my_form, REQ_PREV_CHAR); form_driver_wrap(my_form, REQ_DEL_CHAR); form_driver_wrap(my_form, REQ_END_LINE); break; case KEY_DC: form_driver_wrap(my_form, REQ_PREV_CHAR); form_driver_wrap(my_form, REQ_DEL_CHAR); form_driver_wrap(my_form, REQ_END_LINE); break; default: // If this is a normal character, it gets printed form_driver_wrap(my_form, ch); break; } } // status_print(status_win, "data: '%s' (%d)", field_buffer(fields[0], 0), // length); (void)strlcpy(temp_ptr, field_buffer(fields[0], 0), length); // get the length of the entry i = strlen(temp_ptr); while (i--) { if (isspace(temp_ptr[i])) temp_ptr[i] = '\0'; else break; } if (!(result_ptr = strdup(temp_ptr))) { vrmr_error(-1, VR_ERR, gettext("malloc failed: %s"), strerror(errno)); goto end; } if (result_ptr[0] == '\0') { free(result_ptr); result_ptr = NULL; } end: free(temp_ptr); unpost_form(my_form); free_form(my_form); free_field(fields[0]); free(fields); del_panel(my_panels[0]); destroy_win(ib_win); update_panels(); doupdate(); return (result_ptr); }
/* * Create and initialize a new popup. popup_btn_action *must* be filled before * this call. * @param rows The number of rows for win_body * @param cols The number of lines for win_body * @param posy Position of the top left corner on the y axis * @param posx Position of the top left corner on the x axis * @param requests An array of strings to put in the form. This can be null: * only the title and the buttons will be present. * @param title A string to print in the popup. */ void popup_new(int rows, int cols, int posy, int posx, char **requests, char *title) { int i, cury = 0, curx = 1, tmp, nb_buttons, nb_fields; WINDOW *inner; win_body = newwin(rows, cols, posy, posx); assert(win_body != NULL && popup_btn_action != NULL); box(win_body, 0, 0); for (nb_buttons = 0; popup_btn_action[nb_buttons]; nb_buttons++); popup_items = malloc(sizeof(ITEM *) * (nb_buttons+1)); assert(popup_items != NULL); assert(popup_btn_action != NULL); for (i = 0; popup_btn_action[i]; i++) { popup_items[i] = new_item(popup_btn_action[i]->key, ""); assert(popup_items[i] != NULL); } popup_items[i] = NULL; popup_menu = new_menu(popup_items); win_menu = derwin(win_body, 3, cols-2, rows-4, 1); assert(popup_menu != NULL && win_menu != NULL); box(win_menu, 0, 0); set_menu_win(popup_menu, win_menu); set_menu_format(popup_menu, 1, nb_buttons); tmp = popup_menu->fcols * (popup_menu->namelen + popup_menu->spc_rows); tmp--; inner = derwin(win_menu, 1, tmp, 1, (cols-3-tmp)/2); assert(inner != NULL); set_menu_sub(popup_menu, inner); set_menu_mark(popup_menu, ""); assert(post_menu(popup_menu) == E_OK); mvwprintw(win_body, 1, 2, "%s", title); for (nb_fields = 0; requests && requests[nb_fields]; nb_fields++); if (nb_fields == 0) { popup_fields = NULL; popup_form = NULL; is_on_button = true; return; } popup_fields = malloc(sizeof(FIELD *) * (nb_fields+1)); assert(popup_fields != NULL); for (i = 0; i < nb_fields && requests[i]; i++) { if (i % 2 == 1) { popup_fields[i] = new_field(1, 41, cury, curx, 0, 0); assert(popup_fields[i] != NULL); set_field_buffer(popup_fields[i], 0, strdup(requests[i])); cury = cury+1; curx = 1; field_opts_on(popup_fields[i], O_ACTIVE); field_opts_on(popup_fields[i], O_EDIT); field_opts_off(popup_fields[i], O_STATIC); set_field_back(popup_fields[i], A_UNDERLINE); } else { popup_fields[i] = new_field(1, 45, cury, curx, 0, 0); assert(popup_fields[i] != NULL); set_field_buffer(popup_fields[i], 0, strdup(requests[i])); curx = strlen(requests[i]) + 2; field_opts_off(popup_fields[i], O_ACTIVE); field_opts_off(popup_fields[i], O_EDIT); } } popup_fields[i] = NULL; popup_form = new_form(popup_fields); assert(popup_form != NULL); win_form = derwin(win_body, rows-6, cols-2, 1, 1); assert(popup_form != NULL && win_form != NULL); assert(set_form_win(popup_form, win_form) == E_OK); int diff_rows = popup_form->cols - win_form->_maxx-2; /* * There isn't enough rows for the form so we resize win_body and * win_form to fit the form. * This resize isn't needed for the lines (as there is always fery few * of them). */ if (diff_rows > 0) { wresize(win_body, win_body->_maxy, win_body->_maxx + diff_rows); wresize(win_form, win_form->_maxy, win_form->_maxx - 2 + diff_rows); } inner = derwin(win_form, win_form->_maxy-2, win_form->_maxx, 2, 0); assert(inner != NULL); set_form_sub(popup_form, inner); assert(post_form(popup_form) == E_OK); is_on_button = false; set_menu_fore(popup_menu, A_NORMAL); // "hide" the button pos_form_cursor(popup_form); }
void column_select_create(ui_t *ui) { int attr_id, column; MENU *menu; column_select_info_t *info; // Cerate a new indow for the panel and form ui_panel_create(ui, 20, 60); // Initialize Filter panel specific data info = sng_malloc(sizeof(column_select_info_t)); // Store it into panel userptr set_panel_userptr(ui->panel, (void*) info); // Initialize the fields info->fields[FLD_COLUMNS_ACCEPT] = new_field(1, 10, ui->height - 2, 13, 0, 0); info->fields[FLD_COLUMNS_SAVE] = new_field(1, 10, ui->height - 2, 25, 0, 0); info->fields[FLD_COLUMNS_CANCEL] = new_field(1, 10, ui->height - 2, 37, 0, 0); info->fields[FLD_COLUMNS_COUNT] = NULL; // Field Labels set_field_buffer(info->fields[FLD_COLUMNS_ACCEPT], 0, "[ Accept ]"); set_field_buffer(info->fields[FLD_COLUMNS_SAVE], 0, "[ Save ]"); set_field_buffer(info->fields[FLD_COLUMNS_CANCEL], 0, "[ Cancel ]"); // Create the form and post it info->form = new_form(info->fields); set_form_sub(info->form, ui->win); post_form(info->form); // Create a subwin for the menu area info->menu_win = derwin(ui->win, 10, ui->width - 2, 7, 0); // Initialize one field for each attribute for (attr_id = 0; attr_id < SIP_ATTR_COUNT; attr_id++) { // Create a new field for this column info->items[attr_id] = new_item("[ ]", sip_attr_get_description(attr_id)); set_item_userptr(info->items[attr_id], (void*) sip_attr_get_name(attr_id)); } info->items[SIP_ATTR_COUNT] = NULL; // Create the columns menu and post it info->menu = menu = new_menu(info->items); // Set current enabled fields // FIXME Stealing Call list columns :/ call_list_info_t *list_info = call_list_info(ui_find_by_type(PANEL_CALL_LIST)); // Enable current enabled fields and move them to the top for (column = 0; column < list_info->columncnt; column++) { const char *attr = list_info->columns[column].attr; for (attr_id = 0; attr_id < item_count(menu); attr_id++) { if (!strcmp(item_userptr(info->items[attr_id]), attr)) { column_select_toggle_item(ui, info->items[attr_id]); column_select_move_item(ui, info->items[attr_id], column); break; } } } // Set main window and sub window set_menu_win(menu, ui->win); set_menu_sub(menu, derwin(ui->win, 10, ui->width - 5, 7, 2)); set_menu_format(menu, 10, 1); set_menu_mark(menu, ""); set_menu_fore(menu, COLOR_PAIR(CP_DEF_ON_BLUE)); menu_opts_off(menu, O_ONEVALUE); post_menu(menu); // Draw a scrollbar to the right info->scroll = ui_set_scrollbar(info->menu_win, SB_VERTICAL, SB_RIGHT); info->scroll.max = item_count(menu) - 1; ui_scrollbar_draw(info->scroll); // Set the window title and boxes mvwprintw(ui->win, 1, ui->width / 2 - 14, "Call List columns selection"); wattron(ui->win, COLOR_PAIR(CP_BLUE_ON_DEF)); title_foot_box(ui->panel); mvwhline(ui->win, 6, 1, ACS_HLINE, ui->width - 1); mvwaddch(ui->win, 6, 0, ACS_LTEE); mvwaddch(ui->win, 6, ui->width - 1, ACS_RTEE); wattroff(ui->win, COLOR_PAIR(CP_BLUE_ON_DEF)); // Some brief explanation abotu what window shows wattron(ui->win, COLOR_PAIR(CP_CYAN_ON_DEF)); mvwprintw(ui->win, 3, 2, "This windows show the list of columns displayed on Call"); mvwprintw(ui->win, 4, 2, "List. You can enable/disable using Space Bar and reorder"); mvwprintw(ui->win, 5, 2, "them using + and - keys."); wattroff(ui->win, COLOR_PAIR(CP_CYAN_ON_DEF)); info->form_active = 0; }
STATIC gchar* post_rest_form( CURL *curl, const form_field_t *form ) { gchar *url_host; gchar *url_path; gchar *headers; struct curl_write_buffer_t body = { .data = NULL, .size = 0 }; gchar content_length[ 10 ]; gchar *html_post; GRegex *url_split_regex; GMatchInfo *match_info; long socket_value; curl_socket_t socket; size_t bytes_sent; char response_buffer[ 1024 ]; CURLcode status; size_t bytes_received; gboolean read_error; /* Split the form action URL into host and path. */ url_split_regex = g_regex_new( "^http[s?]://([a-zA-Z0-9_\\.-]+)/(.*)$", 0, 0, NULL ); if( g_regex_match( url_split_regex, form_action, 0, &match_info ) ) { url_host = g_match_info_fetch( match_info, 1 ); url_path = g_match_info_fetch( match_info, 2 ); g_match_info_free( match_info ); g_regex_unref( url_split_regex ); /* Build the HTML post. */ if( url_host != NULL ) { /* Build the body. */ if( form_name != NULL ) { body.data = g_strconcat( form_name, "=", form_value, NULL ); body.size = strlen( body.data ); } g_slist_foreach( form->input_fields, fill_body_with_input, &body ); /* Build the headers. */ g_sprintf( content_length, "%d\n\0", (gint) body.size ); headers = g_strconcat( "POST ", url_path, " HTTP/1.1\n", "Host: ", url_host, "\n", "Content-Type: application/x-www-form-urlencoded\n", "Content-Length: ", content_length, NULL ); g_free( url_path ); g_free( url_host ); /* Combine the headers and the body. */ html_post = g_strconcat( headers, "\n", body.data, NULL ); g_free( body.data ); g_free( headers ); printf( "DEBUG: Sending:\n-------\n%s-------", html_post ); /* Prepare a connection. */ curl_easy_setopt( curl, CURLOPT_URL, form_action ); curl_easy_setopt( curl, CURLOPT_CONNECT_ONLY, 1 ); curl_easy_perform( curl ); curl_easy_getinfo( curl, CURLINFO_LASTSOCKET, &socket_value ); socket = socket_value; /* Wait for the socket to become ready for sending. */ if( wait_for_socket( socket, FALSE, 60000L ) == FALSE ) { g_free( html_post ); g_fprintf( stderr, "Timeout connecting to " "the Google REST service\n" ); } else { /* Submit the post. */ curl_easy_send( curl, html_post, strlen( html_post ), &bytes_sent ); /* To do: verify that all the bytes were sent; if not, send the remainding bytes in a second, third, ... call. */ printf( "DEBUG: Sent %d out of %d bytes\n", (int)bytes_sent, (int) strlen(html_post) ); g_free( html_post ); /* Receive the response. */ read_error = FALSE; do { /* Wait for the socket to become ready for receiving. */ if( wait_for_socket( socket, TRUE, 60000L ) == FALSE ) { read_error = TRUE; g_fprintf( stderr, "Timeout connecting to " "the Google REST service\n" ); break; } /* Copy chunks of data into html_response. */ else { status = curl_easy_recv( curl, response_buffer, sizeof( response_buffer ), &bytes_received ); if( status == CURLE_OK ) { receive_curl_response( response_buffer, bytes_received, 1, &html_response ); } } } while( ( status == CURLE_AGAIN ) && ( read_error == FALSE ) ); printf( "DEBUG: CURL code %d: %s\n", (int)status, curl_easy_strerror( status ) ); } } } } #endif #if 0 /** * Auxiliary function used by decode_user_code_response to copy a JSON * response into a local data structure. * @param node [in] Object with JSON data (unused). * @param member_name [in] Name of the JSON field. * @param member_node [in] Node with JSON data. * @param user_code_ptr [out] Pointer to the structure where the JSON * data will be stored. * @return Nothing. */ STATIC void parse_user_code_json( const gchar *member_name, JsonNode *member_node, gpointer user_code_ptr ) { struct user_code_t *user_code = user_code_ptr; SET_JSON_MEMBER( user_code, device_code ); SET_JSON_MEMBER( user_code, verification_url ); SET_JSON_MEMBER( user_code, user_code ); } #endif /** * Decode the initial OAuth2 response with device code, user code, and * verification URL. * @param user_code_response [in] Raw JSON response data. * @return \a user_code_t structure with authentication data, or \a FALSE * if the user code could not be obtained. */ #if 0 STATIC struct user_code_t* decode_user_code_response( const gchar *user_code_response ) { struct user_code_t *user_code; user_code = g_new0( struct user_code_t, 1 ); if( user_code_response != NULL ) { /* Decode the JSON response. */ decode_json_reply( user_code_response, parse_user_code_json, user_code ); /* Verify that all fields have been decoded. */ if( ( user_code->device_code == NULL ) || ( user_code->user_code == NULL ) || ( user_code->verification_url == NULL ) ) { g_free( (gchar*) user_code->device_code ); g_free( (gchar*) user_code->user_code ); g_free( (gchar*) user_code->verification_url ); g_free( user_code ); user_code = NULL; } } return( user_code ); } #endif /** * Obtain a device code for device access. The CURL session must include the * user's login to Google, which may be obtained by calling \a login_to_gmail * with the user's credentials. * @param curl [in] CURL handle. * @param client_id [in] Google Developer Client ID. * @return Device code or \a NULL if an error occurred. * Test: manual (via non-automated test). */ struct user_code_t* obtain_device_code( CURL *curl, const gchar *client_id ) { /* Note: the following code is more elegant than the code that is currently used but is disabled because a bug in Google's API system prevents devices from using the tasks scope. */ #if 0 static gchar *form_action = "https://accounts.google.com/o/oauth2/device/code"; gchar *scope = // "https://www.googleapis.com/auth/userinfo.email " // "https://www.googleapis.com/auth/userinfo.profile"; "https://www.googleapis.com/auth/tasks"; form_field_t form = { .name = NULL, .value = NULL, .action = form_action, .input_fields = NULL }; gchar *user_code_response; struct user_code_t *user_code; gboolean success; /* Create a user code request. */ add_input_to_form( &form, "client_id", client_id ); add_input_to_form( &form, "scope", scope ); /* Post the request and decode the response. */ user_code_response = post_form( curl, &form ); destroy_form_inputs( &form ); g_printf( "%s\n", user_code_response ); user_code = decode_user_code_response( user_code_response ); return( user_code ); #endif } STATIC gboolean submit_approval_form( CURL *curl, const gchar *approval_page ) { form_field_t *approval_form; const gchar *const approval_names[ ] = { "submit_access", NULL }; gchar *form_response; gboolean success; approval_form = find_form( approval_page, "https://accounts.google.com/o/oauth2/", approval_names ); if( approval_form != NULL ) { g_printf( "Submitting approval form\n" ); /* Submit the approval form. */ form_response = post_form( curl, approval_form ); destroy_form( approval_form ); g_free( form_response ); success = TRUE; } else { success = FALSE; } return( success ); }
void from_to_selector(const char *curr_path, char **from, char **to, int *action) { const size_t n_fields = 3; const size_t starty = 6; const size_t startx = 25; FIELD *field[n_fields]; FORM *my_form; int width[] = { MAX_FROM_DATE, MAX_TO_DATE }; int height[] = { 1, 1 }; initscr(); curs_set(1); cbreak(); clear(); noecho(); keypad(stdscr, TRUE); for ( size_t i = 0; i < n_fields - 1; ++i ) field[i] = new_field(height[i], width[i], starty + i * 2, startx, 0, 0); field[n_fields - 1] = NULL; set_field_back( field[0], A_UNDERLINE ); field_opts_off( field[0], O_AUTOSKIP ); set_field_back( field[1], A_UNDERLINE ); field_opts_off( field[1], O_AUTOSKIP ); my_form = new_form(field); post_form(my_form); refresh(); mvprintw( 0, 0, curr_path ); mvprintw( 4, 10, "Enter period for report:" ); mvprintw( 6, 10, "From: " ); mvprintw( 8, 10, "To: " ); mvprintw( 10, 10, "(F2) = Execute | (ESC) = Previous Screen" ); move( 6, 25 ); set_current_field( my_form, field[0] ); int ch; do { ch = getch(); switch ( ch ) { case KEY_UP: form_driver(my_form, REQ_PREV_FIELD); form_driver(my_form, REQ_END_LINE); break; case KEY_LEFT: form_driver(my_form, REQ_LEFT_CHAR); break; case KEY_RIGHT: form_driver(my_form, REQ_RIGHT_CHAR); break; case KEY_BACKSPACE: form_driver(my_form, REQ_PREV_CHAR); form_driver(my_form, REQ_DEL_CHAR); break; case ENTER: form_driver( my_form, REQ_NEXT_FIELD ); form_driver( my_form, REQ_END_LINE ); break; case KEY_F(2): { char my_from[MAX_FROM_DATE]; strncpy( my_from, compress_str(field_buffer( field[0], 0 )), MAX_FROM_DATE ); *from = malloc( strlen( my_from ) + 1 ); strcpy( *from, my_from ); char my_to[MAX_TO_DATE]; strncpy( my_to, compress_str(field_buffer( field[1], 0 )), MAX_TO_DATE ); *to = malloc( strlen( my_to ) + 1 ); strcpy( *to, my_to ); } break; case DEL: form_driver(my_form, REQ_DEL_CHAR); break; default: if ( ch == '\'' ) break; form_driver( my_form, ch ); break; } } while ( (ch != ESC) && (ch != KEY_F(2)) ); *action = ch; unpost_form( my_form ); free_form( my_form ); for ( size_t i = 0; i < n_fields - 1; ++i ) free_field( field[i] ); return; }
int main(int argc, char *argv[]) { // Initial values WINDOW *title_win; // Title window pointer FORM *title_form; int row, col; // Start screen initscr(); clear(); noecho(); cbreak(); if (has_colors() == TRUE) // Test if terminal has color start_color(); getmaxyx(stdscr, row, col); // Check if terminal is a proper size if (row < MIN_HEIGHT || col < MIN_WIDTH) { char term_size_err1[] = "Your terminal is too small!"; char term_size_err2[] = "Resize and try again."; mvprintw(row / 2 - 1, (col - strlen(term_size_err1)) / 2, "%s", term_size_err1); mvprintw(row / 2 , (col - strlen(term_size_err2)) / 2, "%s", term_size_err2); getch(); endwin(); return 0; } // Header header(col); // Staffs staff(row, col); refresh(); // Title Window int startx = (col - TITLE_WINDOW_WIDTH) / 2; int starty = (row - TITLE_WINDOW_HEIGHT) / 2; title_win = title_info_win(TITLE_WINDOW_HEIGHT, TITLE_WINDOW_WIDTH, starty, startx); keypad(title_win, true); int x_mins[8] = { WIN_X_BUFFER + strlen("Project Title: "), WIN_X_BUFFER + strlen("Song Title: "), WIN_X_BUFFER + strlen("Artist: "), WIN_X_BUFFER + strlen("Tabbed by: "), WIN_X_BUFFER + strlen("Email: "), WIN_X_BUFFER + strlen("Number of Strings: "), WIN_X_BUFFER + strlen("Tuning: (1)"), TITLE_WINDOW_WIDTH - WIN_X_BUFFER - strlen("OK") - strlen("CANCEL") - 9, }; /* Input fields for windows */ fields[0] = new_field(1, TITLE_WINDOW_WIDTH - x_mins[0] - 2 * WIN_X_BUFFER, WIN_Y_BUFFER + WIN_HEADER , x_mins[0], 0, 0); fields[1] = new_field(1, TITLE_WINDOW_WIDTH - x_mins[1] - 2 * WIN_X_BUFFER, WIN_Y_BUFFER + WIN_HEADER + 4 , x_mins[1], 0, 0); fields[2] = new_field(1, TITLE_WINDOW_WIDTH - x_mins[2] - 2 * WIN_X_BUFFER, WIN_Y_BUFFER + WIN_HEADER + 6 , x_mins[2], 0, 0); fields[3] = new_field(1, TITLE_WINDOW_WIDTH - x_mins[3] - 2 * WIN_X_BUFFER, WIN_Y_BUFFER + WIN_HEADER + 8 , x_mins[3], 0, 0); fields[4] = new_field(1, TITLE_WINDOW_WIDTH - x_mins[4] - 2 * WIN_X_BUFFER, WIN_Y_BUFFER + WIN_HEADER + 10, x_mins[4], 0, 0); fields[5] = new_field(1, 1 , WIN_Y_BUFFER + WIN_HEADER + 14, x_mins[5], 0, 0); int i; for (i = 0; i < strings; i++) fields[6 + i] = new_field(1, 2, WIN_Y_BUFFER + WIN_HEADER + 16, x_mins[6] + i * 6, 0, 0); for (i = 0; i < 8 - strings; i++) fields[6 + strings + i] = NULL; for (i = 0; i < 12; i++) { // Needs to be able to change with string change set_field_back(fields[i], A_UNDERLINE); field_opts_off(fields[i], O_AUTOSKIP); } /* Create the title window form */ set_form_win(title_form, title_win); title_form = new_form(fields); post_form(title_form); refresh(); int movements[8][2] = { {WIN_Y_BUFFER + WIN_HEADER , x_mins[0]}, {WIN_Y_BUFFER + WIN_HEADER + 4 , x_mins[1]}, {WIN_Y_BUFFER + WIN_HEADER + 6 , x_mins[2]}, {WIN_Y_BUFFER + WIN_HEADER + 8 , x_mins[3]}, {WIN_Y_BUFFER + WIN_HEADER + 10 , x_mins[4]}, {WIN_Y_BUFFER + WIN_HEADER + 14 , x_mins[5]}, {WIN_Y_BUFFER + WIN_HEADER + 16 , x_mins[6]}, {WIN_Y_BUFFER + WIN_HEADER + 20 , x_mins[7]}, }; int y, x; wmove(title_win, movements[0][0], movements[0][1]); wrefresh(title_win); while (true) { ch = wgetch(title_win); getyx(title_win, y, x); if (ch == KEY_UP) { if (y == movements[7][0]) move(movements[6][0], movements[6][1]); else if (y == movements[6][0] && x == movements[6][1]) { form_driver(title_form, REQ_PREV_FIELD); form_driver(title_form, REQ_END_LINE); } else if (y != movements[7][0] && y != movements[6][0]){ form_driver(title_form, REQ_PREV_FIELD); form_driver(title_form, REQ_END_LINE); } } else if (ch == KEY_DOWN) { if (y == movements[6][0]) move(movements[7][0], movements[7][1]); else if (y != movements[7][0] && y != movements[6][0]){ form_driver(title_form, REQ_NEXT_FIELD); form_driver(title_form, REQ_END_LINE); } } else if (ch == KEY_LEFT) { if (y == movements[6][0]) { form_driver(title_form, REQ_PREV_FIELD); form_driver(title_form, REQ_END_LINE); } else if (y == movements[7][0] && x == (movements[7][1] + BUTTON_WIDTH)){ // Is at CANCEL button move(movements[7][0], movements[7][1]); } } else if (ch == KEY_RIGHT) { if (y == movements[6][0]) { form_driver(title_form, REQ_NEXT_FIELD); form_driver(title_form, REQ_END_LINE); } else if (y == movements[7][0] && x == movements[7][1]) { // Is at OK button move(movements[7][0], movements[7][1] + BUTTON_WIDTH); } } else if (ch == '\n' && y == movements[7][0]) { if (x == movements[7][1]) { // OK continue; } else { // CANCEL clear(); endwin(); break; } /* ch is a letter, number or special char */ } else if (((ch >= 'a'&& ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || (ch >= 33 && ch <= 46) || ch == ' ' || ch == 64)) { form_driver(title_form, ch); } } getch(); destroy_win(title_win); clear(); refresh(); getch(); endwin(); return 0; }
void set_new_db_conn(const char *curr_path) { const int n_fields = 5; const int width = 20; const int starty = 4; const int startx = 20; FIELD *field[n_fields]; FORM *my_form; char *screen_title = "New DB Connection"; initscr(); curs_set(1); cbreak(); clear(); noecho(); keypad(stdscr, TRUE); for (size_t i = 0; i < n_fields - 1; ++i) { field[i] = new_field(1, width, starty + i * 2, startx, 0, 0); } field[n_fields - 1] = NULL; set_field_back(field[0], A_UNDERLINE); field_opts_off(field[0], O_AUTOSKIP); set_field_back(field[1], A_UNDERLINE); field_opts_off(field[1], O_AUTOSKIP); set_field_back(field[2], A_UNDERLINE); field_opts_off(field[2], O_AUTOSKIP); field_opts_off(field[2], O_PUBLIC); set_field_back(field[3], A_UNDERLINE); field_opts_off(field[3], O_AUTOSKIP); my_form = new_form(field); post_form(my_form); refresh(); mvprintw(0, 0, menu_path(curr_path, screen_title)); mvprintw(4, 10, "Server: "); mvprintw(6, 10, "User: "******"Password: "******"DB: "); mvprintw(14, 10, "(F2) = Save and Exit | (F4) = Exit without saving"); move(4, 20); refresh(); int ch; do { ch = getch(); switch(ch) { case KEY_DOWN: form_driver(my_form, REQ_NEXT_FIELD); form_driver(my_form, REQ_END_LINE); break; case KEY_UP: form_driver(my_form, REQ_PREV_FIELD); form_driver(my_form, REQ_END_LINE); break; case KEY_LEFT: form_driver(my_form, REQ_LEFT_CHAR); break; case KEY_RIGHT: form_driver(my_form, REQ_RIGHT_CHAR); break; case ENTER: form_driver(my_form, REQ_NEXT_FIELD); form_driver(my_form, REQ_END_LINE); break; case KEY_BACKSPACE: form_driver(my_form, REQ_PREV_CHAR); form_driver(my_form, REQ_DEL_CHAR); break; case DEL: form_driver(my_form, REQ_DEL_CHAR); break; default: if (is_space(ch) == 0) form_driver(my_form, ch); break; } } while( (ch != KEY_F(2)) && (ch != KEY_F(4)) ); if (ch == KEY_F(2)) { char *server = field_buffer(field[0], 0); char *admin = field_buffer(field[1], 0); char *pass = field_buffer(field[2], 0); char *db = field_buffer(field[3], 0); strcpy(server, compress_str(server)); strcpy(admin, compress_str(admin)); strcpy(pass, compress_str(pass)); strcpy(db, compress_str(db)); int result = set_db_cnf(server, admin, pass, db); mvprintw(16, 10, "**Warning: The system will apply changes to the configuration now."); close_db(); init_db(); mvprintw(18, 10, "Press any key to continue..."); ch = getch(); if (connect_to_db() == 1) { mvprintw(20, 10, "[!] Unable to connect to database with new configuration."); } else { mvprintw(20, 10, "[!] Connection successful."); } ch = getch(); } unpost_form(my_form); free_form(my_form); for (size_t i = 0; i < n_fields -1; ++i) { free_field(field[i]); } endwin(); return; }