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.
 
 
 
 

61 lines
1.7 KiB

  1. #include "collection.h"
  2. #include "ui_collection.h"
  3. #include <QMessageBox>
  4. #include <QObject>
  5. #include "interface/collectionitem.h"
  6. collection::collection(CrunchyrollAPI* _api,query_t _series,QWidget *parent) :
  7. QDialog(parent),
  8. ui(new Ui::collection)
  9. {
  10. ui->setupUi(this);
  11. api = _api;
  12. series = _series;
  13. connect(ui->results,SIGNAL(itemSelectionChanged()),this,SLOT(selected()));
  14. ui->results->setItemDelegate(new ItemSizeDelegateCollections);
  15. fetchCollections();
  16. }
  17. collection::~collection()
  18. {
  19. delete ui;
  20. }
  21. void collection::fetchCollections(){
  22. ui->results->clear();
  23. auto response = api->getCollections(series.series_id.toInt());
  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<collection_t> results = response.first;
  31. for(collection_t result:results){
  32. collectionitem *item = new collectionitem(result);
  33. QListWidgetItem* li = new QListWidgetItem();
  34. ui->results->addItem(li);
  35. ui->results->setItemWidget(ui->results->item(ui->results->count()-1),item);
  36. }
  37. }
  38. QVector<collection_t> collection::getSelectedCollections(){
  39. return selection;
  40. }
  41. void collection::selected(){
  42. QList<QListWidgetItem*> items = ui->results->selectedItems();
  43. QVector<collection_t> collections;
  44. for(auto item:items){
  45. collectionitem *q = dynamic_cast<collectionitem*>(ui->results->itemWidget(item));
  46. if(q)
  47. collections.push_back(q->getCollection());
  48. else
  49. qWarning("Cannot cast abstract item object");
  50. }
  51. selection = collections;
  52. }