diff --git a/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp index c12a89c7..595f3a29 100644 --- a/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp +++ b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp @@ -81,6 +81,7 @@ void ComicVineDialog::doStackedWidgets() content->addWidget(searchSingleComic = new SearchSingleComic); content->addWidget(searchVolume = new SearchVolume); content->addWidget(selectVolume = new SelectVolume); + content->addWidget(selectComic = new SelectComic); } void ComicVineDialog::doConnections() @@ -189,13 +190,13 @@ void ComicVineDialog::debugClientResults(const QString & string) if(p.getNumResults() == 0) showSearchSingleComic(); else - showSelectComic(); + showSelectComic(string); break; case Volume: if(p.getNumResults() == 0) showSearchVolume(); else - showSelectVolume(); + showSelectVolume(string); break; } } @@ -238,14 +239,16 @@ void ComicVineDialog::showSearchVolume() skipButton->setHidden(true); } -void ComicVineDialog::showSelectVolume() +void ComicVineDialog::showSelectVolume(const QString & json) { content->setCurrentWidget(selectVolume); + selectVolume->load(json); } -void ComicVineDialog::showSelectComic() +void ComicVineDialog::showSelectComic(const QString &json) { - + content->setCurrentWidget(selectComic); + selectComic->load(json); } void ComicVineDialog::showLoading() diff --git a/YACReaderLibrary/comic_vine/comic_vine_dialog.h b/YACReaderLibrary/comic_vine/comic_vine_dialog.h index eceb6970..1d330166 100644 --- a/YACReaderLibrary/comic_vine/comic_vine_dialog.h +++ b/YACReaderLibrary/comic_vine/comic_vine_dialog.h @@ -43,8 +43,8 @@ protected slots: void search(); void launchSearchVolume(); void launchSearchComic(); - void showSelectVolume(); - void showSelectComic(); + void showSelectVolume(const QString & json); + void showSelectComic(const QString & json); private: enum ScrapperMode @@ -94,6 +94,7 @@ private: SearchSingleComic * searchSingleComic; SearchVolume * searchVolume; SelectVolume * selectVolume; + SelectComic * selectComic; }; #endif // COMIC_VINE_DIALOG_H diff --git a/YACReaderLibrary/comic_vine/model/json_model.h b/YACReaderLibrary/comic_vine/model/json_model.h index c22c6dd6..443e9a20 100644 --- a/YACReaderLibrary/comic_vine/model/json_model.h +++ b/YACReaderLibrary/comic_vine/model/json_model.h @@ -8,6 +8,7 @@ class JSONModel : public QAbstractItemModel Q_OBJECT public: explicit JSONModel(QObject *parent = 0); + virtual void load(const QString & json) = 0 ; signals: diff --git a/YACReaderLibrary/comic_vine/model/response_parser.cpp b/YACReaderLibrary/comic_vine/model/response_parser.cpp index 600d156c..759067a3 100644 --- a/YACReaderLibrary/comic_vine/model/response_parser.cpp +++ b/YACReaderLibrary/comic_vine/model/response_parser.cpp @@ -27,7 +27,6 @@ void ResponseParser::loadJSONResponse(const QString &response) if (!sc.property("error").isValid() && sc.property("error").toString() != "OK") { error = true; - numResults = -2; qDebug("Error detected"); } else @@ -36,7 +35,6 @@ void ResponseParser::loadJSONResponse(const QString &response) if(sc.property("number_of_total_results").isValid()) numResults = sc.property("number_of_total_results").toString().toInt();// sc.property("number_of_total_results").toInt32(); else - numResults = -3; - qDebug() << sc.property("number_of_total_results").toString(); + qDebug() << sc.property("oops").toString(); } } diff --git a/YACReaderLibrary/comic_vine/model/volumes_model.cpp b/YACReaderLibrary/comic_vine/model/volumes_model.cpp index 44b1ab63..193bbdfe 100644 --- a/YACReaderLibrary/comic_vine/model/volumes_model.cpp +++ b/YACReaderLibrary/comic_vine/model/volumes_model.cpp @@ -1,6 +1,110 @@ #include "volumes_model.h" +#include + + VolumesModel::VolumesModel(QObject *parent) : JSONModel(parent) { } + +void VolumesModel::load(const QString &json) +{ + QScriptEngine engine; + QScriptValue sc; + sc = engine.evaluate("(" + json + ")"); + + if (!sc.property("error").isValid() && sc.property("error").toString() != "OK") + { + qDebug("Error detected"); + } + else + { + QScriptValueIterator it(sc.property("results")); + while (it.hasNext()) { + it.next(); + qDebug("Nick %s",it.value().property("nick").toString().toStdString().c_str()); + } + /* + if(sc.property("number_of_total_results").isValid()) + sc.property("number_of_total_results").toString().toInt();// sc.property("number_of_total_results").toInt32(); + else + qDebug() << sc.property("oops").toString();*/ + } +} + +QModelIndex VolumesModel::parent(const QModelIndex &index) const +{ + Q_UNUSED(index) + return QModelIndex(); //no parent +} + +int VolumesModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent) + return _data.count(); +} + +int VolumesModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent) + if(_data.isEmpty()) + return 0; + else + return _data.at(0).count(); +} + +QVariant VolumesModel::data(const QModelIndex &index, int role) const +{ + if (role != Qt::DisplayRole) + return QVariant(); + + int row = index.row(); + int column = index.column(); + return _data[row][column]; +} + +Qt::ItemFlags VolumesModel::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return 0; + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; +} + +QVariant VolumesModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + { + switch(section)//TODO obtener esto de la query + { + case SERIES: + return QVariant(QString("series")); + case YEAR: + return QVariant(QString(tr("year"))); + case ISSUES: + return QVariant(QString(tr("issues"))); + case PUBLISHER: + return QVariant(QString(tr("publisher"))); + } + } + + if (orientation == Qt::Horizontal && role == Qt::TextAlignmentRole) + { + switch(section)//TODO obtener esto de la query + { + case YEAR: + return QVariant(Qt::AlignRight | Qt::AlignVCenter); + case ISSUES: + return QVariant(Qt::AlignRight | Qt::AlignVCenter); + } + } + + return QVariant(); +} + +QModelIndex VolumesModel::index(int row, int column, const QModelIndex &parent) const +{ + return QModelIndex(); +} + diff --git a/YACReaderLibrary/comic_vine/model/volumes_model.h b/YACReaderLibrary/comic_vine/model/volumes_model.h index b8d402b2..51c04eac 100644 --- a/YACReaderLibrary/comic_vine/model/volumes_model.h +++ b/YACReaderLibrary/comic_vine/model/volumes_model.h @@ -8,11 +8,32 @@ class VolumesModel : public JSONModel Q_OBJECT public: explicit VolumesModel(QObject *parent = 0); + //receive a valid json with a list of volumes + void load(const QString & json); + //QAbstractItemModel methods + QModelIndex parent(const QModelIndex &index) const; + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent) const; + QVariant data(const QModelIndex &index, int role) const; + Qt::ItemFlags flags(const QModelIndex &index) const; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; signals: public slots: +private: + QList > _data; + + enum Column { + SERIES, + YEAR, + ISSUES, + PUBLISHER + }; + }; #endif // VOLUMES_MODEL_H diff --git a/YACReaderLibrary/comic_vine/select_comic.cpp b/YACReaderLibrary/comic_vine/select_comic.cpp index 111936b3..365fb7ab 100644 --- a/YACReaderLibrary/comic_vine/select_comic.cpp +++ b/YACReaderLibrary/comic_vine/select_comic.cpp @@ -3,6 +3,13 @@ SelectComic::SelectComic(QWidget *parent) :QWidget(parent) -{} +{ + +} + +void SelectComic::load(const QString &json) +{ + +} SelectComic::~SelectComic() {} diff --git a/YACReaderLibrary/comic_vine/select_comic.h b/YACReaderLibrary/comic_vine/select_comic.h index c4ad4588..62bf5a5c 100644 --- a/YACReaderLibrary/comic_vine/select_comic.h +++ b/YACReaderLibrary/comic_vine/select_comic.h @@ -8,6 +8,7 @@ class SelectComic : public QWidget Q_OBJECT public: SelectComic(QWidget * parent = 0); + void load(const QString & json); virtual ~SelectComic(); }; diff --git a/YACReaderLibrary/comic_vine/select_volume.cpp b/YACReaderLibrary/comic_vine/select_volume.cpp index 52a4d9f0..1508c051 100644 --- a/YACReaderLibrary/comic_vine/select_volume.cpp +++ b/YACReaderLibrary/comic_vine/select_volume.cpp @@ -8,7 +8,7 @@ #include "volumes_model.h" SelectVolume::SelectVolume(QWidget *parent) - :QWidget(parent) + :QWidget(parent),model(0) { QString labelStylesheet = "QLabel {color:white; font-size:12px;font-family:Arial;}"; QString tableStylesheet = "" @@ -68,5 +68,15 @@ SelectVolume::SelectVolume(QWidget *parent) setContentsMargins(0,0,0,0); } +void SelectVolume::load(const QString & json) +{ + if(model != 0) + delete model; + else + model = new VolumesModel(); + + model->load(json); +} + SelectVolume::~SelectVolume() {} diff --git a/YACReaderLibrary/comic_vine/select_volume.h b/YACReaderLibrary/comic_vine/select_volume.h index 3c5d2d64..d60bbb8f 100644 --- a/YACReaderLibrary/comic_vine/select_volume.h +++ b/YACReaderLibrary/comic_vine/select_volume.h @@ -12,6 +12,7 @@ class SelectVolume : public QWidget Q_OBJECT public: SelectVolume(QWidget * parent = 0); + void load(const QString & json); virtual ~SelectVolume(); private: QLabel * cover;