Ejemplo n.º 1
0
void add_to_shelf_IO(goods_t *l)
{

  goods_t item = generate_goods();
  printf("\n\n");
  display_goods(item);
  printf("\n\tAre you sure you want to add %s to your shelf? [Y]es/[N]o/[E]dit  _  ", item.name);

  while (1)
    {
      char input = read_char();
      
      switch(input)
	{
	case 'Y':
	  add_to_shelf(item, l);
	  return;
	case 'N':
	  return;
	case 'E':
	  {
	    goods_t edItem = generate_goods();
	    add_to_shelf(edItem, l);
	    return;
	  }
	default:
	  printf("\n\tInvalid input _");
	  break;
	}
    }
 
}
Ejemplo n.º 2
0
void MainWindow::on_all_table_customContextMenuRequested(const QPoint &pos)
{
    QModelIndex index = ui->all_table->indexAt(pos);
    if(!index.isValid())
        return;
    book_name = ui->all_table->selectedItems()[0]->text().toStdString();
    selected_row = ui->all_table->selectedItems()[0];
    QMenu* menu = new QMenu(this);
    QAction* action = 0;
    if(DB::db()->user()->get_library()->is_in_library(book_name))
    {
        cerr << "1" << endl;
        if(!DB::db()->user()->get_library()->is_in_starred(book_name))
        {
            action = new QAction("Like this", this);
            menu->addAction(action);
            connect(action,SIGNAL(triggered()),this,SLOT(like()));
        }

        vector<Shelf*> shelves = DB::db()->user()->get_library()->get_shelves();
        int count = 0;
        for(int i = 0; i < shelves.size(); i++)
        {
            if(shelves[i]->get_name() == "default")
                continue;
            if(shelves[i]->has_book(book_name))
                continue;
            count++;
        }
        if(count > 0)
        {
            action = new QAction("Add to Shelf", this);
            menu->addAction(action);
            connect(action,SIGNAL(triggered()),this,SLOT(add_to_shelf()));
        }
    }
    else
    {

        action = new QAction("Add To Library",this);
        menu->addAction(action);
        connect(action,SIGNAL(triggered()),this,SLOT(add_to_library()));
    }
    menu->popup(ui->all_table->viewport()->mapToGlobal(pos));
}