You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

57 lines
1.5 KiB

  1. #include "query.h"
  2. #include "ui_query.h"
  3. #include <QMessageBox>
  4. #include <QObject>
  5. #include "interface/queryitem.h"
  6. query::query(CrunchyrollAPI* _api,QWidget *parent) :
  7. QDialog(parent),
  8. ui(new Ui::query)
  9. {
  10. ui->setupUi(this);
  11. api = _api;
  12. connect(ui->search,SIGNAL(clicked()),this,SLOT(doSearch()));
  13. connect(ui->results,SIGNAL(currentRowChanged(int)),this,SLOT(selected(int)));
  14. ui->results->setItemDelegate(new ItemSizeDelegate);
  15. }
  16. query::~query()
  17. {
  18. delete ui;
  19. }
  20. void query::doSearch(){
  21. ui->results->clear();
  22. if(ui->name->text().count()<1) return;
  23. auto response = api->searchMedia(ui->name->text());
  24. api_status_t status = response.second;
  25. if(status.failed){
  26. QMessageBox::critical(this,"API Error","An error occurred:\n"
  27. + status.description);
  28. return;
  29. }
  30. QVector<query_t> results = response.first;
  31. for(query_t result:results){
  32. queryitem *item = new queryitem(result);
  33. // ui->
  34. QListWidgetItem* li = new QListWidgetItem();
  35. ui->results->addItem(li);
  36. ui->results->setItemWidget(ui->results->item(ui->results->count()-1),item);
  37. }
  38. }
  39. query_t query::getSelectedQuery(){
  40. return selection;
  41. }
  42. void query::selected(int row){
  43. QListWidgetItem* item = ui->results->item(row);
  44. queryitem *q = dynamic_cast<queryitem*>(ui->results->itemWidget(item));
  45. if(q)
  46. selection = q->getSeries();
  47. else
  48. qWarning("Cannot cast abstract item object");
  49. }