Esempio n. 1
0
/*
 * Recursive function responsible to create fields, position them and setting
 * the modifiable fields. All of this from a service dictionary.
 * To keep the cursor from moving on signal, a string is affected to mark each
 * field. This is used by repos_cursor().
 * @param longest_key_len The longest length for a label
 * @param pos The index in main_fields[]
 * @param jobj The service dictionary
 * @param is_obj_modifiable Use to set the whole object as modifiable (usefull
 *	for IPv4.Configuration for example)
 * @param obj_str The string representing the "hash" of a surrounding object
 */
static void render_fields_from_jobj(int longest_key_len, int *pos,
		struct json_object *jobj, bool is_obj_modifiable,
		const char *obj_str)
{
	bool is_autoconnect = false, is_modifiable = false;
	struct userptr_data *data;

	json_object_object_foreach(jobj, key, val) {
		main_fields[*pos] = render_label(longest_key_len, key);
		assert(main_fields[*pos] != NULL);
		(*pos)++;

		is_modifiable = string_ends_with_configuration(key);
		is_modifiable |= is_obj_modifiable;

		if (json_object_get_type(val) == json_type_object) {
			move_field(main_fields[(*pos)-1], ++cur_y, cur_x);
			cur_y++;
			render_fields_from_jobj(longest_key_len, pos, val,
					is_modifiable, key);
			is_modifiable = false;
		} else {
			// insert the page delimiter
			if (cur_y >= win_body_lines-4) {
				cur_y = 1;
				set_new_page(main_fields[(*pos)-1], TRUE);
				move_field(main_fields[(*pos)-1], cur_y, cur_x);
				nb_pages++;
			}

			main_fields[*pos] = render_field(longest_key_len, val);
			assert(main_fields[*pos] != NULL);
			is_autoconnect = strcmp(key, key_serv_autoconnect) == 0;

			if (is_modifiable || is_autoconnect) {
				field_opts_on(main_fields[*pos], O_EDIT);
				field_opts_off(main_fields[*pos], O_BLANK);
				set_field_back(main_fields[*pos], A_UNDERLINE);
			} else
				field_opts_off(main_fields[*pos], O_EDIT);

			// Specific operations on fields
			config_fields_type(*pos, is_autoconnect, obj_str, key);

			field_opts_on(main_fields[*pos], O_NULLOK);
			data = malloc(sizeof(struct userptr_data));
			data->dbus_name = strdup(get_str_key());
			data->pretty_name = NULL;
			set_field_userptr(main_fields[*pos], data);

			(*pos)++;
		}

		cur_y++;
	}
Esempio n. 2
0
/*
 *  Creates a new field at y, and sets the field's text to str.
 *  Sets the value of pField to point to the new field.
 */
void ListBox::createField(FIELD **pField, int y, std::string str) {
    *pField = new_field(1, getWidth() - 2, y, 0, 0, 0);
    set_field_buffer(*pField, 0, str.data());
    set_field_back(*pField, A_NORMAL);
    field_opts_off(*pField, O_AUTOSKIP);
    field_opts_on(*pField, O_BLANK);
}
Esempio n. 3
0
void AddProjectForm::eventhandle(NEvent* ev) 	//обработчик событий
{
    if ( ev->done )
	return;
    NMouseEvent* mevent = (NMouseEvent*)ev;
    if ( ev->type == NEvent::evMOUSE)
    {
	NForm::eventhandle(ev); //предок
    }
    if ( ev->type == NEvent::evKB )
    {
	ev->done = true;
        switch(ev->keycode)
	{
	    case KEY_ENTER:
	    case '\n': //ENTER
	    {
		form_driver(frm, REQ_NEXT_FIELD); //костыль чтобы текущее поле не потеряло значение
		char* email = strlowcase(rtrim(field_buffer(fields[emailfield],0)));
		char* passw = rtrim(field_buffer(fields[passwfield],0));
		kLogPrintf("AddProjectForm OK name=[%s] url=[%s] email=[%s]\n passw=[%s]\n", projname.c_str(), projurl.c_str(), email, passw);
		if (srv!=NULL)
		{
		    std::string errmsg;
		    bool success = true;
		    if (!userexist) //если аккаунта еще нет то создаем
		    {
			char* username = strlowcase(rtrim(field_buffer(fields[usernamefield],0)));
			char* teamname = rtrim(field_buffer(fields[teamfield],0));
			success = srv->createaccount(projurl.c_str(),email,passw, username, teamname, errmsg);
		    }
		    if (success)
			success = srv->projectattach(projurl.c_str(), projname.c_str(), email, passw, errmsg); //подключить проект
		    if (success)
			putevent(new TuiEvent(evADDPROJECT)); //создаем событие чтобы закрыть форму
		    else
		    {
			//СООБЩЕНИЕ ОБ ОШИБКЕ
			errmsg = " Error: " + errmsg;
			set_field_buffer(fields[errmsgfield], 0, errmsg.c_str());
			field_opts_on(fields[errmsgfield], O_VISIBLE); //делаем видимой строку ошибки
			this->refresh();
		    }
		}
		break;
	    }
	    case 27:
		putevent(new TuiEvent(evADDPROJECT)); //код закрытия окна
		break;
	    default:
		kLogPrintf("AddProjectForm::KEYCODE=%d\n", ev->keycode);
		ev->done = false;
		NForm::eventhandle(ev); //предок
		break;
	} //switch
    }
}
Esempio n. 4
0
void
save_set_msg(ui_t *ui, sip_msg_t *msg)
{
    // Get panel information
    save_info_t *info = save_info(ui);
    info->msg = msg;

    // make 'current SIP message' field visible
    field_opts_on(info->fields[FLD_SAVE_MESSAGE], O_VISIBLE);
}
Esempio n. 5
0
/*
 * Create a field and fill the buffer with label_str. This field cannot be
 * modified nor visited by the cursor.
 * @param longest_key_len What is the longest length of a label field, this
 *	information is used to place the field on the x axis
 * @param label_str The string to fill the label buffer with
 */
static FIELD* render_label(int longest_key_len, const char *label_str)
{
	FIELD *result;

	result = new_field(1, longest_key_len-4, cur_y, cur_x, 0, 0);

	if (result) {
		field_opts_on(result, O_VISIBLE);
		field_opts_off(result, O_EDIT);
		field_opts_off(result, O_ACTIVE);
		set_field_buffer(result, 0, label_str);
	}

	return result;
}
Esempio n. 6
0
static FIELD *
another_field(FORM * form, FIELD * field)
{
    FIELD **f = form_fields(form);
    FIELD *result = 0;
    int n;

    for (n = 0; f[n] != 0; ++n) {
	if (f[n] != field) {
	    result = f[n];
	    field_opts_on(result, O_SELECTABLE);
	    break;
	}
    }
    return result;
}
Esempio n. 7
0
static int
my_form_driver(FORM * form, int c)
{
    static bool insert_mode = TRUE;
    FIELD *field;

    switch (c) {
    case MY_QUIT:
	if (form_driver(form, REQ_VALIDATION) == E_OK)
	    return (TRUE);
	break;
    case MY_HELP:
	help_edit_field();
	break;
    case MY_EDT_MODE:
	if ((field = current_field(form)) != 0) {
	    set_current_field(form, another_field(form, field));
	    if ((unsigned) field_opts(field) & O_EDIT) {
		field_opts_off(field, O_EDIT);
		set_field_status(field, 0);
	    } else {
		field_opts_on(field, O_EDIT);
	    }
	    set_current_field(form, field);
	}
	break;
    case MY_INS_MODE:
	/* there should be a form_status() function, but there is none */
	if (!insert_mode) {
	    if (form_driver(form, REQ_INS_MODE) == E_OK) {
		insert_mode = TRUE;
	    }
	} else {
	    if (form_driver(form, REQ_OVL_MODE) == E_OK) {
		insert_mode = FALSE;
	    }
	}
	show_insert_mode(insert_mode);
	refresh();
	break;
    default:
	beep();
	break;
    }
    return (FALSE);
}
Esempio n. 8
0
/*
 * 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);
}
Esempio n. 9
0
File: menus.c Progetto: aspacsa/vlp
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;
}
Esempio n. 10
0
File: menus.c Progetto: aspacsa/vlp
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;
}
Esempio n. 11
0
File: menus.c Progetto: aspacsa/vlp
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;
}
Esempio n. 12
0
File: menus.c Progetto: aspacsa/vlp
void set_visible_fields(FIELD *fields[], size_t start, size_t end) {
  for ( size_t i = start; i <= end; ++i )
    field_opts_on( fields[i], O_VISIBLE );
  return;
}
Esempio n. 13
0
FILE *openFile(){
    FIELD *field[3];
    FORM  *my_form;
    int ch;

    int contLoop = 1;
    FILE *file;
    char *fname = (char*)malloc(50*sizeof(char));;

    while(contLoop){

        /* Initialize the fields */
        field[0] = new_field(1, 30, 5, 1, 0, 0); //filename
        field[1] = new_field(1, 1, 7, 33, 0, 0); //overwrite?
        field[2] = NULL;

        /* Set field options */
        set_field_back(field[0], A_UNDERLINE);  /* Print a line for the option  */
        field_opts_off(field[0], O_AUTOSKIP);   /* Don't go to next field when this */
                            /* Field is filled up       */
        //set_field_back(field[1], A_UNDERLINE); 
        field_opts_off(field[1], O_AUTOSKIP);
        field_opts_off(field[1], O_VISIBLE);

        /* Create the form and post it */
        my_form = new_form(field);
        post_form(my_form);
        refresh();
        mvprintw(0,0,"iCal Generator\nWritten by Derek Redfern");
        mvprintw(4, 1, "Path and name of iCal file to create (without extension):");
        
        refresh();
        form_driver(my_form, REQ_FIRST_FIELD);
        /* Loop through to get user requests */
        while((ch = getch()) != '\n')
        {   switch(ch)
            {   case KEY_BACKSPACE:
                    form_driver(my_form, REQ_LEFT_CHAR);
                    form_driver(my_form, REQ_DEL_CHAR);
                    break;
                case KEY_LEFT:
                    form_driver(my_form, REQ_LEFT_CHAR);
                    break;
                case KEY_RIGHT:
                    form_driver(my_form, REQ_RIGHT_CHAR);
                    break;
                default:
                    /* If this is a normal character, it gets */
                    /* Printed                */    
                    form_driver(my_form, ch);
                    break;
            }
        }

        form_driver(my_form,REQ_VALIDATION);
        char *temp = field_buffer(field[0],0);
        int length = strlen(temp);
        strncpy(fname,temp,length);
        trimTrailingWhitespace(fname);
        strcat(fname,".ics");
        file = fopen(fname,"r");
        if (!(file==NULL)){
            mvprintw(7, 1, "Overwrite existing file? [y/n]: ");
            field_opts_on(field[1], O_VISIBLE);
            form_driver(my_form, REQ_NEXT_FIELD);
            field_opts_off(field[0], O_ACTIVE);

            while((ch = getch()) != '\n')
            {   switch(ch)
                {   case KEY_BACKSPACE:
                        form_driver(my_form, REQ_DEL_PREV);
                        break;
                    case 'y':   
                        form_driver(my_form, ch);
                        break;
                    case 'n':
                        form_driver(my_form, ch);
                        break;
                }
            }
            form_driver(my_form,REQ_VALIDATION);
            char *confirm = field_buffer(field[1],0);
            if (confirm[0]=='y'){ //confirm overwrite
                contLoop=0;
            } else {
                fclose(file); //close test file
            }
        } else {
            contLoop=0; //no file exists, proceed with write
        }

        /* Un post form and free the memory */
        unpost_form(my_form);
        free_form(my_form);
        free_field(field[0]);
        free_field(field[1]); 
    }
    file = fopen(fname,"w");
    return file;
}
Esempio n. 14
0
int main()
{
	int ch, done;
	ITEM *cur;
	
	/* coreboot data structures */
	lib_get_sysinfo();

	struct cb_cmos_option_table *opttbl = get_system_option_table();

	if (opttbl == NULL) {
		printf("Could not find coreboot option table\n");
		halt();
	}

	/* display initialization */
	initscr();
	keypad(stdscr, TRUE);
	cbreak();
	noecho();
	start_color();
	leaveok(stdscr, TRUE);
	curs_set(1);

	erase();
	box(stdscr, 0, 0);
	mvaddstr(0, 2, "coreboot configuration utility");

	/* prep CMOS layout into libcurses data structures */
	
	/* determine number of options, and maximum option name length */
	int numopts=0;
	int maxlength=0;
	struct cb_cmos_entries *option = first_cmos_entry(opttbl);
	while (option) {
		if ((option->config != 'r') && (strcmp("check_sum", option->name) != 0)) {
			maxlength = max(maxlength, strlen(option->name));
			numopts++;
		}
		option = next_cmos_entry(option);
	}
	if (numopts == 0) {
		printf("NO CMOS OPTIONS FOUND. EXITING!!!");
		return 1;
	}
	FIELD **fields = malloc(sizeof(FIELD*)*(2*numopts+1));
	int i;

	/* walk over options, fetch details */
	option = first_cmos_entry(opttbl);
	for (i=0;i<numopts;i++) {
		while ((option->config == 'r') || (strcmp("check_sum", option->name) == 0)) {
			option = next_cmos_entry(option);
		}
		fields[2*i] = new_field(1, strlen(option->name), i*2, 1, 0, 0);
		set_field_buffer(fields[2*i], 0, option->name);
		field_opts_off(fields[2*i], O_ACTIVE);

		fields[2*i+1] = new_field(1, 40, i*2, maxlength+2, 0, 0);
		char *buf = NULL;
		int fail = get_option_as_string(use_nvram, opttbl, &buf, option->name);
		switch (option->config) {
		case 'h': {
			set_field_type(fields[2*i+1], TYPE_INTEGER, 0, 0, (1<<option->length)-1);
			field_opts_on(fields[2*i+1], O_BLANK);
			break;
			  }
		case 's': {
			set_max_field(fields[2*i+1], option->length/8);
			field_opts_off(fields[2*i+1], O_STATIC);
			break;
			  }
		case 'e': {
			int numvals = 0;
			struct cb_cmos_enums *cmos_enum = first_cmos_enum_of_id(opttbl, option->config_id);

			/* if invalid data in CMOS, set buf to first enum */
			if (fail && cmos_enum) {
				buf = cmos_enum->text;
			}

			while (cmos_enum) {
				numvals++;
				cmos_enum = next_cmos_enum_of_id(cmos_enum, option->config_id);
			}

			char **values = malloc(sizeof(char*)*numvals + 1);
			int cnt = 0;

			cmos_enum = first_cmos_enum_of_id(opttbl, option->config_id);
			while (cmos_enum) {
				values[cnt] = cmos_enum->text;
				cnt++;
				cmos_enum = next_cmos_enum_of_id(cmos_enum, option->config_id);
			}
			values[cnt] = NULL;
			field_opts_off(fields[2*i+1], O_EDIT);
			set_field_type(fields[2*i+1], TYPE_ENUM, values, 1, 1);
			free(values); // copied by set_field_type
			break;
			  }
		default:
			  break;
		}
		if (buf) set_field_buffer(fields[2*i+1], 0, buf);
#if HOSTED
// underline is non-trivial on VGA text
		set_field_back(fields[2*i+1], A_UNDERLINE);
#endif
		field_opts_off(fields[2*i+1], O_BLANK | O_AUTOSKIP | O_NULLOK);

		option = next_cmos_entry(option);
	}
	fields[2*numopts]=NULL;

	FORM *form = new_form(fields);
	int numlines = min(numopts*2, 16);
	WINDOW *w = newwin(numlines+2, 70, 2, 1);
	WINDOW *inner_w = newpad(numopts*2, 68);
	box(w, 0, 0);
	mvwaddstr(w, 0, 2, "Press F1 when done");
	set_form_win(form, w);
	set_form_sub(form, inner_w);
	post_form(form);

	done = 0;
	while(!done) {
		ch=getch();
		if (ch == ERR) continue;
		switch (ch) {
		case KEY_DOWN:
			form_driver(form, REQ_NEXT_FIELD);
			break;
		case KEY_UP:
			form_driver(form, REQ_PREV_FIELD);
			break;
		case KEY_LEFT:
			if (field_type(current_field(form)) == TYPE_ENUM) {
				form_driver(form, REQ_PREV_CHOICE);
			} else {
				form_driver(form, REQ_LEFT_CHAR);
			}
			break;
		case KEY_RIGHT:
			if (field_type(current_field(form)) == TYPE_ENUM) {
				form_driver(form, REQ_NEXT_CHOICE);
			} else {
				form_driver(form, REQ_RIGHT_CHAR);
			}
			break;
		case KEY_BACKSPACE:
		case '\b':
			form_driver(form, REQ_DEL_PREV);
			break;
		case KEY_DC:
			form_driver(form, REQ_DEL_CHAR);
			break;
		case KEY_F(1):
			done=1;
			break;
		default:
			form_driver(form, ch);
			break;
		}
		render_form(form);
	}

	for (i = 0; i < numopts; i++) {
		char *name = field_buffer(fields[2*i], 0);
		char *value = field_buffer(fields[2*i+1], 0);
		char *ptr;
		for (ptr = value + strlen (value) - 1;
		     ptr >= value && *ptr == ' '; ptr--);
		ptr[1] = '\0';
		set_option_from_string(use_nvram, opttbl, value, name);
	}

	unpost_form(form);
	free_form(form);
	touchwin(stdscr);
	refresh();

	endwin();
	/* TODO: reboot */
	halt();
}
Esempio n. 15
0
void AddAccMgrForm::eventhandle(NEvent* ev) 	//обработчик событий
{
    if ( ev->done )
	return;
    NMouseEvent* mevent = (NMouseEvent*)ev;
    if ( ev->type == NEvent::evMOUSE)
    {
	NForm::eventhandle(ev); //предок
    }
    if ( ev->type == NEvent::evKB )
    {
	ev->done = true;
        switch(ev->keycode)
	{
	    case KEY_ENTER:
	    case '\n': //ENTER
	    {
		form_driver(frm, REQ_NEXT_FIELD); //костыль чтобы текущее поле не потеряло значение
		char* username = rtrim(field_buffer(fields[usernamefield],0));
		char* passw = rtrim(field_buffer(fields[passwfield],0));
		mgrurl = rtrim(field_buffer(fields[urlfield],0));
		char* mgrname = rtrim(field_buffer(fields[namefield],0));
		kLogPrintf("AddAccMgrForm OK username=[%s] passw=[%s]\n", username, passw);
		if (srv!=NULL)
		{
		    std::string errmsg;
		    bool success = srv->accountmanager(mgrurl.c_str(), username, passw, false, errmsg);
		    if (success)
		    {
			Item* account_manager = NULL;
			if (srv !=NULL)
			    account_manager = srv->findaccountmanager(mgrname);
			if (account_manager == NULL) //для кастомных менеджеров сохраняем в конфигах
			{
			    //проверить есть-ли уже в конфиге такой аккаунт менеджер
			    //то обновляем существующую запись, иначе добавляем новую
			    bool exist = false;
			    Item* boinctui_cfg = gCfg->getcfgptr();
			    if (boinctui_cfg != NULL)
			    {
				std::vector<Item*> mgrlist = boinctui_cfg->getItems("accmgr");
				std::vector<Item*>::iterator it;
				for (it = mgrlist.begin(); it != mgrlist.end(); it++)
				{
				    Item* namecfg = (*it)->findItem("name");
				    Item* urlcfg =  (*it)->findItem("url");
				    if (namecfg != NULL)
					if (strcmp(namecfg->getsvalue(),mgrname) == 0)
					{
					    exist = true;
					    //обновить значение url в конфиге
					    Item* urlcfg = (*it)->findItem("url");
					    if (urlcfg != NULL)
						urlcfg->setsvalue(mgrurl.c_str());
					}
				    if (urlcfg != NULL)
				    {
					if (strcmp(urlcfg->getsvalue(),mgrurl.c_str()) == 0)
					{
					    exist = true;
					    //обновить значение имени в конфиге
					    Item* namecfg = (*it)->findItem("name");
					    if (namecfg != NULL)
						namecfg->setsvalue(mgrname);
					}
				    }
				    if (exist)
					break;
				}
				if (!exist)
				{
				    //записать в конфиг как новый
				    Item* accmgr  = new Item("accmgr");
				    boinctui_cfg->addsubitem(accmgr);
				    Item* name  = new Item("name");
				    name->setsvalue(mgrname);
				    Item* url  = new Item("url");
				    url->setsvalue(mgrurl.c_str());
				    accmgr->addsubitem(name);
				    accmgr->addsubitem(url);
				}
			    }
			}
			putevent(new TuiEvent(evADDACCMGR)); //создаем событие чтобы закрыть форму
		    }
		    else
		    {
			//СООБЩЕНИЕ ОБ ОШИБКЕ
			errmsg = " Error: " + errmsg;
			set_field_buffer(fields[errmsgfield], 0, errmsg.c_str());
			field_opts_on(fields[errmsgfield], O_VISIBLE); //делаем видимой строку ошибки
			this->refresh();
		    }
		}
		break;
	    }
	    case 27:
		putevent(new TuiEvent(evADDACCMGR, srv, mgrname.c_str())); //код закрытия окна
		break;
	    default:
		kLogPrintf("AddAccMgrForm::KEYCODE=%d\n", ev->keycode);
		ev->done = false;
		NForm::eventhandle(ev); //предок
		break;
	} //switch
    }
}