Example #1
0
static void load_values(struct regedit *regedit)
{
	struct tree_node *node;

	node = item_userptr(current_item(regedit->keys->menu));
	value_list_load(regedit->vl, node->key);
}
Example #2
0
void
column_select_update_columns(ui_t *ui)
{
    int column, attr_id;

    // Get panel information
    column_select_info_t *info = column_select_info(ui);

    // Set enabled fields
    ui_t *ui_list = ui_find_by_type(PANEL_CALL_LIST);
    call_list_info_t *list_info = call_list_info(ui_list);

    // Reset column count
    list_info->columncnt = 0;

    // Add all selected columns
    for (column = 0; column < item_count(info->menu); column++) {
        // If column is active
        if (!strncmp(item_name(info->items[column]), "[ ]", 3))
            continue;

        // Get column attribute
        attr_id = sip_attr_from_name(item_userptr(info->items[column]));
        // Add a new column to the list
        call_list_add_column(ui_list, attr_id, sip_attr_get_name(attr_id),
                             sip_attr_get_title(attr_id), sip_attr_get_width(attr_id));
    }
}
Example #3
0
/*
 * Free the menu and items memory.
 */
void __renderers_free_home_page(void)
{
	int i;
	struct userptr_data *data;

	if (!main_menu)
		return;

	unpost_menu(main_menu);

	for (i = 0; i < nb_items; i++) {
		free((void *) main_items[i]->description.str);
		free((void *) main_items[i]->name.str);

		data = item_userptr(main_items[i]);
		free((void *) data->dbus_name);
		free((void *) data->pretty_name);
		free(data);

		free_item(main_items[i]);
	}

	free_menu(main_menu);
	free(main_items);
	nb_items = 0;
	main_menu = NULL;
	main_items = NULL;
}
Example #4
0
int mainmenu(int height, int width) {
    int ret;
    ITEM **menu_items;
    MENU *main_menu;
    int n_choices, i;

    clean_main_menu();
    build_main_menu(instance_path);

    n_choices = menu_size;
    menu_items = (ITEM **) calloc(n_choices + 1, sizeof (ITEM *));
    for (i = 0; i < n_choices; ++i) {
        menu_items[i] = new_item(menu_values[i], menu_values[i]);
        set_item_userptr(menu_items[i], (void *) menu_selected);
    }
    menu_items[n_choices] = (ITEM *) NULL;
    main_menu = new_menu((ITEM **) menu_items);
    menu_opts_off(main_menu, O_SHOWDESC);

    set_menu_sub(main_menu, derwin(stdscr, 10, 50, 6, 10));

    post_menu(main_menu);
    attron(A_BOLD);
    mvprintw(0, 0, name);
    mvprintw(0, width - strlen(vers), vers);
    attroff(A_BOLD);
    refresh();
    pos_menu_cursor(main_menu);
    while ((i = getch()) != KEY_F(4)) {
        switch (i) {
            case KEY_DOWN:
                menu_driver(main_menu, REQ_DOWN_ITEM);
                break;
            case KEY_UP:
                menu_driver(main_menu, REQ_UP_ITEM);
                break;
            case 10:
            {
                ITEM *cur;
                int (*p)(char *);
                cur = current_item(main_menu);
                p = (int (*)(char *))item_userptr(cur);
                ret = p((char *) item_name(cur));
                pos_menu_cursor(main_menu);
                goto menu_sel;
            }
        }
    }
    if (i == KEY_F(4)) {
        ret = menu_size - 1;
    }

menu_sel:
    unpost_menu(main_menu);
    free_menu(main_menu);
    for (i = 0; i < n_choices; ++i)
        free_item(menu_items[i]);
    return ret;
}
Example #5
0
selection_action_fn *
selection_selected_action(struct selection *selection)
{
    if (selection->index < 0) return NULL;
    if (selection->index >= selection->items_count) return NULL;
    
    ITEM *item = selection->items[selection->index];
    struct selection_item *selection_item = item_userptr(item);
    return selection_item->action;
}
Example #6
0
void displayMenu(int y, int x, char title[],int numOfOpt, char *options[], void (*p[])(void)){
	int i,c;
	WINDOW *menuWindow;
	MENU *myMenu;
	ITEM **myOptions;
	ITEM *currentOption;
	initscr();
	noecho();
	cbreak();
	keypad(stdscr,TRUE);
	init_pair(1,COLOR_CYAN,COLOR_BLACK);
	myOptions=(ITEM **)calloc(numOfOpt+1,sizeof(ITEM *));
	for(i=0;i<numOfOpt;i++){
		myOptions[i]=new_item(options[i]," ");
		set_item_userptr(myOptions[i],p[i]);	
	}
	myOptions[numOfOpt]=(ITEM *)NULL;
	myMenu=new_menu(myOptions);
	menuWindow = newwin(8,20,(LINES-y)/2,(COLS-x)/2);
	keypad(menuWindow,TRUE);
	set_menu_win(myMenu,menuWindow);
	set_menu_sub(myMenu, derwin(menuWindow,y-4,x-2,3,1));
	set_menu_format(myMenu,numOfOpt,1);
	menu_opts_off(myMenu, O_SHOWDESC);
	set_menu_mark(myMenu," * ");
	post_menu(myMenu);
	wrefresh(menuWindow);
	while((c=wgetch(menuWindow))!=KEY_F(2)){
		switch(c){
			case KEY_UP:
				menu_driver(myMenu,REQ_UP_ITEM);
				break;
			case KEY_DOWN:
				menu_driver(myMenu,REQ_DOWN_ITEM);
				break;
			case 10:{
				ITEM *temp;
				temp=current_item(myMenu);
				void(*pointer)(void);
				pointer=item_userptr(temp);
				pointer();
				pos_menu_cursor(myMenu);
				menu_driver(myMenu,REQ_DOWN_ITEM);
				break;
				}
			wrefresh(menuWindow);
		}
	}
	/*unpost_menu(myMenu);*/
	/*for(i=0;i<numOfOpt;++i){*/
		/*free_item(myOptions[i]);*/
	/*}*/
	/*free_menu(myMenu);*/
	/*free(optionsNumbers);*/
}
Example #7
0
int search_item(char* searchterm, int startfrom, struct NBT_Window* window) {
  const size_t searchlen = strlen(searchterm);
  int i = (startfrom > 0) ? startfrom : 0;
  ITEM* item;
  for (item = window->items[i]; item; item = window->items[++i]) {
    nbt_node* node = item_userptr(item);
    if (matchStartString(searchterm, searchlen, node->name) == 1)
      return i;
  }
  return -1;
};
Example #8
0
void exec_action_context_services(int ch)
{
	ITEM *item;

	switch (ch) {
		case KEY_DOWN:
			menu_driver(my_menu, REQ_DOWN_ITEM);
			break;

		case KEY_UP:
			menu_driver(my_menu, REQ_UP_ITEM);
			break;

		case KEY_ENTER:
		case 10:
			item = current_item(my_menu);
			exec_action(item_userptr(item));
			break;
	}
}
Example #9
0
File: nchgdc.c Project: Eeketh/hgd
int
hgd_unpost_and_free_content_menu(struct ui *u, int which)
{
	ITEM			**items;
	int			  n_items, i;

	if (u->content_menus[which] == NULL)
		return (HGD_OK);

	DPRINTF(HGD_D_INFO, "free menu: %s", window_names[which]);

	if ((n_items = item_count(u->content_menus[which])) == ERR) {
		DPRINTF(HGD_D_ERROR, "Couldn't get item count");
		return (HGD_FAIL);
	}

	if ((items = menu_items(u->content_menus[which])) == NULL) {
		DPRINTF(HGD_D_ERROR, "Got NULL items array");
		return (HGD_FAIL);
	}

	if (unpost_menu(u->content_menus[which]) != E_OK)
		DPRINTF(HGD_D_ERROR, "could not unpost menu %d", errno);

	/* must come before freeing items */
	if (free_menu(u->content_menus[which]) != E_OK)
		DPRINTF(HGD_D_ERROR, "could not free menu");

	for (i = 0; i < n_items; i++) {
		free((char *) item_name(items[i]));
		free((char *) item_description(items[i]));
		free(item_userptr(items[i]));
		if (free_item(items[i]) != OK)
			DPRINTF(HGD_D_ERROR, "can't free item");
	}

	free(items);
	u->content_menus[which] = NULL;

	return (HGD_OK);
}
Example #10
0
void
selection_free_or_die(struct selection *selection)
{
    if (!selection) return;
    
    if (selection->menu) {
        unpost_menu(selection->menu);
        free_menu(selection->menu);
    }
    if (selection->sub_window) delwin(selection->sub_window);
    if (selection->window) delwin(selection->window);
    
    for (int i = 0; i < selection->items_count; ++i) {
        free_or_die((char *)item_name(selection->items[i]));
        free_or_die((char *)item_description(selection->items[i]));
        free_or_die(item_userptr(selection->items[i]));
        free_item(selection->items[i]);
    }
    free_or_die(selection->items);
    free_or_die(selection->title);
    free_or_die(selection);
}
Example #11
0
/* menu handler */
void menu_handler(void) {

  int c;

  keypad(sub_window,TRUE);  /* enable keypad on the menu */
  wtimeout(sub_window,-1);  /* wait for input */

  while((c=wgetch(sub_window))) {
    switch (c) {
      case KEY_MOUSE:
        menu_driver(menu_ptr,KEY_MOUSE);
        break;
      case 9: /* TAB */
      case 'k':
      case KEY_DOWN:
        menu_driver(menu_ptr,REQ_DOWN_ITEM);
        break;
      case 'j':
      case KEY_UP:
        menu_driver(menu_ptr,REQ_UP_ITEM);
        break;
      case 27:  /* ESC */
      case 'q':
        delete_menu();
        finish(0);
        break;
      case 13:
      case KEY_ENTER:
      case KEY_RIGHT:
        func_ptr = item_userptr(current_item(menu_ptr));
        delete_menu();
        return;
      default: break;
    }
  }
  
  return;
}
Example #12
0
File: nchgdc.c Project: Eeketh/hgd
/* uh oh, someone hit enter on the files menu! */
int
hgd_enter_on_files_menu(struct ui *u)
{
	DPRINTF(HGD_D_INFO, "Selected item on files menu");

	char			*new_cwd = NULL;
	ITEM			*item;
	struct dirent		*dirent;

	if ((item = current_item(u->content_menus[HGD_WIN_FILES])) == NULL) {
	    DPRINTF(HGD_D_WARN, "Could not get current item");
	    return (HGD_FAIL);
	}

	dirent = (struct dirent *) item_userptr(item);

	switch (dirent->d_type) {
	case DT_DIR:
		DPRINTF(HGD_D_INFO, "switch cwd: dirent->d_name");

		if (strcmp(dirent->d_name, "..") == 0)
			new_cwd = xstrdup(dirname(u->cwd));
		else
			xasprintf(&new_cwd, "%s/%s", u->cwd, dirent->d_name);

		free(u->cwd);
		u->cwd = new_cwd;

		break;
	default:
		hgd_ui_queue_track(u, dirent->d_name);
		break;
	};

	return (HGD_OK);
}
Example #13
0
int main(){	
    main_pid = getpid();
    char line[BUF][BUF];
    FILE *rlist = NULL; 
    int igt     = 0;
    int total   = 0;
    rlist       = fopen("STATIONS.txt", "r");
    while( fgets ( line[igt], BUF, rlist )) {
        /* get rid of ending \n from fgets */
        line[igt][strlen(line[igt]) - 1] = '\0';
        char *line_f        = line[igt];
        uris[igt]           = strtok(line_f,    "@");
        choices[igt]        = strtok(NULL,      "@");
        descriptions[igt]   = strtok(NULL,      "@");
        igt++;
    }
    
	/* Initialize curses */	
    ITEM **my_items;
	int c;				
	MENU *my_menu;
        int n_choices, i;
	ITEM *cur_item;
	initscr();
    /*We dont really need colors for now...*/
    /*start_color();*/
        cbreak();
        noecho();
	keypad(stdscr, TRUE);
    /*wborder(0 , 0,0,0,0,0,0,0,0,);*/
    /*init_pair(1, COLOR_RED,COLOR_WHITE);*/
    /*init_pair(2, COLOR_GREEN,COLOR_WHITE);*/
    /*init_pair(3, COLOR_MAGENTA,COLOR_WHITE);*/
	/* Initialize items */
        n_choices = ARRAY_SIZE(choices);
        my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *));
        for(i = 0; i < n_choices; ++i) {
            my_items[i] = new_item(choices[i],descriptions[i]);
		    /* The F*cking user pointer */
		    set_item_userptr(my_items[i], func);
	    }
	my_items[n_choices] = (ITEM *)NULL;

	/* Create menu */
	my_menu = new_menu((ITEM **)my_items);
    set_menu_opts(my_menu,O_SHOWDESC);
    int y_lines_menu = LINES - y_lines_reserved;
    set_menu_format(my_menu,y_lines_menu,1);

	/* Post the menu */
    /*Help thingy*/
    hacete_una_linea_putin(5);
	mvprintw(LINES - 4, 0, " Press <ENTER> to play the station,");
	mvprintw(LINES - 3, 0, " any <arrow> to move the menu buffer, <Q> to Quit or");
	mvprintw(LINES - 2, 0, " <K> to Kill child mplayer process.");
    hacete_una_linea_putin(1);
	post_menu(my_menu);
	refresh();

    /*big loop thingy*/
    while((c = getch()) != 113){
        switch(c){
            case KEY_DOWN:
                menu_driver(my_menu, REQ_DOWN_ITEM);
                break;
            case KEY_UP:
                menu_driver(my_menu, REQ_UP_ITEM);
                break;
            case KEY_LEFT:
                menu_driver(my_menu, REQ_SCR_UPAGE);
                break;
            case KEY_RIGHT:
                menu_driver(my_menu, REQ_SCR_DPAGE);
                break;
            case 107:   // k
                kill_child();
                break;
            case 10: {    /* Enter  == Play some radio! */
                ITEM *cur;
                void (*p)(char *);
                if (*contador >= 1){
                    kill_child();
                }
                cur = current_item(my_menu);
                description_fn = (char *)item_description(cur);
                p = item_userptr(cur);
                p((char *)item_name(cur));
                pos_menu_cursor(my_menu);
                play_radio();
                cuenta = cuenta + 1;
                break;
            }
            break;
        }
    }
    /*That's all, free memory, kill any pid and exit.*/
    unpost_menu(my_menu);
    for(i = 0; i < n_choices; ++i){
        free_item(my_items[i]);
    }
    free_menu(my_menu);
    endwin();
    kill_child();
    exit(0);
}
Example #14
0
static void *get_selected_hidden(smsgloader *_this)
{

    VERBOSE_DEBUGPR("scommenu - retrieving msglistitemhandle %p for msg item\n",item_userptr(current_item(_this->loadmenu)));
    return item_userptr(current_item(_this->loadmenu));
}
Example #15
0
File: gui.c Project: gmy987/zoltar
/* main gui loop function, can be called repeatedly, until returning 0 */
int loopGui() {
  int c;

  updateGui(guiProgramData, guiContext);

  c = getch();
  
  if(c=='q') {
    return 0;
  }

  switch(guiState) {
    case GUI_STATE_MAIN:
      switch(c) {
        case KEY_DOWN:
          menu_driver(mainMenu, REQ_DOWN_ITEM);
          break;
        case KEY_UP:
          menu_driver(mainMenu, REQ_UP_ITEM);
          break;
        case 10: /* enter */
          {
            switch((int)item_userptr(current_item(mainMenu))) {
              case MENU_ITEM_EXIT:
                return 0;
              case MENU_ITEM_OPMODE:
                set_menu_fore(mainMenu, A_NORMAL);
                guiState = GUI_STATE_OPMODE;
                break;
              case MENU_ITEM_SPECTRA:
                set_menu_fore(mainMenu, A_NORMAL);
                guiState = GUI_STATE_SPECTRA;
                break;
              case MENU_ITEM_INVARIANTS:
                set_menu_fore(mainMenu, A_NORMAL);
                guiState = GUI_STATE_INVARIANTTYPES;
                break;
              default:
                set_menu_fore(mainMenu, A_NORMAL);
                guiState = GUI_STATE_TMP;
                break;
            }
          }
          break;
        default:
          break;
      }
      break;
    case GUI_STATE_OPMODE:
      switch(c) {
        case KEY_DOWN:
          menu_driver(opmodeMenu, REQ_DOWN_ITEM);
          break;
        case KEY_UP:
          menu_driver(opmodeMenu, REQ_UP_ITEM);
          break;
        case 10: /* enter */
          {
            switch((int)item_userptr(current_item(opmodeMenu))) {
              case MENU_ITEM_TRAINING:
                guiProgramData->opMode = 0; /* TODO: define this */
                guiDataChanged = 1;
                break;
              case MENU_ITEM_TESTING:
                guiProgramData->opMode = 1; /* TODO: define this */
                guiDataChanged = 1;
                break;
              default:
                break;
            }
            set_menu_fore(mainMenu, A_STANDOUT);
            guiState = GUI_STATE_MAIN;
          }
          break;
        case KEY_BACKSPACE:
          set_menu_fore(mainMenu, A_STANDOUT);
          guiState = GUI_STATE_MAIN;
          break;
      }
      break;
    case GUI_STATE_SPECTRA:
      switch(c) {
        case KEY_DOWN:
          menu_driver(spectraMenu, REQ_DOWN_ITEM);
          break;
        case KEY_UP:
          menu_driver(spectraMenu, REQ_UP_ITEM);
          break;
        case 10: /* enter */
          guiSelectedSpectrum = item_index(current_item(spectraMenu));
          if(guiSelectedSpectrum >= 0) {
            guiState = GUI_STATE_SPECTRA_OP;
          }
          break;
        case KEY_BACKSPACE:
          set_menu_fore(mainMenu, A_STANDOUT);
          guiState = GUI_STATE_MAIN;
          break;
      }
      break;
    case GUI_STATE_SPECTRA_OP:
      switch(c) {
        case KEY_DOWN:
          menu_driver(spectraOpMenu, REQ_DOWN_ITEM);
          break;
        case KEY_UP:
          menu_driver(spectraOpMenu, REQ_UP_ITEM);
          break;
        case 10: /* enter */
          switch((int)item_userptr(current_item(spectraOpMenu))) {
            case MENU_ITEM_DATA:
              guiSelectedSFLResultOffset = 0;
              guiState = GUI_STATE_SPECTRUM_DATA;
              break;
            case MENU_ITEM_SFL:
              guiState = GUI_STATE_SFL_COEFF;
              break;
            default:
              guiState = GUI_STATE_SPECTRA;
              break;
          }
          break;
        case KEY_BACKSPACE:
          guiState = GUI_STATE_SPECTRA;
          break;
      }
      break;
    case GUI_STATE_SFL_COEFF:
      switch(c) {
        case KEY_DOWN:
          menu_driver(sflCoeffMenu, REQ_DOWN_ITEM);
          break;
        case KEY_UP:
          menu_driver(sflCoeffMenu, REQ_UP_ITEM);
          break;
        case 10: /* enter */
          switch((int)item_userptr(current_item(sflCoeffMenu))) {
            case S_OCHIAI:
            case S_JACCARD:
            case S_TARANTULA:
              guiSelectedSFLCoeff = (int)item_userptr(current_item(sflCoeffMenu));
              guiSFL = performSFL(guiProgramData, guiSelectedSpectrum, guiSelectedSFLCoeff);
              guiSelectedSFLResultOffset = 0;
              guiState = GUI_STATE_SFL_RESULT;
              break;
            default:
              guiState = GUI_STATE_SPECTRA_OP;
              break;
          }
          break;
        case KEY_BACKSPACE:
          guiState = GUI_STATE_SPECTRA_OP;
          break;
      }
      break;
    case GUI_STATE_SFL_RESULT:
      switch(c) {
        case KEY_DOWN:
          if(guiSelectedSFLResultOffset < (int)getSpectrum(guiProgramData, guiSelectedSpectrum)->nComponents - SFL_VISIBLE_RESULTS) {
            guiSelectedSFLResultOffset += 1;
          }
          break;
        case KEY_UP:
          if(guiSelectedSFLResultOffset > 0) {
            guiSelectedSFLResultOffset -= 1;
          }
          break;
        case KEY_NPAGE:
          guiSelectedSFLResultOffset += SFL_VISIBLE_RESULTS;
          if(guiSelectedSFLResultOffset > (int)getSpectrum(guiProgramData, guiSelectedSpectrum)->nComponents - SFL_VISIBLE_RESULTS) {
            guiSelectedSFLResultOffset = (int)getSpectrum(guiProgramData, guiSelectedSpectrum)->nComponents - SFL_VISIBLE_RESULTS;
          }
          if(guiSelectedSFLResultOffset < 0) {
            guiSelectedSFLResultOffset = 0;
          }
          break;
        case KEY_PPAGE:
          guiSelectedSFLResultOffset -= SFL_VISIBLE_RESULTS;
          if(guiSelectedSFLResultOffset < 0) {
            guiSelectedSFLResultOffset = 0;
          }
          break;
        case KEY_BACKSPACE:
          guiState = GUI_STATE_SFL_COEFF;
          break;
      }
      break;
    case GUI_STATE_SPECTRUM_DATA:
      switch(c) {
        case KEY_DOWN:
          if(guiSelectedSFLResultOffset < (int)getSpectrum(guiProgramData, guiSelectedSpectrum)->nComponents - SFL_VISIBLE_RESULTS) {
            guiSelectedSFLResultOffset += 1;
          }
          break;
        case KEY_UP:
          if(guiSelectedSFLResultOffset > 0) {
            guiSelectedSFLResultOffset -= 1;
          }
          break;
        case KEY_NPAGE:
          guiSelectedSFLResultOffset += SFL_VISIBLE_RESULTS;
          if(guiSelectedSFLResultOffset > (int)getSpectrum(guiProgramData, guiSelectedSpectrum)->nComponents - SFL_VISIBLE_RESULTS) {
            guiSelectedSFLResultOffset = (int)getSpectrum(guiProgramData, guiSelectedSpectrum)->nComponents - SFL_VISIBLE_RESULTS;
          }
          if(guiSelectedSFLResultOffset < 0) {
            guiSelectedSFLResultOffset = 0;
          }
          break;
        case KEY_PPAGE:
          guiSelectedSFLResultOffset -= SFL_VISIBLE_RESULTS;
          if(guiSelectedSFLResultOffset < 0) {
            guiSelectedSFLResultOffset = 0;
          }
          break;
        case KEY_BACKSPACE:
          guiState = GUI_STATE_SPECTRA_OP;
          break;
      }
      break;
    case GUI_STATE_INVARIANTTYPES:
      switch(c) {
        case KEY_DOWN:
          menu_driver(invariantTypesMenu, REQ_DOWN_ITEM);
          break;
        case KEY_UP:
          menu_driver(invariantTypesMenu, REQ_UP_ITEM);
          break;
        case 10: /* enter */
          guiSelectedInvariantType = item_index(current_item(invariantTypesMenu));
          if(guiSelectedInvariantType >= 0) {
            refreshInvariantsList();
            guiState = GUI_STATE_INVARIANTS;
            guiSelectedInvariantMode = INV_MODE_RANGE;
          }
          break;
        case KEY_BACKSPACE:
          set_menu_fore(mainMenu, A_STANDOUT);
          guiState = GUI_STATE_MAIN;
          break;
      }
      break;
    case GUI_STATE_INVARIANTS:
      switch(c) {
        case KEY_DOWN:
          menu_driver(invariantsMenuScr, REQ_DOWN_ITEM);
          menu_driver(invariantsMenuRng, REQ_DOWN_ITEM);
          menu_driver(invariantsMenuBmsk, REQ_DOWN_ITEM);
          break;
        case KEY_UP:
          menu_driver(invariantsMenuScr, REQ_UP_ITEM);
          menu_driver(invariantsMenuRng, REQ_UP_ITEM);
          menu_driver(invariantsMenuBmsk, REQ_UP_ITEM);
          break;
        case KEY_RIGHT:
          guiSelectedInvariantMode = (guiSelectedInvariantMode + 1 + 3)%3;
          break;
        case KEY_LEFT:
          guiSelectedInvariantMode = (guiSelectedInvariantMode - 1 + 3)%3;
          break;
        case KEY_NPAGE:
          {
            int i;
            for(i=0; i<10; i++) {
              menu_driver(invariantsMenuScr, REQ_DOWN_ITEM);
              menu_driver(invariantsMenuRng, REQ_DOWN_ITEM);
              menu_driver(invariantsMenuBmsk, REQ_DOWN_ITEM);
            }
          }
          break;
        case KEY_PPAGE:
          {
            int i;
            for(i=0; i<10; i++) {
              menu_driver(invariantsMenuScr, REQ_UP_ITEM);
              menu_driver(invariantsMenuRng, REQ_UP_ITEM);
              menu_driver(invariantsMenuBmsk, REQ_UP_ITEM);
            }
          }
          break;
        case 10: /* enter */
          guiSelectedInvariant = item_index(current_item(invariantsMenuScr));
          if(guiSelectedInvariant >= 0) {
            guiInv = getInvariantType(guiProgramData, guiSelectedInvariantType)->data[guiSelectedInvariant];
            guiState = GUI_STATE_INVARIANT_EDIT;
            guiEditState = GUI_EDIT_STATE_NONE;
            guiSelectedEditState = 0;
          }
          break;
        case KEY_BACKSPACE:
          guiState = GUI_STATE_INVARIANTTYPES;
          break;
      }
      break;
    case GUI_STATE_INVARIANT_EDIT:
      if(guiEditState == GUI_EDIT_STATE_NONE) {
        switch(c) {
          case KEY_UP:
            guiSelectedEditState = (guiSelectedEditState - 1 + 4)%4;
            break;
          case KEY_DOWN:
            guiSelectedEditState = (guiSelectedEditState + 1 + 4)%4;
            break;
          case 10: /* enter */
            guiEditState = guiSelectedEditState+1;
            guiSelectedInvariant = item_index(current_item(invariantsMenuScr));
            break;
          case KEY_BACKSPACE:
            refreshInvariantsList();
            guiState = GUI_STATE_INVARIANTS;
            break;
        }
      }
      if(guiEditState != GUI_EDIT_STATE_NONE) {
        if(guiEditState == GUI_EDIT_STATE_MIN) {
          switch(guiInv.datatype) {
            case DATA_TYPE_INT:
              editValue(textMin, &guiInv.range.i.min, DATA_TYPE_INT);
              break;
            case DATA_TYPE_UINT:
            case DATA_TYPE_UNSET:
              editValue(textMin, &guiInv.range.u.min, DATA_TYPE_UINT);
              break;
            case DATA_TYPE_DOUBLE:
              editValue(textMin, &guiInv.range.d.min, DATA_TYPE_DOUBLE);
              break;
            case DATA_TYPE_PTR:
              editValue(textMin, &guiInv.range.p.min, DATA_TYPE_PTR);
              break;
          }
        } else if(guiEditState == GUI_EDIT_STATE_MAX) {
          switch(guiInv.datatype) {
            case DATA_TYPE_INT:
              editValue(textMax, &guiInv.range.i.max, DATA_TYPE_INT);
              break;
            case DATA_TYPE_UINT:
            case DATA_TYPE_UNSET:
              editValue(textMax, &guiInv.range.u.max, DATA_TYPE_UINT);
              break;
            case DATA_TYPE_DOUBLE:
              editValue(textMax, &guiInv.range.d.max, DATA_TYPE_DOUBLE);
              break;
            case DATA_TYPE_PTR:
              editValue(textMax, &guiInv.range.p.max, DATA_TYPE_PTR);
              break;
          }
        } else if(guiEditState == GUI_EDIT_STATE_FIRST) {
          editValue(textFirst, &guiInv.bitmask.first, DATA_TYPE_PTR);
        } else if(guiEditState == GUI_EDIT_STATE_MASK) {
          editValue(textMask, &guiInv.bitmask.mask, DATA_TYPE_PTR);
        }
        guiEditState = GUI_EDIT_STATE_NONE;
        getInvariantType(guiProgramData, guiSelectedInvariantType)->data[guiSelectedInvariant] = guiInv;
        guiDataChanged = 1;
      }
      break;
    case GUI_STATE_TMP:
    default:
      switch(c) {
        case KEY_BACKSPACE:
          set_menu_fore(mainMenu, A_STANDOUT);
          guiState = GUI_STATE_MAIN;
          break;
      }
      break;
  }
  return 1;
}
Example #16
0
int
main (int argc, char *argv[])
{
  vc_component *v = NULL;
  fpos_t *fpos = NULL;
  long pos = 0;
  FILE *fp = NULL;
  ITEM *it = NULL;
  int entry_number = 0;

  bool done = FALSE;
  int win_state = WINDOW_INDEX;
  int command = 0;

  set_defaults ();
  process_command_line_args (argc, argv);
  /*
   * process_environment_variables(); 
   * process_configuration_file(); 
   */

  signal (SIGINT, finish);      /* catch interrupt for exiting */
  signal (SIGWINCH, resize);    /* catch interrupt for resizing */
  initscr ();

  keypad (stdscr, TRUE);        /* enable keypad for use of arrow keys */
  nonl ();                      /* tell curses not to do NL->CR/NL on output */
  cbreak ();                    /* take input chars immediately */
  noecho ();

  init_index (data_path);
  set_index_help_fcn (show_index_help);
  init_view ();
  set_view_help_fcn (show_view_help);
  init_edit ();
  set_edit_help_fcn (show_edit_help);
  init_help ();

  while (!done)
    {
      switch (win_state)
        {
        case WINDOW_INDEX:

      /*-------------------
         display the index
        -------------------*/

          display_index ();
          command = process_index_commands ();

          switch (command)
            {
            case INDEX_COMMAND_VIEW:
              win_state = WINDOW_VIEW;
              break;
            case INDEX_COMMAND_RAW_VIEW:
              win_state = WINDOW_RAW_VIEW;
              break;
            case INDEX_COMMAND_EDIT:
              win_state = WINDOW_EDIT;
              break;
            case INDEX_COMMAND_ADD:
              win_state = WINDOW_ADD;
              break;
            case INDEX_COMMAND_DELETE:
              win_state = WINDOW_DELETE;
              break;
            case INDEX_COMMAND_QUIT:
              done = TRUE;
              break;
            default:
              break;
            }

          break;

        case WINDOW_RAW_VIEW:

      /*-------------------------------------------------
         view the currently selected item with the pager
        -------------------------------------------------*/

          it = get_current_item ();

          /* only display if there is an item that is selected */
          if (NULL == it)
            {
              v = NULL;
            }
          else
            {
              fpos = (fpos_t *) item_userptr (it);

              fp = fopen (data_path, "r");
              fsetpos (fp, fpos);
              v = parse_vcard_file (fp);
              fclose (fp);
            }

          if (v != NULL)
            {
              raw_view (v);
              vc_delete_deep (v);
              v = NULL;
            }

          win_state = WINDOW_INDEX;

          break;

        case WINDOW_VIEW:

      /*----------------------------------
         view the currently selected item
        ----------------------------------*/

          it = get_current_item ();

          /* only display if there is an item that is selected */
          if (NULL == it)
            {
              v = NULL;
            }
          else
            {
              fpos = (fpos_t *) item_userptr (it);

              fp = fopen (data_path, "r");
              fsetpos (fp, fpos);
              v = parse_vcard_file (fp);
              fclose (fp);
            }

          if (v != NULL)
            {
              entry_number = get_entry_number (it);
              view_vcard (entry_number, v);
              command = process_view_commands ();

              switch (command)
                {
                case VIEW_COMMAND_EDIT:
                  win_state = WINDOW_EDIT;
                  break;
                case VIEW_COMMAND_INDEX:
                  win_state = WINDOW_INDEX;
                  break;
                case VIEW_COMMAND_PREVIOUS:
                  select_previous_item ();
                  win_state = WINDOW_VIEW;
                  break;
                case VIEW_COMMAND_NEXT:
                  select_next_item ();
                  win_state = WINDOW_VIEW;
                  break;
                default:
                  break;
                }
            }
          else
            {
              win_state = WINDOW_INDEX;
            }

          vc_delete_deep (v);
          v = NULL;

          break;

        case WINDOW_EDIT:

      /*--------------
         edit a vcard
        --------------*/

          it = get_current_item ();

          /* only display if there is an item that is selected */
          if (NULL != it)
            {
              fpos = (fpos_t *) item_userptr (it);

              fp = fopen (data_path, "r");
              fsetpos (fp, fpos);
              pos = ftell (fp);
              fclose (fp);
              fp = NULL;

              if (EDIT_SUCCESSFUL == edit_entry (data_path, pos))
                {
                  refresh_index ();
                }
            }

          win_state = WINDOW_INDEX;
          break;

        case WINDOW_ADD:
          if (ADD_SUCCESSFUL == add_entry (data_path))
            {
              refresh_index ();
            }

          win_state = WINDOW_INDEX;
          break;
        case WINDOW_DELETE:

          it = get_current_item ();

          /* only delete if there is an item that is selected */
          if (NULL != it)
            {
              fpos = (fpos_t *) item_userptr (it);

              fp = fopen (data_path, "r");
              fsetpos (fp, fpos);
              pos = ftell (fp);
              fclose (fp);
              fp = NULL;

              if (DELETE_SUCCESSFUL == delete_entry (data_path, pos))
                {
                  refresh_index ();
                }
            }

          win_state = WINDOW_INDEX;
          break;
        default:
          break;
        }
    }

  finish (0);
  exit (EXIT_SUCCESS);
  return (0);
}
Example #17
0
int main()
{	ITEM **my_items;
	int c;
	MENU *my_menu;
        WINDOW *my_menu_win;
        int n_choices, i;
	/* Initialize curses */
	initscr();
	start_color();
        cbreak();
        noecho();
	keypad(stdscr, TRUE);
	clear();	
	refresh();
	init_pair(1, COLOR_RED, COLOR_BLACK);
	getmaxyx(stdscr,y,x);
	/* Create items */
        n_choices = ARRAY_SIZE(choices);
        my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *));
        for(i=0;i<n_choices;++i)
	{
                my_items[i] = new_item(choices[i],"");
		set_item_userptr(my_items[i], func);
	}
	my_items[n_choices] = (ITEM *)NULL;
	/* Crate menu */
	my_menu = new_menu((ITEM **)my_items);
	/* Create the window to be associated with the menu */
        my_menu_win = newwin(10, 45, (y/2)-6,(x/2)-22 );
        keypad(my_menu_win, TRUE);
     
	/* Set main window and sub window */
        set_menu_win(my_menu, my_menu_win);
        set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
	/* Set menu mark to the string " * " */
        set_menu_mark(my_menu, " * ");
	/* Print a border around the main window and print a title */
        box(my_menu_win, 0, 0);
	print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Ncurses Phone Book (NPB)", COLOR_PAIR(1));
	mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
	mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
	mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
	mvprintw(LINES - 2, 0, "Press ESC to exit");
	refresh();
	/* Post the menu */
	post_menu(my_menu);
	wrefresh(my_menu_win);
//upon();
	while((c = wgetch(my_menu_win)) != 27)
	{       switch(c)
	        {	case KEY_DOWN:
				menu_driver(my_menu, REQ_DOWN_ITEM);
				break;
			case KEY_UP:
				menu_driver(my_menu, REQ_UP_ITEM);
				break;
			case 10: /* Enter */
			{	ITEM *cur;
				void (*p)(char *);
				cur = current_item(my_menu);
				p = item_userptr(cur);
				p((char *)item_name(cur));
				refresh();
				//printw("%s",item_name(cur));
				if(!strcmp("[6] Exit",item_name(cur)))
				{
					unpost_menu(my_menu);
				        free_menu(my_menu);
					endwin();
					return 0;
				}
				else if(!strcmp("[3] Searching for a contact by name",item_name(cur)))
				{
					upon("Search by name");
					//if(strlen(str)>1)
					
					clear();
					set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
					/* Set menu mark to the string " * " */
				        set_menu_mark(my_menu, " * ");
					/* Print a border around the main window and print a title */
				        box(my_menu_win, 0, 0);
					print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Simple Phone Book Application", COLOR_PAIR(1));
					mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
					mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
					mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
					mvprintw(LINES - 2, 0, "Press ESC to exit");
					refresh();
					/* Post the menu */
					post_menu(my_menu);
					wrefresh(my_menu_win);
				}
				else if(!strcmp("[4] Searching for a contact by number",item_name(cur)))
				{
					upon("Search by number");
					clear();
					set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
					/* Set menu mark to the string " * " */
				        set_menu_mark(my_menu, " * ");
					/* Print a border around the main window and print a title */
				        box(my_menu_win, 0, 0);
					print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Simple Phone Book Application", COLOR_PAIR(1));
					mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
					mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
					mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
					mvprintw(LINES - 2, 0, "Press ESC to exit");
					refresh();
					/* Post the menu */
					post_menu(my_menu);
					wrefresh(my_menu_win);
				}
				else if(!strcmp("[2] Removing a contact",item_name(cur)))
				{
					upon("Enter contact name to remove");
					clear();
					set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
					/* Set menu mark to the string " * " */
				        set_menu_mark(my_menu, " * ");
					/* Print a border around the main window and print a title */
				        box(my_menu_win, 0, 0);
					print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Simple Phone Book Application", COLOR_PAIR(1));
					mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
					mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
					mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
					mvprintw(LINES - 2, 0, "Press ESC to exit");
					refresh();
					/* Post the menu */
					post_menu(my_menu);
					wrefresh(my_menu_win);
				}
				else if(!strcmp("[5] Displaying contact list",item_name(cur)))
				{
					show();
					clear();
					set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
					/* Set menu mark to the string " * " */
				        set_menu_mark(my_menu, " * ");
					/* Print a border around the main window and print a title */
				        box(my_menu_win, 0, 0);
					print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Simple Phone Book Application", COLOR_PAIR(1));
					mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
					mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
					mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
					mvprintw(LINES - 2, 0, "Press ESC to exit");
					refresh();
					/* Post the menu */
					post_menu(my_menu);
					wrefresh(my_menu_win);
				}
				else if(!strcmp("[1] Adding a contact",item_name(cur)))
				{
					int ret=uponadd();			
					clear();
					set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
					/* Set menu mark to the string " * " */
				        set_menu_mark(my_menu, " * ");
					/* Print a border around the main window and print a title */
				        box(my_menu_win, 0, 0);
					print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Simple Phone Book Application", COLOR_PAIR(1));
					mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
					mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
					mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
					mvprintw(LINES - 2, 0, "Press ESC to exit");
					refresh();
					/* Post the menu */
					post_menu(my_menu);
					wrefresh(my_menu_win);
					if(ret==1)
					{
					int trash=outprint();
					clear();
					set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
					/* Set menu mark to the string " * " */
				        set_menu_mark(my_menu, " * ");
					/* Print a border around the main window and print a title */
				        box(my_menu_win, 0, 0);
					print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Simple Phone Book Application", COLOR_PAIR(1));
					mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
					mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
					mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
					mvprintw(LINES - 2, 0, "Press ESC to exit");
					refresh();
					/* Post the menu */
					post_menu(my_menu);
					wrefresh(my_menu_win);
					}
				}
				pos_menu_cursor(my_menu);
				break;
			}
		}
                wrefresh(my_menu_win);
	}	
	/* Unpost and free all the memory taken up */
        unpost_menu(my_menu);
        free_menu(my_menu);
//        for(i = 0; i < n_choices; ++i)
  //              free_item(my_items[i]);
	endwin();
}
Example #18
0
int main(int argc, char *argv[]) {

	const char  title[] = "MAME YOUR POISON:";
	char       *cfg     = NULL, cmdline[1024];
	const char *c;
	Game       *g;
	int         i;

	if((NULL == (rom = fullPath(romPath))) ||
	   (NULL == (xml = fullPath(xmlFile)))) {
		(void)printf("%s: malloc() fail (rom/xml)\n", argv[0]);
		return 1;
	}

	// ncurses setup
	initscr();
	cbreak();
	noecho();
	set_escdelay(0);
	curs_set(0);

	// Determine if screen is in portrait or landscape mode, get
	// path to corresponding advmame config file.  Method is to
	// check for 'rotate=0' in TFT module config file.  If present
	// (system() returns 0), is portrait screen, else landscape.
	c = cfgWide; // Assume landscape screen to start
	for(i=0; i<N_TFT_FILES; i++) { // Check each TFT config location...
		(void)sprintf(cmdline, "grep %s=0 %s",
		  tftCfg[i].keyword, tftCfg[i].filename);
		if(!system(cmdline)) { // Found portrait reference!
			c = cfgTall;
			break;
		}
	}
	if(NULL == (cfg = fullPath(c))) {
		endwin();
		(void)printf("%s: malloc() fail (cfg)\n", argv[0]);
		return 1;
	}

	mvprintw(0, (COLS - strlen(title)) / 2, title);
	mvprintw(LINES-2, 0     , "Up/Down: Choose");
	mvprintw(LINES-1, 0     , "Enter  : Run game");
	mvprintw(LINES-2, COLS/2, "R  : Rescan ROMs");
	mvprintw(LINES-1, COLS/2, geteuid() ? "Esc: Quit" : "Esc: Shutdown");

	mainWin = newwin(LINES-3, COLS, 1, 0);
	keypad(mainWin, TRUE);
	box(mainWin, 0, 0);

	refresh();

	find_roms();

	for(;;) {
		switch(wgetch(mainWin)) {
		   case KEY_DOWN:
			menu_driver(menu, REQ_DOWN_ITEM);
			break;
		   case KEY_UP:
			menu_driver(menu, REQ_UP_ITEM);
			break;
		   case KEY_NPAGE:
			menu_driver(menu, REQ_SCR_DPAGE);
			break;
		   case KEY_PPAGE:
			menu_driver(menu, REQ_SCR_UPAGE);
			break;
		   case 'r': // Re-scan ROM folder
			find_roms();
			break;
		   case 'R': // Rotate-and-reboot
			if(!geteuid()) { // Must be root
				clear();
				refresh();
				endwin();
				for(i=0; i<N_TFT_FILES; i++) {
					(void)sprintf(cmdline, 
					  "sed -i 's/%s=90/Fo0BaR/;"
						  "s/%s=0/%s=90/;"
						  "s/Fo0BaR/%s=0/' %s",
					  tftCfg[i].keyword, tftCfg[i].keyword, 
					  tftCfg[i].keyword, tftCfg[i].keyword, 
					  tftCfg[i].filename);
					(void)system(cmdline);
				}
				(void)system("reboot");
			}
			break;
		   case 27: // Esc = shutdown (if run as root) or quit
			clear();
			refresh();
			endwin();
			if(geteuid()) return 0; // Not root, quit to console
			(void)system("shutdown -h now");
			break;
		   case '\n': // Enter
		   case 'z':
		   case 'x':
			if((g = item_userptr(current_item(menu)))) {
				(void)sprintf(cmdline, "%s -cfg %s %s",
				  mameCmd, cfg, g->name);
				def_prog_mode();
				endwin();
				i = system(cmdline);
				reset_prog_mode();
				if(i) { // If error message, wait for input
					(void)printf("Press any button...");
					fflush(stdout);
					while(!getch());
				}
			}
			break;
		}
		wrefresh(mainWin);
	}

	return 0;
}
Example #19
0
int main()
{	ITEM **my_items;
	int c;				
	MENU *my_menu;
        int n_choices, i;
	ITEM *cur_item;
	
	/* Initialize curses */	
	initscr();
	start_color();
        cbreak();
        noecho();
	keypad(stdscr, TRUE);
	init_pair(1, COLOR_RED, COLOR_BLACK);
	init_pair(2, COLOR_GREEN, COLOR_BLACK);
	init_pair(3, COLOR_MAGENTA, COLOR_BLACK);

	/* Initialize items */
        n_choices = ARRAY_SIZE(choices);
        my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *));
        for(i = 0; i < n_choices; ++i)
	{       my_items[i] = new_item(choices[i], choices[i]);
		/* Set the user pointer */
		set_item_userptr(my_items[i], func);
	}
	my_items[n_choices] = (ITEM *)NULL;

	/* Create menu */
	my_menu = new_menu((ITEM **)my_items);

	/* Post the menu */
	mvprintw(LINES - 3, 0, "Press <ENTER> to see the option selected");
	mvprintw(LINES - 2, 0, "Up and Down arrow keys to naviage (F1 to Exit)");
	post_menu(my_menu);
	refresh();

	while((c = getch()) != KEY_F(1))
	{       switch(c)
	        {	case KEY_DOWN:
				menu_driver(my_menu, REQ_DOWN_ITEM);
				break;
			case KEY_UP:
				menu_driver(my_menu, REQ_UP_ITEM);
				break;
			case 10: /* Enter */
			{	ITEM *cur;
				void (*p)(char *);

				cur = current_item(my_menu);
				p = item_userptr(cur);
				p((char *)item_name(cur));
				pos_menu_cursor(my_menu);
				break;
			}
			break;
		}
	}	
	unpost_menu(my_menu);
	for(i = 0; i < n_choices; ++i)
		free_item(my_items[i]);
	free_menu(my_menu);
	endwin();
}
Example #20
0
void viewListPlayers(FootBallGame::TeamNumber teamNumber) {
  String teamName;
  int nChoices;
  ITEM **items;
  const char *itemName;
  const ITEM *currentItem;
  LinkedList<String*> names = LinkedList<String*>(deleteString);
  LinkedList<int*> pids = LinkedList<int*>(deleteInt);

  const int window_nlines = 10,
            window_ncols  = 90;

  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);

    // Set up the items of menu.
    FootBallTeam *team = game.getFootBallTeam(teamNumber);
    if (team != NULL) {
      nChoices = team->getPlayerCount() + 2;
      items = new ITEM* [nChoices];

      TeamIterator iterator, end;
      team->begin(iterator);
      team->end(end);
      for (int i = 0; iterator != end; i++, iterator++) {
        Player *player = *iterator;
        String *playerName = new String;
        int *pid = new int;
        player->getName(*playerName);
        *pid = player->getPid();
        names.append(playerName);
        pids.append(pid);
        items[i] = new_item(playerName->c_str(), NULL);
        set_item_userptr(items[i], pid);
      }
    } else  {
      nChoices = 2;
      items = new ITEM* [nChoices];
    }
    items[nChoices-2] = new_item("Exit", NULL);
    items[nChoices-1] = NULL;

    // Create the menu
    MENU *menu = new_menu((ITEM **)items);
    set_menu_win(menu, window);
    set_menu_sub(menu, derwin(window, 10, 80, 0, 10));
    set_menu_mark(menu, NULL);
    // Do not Show the item descritpions
    menu_opts_off(menu, O_SHOWDESC);

    post_menu(menu);
    wrefresh(window);
    refresh();
    
    int c;
    bool restart = false;
    while (!restart && (c = wgetch(window))) {
      switch (c) {
        case KEY_DOWN:
          menu_driver(menu, REQ_DOWN_ITEM);
          break;
        case KEY_UP:
          menu_driver(menu, REQ_UP_ITEM);
          break;
        case 10: // Enter
          currentItem = current_item(menu);
          itemName = item_name(currentItem);
          if (itemName != NULL) {
            if (strcmp(itemName, "Exit") == 0) {
              // Delete allocated data
              unpost_menu(menu);
              free_menu(menu); 
              for (int i = 0; i < nChoices-1; i++) 
                free_item(items[i]);
              delete[] items;
              delwin(window); 
              return;
            } else  {
              int *pid = (int*)item_userptr(currentItem);
              // Delete allocated data
              unpost_menu(menu);
              free_menu(menu); 
              for (int i = 0; i < nChoices-1; i++) 
                free_item(items[i]);
              delete[] items;
              delwin(window); 
              viewPlayer(team, itemName, *pid);
              restart = true;
            }
          }
      }
    }
  }
}
Example #21
0
void
column_select_save_columns(ui_t *ui)
{
    int column;
    FILE *fi, *fo;
    char columnopt[128];
    char line[1024];
    char *home = getenv("HOME");
    char userconf[128], tmpfile[128];

    // No home dir...
    if (!home)
        return;

    // Read current $HOME/.sngreprc file
    sprintf(userconf, "%s/.sngreprc", home);
    sprintf(tmpfile, "%s/.sngreprc.old", home);

    // Remove old config file
    unlink(tmpfile);

    // Move home file to temporal dir
    rename(userconf, tmpfile);

    // Create a new user conf file
    if (!(fo = fopen(userconf, "w"))) {
        dialog_run("Unable to open %s: %s", userconf, strerror(errno));
        return;
    }

    // Read all lines of old sngreprc file
    if ((fi = fopen(tmpfile, "r"))) {

        // Read all configuration file
        while (fgets(line, 1024, fi) != NULL) {
            // Ignore lines starting with set (but keep settings)
            if (strncmp(line, "set ", 4) || strncmp(line, "set cl.column", 13)) {
                // Put everyting in new .sngreprc file
                fputs(line, fo);
            }
        }
        fclose(fi);
    }

    // Get panel information
    column_select_info_t *info = column_select_info(ui);

    // Add all selected columns
    for (column = 0; column < item_count(info->menu); column++) {
        // If column is active
        if (!strncmp(item_name(info->items[column]), "[ ]", 3))
            continue;

        // Add the columns settings
        sprintf(columnopt, "set cl.column%d %s\n", column, (const char*) item_userptr(info->items[column]));
        fputs(columnopt, fo);
    }
    fclose(fo);

    // Show a information dialog
    dialog_run("Column layout successfully saved to %s", userconf);
}
Example #22
0
static void handle_tree_input(struct regedit *regedit, int c)
{
	struct tree_node *node;

	switch (c) {
	case KEY_DOWN:
		menu_driver(regedit->keys->menu, REQ_DOWN_ITEM);
		load_values(regedit);
		break;
	case KEY_UP:
		menu_driver(regedit->keys->menu, REQ_UP_ITEM);
		load_values(regedit);
		break;
	case '\n':
	case KEY_ENTER:
	case KEY_RIGHT:
		node = item_userptr(current_item(regedit->keys->menu));
		if (node && tree_node_has_children(node)) {
			tree_node_load_children(node);
			print_path(regedit, node->child_head);
			tree_view_update(regedit->keys, node->child_head);
			value_list_load(regedit->vl, node->child_head->key);
		}
		break;
	case KEY_LEFT:
		node = item_userptr(current_item(regedit->keys->menu));
		if (node && node->parent) {
			print_path(regedit, node->parent);
			node = tree_node_first(node->parent);
			tree_view_update(regedit->keys, node);
			value_list_load(regedit->vl, node->key);
		}
		break;
	case 'n':
	case 'N':
		node = item_userptr(current_item(regedit->keys->menu));
		add_reg_key(regedit, node, false);
		break;
	case 's':
	case 'S':
		node = item_userptr(current_item(regedit->keys->menu));
		add_reg_key(regedit, node, true);
		break;
	case 'd':
	case 'D': {
		int sel;

		node = item_userptr(current_item(regedit->keys->menu));
		if (!node->parent) {
			break;
		}
		sel = dialog_notice(regedit, DIA_CONFIRM,
				    "Delete Key",
				     "Really delete key \"%s\"?",
				     node->name);
		if (sel == DIALOG_OK) {
			WERROR rv;
			struct tree_node *pop;
			struct tree_node *parent = node->parent;

			rv = reg_key_del(node, parent->key, node->name);
			if (W_ERROR_IS_OK(rv)) {
				tree_view_clear(regedit->keys);
				pop = tree_node_pop(&node);
				tree_node_free_recursive(pop);
				node = parent->child_head;
				if (node == NULL) {
					node = tree_node_first(parent);
					print_path(regedit, node);
				}
				tree_view_update(regedit->keys, node);
				value_list_load(regedit->vl, node->key);
			} else {
				dialog_notice(regedit, DIA_ALERT, "Delete Key",
					      "Failed to delete key.");
			}
		}
		break;
	}
	}

	tree_view_show(regedit->keys);
	value_list_show(regedit->vl);
}
Example #23
0
static void handle_value_input(struct regedit *regedit, int c)
{
	struct value_item *vitem;
	bool binmode = false;

	switch (c) {
	case KEY_DOWN:
		menu_driver(regedit->vl->menu, REQ_DOWN_ITEM);
		break;
	case KEY_UP:
		menu_driver(regedit->vl->menu, REQ_UP_ITEM);
		break;
	case 'b':
	case 'B':
		binmode = true;
		/* Falthrough... */
	case '\n':
	case KEY_ENTER:
		vitem = item_userptr(current_item(regedit->vl->menu));
		if (vitem) {
			struct tree_node *node;
			node = item_userptr(current_item(regedit->keys->menu));
			dialog_edit_value(regedit, node->key, vitem->type,
					  vitem, binmode);
			value_list_load(regedit->vl, node->key);
		}
		break;
	case 'n':
	case 'N': {
		int new_type;
		int sel;

		sel = dialog_select_type(regedit, &new_type);
		if (sel == DIALOG_OK) {
			struct tree_node *node;
			node = item_userptr(current_item(regedit->keys->menu));
			dialog_edit_value(regedit, node->key, new_type, NULL,
					  false);
			value_list_load(regedit->vl, node->key);
		}
		break;
	}
	case 'd':
	case 'D':
		vitem = item_userptr(current_item(regedit->vl->menu));
		if (vitem) {
			int sel;

			sel = dialog_notice(regedit, DIA_CONFIRM,
					    "Delete Value",
					     "Really delete value \"%s\"?",
					     vitem->value_name);
			if (sel == DIALOG_OK) {
				ITEM *it = current_item(regedit->keys->menu);
				struct tree_node *node = item_userptr(it);
				reg_del_value(regedit, node->key,
					      vitem->value_name);
				value_list_load(regedit->vl, node->key);
			}
		}
		break;
	}

	value_list_show(regedit->vl);
}
Example #24
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;
}
Example #25
0
/*
 * Return codes:
 *  0 - action performed
 * -1 - quit was pressed (only for main menu)
 * +1 - backspace or escape was pressed, back to previous menu
 */
static int
do_menu(struct menuoption *runmenu, int num, int upper, const char *title, ...)
{
	int ch, i, y, x;
//	char buf[BUFSIZ];
	char *buf;
	struct menuoption *curmenu;
	ITEM **mitems, *mitem;
	MENU *mmenu;
	WINDOW *msubwin;
	va_list ap;

	/* Clear screen and print title */
	if (upper)
		show_mainwin(0);
	else
		show_mainwin(1);
	va_start(ap, title);
	head_mainwin(title, ap);
	va_end(ap);

	x = 0;
	y = 0;
	if (upper)
		msubwin = create_uppersubwin();
	else
		msubwin = create_lowersubwin(&y, &x);

	mitems = (ITEM **)calloc(num + 1, sizeof(ITEM*));
	for (curmenu = runmenu, i = 0; i < num; i++) {
		ch = sizeof buf > x ? x - 1 : sizeof buf - 1;
//		if (snprintf(buf, ch, "%s", curmenu->m_name) <= 0) {
		if (asprintf(&buf, "%s", curmenu->m_name) <= 0) {
			ask_ok("Error creating the menu.");
			for (i--; i >= 0; i--)
				free(mitems[i]);
			return 0;
		}
		mitems[i] = new_item(buf, NULL);
		set_item_userptr(mitems[i], (void *)curmenu);
//		warnx("%ld %s", (long)curmenu, curmenu->m_name);
		curmenu++;
	}
	mitems[num] = NULL;

	mmenu = new_menu(mitems);
	set_menu_win(mmenu, mainwin);
	set_menu_sub(mmenu, msubwin);
	set_menu_format(mmenu, upper ? 1 : y, 1);
	if (colouring) {
		set_menu_fore(mmenu, COLOR_PAIR(1));
		set_menu_back(mmenu, COLOR_PAIR(1));
		set_menu_grey(mmenu, COLOR_PAIR(1));
	}
	set_menu_mark(mmenu, ">");
	if (post_menu(mmenu)) {
		ask_ok("Error posting the menu.");
		return 1;
	}
	show_mainwin(0);
	show_lowersubwin(0, msubwin);

	while ((ch = getch()) != '\n' && ch != '\b') {
		switch (ch) {
			case KEY_DOWN:
				menu_driver(mmenu, REQ_NEXT_ITEM);
				break;
			case KEY_UP:
				menu_driver(mmenu, REQ_PREV_ITEM);
				break;
			case KEY_NPAGE:
				menu_driver(mmenu, REQ_SCR_DPAGE);
				break;
			case KEY_PPAGE:
				menu_driver(mmenu, REQ_SCR_UPAGE);
				break;
			case KEY_END:
				menu_driver(mmenu, REQ_LAST_ITEM);
				break;
			case KEY_HOME:
				menu_driver(mmenu, REQ_FIRST_ITEM);
				break;
		}
		show_mainwin(0);
		show_lowersubwin(0, msubwin);
	}

	mitem = current_item(mmenu);
	curmenu = (struct menuoption *)item_userptr(mitem);

	unpost_menu(mmenu);
	delwin(msubwin);
	free_menu(mmenu);
	for (i = 0; i < num; i++)
		free_item(mitems[i]);
	free(mitems);

	if (ch != '\b' && curmenu->m_action != NULL) {
		curmenu->m_action(curmenu->m_argv);
		return 0;
	} else {
		return 1;
	}
}
Example #26
0
/* Starts the program and prints the main menu */
int main(int qw) {
    static int mm = -1;
    mm++;
    initscr();
    curs_set(0);
    noecho();
    if(qw == 2)
        banner(4);
    else if(qw == 1)
        banner(3);
    ITEM **my_items;
    int c;
    MENU *my_menu;
    WINDOW *my_menu_win;
    int n_choices, i;
    ITEM *cur;
    /* Initialize curses */
    initscr();
    start_color();
    init_pair(5, COLOR_RED, COLOR_BLACK);
    init_pair(6, COLOR_BLACK, COLOR_RED);
    init_pair(7, COLOR_CYAN, COLOR_BLACK);
    cbreak();
    noecho();
    keypad(stdscr, TRUE);
    init_pair(1, COLOR_RED, COLOR_BLACK);
START:
    attrset(COLOR_PAIR(7));
    n_choices = ARRAY_SIZE(choices_index);
    my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *));
    for(i = 0; i < n_choices; ++i) {
        my_items[i] = new_item(choices_index[i], NULL);
        if(i == 0)
            /* Set the user pointer */
            set_item_userptr(my_items[i], mains);
        else if(i == 1)
            set_item_userptr(my_items[i], race_menu);
        else if(i == 2)
            set_item_userptr(my_items[i], exitit);
    }
    my_items[n_choices] = (ITEM *)NULL;
    /* Crate menu */
    my_menu = new_menu((ITEM **)my_items);

    /* Create the window to be associated with the menu */
    my_menu_win = newwin(8, 25, 15, 70);
    keypad(my_menu_win, TRUE);

    /* Set main window and sub window */
    set_menu_win(my_menu, my_menu_win);
    set_menu_sub(my_menu, derwin(my_menu_win, 5, 19, 3, 1));

    /* Set menu mark to the string " * " */
    set_menu_mark(my_menu, "--> ");

    /* Print a border around the main window and print a title */
    box(my_menu_win, 0, 0);
    print_in_middle1(my_menu_win, 1, 0, 25, "CHOOSE A GAME", COLOR_PAIR(7));
    attrset(COLOR_PAIR(7));
    mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
    mvwhline(my_menu_win, 2, 1, ACS_HLINE, 24);
    mvwaddch(my_menu_win, 2, 24, ACS_RTEE);
    mvprintw(LINES - 2, 1, " Press F1 to exit");
    /* Post the menu */
    mvprintw(LINES - 3, 1, " Press <ENTER> to see the option selected");
    mvprintw(LINES - 2, 1, " Up and Down arrow keys to navigate (F1 to Exit)");
    post_menu(my_menu);
    if(!mm)
        moto(0);
    else
        moto(1);
    refresh();

    /* Post the menu */
    post_menu(my_menu);
    wrefresh(my_menu_win);

    while((c = wgetch(my_menu_win)) != KEY_F(1))
    {   switch(c)
        {
        case KEY_DOWN:
            menu_driver(my_menu, REQ_DOWN_ITEM);
            break;
        case KEY_UP:
            menu_driver(my_menu, REQ_UP_ITEM);
            break;
        case 10:
            cur = current_item(my_menu);
            endwin();
            unpost_menu(my_menu);
            clear();
            refresh();
            void (*p)(char *);
            cur = current_item(my_menu);
            p = item_userptr(cur);
            p((char *)item_name(cur));
            pos_menu_cursor(my_menu);
            initscr();	/* Post the menu */
            attrset(COLOR_PAIR(7));
            mvprintw(LINES - 3, 1, " Press <ENTER> to see the option selected");
            mvprintw(LINES - 2, 1, " Up and Down arrow keys to naviage (F1 to Exit)");
            goto START;
            refresh();
            break;
        }
        wrefresh(my_menu_win);
    }

    /* Unpost and free all the memory taken up */
    for(i = 0; i < n_choices; ++i)
        free_item(my_items[i]);
    free_menu(my_menu);
    endwin();
    exit(1);
}
Example #27
0
int main(void)
{
    tui_init();

    tab_window *ltab = malloc(sizeof *ltab);
    tab_window *rtab = malloc(sizeof *ltab);
    int ch;
    void (*p)(tab_window *, const char *);
    tab_window *active_tab;
    ltab->win = tui_new_win(0, 0, LINES, COLS / 2 , 2);
    rtab->win = tui_new_win(0, COLS / 2, LINES, COLS / 2, 2);

    mvwprintw(ltab->win->decoration, 1,1, "/");
    mvwprintw(rtab->win->decoration, 1,1, "/");

    set_panel_userptr(ltab->win->panel, rtab);
    set_panel_userptr(rtab->win->panel, ltab);

    top_panel(ltab->win->panel);

    active_tab = ltab;

    strncpy(ltab->path, "/", PATH_MAX - 1);
    strncpy(rtab->path, "/", PATH_MAX - 1);
    ltab->items_num = scan_dir(ltab->path, &ltab->files, dirsortbyname);
    rtab->items_num = scan_dir(rtab->path, &rtab->files, dirsortbyname);

    tui_make_menu(ltab, event_handler);
    tui_make_menu(rtab, event_handler);

    touchwin(panel_window(active_tab->win->panel));
    update_panels();
    doupdate();

    while ((ch = getch()) != KEY_F(12))
    {
        p = (void (*)(tab_window *, const char *))(uintptr_t)item_userptr(current_item(active_tab->menu));
        switch (ch)
        {
            case '\t':
                active_tab = (tab_window *) panel_userptr(active_tab->win->panel);
                top_panel(active_tab->win->panel);
                break;
            case KEY_DOWN:
                menu_driver(active_tab->menu, REQ_DOWN_ITEM);
                break;
            case KEY_UP:
                menu_driver(active_tab->menu, REQ_UP_ITEM);
                break;
            case KEY_NPAGE:
                menu_driver(active_tab->menu, REQ_SCR_DPAGE);
                break;
            case KEY_PPAGE:
                menu_driver(active_tab->menu, REQ_SCR_UPAGE);
                break;
            case KEY_HOME:
                menu_driver(active_tab->menu, REQ_FIRST_ITEM);
                break;
            case KEY_END:
                menu_driver(active_tab->menu, REQ_LAST_ITEM);
                break;
            case 13: // enter
                p(active_tab, "select");
                break;
            case KEY_F(2):
                p(active_tab, "remove");
                break;
            case KEY_F(3):
                p(active_tab, "rename");
                break;
            default:break;
        }
        touchwin(panel_window(active_tab->win->panel));
        update_panels();
        doupdate();
    }
    for(int i = 0; i < ltab->items_num ; ++i)
    {
        free(ltab->files[i]);
    }
    free(ltab->files);
    for(int i = 0; i < rtab->items_num; ++i)
    {
        free(rtab->files[i]);
    }
    free(rtab->files);
    tui_destroy_menu(rtab);
    tui_destroy_menu(ltab);
    tui_del_win(ltab);
    tui_del_win(rtab);
    free(ltab);
    free(rtab);
    endwin();
}