Beispiel #1
0
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);
}
Beispiel #2
0
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;
}
Beispiel #3
0
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();
}
Beispiel #4
0
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 bool create(void)
{
	const char *title;

	if (screen_lines < 6 || screen_cols < 36) {
		form_widget.close();
		beep();
		return FALSE;
	}
	widget_init(&form_widget,
		    6, 36, SCREEN_CENTER, SCREEN_CENTER,
		    attr_textbox, WIDGET_BORDER | WIDGET_SUBWINDOW | WIDGET_CURSOR_VISIBLE);
	title = _("Sound Card");
	mvwprintw(form_widget.window, 0, (36 - 2 - get_mbs_width(title)) / 2, " %s ", title);

	set_form_win(form, form_widget.window);
	set_form_sub(form, form_widget.subwindow);
	return TRUE;
}
Beispiel #6
0
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);
}
Beispiel #7
0
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);
}
Beispiel #8
0
/*
 * 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);
}
Beispiel #9
0
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;
      }
    }
  }
}
Beispiel #10
0
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;
}
Beispiel #11
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();
}
Beispiel #12
0
int uponadd()
{
	FIELD *field[3];
	FORM  *my_form;
	WINDOW *my_form_win;
	int ch, rows, cols;
	int ext=0;
	/* Initialize curses */
	initscr();
	start_color();
	cbreak();
	noecho();
	keypad(stdscr, TRUE);
	/* Initialize few color pairs */
   	init_pair(1, COLOR_RED, COLOR_BLACK);
	/* Initialize the fields */
	field[0] = new_field(1, 40, 1, 0, 0, 0);
	field[1] = new_field(1, 40, 3, 0, 0, 0);
	field[2] = NULL;
	/* Set field options */
	set_field_back(field[0], A_UNDERLINE);
	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);
	int trash =set_field_type(field[0],TYPE_ALPHA,1);
	trash=set_field_type(field[1],TYPE_INTEGER,1);
	/* Create the form and post it */
	my_form = new_form(field);

	/* Calculate the area required for the form */
	scale_form(my_form, &rows, &cols);

	/* Create the window to be associated with the form */
	int xx,yy;
	getmaxyx(stdscr,yy,xx);
        my_form_win = newwin(rows + 4, cols + 4, (yy/2), (xx/2)-18);
        keypad(my_form_win, TRUE);

	/* Set main window and sub window */
        set_form_win(my_form, my_form_win);
        set_form_sub(my_form, derwin(my_form_win,rows,cols,2,2));

	/* Print a border around the main window and print a title */
        box(my_form_win, 0, 0);
	print_in_middle(my_form_win, 1, 0, cols + 4, "Add contact", COLOR_PAIR(1));
	post_form(my_form);
	wrefresh(my_form_win);
	mvprintw(LINES - 2, 0, "Use arrow keys to switch between fields | Press ESC to cancel");
	move((y/2)+3,(x/2)-16);
	refresh();
	/* Loop through to get user requests */
	while((ch = wgetch(my_form_win)) != 27)
	{	switch(ch)
		{	case KEY_DOWN:
				/* Go to next field */
				form_driver(my_form, REQ_NEXT_FIELD);
				/* Go to the end of the present buffer */
				/* Leaves nicely at the last character */
				form_driver(my_form, REQ_END_LINE);
				break;
			case KEY_UP:
				/* Go to previous field */
				form_driver(my_form, REQ_PREV_FIELD);
				form_driver(my_form, REQ_END_LINE);
				break;
			case KEY_BACKSPACE:
				/* Go to previous field */
				form_driver(my_form,REQ_DEL_PREV);
				break;
			case KEY_DC:
				form_driver(my_form,REQ_DEL_CHAR);
				break;
			case KEY_HOME:
				form_driver(my_form,REQ_BEG_FIELD);
				break;
			case KEY_END:
				form_driver(my_form,REQ_END_FIELD);
				break;
			case KEY_LEFT:
				form_driver(my_form,REQ_LEFT_CHAR);
				break;
			case KEY_RIGHT:
				form_driver(my_form,REQ_RIGHT_CHAR);
				break;
			case 9:
				form_driver(my_form,REQ_NEXT_FIELD);
				break;
			case 10:
				{
				char *str=malloc(1000);
				form_driver(my_form,REQ_BEG_FIELD);
				sprintf(str, "%s", field_buffer(field[0],0));
				size_t len = 0;
			        char *frontp = str - 1;
    				char *endp = NULL;
				len = strlen(str);
    				endp = str + len;
				while( isspace(*(++frontp)) );
				while( isspace(*(--endp)) && endp != frontp );
				if( str + len - 1 != endp )		
            			*(endp + 1) = '\0';
				else if( frontp != str &&  endp == frontp )
				*str = '\0';
				endp = str;
			        if( frontp != str )
			        {
			            while( *frontp ) *endp++ = *frontp++;
			            *endp = '\0';
			        }
				char *stp=malloc(1000);
				strcpy(stp,str);
				//mvprintw(LINES - 3, 0, "%s %d",stp,strlen(stp));
				//refresh();
				sprintf(str, "%s", field_buffer(field[1],0));
				len=0;
				frontp=str-1;
				endp=NULL;
				len = strlen(str);
    				endp = str + len;
				while( isspace(*(++frontp)) );
				while( isspace(*(--endp)) && endp != frontp );
				if( str + len - 1 != endp )		
            			*(endp + 1) = '\0';
				else if( frontp != str &&  endp == frontp )
				*str = '\0';
				endp = str;
			        if( frontp != str )
			        {
			            while( *frontp ) *endp++ = *frontp++;
			            *endp = '\0';
			        }
				if((strlen(stp)>0) && (strlen(str)>0))
				{
				newcontact(stp,str);
				ext=1;
				}
				else if(strlen(str)==0)
				form_driver(my_form, REQ_NEXT_FIELD);
				}
			default:
				/* If this is a normal character, it gets */
				/* Printed				  */	
				form_driver(my_form, ch);
				break;
		}
	if(ext==1)
	   break;
	}
	/* Un post form and free the memory */
	unpost_form(my_form);
	free_form(my_form);
	free_field(field[0]);
	free_field(field[1]); 
	endwin();
	return ext;
}
Beispiel #13
0
PANEL *
save_raw_create()
{
    PANEL *panel;
    WINDOW *win;
    int height, width;
    save_raw_info_t *info;
    char savefile[128];

    // Calculate window dimensions
    height = 10;
    width = 90;

    // Cerate a new indow for the panel and form
    win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2);

    // Create a new panel
    panel = new_panel(win);

    // Initialize save panel specific data
    info = malloc(sizeof(save_raw_info_t));
    memset(info, 0, sizeof(save_raw_info_t));

    // Store it into panel userptr
    set_panel_userptr(panel, (void*) info);

    // Initialize the fields
    info->fields[FLD_SAVE_RAW_FILE] = new_field(1, 68, 3, 15, 0, 0);
    info->fields[FLD_SAVE_RAW_SELECTED] = new_field(1, 1, 4, 5, 0, 0);
    info->fields[FLD_SAVE_RAW_SAVE] = new_field(1, 10, height - 2, 30, 0, 0);
    info->fields[FLD_SAVE_RAW_CANCEL] = new_field(1, 10, height - 2, 50, 0, 0);
    info->fields[FLD_SAVE_RAW_COUNT] = NULL;

    // Set fields options
    field_opts_off(info->fields[FLD_SAVE_RAW_FILE], O_AUTOSKIP);

    // Change background of input fields
    set_field_back(info->fields[FLD_SAVE_RAW_FILE], A_UNDERLINE);

    // Create the form and post it
    info->form = new_form(info->fields);
    set_form_sub(info->form, win);
    post_form(info->form);

    // Fields labels
    mvwprintw(win, 3, 3, "Save file:");
    mvwprintw(win, 4, 4, "[ ] Only save selected calls");

    // Set Default field values
    sprintf(savefile, "%s/sngrep-raw-%u.txt", get_option_value("sngrep.savepath"),
            (unsigned) time(NULL));

    set_field_buffer(info->fields[FLD_SAVE_RAW_FILE], 0, savefile);
    set_field_buffer(info->fields[FLD_SAVE_RAW_SELECTED], 0,
                     is_option_enabled("sngrep.saveselected") ? "*" : "");
    set_field_buffer(info->fields[FLD_SAVE_RAW_SAVE], 0, "[  Save  ]");
    set_field_buffer(info->fields[FLD_SAVE_RAW_CANCEL], 0, "[ Cancel ]");

    // Set the window title and boxes
    mvwprintw(win, 1, 28, "Save raw data to file");
    wattron(win, COLOR_PAIR(CP_BLUE_ON_DEF));
    title_foot_box(panel_window(panel));
    mvwhline(win, height - 3, 1, ACS_HLINE, width - 1);
    mvwaddch(win, height - 3, 0, ACS_LTEE);
    mvwaddch(win, height - 3, width - 1, ACS_RTEE);
    wattroff(win, COLOR_PAIR(CP_BLUE_ON_DEF));

    // Set default cursor position
    set_current_field(info->form, info->fields[FLD_SAVE_RAW_FILE]);
    wmove(win, 3, 15);
    curs_set(1);

    return panel;
}
Beispiel #14
0
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);
}
Beispiel #15
0
/*  trafvol_section_init

    This function creates the trafvol section window and the fields inside it.
    
    Returncodes:
         0: ok
        -1: error
*/
static int
trafvol_section_init(const int debuglvl, int height, int width, int startx,
            int starty, unsigned int ifac_num)
{
    size_t          i = 0;
    int             rows = 0,
                    cols = 0;
    int             max_height = 0,
                    max_width = 0,
                    toprow = 0,
                    num_rows = (int)ifac_num;
    unsigned int    ifacs = 0,
                    ifac_fields = 0,
                    ifac_start = 4;

    /* get and check the screen dimentions */
    getmaxyx(stdscr, max_height, max_width);
    if(width > max_width)
        return(-1);

    /* set the number of fields: 
    
        interfacename,
        today in, today out,
        yesterday in, yesterday out,
        7 days in, 7 days out,
        this month in, this month out,
        last month in, last month out
    */
    TrafVolSection.n_fields = 11 * (size_t)ifac_num;
    
    /* alloc the needed memory */
    if(!(TrafVolSection.fields = (FIELD **)calloc(TrafVolSection.n_fields + 1, sizeof(FIELD *))))
    {
        (void)vrprint.error(-1, VR_ERR, gettext("calloc failed: %s (in: %s:%d)."),
                                strerror(errno),
                                __FUNC__, __LINE__);
        return(-1);
    }

    /* create iface stats fields */
    for(ifacs = 0, ifac_fields = 0; ifacs < ifac_num; ifacs++)
    {
        toprow = (int)(ifac_start+ifacs);

        /* interface name */
        TrafVolSection.fields[ifac_fields] = new_field(1, 15, toprow, 0, 0, 1);
        set_field_buffer_wrap(debuglvl, TrafVolSection.fields[ifac_fields], 1, "ifacname");
        ifac_fields++;

        TrafVolSection.fields[ifac_fields] = new_field(1, 5, toprow, 16, 0, 1);
        set_field_buffer_wrap(debuglvl, TrafVolSection.fields[ifac_fields], 1, "t-in");
        ifac_fields++;

        TrafVolSection.fields[ifac_fields] = new_field(1, 5, toprow, 22, 0, 1);
        set_field_buffer_wrap(debuglvl, TrafVolSection.fields[ifac_fields], 1, "t-ou");
        ifac_fields++;

        TrafVolSection.fields[ifac_fields] = new_field(1, 5, toprow, 28, 0, 1);
        set_field_buffer_wrap(debuglvl, TrafVolSection.fields[ifac_fields], 1, "y-in");
        ifac_fields++;

        TrafVolSection.fields[ifac_fields] = new_field(1, 5, toprow, 34, 0, 1);
        set_field_buffer_wrap(debuglvl, TrafVolSection.fields[ifac_fields], 1, "y-ou");
        ifac_fields++;

        TrafVolSection.fields[ifac_fields] = new_field(1, 5, toprow, 40, 0, 1);
        set_field_buffer_wrap(debuglvl, TrafVolSection.fields[ifac_fields], 1, "7-in");
        ifac_fields++;

        TrafVolSection.fields[ifac_fields] = new_field(1, 5, toprow, 46, 0, 1);
        set_field_buffer_wrap(debuglvl, TrafVolSection.fields[ifac_fields], 1, "7-ou");
        ifac_fields++;

        TrafVolSection.fields[ifac_fields] = new_field(1, 5, toprow, 52, 0, 1);
        set_field_buffer_wrap(debuglvl, TrafVolSection.fields[ifac_fields], 1, "t-in");
        ifac_fields++;

        TrafVolSection.fields[ifac_fields] = new_field(1, 5, toprow, 58, 0, 1);
        set_field_buffer_wrap(debuglvl, TrafVolSection.fields[ifac_fields], 1, "t-ou");
        ifac_fields++;

        TrafVolSection.fields[ifac_fields] = new_field(1, 5, toprow, 64, 0, 1);
        set_field_buffer_wrap(debuglvl, TrafVolSection.fields[ifac_fields], 1, "l-in");
        ifac_fields++;

        TrafVolSection.fields[ifac_fields] = new_field(1, 5, toprow, 70, 0, 1);
        set_field_buffer_wrap(debuglvl, TrafVolSection.fields[ifac_fields], 1, "l-ou");
        ifac_fields++;
    }

    /* terminate the field array */
    TrafVolSection.fields[TrafVolSection.n_fields] = NULL;

    /* create the window and the panel */
    if(!(TrafVolSection.win = create_newwin(height, width, startx, starty,
            gettext("Traffic Volume Section"), vccnf.color_win)))
    {
        (void)vrprint.error(-1, VR_ERR, gettext("creating window failed."));
        return(-1);
    }

    if(!(TrafVolSection.panel[0] = new_panel(TrafVolSection.win)))
    {
        (void)vrprint.error(-1, VR_ERR, gettext("creating panel failed."));
        return(-1);
    }

    /* field options */
    for(i = 0; i < TrafVolSection.n_fields; i++)
    {
        if(debuglvl >= LOW)
            set_field_back(TrafVolSection.fields[i],
                    vccnf.color_win);
        else
            set_field_back(TrafVolSection.fields[i],
                    vccnf.color_win);

        field_opts_off(TrafVolSection.fields[i], O_AUTOSKIP);
        /* set status to false */
        set_field_status(TrafVolSection.fields[i], FALSE);
    }

    /* Create the form and post it */
    if(!(TrafVolSection.form = new_form(TrafVolSection.fields)))
    {
        (void)vrprint.error(-1, VR_ERR, gettext("creating form failed."));
        return(-1);
    }
    /* Calculate the area required for the form */
    scale_form(TrafVolSection.form, &rows, &cols);
    keypad(TrafVolSection.win, TRUE);
    /* Set main window and sub window */
    set_form_win(TrafVolSection.form, TrafVolSection.win);
    set_form_sub(TrafVolSection.form, derwin(TrafVolSection.win, rows, cols, 1, 2));

    if(post_form(TrafVolSection.form) != E_OK)
    {
        (void)vrprint.error(-1, VR_ERR, gettext("posting the form failed."));
        return(-1);
    }

    mvwprintw(TrafVolSection.win, 3, 2,  gettext("Interface"));
    mvwprintw(TrafVolSection.win, 2, 18, gettext("Today"));
    mvwprintw(TrafVolSection.win, 3, 18, gettext("In"));
    mvwprintw(TrafVolSection.win, 3, 24, gettext("Out"));
    mvwprintw(TrafVolSection.win, 2, 30, gettext("Yesterday"));
    mvwprintw(TrafVolSection.win, 3, 30, gettext("In"));
    mvwprintw(TrafVolSection.win, 3, 36, gettext("Out"));
    mvwprintw(TrafVolSection.win, 2, 42, gettext("7-days"));
    mvwprintw(TrafVolSection.win, 3, 42, gettext("In"));
    mvwprintw(TrafVolSection.win, 3, 48, gettext("Out"));
    mvwprintw(TrafVolSection.win, 2, 54, gettext("This month"));
    mvwprintw(TrafVolSection.win, 3, 54, gettext("In"));
    mvwprintw(TrafVolSection.win, 3, 60, gettext("Out"));
    mvwprintw(TrafVolSection.win, 2, 66, gettext("Last month"));
    mvwprintw(TrafVolSection.win, 3, 66, gettext("In"));
    mvwprintw(TrafVolSection.win, 3, 72, gettext("Out"));
    mvwhline(TrafVolSection.win,  4, 1,  ACS_HLINE, 76);
    mvwaddch(TrafVolSection.win,  4, 0,  ACS_LTEE);
    mvwaddch(TrafVolSection.win,  4, 77, ACS_RTEE);

    mvwvline(TrafVolSection.win,  5, 17, ACS_VLINE, num_rows);
    mvwaddch(TrafVolSection.win,  4, 17, ACS_TTEE);
    mvwvline(TrafVolSection.win,  5, 23, ACS_VLINE, num_rows);
    mvwaddch(TrafVolSection.win,  4, 23, ACS_TTEE);
    mvwvline(TrafVolSection.win,  5, 29, ACS_VLINE, num_rows);
    mvwaddch(TrafVolSection.win,  4, 29, ACS_TTEE);
    mvwvline(TrafVolSection.win,  5, 35, ACS_VLINE, num_rows);
    mvwaddch(TrafVolSection.win,  4, 35, ACS_TTEE);
    mvwvline(TrafVolSection.win,  5, 41, ACS_VLINE, num_rows);
    mvwaddch(TrafVolSection.win,  4, 41, ACS_TTEE);
    mvwvline(TrafVolSection.win,  5, 47, ACS_VLINE, num_rows);
    mvwaddch(TrafVolSection.win,  4, 47, ACS_TTEE);
    mvwvline(TrafVolSection.win,  5, 53, ACS_VLINE, num_rows);
    mvwaddch(TrafVolSection.win,  4, 53, ACS_TTEE);
    mvwvline(TrafVolSection.win,  5, 59, ACS_VLINE, num_rows);
    mvwaddch(TrafVolSection.win,  4, 59, ACS_TTEE);
    mvwvline(TrafVolSection.win,  5, 65, ACS_VLINE, num_rows);
    mvwaddch(TrafVolSection.win,  4, 65, ACS_TTEE);
    mvwvline(TrafVolSection.win,  5, 71, ACS_VLINE, num_rows);
    mvwaddch(TrafVolSection.win,  4, 71, ACS_TTEE);

    /* don't print this line if it overlaps with the window border */
    if(5 + num_rows + 1 < height)
    {
        mvwhline(TrafVolSection.win,  5 + num_rows, 1,  ACS_HLINE, 76);
        mvwaddch(TrafVolSection.win,  5 + num_rows, 0,  ACS_LTEE);
        mvwaddch(TrafVolSection.win,  5 + num_rows, 77, ACS_RTEE);
    }

    mvwaddch(TrafVolSection.win,  5 + num_rows, 17, ACS_BTEE);
    mvwaddch(TrafVolSection.win,  5 + num_rows, 23, ACS_BTEE);
    mvwaddch(TrafVolSection.win,  5 + num_rows, 29, ACS_BTEE);
    mvwaddch(TrafVolSection.win,  5 + num_rows, 35, ACS_BTEE);
    mvwaddch(TrafVolSection.win,  5 + num_rows, 41, ACS_BTEE);
    mvwaddch(TrafVolSection.win,  5 + num_rows, 47, ACS_BTEE);
    mvwaddch(TrafVolSection.win,  5 + num_rows, 53, ACS_BTEE);
    mvwaddch(TrafVolSection.win,  5 + num_rows, 59, ACS_BTEE);
    mvwaddch(TrafVolSection.win,  5 + num_rows, 65, ACS_BTEE);
    mvwaddch(TrafVolSection.win,  5 + num_rows, 71, ACS_BTEE);

    return(0);
}
Beispiel #16
0
PANEL *
filter_create()
{
    PANEL *panel;
    WINDOW *win;
    int height, width;
    filter_info_t *info;
    const char *method;

    // Calculate window dimensions
    height = 16;
    width = 50;

    // Cerate a new indow for the panel and form
    win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2);

    // Create a new panel
    panel = new_panel(win);

    // Initialize Filter panel specific data
    info = sng_malloc(sizeof(filter_info_t));

    // Store it into panel userptr
    set_panel_userptr(panel, (void*) info);

    // Initialize the fields
    info->fields[FLD_FILTER_SIPFROM] = new_field(1, 28, 3, 18, 0, 0);
    info->fields[FLD_FILTER_SIPTO] = new_field(1, 28, 4, 18, 0, 0);
    info->fields[FLD_FILTER_SRC] = new_field(1, 18, 5, 18, 0, 0);
    info->fields[FLD_FILTER_DST] = new_field(1, 18, 6, 18, 0, 0);
    info->fields[FLD_FILTER_PAYLOAD] = new_field(1, 28, 7, 18, 0, 0);
    info->fields[FLD_FILTER_REGISTER] = new_field(1, 1, 9, 15, 0, 0);
    info->fields[FLD_FILTER_INVITE] = new_field(1, 1, 10, 15, 0, 0);
    info->fields[FLD_FILTER_SUBSCRIBE] = new_field(1, 1, 11, 15, 0, 0);
    info->fields[FLD_FILTER_NOTIFY] = new_field(1, 1, 12, 15, 0, 0);
    info->fields[FLD_FILTER_OPTIONS] = new_field(1, 1, 9, 37, 0, 0);
    info->fields[FLD_FILTER_PUBLISH] = new_field(1, 1, 10, 37, 0, 0);
    info->fields[FLD_FILTER_MESSAGE] = new_field(1, 1, 11, 37, 0, 0);
    info->fields[FLD_FILTER_FILTER] = new_field(1, 10, height - 2, 11, 0, 0);
    info->fields[FLD_FILTER_CANCEL] = new_field(1, 10, height - 2, 30, 0, 0);
    info->fields[FLD_FILTER_COUNT] = NULL;

    // Set fields options
    field_opts_off(info->fields[FLD_FILTER_SIPFROM], O_AUTOSKIP);
    field_opts_off(info->fields[FLD_FILTER_SIPTO], O_AUTOSKIP);
    field_opts_off(info->fields[FLD_FILTER_SRC], O_AUTOSKIP);
    field_opts_off(info->fields[FLD_FILTER_DST], O_AUTOSKIP);
    field_opts_off(info->fields[FLD_FILTER_PAYLOAD], O_AUTOSKIP);
    field_opts_off(info->fields[FLD_FILTER_REGISTER], O_AUTOSKIP);
    field_opts_off(info->fields[FLD_FILTER_INVITE], O_AUTOSKIP);
    field_opts_off(info->fields[FLD_FILTER_SUBSCRIBE], O_AUTOSKIP);
    field_opts_off(info->fields[FLD_FILTER_NOTIFY], O_AUTOSKIP);
    field_opts_off(info->fields[FLD_FILTER_OPTIONS], O_AUTOSKIP);
    field_opts_off(info->fields[FLD_FILTER_PUBLISH], O_AUTOSKIP);
    field_opts_off(info->fields[FLD_FILTER_MESSAGE], O_AUTOSKIP);
    field_opts_off(info->fields[FLD_FILTER_FILTER], O_EDIT);
    field_opts_off(info->fields[FLD_FILTER_CANCEL], O_EDIT);

    // Change background of input fields
    set_field_back(info->fields[FLD_FILTER_SIPFROM], A_UNDERLINE);
    set_field_back(info->fields[FLD_FILTER_SIPTO], A_UNDERLINE);
    set_field_back(info->fields[FLD_FILTER_SRC], A_UNDERLINE);
    set_field_back(info->fields[FLD_FILTER_DST], A_UNDERLINE);
    set_field_back(info->fields[FLD_FILTER_PAYLOAD], A_UNDERLINE);

    // Create the form and post it
    info->form = new_form(info->fields);
    set_form_sub(info->form, win);
    post_form(info->form);

    // Fields labels
    mvwprintw(win, 3, 3, "SIP From:");
    mvwprintw(win, 4, 3, "SIP To:");
    mvwprintw(win, 5, 3, "Source:");
    mvwprintw(win, 6, 3, "Destination:");
    mvwprintw(win, 7, 3, "Payload:");
    mvwprintw(win, 9, 3, "REGISTER   [ ]");
    mvwprintw(win, 10, 3, "INVITE     [ ]");
    mvwprintw(win, 11, 3, "SUBSCRIBE  [ ]");
    mvwprintw(win, 12, 3, "NOTIFY     [ ]");
    mvwprintw(win, 9, 25, "OPTIONS    [ ]");
    mvwprintw(win, 10, 25, "PUBLISH    [ ]");
    mvwprintw(win, 11, 25, "MESSAGE    [ ]");

    // Get Method filter
    if (!(method = filter_get(FILTER_METHOD)))
        method = setting_get_value(SETTING_FILTER_METHODS);

    // Set Default field values
    set_field_buffer(info->fields[FLD_FILTER_SIPFROM], 0, filter_get(FILTER_SIPFROM));
    set_field_buffer(info->fields[FLD_FILTER_SIPTO], 0, filter_get(FILTER_SIPTO));
    set_field_buffer(info->fields[FLD_FILTER_SRC], 0, filter_get(FILTER_SOURCE));
    set_field_buffer(info->fields[FLD_FILTER_DST], 0, filter_get(FILTER_DESTINATION));
    set_field_buffer(info->fields[FLD_FILTER_PAYLOAD], 0, filter_get(FILTER_PAYLOAD));
    set_field_buffer(info->fields[FLD_FILTER_REGISTER], 0,
                     strcasestr(method, sip_method_str(SIP_METHOD_REGISTER)) ? "*" : "");
    set_field_buffer(info->fields[FLD_FILTER_INVITE], 0,
                     strcasestr(method, sip_method_str(SIP_METHOD_INVITE)) ? "*" : "");
    set_field_buffer(info->fields[FLD_FILTER_SUBSCRIBE], 0,
                     strcasestr(method,sip_method_str(SIP_METHOD_SUBSCRIBE)) ? "*" : "");
    set_field_buffer(info->fields[FLD_FILTER_NOTIFY], 0,
                     strcasestr(method, sip_method_str(SIP_METHOD_NOTIFY)) ? "*" : "");
    set_field_buffer(info->fields[FLD_FILTER_OPTIONS], 0,
                     strcasestr(method, sip_method_str(SIP_METHOD_OPTIONS)) ? "*" : "");
    set_field_buffer(info->fields[FLD_FILTER_PUBLISH], 0,
                     strcasestr(method,  sip_method_str(SIP_METHOD_PUBLISH)) ? "*" : "");
    set_field_buffer(info->fields[FLD_FILTER_MESSAGE], 0,
                     strcasestr(method,  sip_method_str(SIP_METHOD_MESSAGE)) ? "*" : "");
    set_field_buffer(info->fields[FLD_FILTER_FILTER], 0, "[ Filter ]");
    set_field_buffer(info->fields[FLD_FILTER_CANCEL], 0, "[ Cancel ]");

    // Set the window title and boxes
    mvwprintw(win, 1, 18, "Filter options");
    wattron(win, COLOR_PAIR(CP_BLUE_ON_DEF));
    title_foot_box(panel);
    mvwhline(win, 8, 1, ACS_HLINE, 49);
    mvwaddch(win, 8, 0, ACS_LTEE);
    mvwaddch(win, 8, 49, ACS_RTEE);
    wattroff(win, COLOR_PAIR(CP_BLUE_ON_DEF));

    // Set default cursor position
    set_current_field(info->form, info->fields[FLD_FILTER_SIPFROM]);
    wmove(win, 3, 18);
    curs_set(1);

    return panel;
}
Beispiel #17
0
static void
main_search(void *arg)
{
	FIELD *mfield[2];
	FORM *mform;
	WINDOW *msubwin;
	int ch, x, j, i = 0;
	char *title;
	char	eb[64];

	/* Clear screen and print title */
	show_mainwin(1);
	head_mainwin("Search for packages");
	msubwin = create_lowersubwin(NULL, &x);
	if (sizeof keyword < x - 10)
		x = sizeof keyword;
	mfield[0] = new_field(1, x - 10, 5, 5, 0, 0);
	mfield[1] = NULL;
	set_field_back(mfield[0], A_UNDERLINE);
	field_opts_off(mfield[0], O_AUTOSKIP);
	mform = new_form(mfield);
	set_form_win(mform, mainwin);
	set_form_sub(mform, msubwin);
	post_form(mform);
	show_mainwin(0);

	keyword[0] = '\0';
	while((ch = getch()) != '\n') {
		switch (ch) {
			case KEY_LEFT:
				form_driver(mform, REQ_LEFT_CHAR);
				i--;
				break;
			case KEY_RIGHT:
				if (keyword[i] != '\0') {
					form_driver(mform, REQ_RIGHT_CHAR);
					i++;
				}
				break;
			case KEY_END:
				form_driver(mform, REQ_END_LINE);
				i = strlen(keyword);
				break;
			case KEY_HOME:
				form_driver(mform, REQ_BEG_LINE);
				i = 0;
				break;
			case '\b':
				form_driver(mform, REQ_DEL_PREV);
				keyword[i] = '\0';
				i--;
				break;
			default:
				if (i < sizeof(keyword) - 2) {
					form_driver(mform, ch);
					for (j = strlen(keyword); j >= i; j--)
						keyword[j+1] = keyword[j];
					keyword[i] = ch;
					i++;
				}
				break;
		}
		show_mainwin(0);
	}
	unpost_form(mform);
	free_form(mform);
	free_field(mfield[0]);
	free_field(mfield[1]);

	if (strlen(keyword) <= 0)
		return;

	if ((i = regcomp(&re, keyword, REG_EXTENDED|REG_NOSUB|REG_ICASE))
			!= 0) {
		regerror(i, &re, eb, sizeof(eb));
		ask_ok("regcomp: %s: %s", keyword, eb);
	} else {
		if (asprintf(&title, "Search results for '%s'", keyword) <= 0) {
			endwin();
			err(1, "asprintf");
		}
		//plisthead.P_Plisthead = &r_plisthead;
		//plisthead.P_count = r_plistcounter;
		//menu_menupkgs(&plisthead, title, compare_keyword);
		regfree(&re);
		free(title);
	}
}
Beispiel #18
0
int
filter_input_box(const int debuglvl, struct vrmr_filter *filter)
{
    WINDOW  *ib_win = NULL;
    PANEL   *my_panels[1];
    FIELD   *cur = NULL,
            *prev = NULL;
    FORM    *my_form = NULL;
    int     height = 0,
            width = 0,
            startx = 0,
            starty = 0,
            max_height = 0,
            max_width = 0,
            ch = 0,
            rows = 0,
            cols = 0,
            quit = 0;
    size_t  i = 0;
    char    not_defined = FALSE;

    /* init fields */
    memset(&FiFi, 0, sizeof(struct FilterFields_));

    /* set the window size */
    getmaxyx(stdscr, max_height, max_width);
    height = 9;
    width = 48;

    /* print on the center of the screen */
    starty = (max_height - height) / 2;
    startx = (max_width - width) / 2;

    /* create window */
    ib_win = create_newwin(height, width, starty, startx, gettext("Filter"), vccnf.color_win);
    if(ib_win == NULL)
    {
        vrmr_error(-1, VR_ERR, gettext("creating window failed."));
        return(-1);
    }

    my_panels[0] = new_panel(ib_win);
    if(my_panels[0] == NULL)
    {
        vrmr_error(-1, VR_ERR, gettext("creating panel failed."));
        return(-1);
    }

    FiFi.n_fields = 2;

    FiFi.fields = (FIELD **)calloc(FiFi.n_fields + 1, sizeof(FIELD *));
    if(FiFi.fields == NULL)
    {
        vrmr_error(-1, VR_ERR, gettext("calloc failed: %s (in: %s:%d)."),
                                strerror(errno), __FUNC__, __LINE__);
        return(-1);
    }

    FiFi.string_fld = (FiFi.fields[0] = new_field(1, 31, 3,  4, 0, 0));
    FiFi.check_fld = (FiFi.fields[1]  = new_field(1,  1, 5,  5, 0, 0));

    set_field_back(FiFi.string_fld, vccnf.color_win_rev);
    field_opts_off(FiFi.string_fld, O_AUTOSKIP);
    set_field_status(FiFi.string_fld, FALSE);
    set_field_buffer_wrap(debuglvl, FiFi.string_fld, 0, filter->str);


    set_field_back(FiFi.check_fld, vccnf.color_win);
    field_opts_off(FiFi.check_fld, O_AUTOSKIP);
    set_field_status(FiFi.check_fld, FALSE);
    set_field_buffer_wrap(debuglvl, FiFi.check_fld, 0, filter->neg ? "X" : " ");

    my_form = new_form(FiFi.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);

    /* XXX: we really should have a wrapper function to just print
     * in the middle of a window to prevent hacks like this. */
    char *s = gettext("Enter filter (leave empty for no filter)");
    mvwprintw(ib_win, 2, (width - StrLen(s))/2, s);
    mvwprintw(ib_win, 6, 6, "[");
    mvwprintw(ib_win, 6, 8, "]");
    mvwprintw(ib_win, 6, 11, gettext("show lines that don't match"));

    update_panels();
    doupdate();

    if(!(cur = current_field(my_form)))
    {
        vrmr_error(-1, VR_INTERR, "NULL pointer (in: %s:%d).",
                                __FUNC__, __LINE__);
        return(-1);
    }

    while(quit == 0)
    {
        /* draw nice markers */
        draw_field_active_mark(cur, prev, ib_win, my_form, vccnf.color_win_mark|A_BOLD);

        not_defined = 0;

        /* get user input */
        ch = wgetch(ib_win);

        if(cur == FiFi.check_fld)
        {
            if(nav_field_toggleX(debuglvl, my_form, ch) < 0)
                not_defined = 1;
        }
        else if(cur == FiFi.string_fld)
        {
            if(nav_field_simpletext(debuglvl, my_form, ch) < 0)
                not_defined = 1;
        }
        else
        {
            not_defined = 1;
        }

        /* the rest is handled here */
        if(not_defined)
        {
            switch(ch)
            {
                case KEY_UP:

                    form_driver(my_form, REQ_PREV_FIELD);
                    form_driver(my_form, REQ_END_LINE);
                    break;

                case KEY_DOWN:
                case 9: // tab

                    form_driver(my_form, REQ_NEXT_FIELD);
                    form_driver(my_form, REQ_END_LINE);
                    break;

                case 10: // enter

                    if(cur == FiFi.check_fld)
                    {
                        quit = 1;
                    }
                    else
                    {
                        form_driver(my_form, REQ_NEXT_FIELD);
                        form_driver(my_form, REQ_END_LINE);
                    }
                    break;

                case 27:
                case KEY_F(10):
                case 'q':
                case 'Q':

                    quit = 1;
                    break;
            }
        }

        /* before we get the new 'cur', store cur in prev */
        prev = cur;
        if(!(cur = current_field(my_form)))
        {
            vrmr_error(-1, VR_INTERR, "NULL pointer (in: %s).", __FUNC__);
            return(-1);
        }

        /* draw and set cursor */
        wrefresh(ib_win);
        pos_form_cursor(my_form);
    }

    /* save here */
    if(filter_save(debuglvl, filter) < 0)
    {
        vrmr_error(-1, VR_ERR, gettext("setting filter failed."));
    }

    unpost_form(my_form);
    free_form(my_form);

    for(i=0; i < FiFi.n_fields; i++)
    {
        free_field(FiFi.fields[i]);
    }
    free(FiFi.fields);

    del_panel(my_panels[0]);
    destroy_win(ib_win);

    update_panels();
    doupdate();

    return(0);
}
Beispiel #19
0
int eq_run (kr_client_t *client, char *sysname) {

	WINDOW *eq_win,*tmpw;
	PANEL  *eq_mainpan,*eq_subpan,*ctrl_subp;
	FORM *eq_form;
	FIELD **field;
	FIELD **ctrl_field;
	FORM *ctrl_form;


  /* Panels Structs */
  ctrls_show_t *ctrls;
  eq_port_t *eqport;

  db_show_t *db;
  hz_show_t *hz;
  bw_show_t *bw;

  eq_saved_val_t *vals;

	int i;
	int max_co,subx,suby,gap;
	int offs = 0;
	int field_idx;
	int in_ctrl = 0;
  int nbands = KRAD_EQ_MAX_BANDS;
  int showed_bands = 1;
  int idx;
  char num[3];

	int ch;
	int res;
  int bandn;

	clear ();

	char *fieldname[3] = {"Power","Frequency","Bandwidth"}; 
  int nctrls = 3;

	eq_win = newwin (0,0,0,0);

	field = calloc (nbands+1,sizeof (FIELD*));

  ctrl_field = calloc (nctrls+1,sizeof (FIELD*));

	max_co = getmaxx (eq_win);

	gap = floor ((max_co) / nbands);

  vals = NULL;
  bandn = 0;
  ch = 0;


  for (i=0;i<nbands;i++) {

    field[i] = new_field (1,2,1, offs, 0, 0);
    set_field_just (field[i], JUSTIFY_CENTER);
    itoa (i,num,digits (i) + 1 );
    set_field_buffer (field[i], 0, num);
    field_opts_off (field[i], O_AUTOSKIP | O_EDIT); 
    offs += gap;

  }

  field[nbands] = NULL;

  offs = 0;
  gap = floor ((max_co ) / nctrls);

  for (i=0;i<nctrls;i++) {

    ctrl_field[i] = new_field (1,strlen (fieldname[i]),1, offs, 0, 0);
    set_field_just (ctrl_field[i], JUSTIFY_CENTER);
    set_field_buffer (ctrl_field[i], 0, fieldname[i]);
    field_opts_off (ctrl_field[i], O_AUTOSKIP | O_EDIT); 
    offs += gap;

  }


  /* Controls generation */
  ctrls = eq_ctrls_gen (eq_win,showed_bands);

  vals = calloc (1,sizeof (eq_saved_val_t));

  eqport = calloc (1,sizeof (eq_port_t));

  db = ctrls->db;
  hz = ctrls->hz;
  bw = ctrls->bw;

  eqport->name = sysname;
  eqport->vals = vals;
  eqport->ctrls = ctrls;


  /* Eq form init */
  eq_form = new_form (field);

  wattron (eq_win,COLOR_PAIR (2) | A_BOLD);
  mvwprintw (eq_win,getmaxy (eq_win) * 0.05,floor ((max_co/2)-((strlen (sysname)+14)/2)),"Equalizer for %s",sysname); 
  wattroff (eq_win,COLOR_PAIR (2) | A_BOLD);

  set_form_win (eq_form, eq_win);
  scale_form (eq_form, &suby, &subx);
  set_form_sub (eq_form, derwin (eq_win,suby, subx , getmaxy (eq_win) * 0.10 , (max_co - subx) / 2 ));

  eq_mainpan = new_panel (eq_win);
  eq_subpan = new_panel (form_sub (eq_form));

  top_panel (eq_mainpan);
  top_panel (eq_subpan);

  post_form (eq_form);

  keypad (eq_win, TRUE);

  set_current_field (eq_form,field[0]);
  set_field_fore (current_field (eq_form),A_BOLD | COLOR_PAIR (3)); 


  /* Eq ctrls form init */

  ctrl_form = new_form (ctrl_field);

  set_form_win (ctrl_form, eq_win);
  scale_form (ctrl_form, &suby, &subx);
  set_form_sub (ctrl_form, derwin (eq_win,suby, subx , getmaxy (eq_win) * 0.90 , (max_co - subx) / 2 ));

  ctrl_subp = new_panel (form_sub (ctrl_form));

  top_panel (ctrl_subp);

  post_form (ctrl_form);


  field_idx = field_index (current_field (eq_form));


  /* Let's show controls! */
  kr_mixer_portgroups (client);
  show_all_panels (ctrls,showed_bands);


	update_panels ();
	doupdate ();

	while (ch != 'q') { 


    res = krm_poll (client,-1); 

    switch (res) {
      case 0:
        continue;
      case 1:
        ch = getch ();
        break;
      case 2:
        eqport->band = bandn;
        kr_delivery_recv (client);
        eq_delivery_handler (client,eqport);
        continue;
      case -1:
        continue;
    }

    switch (ch) { 

      case KEY_LEFT:

      	if (in_ctrl) {
          set_field_fore (current_field (ctrl_form),A_NORMAL); 
          form_driver (ctrl_form, REQ_PREV_FIELD);
          set_field_fore (current_field (ctrl_form),A_BOLD | COLOR_PAIR (1)); 
          idx = field_index (current_field (ctrl_form));
      	}
      	else {
      		set_field_fore (current_field (eq_form),A_NORMAL); 
      		form_driver (eq_form, REQ_PREV_FIELD);
      		set_field_fore (current_field (eq_form),A_BOLD | COLOR_PAIR (3)); 
          bandn = field_index (current_field (eq_form));
          kr_mixer_portgroups (client); 
      	}
        break;
      case KEY_RIGHT:
      	if (in_ctrl) {
          set_field_fore (current_field (ctrl_form),A_NORMAL); 
          form_driver (ctrl_form, REQ_NEXT_FIELD);
          set_field_fore (current_field (ctrl_form),A_BOLD | COLOR_PAIR (1)); 
          idx = field_index (current_field (ctrl_form));
          
        }
      	else {
          set_field_fore (current_field (eq_form),A_NORMAL); 
          form_driver (eq_form, REQ_NEXT_FIELD);
          set_field_fore (current_field (eq_form),A_BOLD | COLOR_PAIR (3));
          bandn = field_index (current_field (eq_form));
          kr_mixer_portgroups (client); 
      	}
        break;
      case KEY_UP:
        if (in_ctrl) {
          switch (idx) {
            case 0:
              vals->db += 0.50;
              kr_mixer_set_effect_control (client, sysname, 0, bandn, "db", vals->db, 0, 0);
              break;
            case 1:
              vals->hz += 5;
              kr_mixer_set_effect_control (client, sysname, 0, bandn, "hz", vals->hz, 0, 0);
              break;
            case 2:
              vals->bw += 0.10;
              kr_mixer_set_effect_control (client, sysname, 0, bandn, "bw", vals->bw, 0, 0);
              break;
          }

        }
        break;
      case KEY_DOWN:
        if (in_ctrl) {
          switch (idx) {
            case 0:
              vals->db -= 0.5;
              kr_mixer_set_effect_control (client, sysname, 0, bandn, "db", vals->db, 0, 0);
              break;
            case 1:
              vals->hz -= 5;
              kr_mixer_set_effect_control (client, sysname, 0, bandn, "hz", vals->hz, 0, 0);
              break;
            case 2:
              vals->bw -= 0.10;
              kr_mixer_set_effect_control (client, sysname, 0, bandn, "bw", vals->bw, 0, 0);
              break;

          }
   
        }
        break;
      case 'w':
        if (in_ctrl) {
          switch (idx) {
            case 0:
              vals->db += 0.10;
              kr_mixer_set_effect_control (client, sysname, 0, bandn, "db", vals->db, 0, 0);
              break;
            case 1:
              vals->hz += 1;
              kr_mixer_set_effect_control (client, sysname, 0, bandn, "hz", vals->hz, 0, 0);
              break;
            case 2:
              break;

          }

        }
        break;
      case 's':
        if (in_ctrl) {
          switch (idx) {
            case 0:
              vals->db -= 0.10;
              kr_mixer_set_effect_control (client, sysname, 0, bandn, "db", vals->db, 0, 0);
              break;
            case 1:
              vals->hz -= 1;
              kr_mixer_set_effect_control (client, sysname, 0, bandn, "hz", vals->hz, 0, 0);
              break;
            case 2:
              break;

          }
   
        }
        break;
      case 9:
        if (in_ctrl) {
          idx = field_index (current_field (ctrl_form));
          set_field_fore (ctrl_field[idx],A_NORMAL);
          /* ncurses bug I suppose */
          form_driver (ctrl_form, REQ_NEXT_FIELD);
          form_driver (ctrl_form, REQ_PREV_FIELD);
          set_current_field (eq_form,field[field_idx]); 
          in_ctrl = 0;
        }
        else {
          field_idx = field_index (current_field (eq_form));
          set_current_field (ctrl_form,ctrl_field[0]); 
          set_field_fore (ctrl_field[0],A_BOLD | COLOR_PAIR (1));  
          /* ncurses bug I suppose */
          form_driver (ctrl_form, REQ_NEXT_FIELD);
          form_driver (ctrl_form, REQ_PREV_FIELD);
          idx = 0;
          in_ctrl = 1;
        }
        break;
      default:
        break;
    }

    update_panels ();
    doupdate ();
  }
 	

  /* CLEANUP */


  for (i=0;i<showed_bands;i++) {

    tmpw = panel_window (db->slider_p[i]);
    del_panel (db->slider_p[i]);
    delwin (tmpw);

    tmpw = panel_window (db->bar_p[i]);
    del_panel (db->bar_p[i]);
    delwin (tmpw);    

    tmpw = panel_window (hz->cell_p[i]);
    del_panel (hz->cell_p[i]);
    delwin (tmpw);

    tmpw = panel_window (bw->bar_p[i]);
    del_panel (bw->bar_p[i]);
    delwin (tmpw);

    tmpw = panel_window (bw->slider_p[i]);
    del_panel (bw->slider_p[i]);
    delwin (tmpw);

    tmpw = panel_window (bw->cell_p[i]);
    del_panel (bw->cell_p[i]);
    delwin (tmpw);

  }


  free (db->bar_w);
  free (db->slider_w);
  free (hz->cell_w);
  free (bw->bar_w);
  free (bw->slider_w);
  free (bw->cell_w);
  free (db->bar_p);
  free (db->slider_p);
  free (hz->cell_p);
  free (bw->bar_p);
  free (bw->slider_p);
  free (bw->cell_p);

  tmpw = panel_window (db->pan);
  del_panel (db->pan);
  delwin (tmpw);

  tmpw = panel_window (hz->pan);
  del_panel (hz->pan);
  delwin (tmpw);

  tmpw = panel_window (bw->pan);
  del_panel (bw->pan);
  delwin (tmpw);

  free (ctrls);
  free (db);
  free (hz);
  free (bw);
  free (vals);
  free (eqport);


  tmpw = form_sub (ctrl_form);

  unpost_form (ctrl_form);
  free_form (ctrl_form);

  for (i=0;i<nctrls;i++) {
    free_field (ctrl_field[i]);
  }

  free (ctrl_field);

  del_panel (ctrl_subp);
  delwin (tmpw);

  tmpw = form_sub (eq_form);

  unpost_form (eq_form);
  free_form (eq_form);

  
  for (i=0;i<nbands;i++) {
    free_field (field[i]);
  }

  free (field);


  del_panel (eq_subpan);
  del_panel (eq_mainpan);

  delwin (tmpw);
  delwin (eq_win);




	return 0;
}
Beispiel #20
0
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;
      }
    }
  }
}
Beispiel #21
0
int main()
{
	FIELD *field[3];
	FORM  *my_form;
	WINDOW *my_form_win;
	int ch, rows, cols;
	
	/* Initialize curses */
	initscr();
	start_color();
	cbreak();
	noecho();
	keypad(stdscr, TRUE);

	/* Initialize few color pairs */
   	init_pair(1, COLOR_RED, COLOR_BLACK);

	/* Initialize the fields */
	field[0] = new_field(1, 10, 6, 1, 0, 0);
	field[1] = new_field(1, 10, 8, 1, 0, 0);
	field[2] = NULL;

	/* Set field options */
	set_field_back(field[0], A_UNDERLINE);
	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);
	
	/* Create the form and post it */
	my_form = new_form(field);
	
	/* Calculate the area required for the form */
	scale_form(my_form, &rows, &cols);

	/* Create the window to be associated with the form */
        my_form_win = newwin(rows + 4, cols + 4, 4, 4);
        keypad(my_form_win, TRUE);

	/* Set main window and sub window */
        set_form_win(my_form, my_form_win);
        set_form_sub(my_form, derwin(my_form_win, rows, cols, 2, 2));

	/* Print a border around the main window and print a title */
        box(my_form_win, 0, 0);
	print_in_middle(my_form_win, 1, 0, cols + 4, "My Form", COLOR_PAIR(1));
	
	post_form(my_form);
	wrefresh(my_form_win);

	mvprintw(LINES - 2, 0, "Use UP, DOWN arrow keys to switch between fields");
	refresh();

	/* Loop through to get user requests */
	while((ch = wgetch(my_form_win)) != KEY_F(1))
	{	switch(ch)
		{	case KEY_DOWN:
				/* Go to next field */
				form_driver(my_form, REQ_NEXT_FIELD);
				/* Go to the end of the present buffer */
				/* Leaves nicely at the last character */
				form_driver(my_form, REQ_END_LINE);
				break;
			case KEY_UP:
				/* Go to previous field */
				form_driver(my_form, REQ_PREV_FIELD);
				form_driver(my_form, REQ_END_LINE);
				break;
			default:
				/* If this is a normal character, it gets */
				/* Printed				  */	
				form_driver(my_form, ch);
				break;
		}
	}

	/* Un post form and free the memory */
	unpost_form(my_form);
	free_form(my_form);
	free_field(field[0]);
	free_field(field[1]); 

	endwin();
	return 0;
}
Beispiel #22
0
void
save_create(ui_t *ui)
{
    save_info_t *info;
    char savepath[128];

    // Pause the capture while saving
    capture_set_paused(1);

    // Cerate a new indow for the panel and form
    ui_panel_create(ui, 15, 68);

    // Initialize save panel specific data
    info = sng_malloc(sizeof(save_info_t));

    // Store it into panel userptr
    set_panel_userptr(ui->panel, (void*) info);

    // Initialize the fields    int total, displayed;

    info->fields[FLD_SAVE_PATH] = new_field(1, 52, 3, 13, 0, 0);
    info->fields[FLD_SAVE_FILE] = new_field(1, 47, 4, 13, 0, 0);
    info->fields[FLD_SAVE_ALL] = new_field(1, 1, 7, 4, 0, 0);
    info->fields[FLD_SAVE_SELECTED] = new_field(1, 1, 8, 4, 0, 0);
    info->fields[FLD_SAVE_DISPLAYED] = new_field(1, 1, 9, 4, 0, 0);
    info->fields[FLD_SAVE_MESSAGE] = new_field(1, 1, 10, 4, 0, 0);
    info->fields[FLD_SAVE_PCAP] = new_field(1, 1, 7, 36, 0, 0);
    info->fields[FLD_SAVE_PCAP_RTP] = new_field(1, 1, 8, 36, 0, 0);
    info->fields[FLD_SAVE_TXT] = new_field(1, 1, 9, 36, 0, 0);
    info->fields[FLD_SAVE_SAVE] = new_field(1, 10, ui->height - 2, 20, 0, 0);
    info->fields[FLD_SAVE_CANCEL] = new_field(1, 10, ui->height - 2, 40, 0, 0);
    info->fields[FLD_SAVE_COUNT] = NULL;

    // Set fields options
    field_opts_off(info->fields[FLD_SAVE_PATH], O_AUTOSKIP);
    field_opts_off(info->fields[FLD_SAVE_FILE], O_AUTOSKIP);
    field_opts_off(info->fields[FLD_SAVE_ALL], O_AUTOSKIP);
    field_opts_off(info->fields[FLD_SAVE_SELECTED], O_AUTOSKIP);
    field_opts_off(info->fields[FLD_SAVE_DISPLAYED], O_AUTOSKIP);
    field_opts_off(info->fields[FLD_SAVE_MESSAGE], O_VISIBLE);

    // Change background of input fields
    set_field_back(info->fields[FLD_SAVE_PATH], A_UNDERLINE);
    set_field_back(info->fields[FLD_SAVE_FILE], A_UNDERLINE);

    // Disable Save RTP if RTP packets are not being captured
    if (!setting_enabled(SETTING_CAPTURE_RTP))
        field_opts_off(info->fields[FLD_SAVE_PCAP_RTP], O_ACTIVE);

    // Create the form and post it
    info->form = new_form(info->fields);
    set_form_sub(info->form, ui->win);
    post_form(info->form);
    form_opts_off(info->form, O_BS_OVERLOAD);

    // Set Default field values
    sprintf(savepath, "%s", setting_get_value(SETTING_SAVEPATH));

    set_field_buffer(info->fields[FLD_SAVE_PATH], 0, savepath);
    set_field_buffer(info->fields[FLD_SAVE_SAVE], 0, "[  Save  ]");
    set_field_buffer(info->fields[FLD_SAVE_CANCEL], 0, "[ Cancel ]");

    // Set window boxes
    wattron(ui->win, COLOR_PAIR(CP_BLUE_ON_DEF));
    // Window border
    title_foot_box(ui->panel);

    // Header and footer lines
    mvwhline(ui->win, ui->height - 3, 1, ACS_HLINE, ui->width - 1);
    mvwaddch(ui->win, ui->height - 3, 0, ACS_LTEE);
    mvwaddch(ui->win, ui->height - 3, ui->width - 1, ACS_RTEE);

    // Save mode box
    mvwaddch(ui->win, 6, 2, ACS_ULCORNER);
    mvwhline(ui->win, 6, 3, ACS_HLINE, 30);
    mvwaddch(ui->win, 6, 32, ACS_URCORNER);
    mvwvline(ui->win, 7, 2, ACS_VLINE, 4);
    mvwvline(ui->win, 7, 32, ACS_VLINE, 4);
    mvwaddch(ui->win, 11, 2, ACS_LLCORNER);
    mvwhline(ui->win, 11, 3, ACS_HLINE, 30);
    mvwaddch(ui->win, 11, 32, ACS_LRCORNER);

    // Save mode box
    mvwaddch(ui->win, 6, 34, ACS_ULCORNER);
    mvwhline(ui->win, 6, 35, ACS_HLINE, 30);
    mvwaddch(ui->win, 6, 64, ACS_URCORNER);
    mvwvline(ui->win, 7, 34, ACS_VLINE, 3);
    mvwvline(ui->win, 7, 64, ACS_VLINE, 3);
    mvwaddch(ui->win, 10, 34, ACS_LLCORNER);
    mvwhline(ui->win, 10, 35, ACS_HLINE, 30);
    mvwaddch(ui->win, 10, 64, ACS_LRCORNER);

    wattroff(ui->win, COLOR_PAIR(CP_BLUE_ON_DEF));

    // Set screen labels
    mvwprintw(ui->win, 1, 27, "Save capture");
    mvwprintw(ui->win, 3, 3, "Path:");
    mvwprintw(ui->win, 4, 3, "Filename:");
    wattron(ui->win, COLOR_PAIR(CP_BLUE_ON_DEF));
    mvwprintw(ui->win, 6, 4, " Dialogs ");
    mvwprintw(ui->win, 6, 36, " Format ");
    wattroff(ui->win, COLOR_PAIR(CP_BLUE_ON_DEF));

    // Set default cursor position
    set_current_field(info->form, info->fields[FLD_SAVE_FILE]);
    form_driver(info->form, REQ_END_LINE);
    curs_set(1);

    // Get filter stats
    sip_stats_t stats = sip_calls_stats();

    // Set default save modes
    info->savemode = (stats.displayed == stats.total) ? SAVE_ALL : SAVE_DISPLAYED;
    info->saveformat = (setting_enabled(SETTING_CAPTURE_RTP))? SAVE_PCAP_RTP : SAVE_PCAP;

}
Beispiel #23
0
void upon(char par[100])
{
	FIELD *field[2];
	FORM  *my_form;
	WINDOW *my_form_win;
	int ch, rows, cols;
	int ext=0;
	/* Initialize curses */
	initscr();
	start_color();
	cbreak();
	noecho();
	keypad(stdscr, TRUE);

	/* Initialize few color pairs */
   	init_pair(1, COLOR_RED, COLOR_BLACK);

	/* Initialize the fields */
	field[0] = new_field(1,40,0,0,0,0);
	//field[1] = new_field(1, 10, 8, 1, 0, 0);
	field[1] = NULL;

	/* Set field options */
	set_field_back(field[0], A_UNDERLINE);
	field_opts_off(field[0], O_AUTOSKIP); /* Don't go to next field when this */
					      /* Field is filled up 		*/
	if(!strcmp("Search by number",par))
		set_field_type(field[0],TYPE_INTEGER,1);
	else
		set_field_type(field[0],TYPE_ALPHA,1);
//	set_field_back(field[1], A_UNDERLINE); 
//	field_opts_off(field[1], O_AUTOSKIP);
//	wmove(WINDOW *win, int y, int x);
	/* Create the form and post it */
	my_form = new_form(field);
	/* Calculate the area required for the form */
	scale_form(my_form, &rows, &cols);
	/* Create the window to be associated with the form */
        my_form_win = newwin(rows + 4, cols + 4, (y/2), (x/2)-18);
        keypad(my_form_win, TRUE);
	/* Set main window and sub window */
        set_form_win(my_form, my_form_win);
//        set_form_sub(my_form, derwin(my_form_win, rows, cols,2,2));
        set_form_sub(my_form, derwin(my_form_win,rows,cols,2,2));
	/* Print a border around the main window and print a title */
        box(my_form_win,0,0);
	print_in_middle(my_form_win, 1, 0, cols + 4,par, COLOR_PAIR(1));
	//mvwhline(my_form_win, 2, 1, ACS_HLINE, 43);
	post_form(my_form);
	wrefresh(my_form_win);
	mvprintw(LINES - 2, 0, "Press ESC to close the window");
	move((y/2)+2,(x/2)-16);
	refresh();

	/* Loop through to get user requests */
	while((ch = wgetch(my_form_win)) != 27)
	{	switch(ch)
		{	case KEY_DOWN:
				/* Go to next field */
				form_driver(my_form, REQ_NEXT_FIELD);
				/* Go to the end of the present buffer */
				/* Leaves nicely at the last character */
				form_driver(my_form, REQ_END_LINE);
				break;
			case KEY_UP:
				/* Go to previous field */
				form_driver(my_form, REQ_PREV_FIELD);
				form_driver(my_form, REQ_END_LINE);
				break;
			case KEY_BACKSPACE:
				/* Go to previous field */
				form_driver(my_form,REQ_DEL_PREV);
				break;
			case KEY_DC:
				form_driver(my_form,REQ_DEL_CHAR);
				break;
			case KEY_HOME:
				form_driver(my_form,REQ_BEG_FIELD);
				break;
			case KEY_END:
				form_driver(my_form,REQ_END_FIELD);
				break;
			case KEY_LEFT:
				form_driver(my_form,REQ_LEFT_CHAR);
				break;
			case KEY_RIGHT:
				form_driver(my_form,REQ_RIGHT_CHAR);
				break;
			case 10:
				{
				str=malloc(1000);
				form_driver(my_form,REQ_BEG_FIELD);
				sprintf(str, "%s", field_buffer(field[0],0));
				size_t len = 0;
			        char *frontp = str - 1;
    				char *endp = NULL;
				len = strlen(str);
    				endp = str + len;
				while( isspace(*(++frontp)) );
				while( isspace(*(--endp)) && endp != frontp );
				if( str + len - 1 != endp )		
            			*(endp + 1) = '\0';
				else if( frontp != str &&  endp == frontp )
				*str = '\0';
				endp = str;
			        if( frontp != str )
			        {
			            while( *frontp ) *endp++ = *frontp++;
			            *endp = '\0';
			        }
//				mvprintw(LINES - 2, 0, "%s %d",str,strlen(str));
//				refresh();
				ext=1;
				if(!strcmp("Search by name",par))				
				find(str);
				else if (!strcmp("Search by number",par))
				findnumber(str);	
				else if (!strcmp("Enter contact name to remove",par))
				del(str);		
				break;
				}
			default:
				/* If this is a normal character, it gets */
				/* Printed				  */	
				form_driver(my_form, ch);
				break;
		}
		if(ext==1)
		break;
	}
	/* Un post form and free the memory */
	unpost_form(my_form);
	free_form(my_form);
	free_field(field[0]);
	free_field(field[1]); 
//	return 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);
}
Beispiel #25
0
PANEL *
call_list_create()
{
    PANEL *panel;
    WINDOW *win;
    int height, width, i, attrid, collen;
    call_list_info_t *info;
    char option[80];
    const char *field, *title;

    // Create a new panel that fill all the screen
    panel = new_panel(newwin(LINES, COLS, 0, 0));
    // Initialize Call List specific data
    info = sng_malloc(sizeof(call_list_info_t));
    // Store it into panel userptr
    set_panel_userptr(panel, (void*) info);

    // Add configured columns
    for (i = 0; i < SIP_ATTR_COUNT; i++) {
        // Get column attribute name from options
        sprintf(option, "cl.column%d", i);
        if ((field = get_option_value(option))) {
            if ((attrid = sip_attr_from_name(field)) == -1)
                continue;
            // Get column width from options
            sprintf(option, "cl.column%d.width", i);
            if ((collen = get_option_int_value(option)) == -1)
                collen = sip_attr_get_width(attrid);
            // Get column title
            title = sip_attr_get_title(attrid);
            // Add column to the list
            call_list_add_column(panel, attrid, field, title, collen);
        }
    }

    // Let's draw the fixed elements of the screen
    win = panel_window(panel);
    getmaxyx(win, height, width);

    // Initialize the fields
    info->fields[FLD_LIST_FILTER] = new_field(1, width - 19, 2, 18, 0, 0);
    info->fields[FLD_LIST_COUNT] = NULL;

    // Create the form and post it
    info->form = new_form(info->fields);
    set_form_sub(info->form, win);

    // Form starts inactive
    call_list_form_activate(panel, 0);

    // Calculate available printable area
    info->list_win = subwin(win, height - 5, width, 4, 0);
    info->group = call_group_create();

    // Get current call list
    info->calls = sip_calls_iterator();
    vector_iterator_set_filter(&info->calls, filter_check_call);
    info->cur_call = info->first_call = -1;

    // Set autoscroll default status
    info->autoscroll = setting_enabled(SETTING_CL_AUTOSCROLL);

    // Apply initial configured method filters
    filter_method_from_setting(setting_get_value(SETTING_FILTER_METHODS));


    // Return the created panel
    return panel;
}