From 9795f514e73b3bfc054cb193660fed8c665e5753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Mon, 7 Oct 2013 16:48:05 +0200 Subject: [PATCH] added new comic_vine folder containing all the ComicVine related clases added QtScript dependency (json parser) --- YACReaderLibrary/YACReaderLibrary.pro | 12 +- YACReaderLibrary/comic_vine/comic_vine.pri | 30 +++ .../{ => comic_vine}/comic_vine_client.cpp | 18 +- .../{ => comic_vine}/comic_vine_client.h | 0 .../{ => comic_vine}/comic_vine_dialog.cpp | 220 ++++-------------- .../comic_vine/comic_vine_dialog.h | 91 ++++++++ .../comic_vine/model/comics_model.cpp | 6 + .../comic_vine/model/comics_model.h | 18 ++ .../comic_vine/model/json_model.cpp | 6 + .../comic_vine/model/json_model.h | 18 ++ .../comic_vine/model/response_parser.cpp | 42 ++++ .../comic_vine/model/response_parser.h | 23 ++ .../comic_vine/model/volumes_model.cpp | 6 + .../comic_vine/model/volumes_model.h | 18 ++ .../comic_vine/scrapper_lineedit.cpp | 21 ++ .../comic_vine/scrapper_lineedit.h | 19 ++ .../comic_vine/search_single_comic.cpp | 54 +++++ .../comic_vine/search_single_comic.h | 21 ++ YACReaderLibrary/comic_vine/search_volume.cpp | 31 +++ YACReaderLibrary/comic_vine/search_volume.h | 20 ++ YACReaderLibrary/comic_vine/select_comic.cpp | 8 + YACReaderLibrary/comic_vine/select_comic.h | 14 ++ YACReaderLibrary/comic_vine/select_volume.cpp | 72 ++++++ YACReaderLibrary/comic_vine/select_volume.h | 23 ++ .../comic_vine/series_question.cpp | 41 ++++ YACReaderLibrary/comic_vine/series_question.h | 22 ++ YACReaderLibrary/comic_vine/title_header.cpp | 53 +++++ YACReaderLibrary/comic_vine/title_header.h | 22 ++ YACReaderLibrary/comic_vine_dialog.h | 158 ------------- 29 files changed, 733 insertions(+), 354 deletions(-) create mode 100644 YACReaderLibrary/comic_vine/comic_vine.pri rename YACReaderLibrary/{ => comic_vine}/comic_vine_client.cpp (75%) rename YACReaderLibrary/{ => comic_vine}/comic_vine_client.h (100%) rename YACReaderLibrary/{ => comic_vine}/comic_vine_dialog.cpp (50%) create mode 100644 YACReaderLibrary/comic_vine/comic_vine_dialog.h create mode 100644 YACReaderLibrary/comic_vine/model/comics_model.cpp create mode 100644 YACReaderLibrary/comic_vine/model/comics_model.h create mode 100644 YACReaderLibrary/comic_vine/model/json_model.cpp create mode 100644 YACReaderLibrary/comic_vine/model/json_model.h create mode 100644 YACReaderLibrary/comic_vine/model/response_parser.cpp create mode 100644 YACReaderLibrary/comic_vine/model/response_parser.h create mode 100644 YACReaderLibrary/comic_vine/model/volumes_model.cpp create mode 100644 YACReaderLibrary/comic_vine/model/volumes_model.h create mode 100644 YACReaderLibrary/comic_vine/scrapper_lineedit.cpp create mode 100644 YACReaderLibrary/comic_vine/scrapper_lineedit.h create mode 100644 YACReaderLibrary/comic_vine/search_single_comic.cpp create mode 100644 YACReaderLibrary/comic_vine/search_single_comic.h create mode 100644 YACReaderLibrary/comic_vine/search_volume.cpp create mode 100644 YACReaderLibrary/comic_vine/search_volume.h create mode 100644 YACReaderLibrary/comic_vine/select_comic.cpp create mode 100644 YACReaderLibrary/comic_vine/select_comic.h create mode 100644 YACReaderLibrary/comic_vine/select_volume.cpp create mode 100644 YACReaderLibrary/comic_vine/select_volume.h create mode 100644 YACReaderLibrary/comic_vine/series_question.cpp create mode 100644 YACReaderLibrary/comic_vine/series_question.h create mode 100644 YACReaderLibrary/comic_vine/title_header.cpp create mode 100644 YACReaderLibrary/comic_vine/title_header.h delete mode 100644 YACReaderLibrary/comic_vine_dialog.h diff --git a/YACReaderLibrary/YACReaderLibrary.pro b/YACReaderLibrary/YACReaderLibrary.pro index 4df1dd97..339441c5 100644 --- a/YACReaderLibrary/YACReaderLibrary.pro +++ b/YACReaderLibrary/YACReaderLibrary.pro @@ -9,7 +9,9 @@ INCLUDEPATH += . INCLUDEPATH += ../common \ ./server \ ./db \ - ../custom_widgets + ../custom_widgets \ + ./comic_vine \ + ./comic_vine/model DEFINES += SERVER_RELEASE @@ -35,7 +37,7 @@ LIBS += -L/usr/local/lib -lpoppler-qt4 CONFIG += release CONFIG -= flat -QT += sql network opengl +QT += sql network opengl script # Input HEADERS += comic_flow.h \ @@ -76,8 +78,6 @@ HEADERS += comic_flow.h \ yacreader_local_server.h \ yacreader_main_toolbar.h \ comics_remover.h \ - comic_vine_dialog.h \ - comic_vine_client.h \ ../common/http_worker.h SOURCES += comic_flow.cpp \ @@ -118,14 +118,13 @@ SOURCES += comic_flow.cpp \ yacreader_local_server.cpp \ yacreader_main_toolbar.cpp \ comics_remover.cpp \ - comic_vine_dialog.cpp \ - comic_vine_client.cpp \ ../common/http_worker.cpp include(./server/server.pri) include(../custom_widgets/custom_widgets_yacreaderlibrary.pri) include(../compressed_archive/wrapper.pri) +include(./comic_vine/comic_vine.pri) RESOURCES += images.qrc files.qrc win32:RESOURCES += images_win.qrc @@ -147,4 +146,3 @@ TRANSLATIONS = yacreaderlibrary_es.ts \ Release:DESTDIR = ../release Debug:DESTDIR = ../debug - diff --git a/YACReaderLibrary/comic_vine/comic_vine.pri b/YACReaderLibrary/comic_vine/comic_vine.pri new file mode 100644 index 00000000..cd929ab4 --- /dev/null +++ b/YACReaderLibrary/comic_vine/comic_vine.pri @@ -0,0 +1,30 @@ + +HEADERS += \ + comic_vine/comic_vine_dialog.h \ + comic_vine/comic_vine_client.h \ + comic_vine/scrapper_lineedit.h \ + comic_vine/title_header.h \ + comic_vine/series_question.h \ + comic_vine/search_single_comic.h \ + comic_vine/search_volume.h \ + comic_vine/select_comic.h \ + comic_vine/select_volume.h \ + comic_vine/model/volumes_model.h \ + comic_vine/model/comics_model.h \ + comic_vine/model/json_model.h \ + comic_vine/model/response_parser.h + +SOURCES += \ + comic_vine/comic_vine_dialog.cpp \ + comic_vine/comic_vine_client.cpp \ + comic_vine/scrapper_lineedit.cpp \ + comic_vine/title_header.cpp \ + comic_vine/series_question.cpp \ + comic_vine/search_single_comic.cpp \ + comic_vine/search_volume.cpp \ + comic_vine/select_comic.cpp \ + comic_vine/select_volume.cpp \ + comic_vine/model/volumes_model.cpp \ + comic_vine/model/comics_model.cpp \ + comic_vine/model/json_model.cpp \ + comic_vine/model/response_parser.cpp diff --git a/YACReaderLibrary/comic_vine_client.cpp b/YACReaderLibrary/comic_vine/comic_vine_client.cpp similarity index 75% rename from YACReaderLibrary/comic_vine_client.cpp rename to YACReaderLibrary/comic_vine/comic_vine_client.cpp index c7c1a0a8..681546b0 100644 --- a/YACReaderLibrary/comic_vine_client.cpp +++ b/YACReaderLibrary/comic_vine/comic_vine_client.cpp @@ -8,28 +8,28 @@ static const QString CV_WEB_ADDRESS = "http://www.comicvine.com/api"; //gets any volumen containing any comic matching 'query' static const QString CV_SEARCH = CV_WEB_ADDRESS + "/search/?api_key=" + CV_API_KEY + - "&format=xml&limit=100&resources=volume" + "&format=json&limit=100&resources=volume" "&field_list=name,start_year,publisher,id,image,count_of_issues" "&query=%1&page=%2"; -//http://comicvine.com/api/search/?api_key=46680bebb358f1de690a5a365e15d325f9649f91&format=xml&limit=100&resources=volume&field_list=name,start_year,publisher,id,image,count_of_issues&query=superman +//http://www.comicvine.com/api/search/?api_key=46680bebb358f1de690a5a365e15d325f9649f91&format=json&limit=100&resources=volume&field_list=name,start_year,publisher,id,image,count_of_issues&query=superman //gets the detail for a volume %1 static const QString CV_SERIES_DETAIL = CV_WEB_ADDRESS + "/volume/4050-%1/?api_key=" + CV_API_KEY + - "&format=xml&field_list=name,start_year,publisher,image,count_of_issues,id"; + "&format=json&field_list=name,start_year,publisher,image,count_of_issues,id"; //gets ids for comics in a volume id %1 static const QString CV_COMIC_IDS = CV_WEB_ADDRESS + "/issues/?api_key=" + CV_API_KEY + - "&format=xml&field_list=name,issue_number,id,image&filter=volume:%1&page=%1";//offset?? + "&format=json&field_list=name,issue_number,id,image&filter=volume:%1&page=%1";//offset?? //gets id for comic number %2 in a volume id %1 static const QString CV_COMIC_ID = CV_WEB_ADDRESS + "/issues/?api_key=" + CV_API_KEY + - "&format=xml&field_list=name,issue_number,id,image" + "&format=json&field_list=name,issue_number,id,image" "&filter=volume:%1,issue_number:%2"; //gets comic detail -static const QString CV_COMIC_DETAIL = CV_WEB_ADDRESS + "/issue/4000-%1/?api_key=" + CV_API_KEY + "&format=xml"; +static const QString CV_COMIC_DETAIL = CV_WEB_ADDRESS + "/issue/4000-%1/?api_key=" + CV_API_KEY + "&format=json"; //gets comic cover URL -static const QString CV_COVER_URL = CV_WEB_ADDRESS + "/issue/4000-%1/?api_key=" + CV_API_KEY + "&format=xml&field_list=image"; +static const QString CV_COVER_URL = CV_WEB_ADDRESS + "/issue/4000-%1/?api_key=" + CV_API_KEY + "&format=json&field_list=image"; //gets comics matching name %1 and number %2 //http://comicvine.com/api/issues/?api_key=46680bebb358f1de690a5a365e15d325f9649f91&limit=20&filter=name:super,issue_number:15 @@ -52,8 +52,8 @@ void ComicVineClient::search(const QString & query, int page) //CV_SEARCH result void ComicVineClient::proccessVolumesSearchData(const QByteArray & data) { - QString xml(data); - emit searchResult(xml); + QString json(data); + emit searchResult(json); } void ComicVineClient::queryTimeOut() diff --git a/YACReaderLibrary/comic_vine_client.h b/YACReaderLibrary/comic_vine/comic_vine_client.h similarity index 100% rename from YACReaderLibrary/comic_vine_client.h rename to YACReaderLibrary/comic_vine/comic_vine_client.h diff --git a/YACReaderLibrary/comic_vine_dialog.cpp b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp similarity index 50% rename from YACReaderLibrary/comic_vine_dialog.cpp rename to YACReaderLibrary/comic_vine/comic_vine_dialog.cpp index 0b4c3ab3..33a06911 100644 --- a/YACReaderLibrary/comic_vine_dialog.cpp +++ b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp @@ -6,9 +6,20 @@ #include #include #include +#include #include "yacreader_busy_widget.h" #include "comic_vine_client.h" +#include "scrapper_lineedit.h" +#include "title_header.h" +#include "series_question.h" +#include "search_single_comic.h" +#include "search_volume.h" +#include "select_comic.h" +#include "select_volume.h" + +#include "response_parser.h" + ComicVineDialog::ComicVineDialog(QWidget *parent) : QDialog(parent),comicVineClient(new ComicVineClient) @@ -69,6 +80,7 @@ void ComicVineDialog::doStackedWidgets() content->addWidget(seriesQuestion = new SeriesQuestion); content->addWidget(searchSingleComic = new SearchSingleComic); content->addWidget(searchVolume = new SearchVolume); + content->addWidget(selectVolume = new SelectVolume); } void ComicVineDialog::doConnections() @@ -142,7 +154,6 @@ void ComicVineDialog::show() titleHeader->setSubTitle(tr("%1 comics selected").arg(comics.length())); showSeriesQuestion(); } - } void ComicVineDialog::doLoading() @@ -164,6 +175,13 @@ void ComicVineDialog::doLoading() void ComicVineDialog::debugClientResults(const QString & string) { + ResponseParser p; + p.loadJSONResponse(string); + + QString debug = QString("%1 \n %2").arg(p.getNumResults()).arg(string); + + QMessageBox::information(0,"-Response-", debug); + switch(status) { case SingleComic: @@ -177,7 +195,7 @@ void ComicVineDialog::debugClientResults(const QString & string) break; } - QMessageBox::information(0,"-Response-", string); + } void ComicVineDialog::showSeriesQuestion() @@ -214,6 +232,11 @@ void ComicVineDialog::showSearchVolume() skipButton->setHidden(true); } +void ComicVineDialog::showSelectVolume() +{ + content->setCurrentWidget(selectVolume); +} + void ComicVineDialog::showLoading() { content->setCurrentIndex(0); @@ -228,193 +251,30 @@ void ComicVineDialog::search() { switch (status) { case Volume: - showLoading(); - comicVineClient->search(searchVolume->getVolumeInfo()); + launchSearchVolume(); break; default: + launchSearchComic(); break; } } -//--------------------------------------- -//TitleHeader -//--------------------------------------- -TitleHeader::TitleHeader(QWidget * parent ) - :QWidget(parent) +void ComicVineDialog::launchSearchVolume() { - mainTitleLabel = new QLabel(); - subTitleLabel = new QLabel(); - - mainTitleLabel->setStyleSheet("QLabel {color:white; font-size:18px;font-family:Arial;}"); - subTitleLabel->setStyleSheet("QLabel {color:white; font-size:12px;font-family:Arial;}"); - - QHBoxLayout * titleLayout = new QHBoxLayout; - QVBoxLayout * titleLabelsLayout = new QVBoxLayout; - - titleLabelsLayout->addWidget(mainTitleLabel); - titleLabelsLayout->addWidget(subTitleLabel); - titleLabelsLayout->setSpacing(0); - - titleLayout->addLayout(titleLabelsLayout); - titleLayout->setContentsMargins(0,0,0,0); - - setLayout(titleLayout); - - setContentsMargins(0,0,0,0); - - setTitle(tr("SEARCH")); + showLoading(); + //TODO: check if volume info is empty. + comicVineClient->search(searchVolume->getVolumeInfo()); } -void TitleHeader::setTitle(const QString & title) +void ComicVineDialog::launchSearchComic() { - mainTitleLabel->setText(title); + showLoading(); + + QString volumeInfo = searchSingleComic->getVolumeInfo(); + QString comicInfo = searchSingleComic->getComicInfo(); + int comicNumber = searchSingleComic->getComicNumber(); + + if(comicInfo.isEmpty() && comicNumber == -1) + comicVineClient->search(volumeInfo); } -void TitleHeader::setSubTitle(const QString & title) -{ - subTitleLabel->setText(title); -} - -void TitleHeader::showButtons(bool show) -{ - if(show) - { - - } - else - { - - } -} - -//--------------------------------------- -//SeriesQuestion -//--------------------------------------- -SeriesQuestion::SeriesQuestion(QWidget * parent) - :QWidget(parent) -{ - QVBoxLayout * l = new QVBoxLayout; - - QLabel * questionLabel = new QLabel(tr("You are trying to get information for various comics at once, are they part of the same series?")); - questionLabel->setStyleSheet("QLabel {color:white; font-size:12px;font-family:Arial;}"); - yes = new QRadioButton(tr("yes")); - no = new QRadioButton(tr("no")); - - QString rbStyle = "QRadioButton {margin-left:27px; margin-top:5px; color:white;font-size:12px;font-family:Arial;}" - "QRadioButton::indicator {width:11px;height:11px;}" - "QRadioButton::indicator::unchecked {image : url(:/images/comic_vine/radioUnchecked.png);}" - "QRadioButton::indicator::checked {image : url(:/images/comic_vine/radioChecked.png);}"; - yes->setStyleSheet(rbStyle); - no->setStyleSheet(rbStyle); - - yes->setChecked(true); - - l->addSpacing(35); - l->addWidget(questionLabel); - l->addWidget(yes); - l->addWidget(no); - l->addStretch(); - - l->setContentsMargins(0,0,0,0); - setLayout(l); - setContentsMargins(0,0,0,0); -} - -bool SeriesQuestion::getYes() -{ - return yes->isChecked(); -} -//--------------------------------------- -//ScrapperLineEdit -//--------------------------------------- -ScrapperLineEdit::ScrapperLineEdit(const QString & title, QWidget * widget) - :QLineEdit(widget) -{ - titleLabel = new QLabel(title,this); - titleLabel->setStyleSheet("QLabel {color:white;}"); - - setStyleSheet(QString("QLineEdit {" - "border:none; background-color: #2E2E2E; color : white; padding-left: %1; padding-bottom: 1px; margin-bottom: 0px;" - "}").arg(titleLabel->sizeHint().width()+6)); - - setFixedHeight(22); -} - -void ScrapperLineEdit::resizeEvent(QResizeEvent *) -{ - QSize szl = titleLabel->sizeHint(); - titleLabel->move(6,(rect().bottom() + 1 - szl.height())/2); -} - -//--------------------------------------- -//SearchSingleComic -//--------------------------------------- -SearchSingleComic::SearchSingleComic(QWidget * parent) - :QWidget(parent) -{ - - QLabel * label = new QLabel(tr("No results found, please provide some aditional information. At least one field is needed.")); - label->setStyleSheet("QLabel {color:white; font-size:12px;font-family:Arial;}"); - - titleEdit = new ScrapperLineEdit(tr("Title:")); - numberEdit = new ScrapperLineEdit(tr("Number:")); - volumeEdit = new ScrapperLineEdit(tr("Series:")); - - numberEdit->setMaximumWidth(126); - - QVBoxLayout * l = new QVBoxLayout; - QHBoxLayout * hl = new QHBoxLayout; - hl->addWidget(titleEdit); - hl->addWidget(numberEdit); - - l->addSpacing(35); - l->addWidget(label); - l->addLayout(hl); - l->addWidget(volumeEdit); - l->addStretch(); - - l->setContentsMargins(0,0,0,0); - setLayout(l); - setContentsMargins(0,0,0,0); -} - -//--------------------------------------- -//SearchVolume -//--------------------------------------- -SearchVolume::SearchVolume(QWidget * parent) - :QWidget(parent) -{ - QLabel * label = new QLabel(tr("No results found, please provide some aditional information.")); - label->setStyleSheet("QLabel {color:white; font-size:12px;font-family:Arial;}"); - - volumeEdit = new ScrapperLineEdit(tr("Series:")); - - QVBoxLayout * l = new QVBoxLayout; - - l->addSpacing(35); - l->addWidget(label); - l->addWidget(volumeEdit); - l->addStretch(); - - l->setContentsMargins(0,0,0,0); - setLayout(l); - setContentsMargins(0,0,0,0); -} - -//--------------------------------------- -//SelectVolume -//--------------------------------------- -SelectVolume::SelectVolume(QWidget *parent) - :QWidget(parent) -{} - -SelectVolume::~SelectVolume() {} - -//--------------------------------------- -//SelectComic -//--------------------------------------- -SelectComic::SelectComic(QWidget *parent) - :QWidget(parent) -{} - -SelectComic::~SelectComic() {} diff --git a/YACReaderLibrary/comic_vine/comic_vine_dialog.h b/YACReaderLibrary/comic_vine/comic_vine_dialog.h new file mode 100644 index 00000000..d4b023a9 --- /dev/null +++ b/YACReaderLibrary/comic_vine/comic_vine_dialog.h @@ -0,0 +1,91 @@ +#ifndef COMIC_VINE_DIALOG_H +#define COMIC_VINE_DIALOG_H + +#include + +#include "comic_db.h" + +class QPushButton; +class QStackedWidget; +class QLabel; +class QRadioButton; +class ComicVineClient; +class QTableView; +class TitleHeader; +class SeriesQuestion; +class SearchSingleComic; +class SearchVolume; +class SelectComic; +class SelectVolume; + + +//---------------------------------------- +class ComicVineDialog : public QDialog +{ + Q_OBJECT +public: + explicit ComicVineDialog(QWidget *parent = 0); + QString databasePath; + QString basePath; + void setComics(const QList & comics); +signals: + +public slots: + void show(); +protected slots: + void goNext(); + void debugClientResults(const QString & string); + //show widget methods + void showSeriesQuestion(); + void showSearchSingleComic(); + void showSearchVolume(); + void showLoading(); + void search(); + void launchSearchVolume(); + void launchSearchComic(); + void showSelectVolume(); +private: + + enum ScrapperStatus + { + SingleComic, + Volume, + SingleComicInSeries, + SelectingComic, + SelectingSeries + }; + + ScrapperStatus status; + + ComicVineClient * comicVineClient; + + int currentIndex; + + TitleHeader * titleHeader; + + QPushButton * skipButton; + QPushButton * backButton; + QPushButton * nextButton; + QPushButton * searchButton; + QPushButton * closeButton; + + //stacked widgets + QStackedWidget * content; + + QWidget * infoNotFound; + QWidget * singleComicBrowser; + + void doLayout(); + void doStackedWidgets(); + void doLoading(); + void doConnections(); + + QList comics; + + SeriesQuestion * seriesQuestion; + SearchSingleComic * searchSingleComic; + SearchVolume * searchVolume; + SelectVolume * selectVolume; +}; + +#endif // COMIC_VINE_DIALOG_H diff --git a/YACReaderLibrary/comic_vine/model/comics_model.cpp b/YACReaderLibrary/comic_vine/model/comics_model.cpp new file mode 100644 index 00000000..5b194f24 --- /dev/null +++ b/YACReaderLibrary/comic_vine/model/comics_model.cpp @@ -0,0 +1,6 @@ +#include "comics_model.h" + +ComicsModel::ComicsModel(QObject *parent) : + JSONModel(parent) +{ +} diff --git a/YACReaderLibrary/comic_vine/model/comics_model.h b/YACReaderLibrary/comic_vine/model/comics_model.h new file mode 100644 index 00000000..86bfb2e5 --- /dev/null +++ b/YACReaderLibrary/comic_vine/model/comics_model.h @@ -0,0 +1,18 @@ +#ifndef COMICS_MODEL_H +#define COMICS_MODEL_H + +#include "json_model.h" + +class ComicsModel : public JSONModel +{ + Q_OBJECT +public: + explicit ComicsModel(QObject *parent = 0); + +signals: + +public slots: + +}; + +#endif // COMICS_MODEL_H diff --git a/YACReaderLibrary/comic_vine/model/json_model.cpp b/YACReaderLibrary/comic_vine/model/json_model.cpp new file mode 100644 index 00000000..d0c4ce41 --- /dev/null +++ b/YACReaderLibrary/comic_vine/model/json_model.cpp @@ -0,0 +1,6 @@ +#include "json_model.h" + +JSONModel::JSONModel(QObject *parent) : + QAbstractItemModel(parent) +{ +} diff --git a/YACReaderLibrary/comic_vine/model/json_model.h b/YACReaderLibrary/comic_vine/model/json_model.h new file mode 100644 index 00000000..c22c6dd6 --- /dev/null +++ b/YACReaderLibrary/comic_vine/model/json_model.h @@ -0,0 +1,18 @@ +#ifndef JSON_MODEL_H +#define JSON_MODEL_H + +#include + +class JSONModel : public QAbstractItemModel +{ + Q_OBJECT +public: + explicit JSONModel(QObject *parent = 0); + +signals: + +public slots: + +}; + +#endif // JSON_MODEL_H diff --git a/YACReaderLibrary/comic_vine/model/response_parser.cpp b/YACReaderLibrary/comic_vine/model/response_parser.cpp new file mode 100644 index 00000000..600d156c --- /dev/null +++ b/YACReaderLibrary/comic_vine/model/response_parser.cpp @@ -0,0 +1,42 @@ +#include "response_parser.h" + +#include +#include + +ResponseParser::ResponseParser(QObject *parent) : + QObject(parent),error(false),numResults(-1) +{ +} + +bool ResponseParser::responseError() +{ + return error; +} + +qint32 ResponseParser::getNumResults() +{ + return numResults; +} + +void ResponseParser::loadJSONResponse(const QString &response) +{ + QScriptEngine engine; + QScriptValue sc; + sc = engine.evaluate("(" + response + ")"); + + if (!sc.property("error").isValid() && sc.property("error").toString() != "OK") + { + error = true; + numResults = -2; + qDebug("Error detected"); + } + else + { + error = false; + 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(); + } +} diff --git a/YACReaderLibrary/comic_vine/model/response_parser.h b/YACReaderLibrary/comic_vine/model/response_parser.h new file mode 100644 index 00000000..17775598 --- /dev/null +++ b/YACReaderLibrary/comic_vine/model/response_parser.h @@ -0,0 +1,23 @@ +#ifndef RESPONSE_PARSER_H +#define RESPONSE_PARSER_H + +#include + +class ResponseParser : public QObject +{ + Q_OBJECT +public: + explicit ResponseParser(QObject *parent = 0); + bool responseError(); + qint32 getNumResults(); +signals: + +public slots: + void loadJSONResponse(const QString & response); + +protected: + bool error; + qint32 numResults; +}; + +#endif // RESPONSE_PARSER_H diff --git a/YACReaderLibrary/comic_vine/model/volumes_model.cpp b/YACReaderLibrary/comic_vine/model/volumes_model.cpp new file mode 100644 index 00000000..44b1ab63 --- /dev/null +++ b/YACReaderLibrary/comic_vine/model/volumes_model.cpp @@ -0,0 +1,6 @@ +#include "volumes_model.h" + +VolumesModel::VolumesModel(QObject *parent) : + JSONModel(parent) +{ +} diff --git a/YACReaderLibrary/comic_vine/model/volumes_model.h b/YACReaderLibrary/comic_vine/model/volumes_model.h new file mode 100644 index 00000000..b8d402b2 --- /dev/null +++ b/YACReaderLibrary/comic_vine/model/volumes_model.h @@ -0,0 +1,18 @@ +#ifndef VOLUMES_MODEL_H +#define VOLUMES_MODEL_H + +#include "json_model.h" + +class VolumesModel : public JSONModel +{ + Q_OBJECT +public: + explicit VolumesModel(QObject *parent = 0); + +signals: + +public slots: + +}; + +#endif // VOLUMES_MODEL_H diff --git a/YACReaderLibrary/comic_vine/scrapper_lineedit.cpp b/YACReaderLibrary/comic_vine/scrapper_lineedit.cpp new file mode 100644 index 00000000..fb3cb2bc --- /dev/null +++ b/YACReaderLibrary/comic_vine/scrapper_lineedit.cpp @@ -0,0 +1,21 @@ +#include "scrapper_lineedit.h" +#include + +ScrapperLineEdit::ScrapperLineEdit(const QString & title, QWidget * widget) + :QLineEdit(widget) +{ + titleLabel = new QLabel(title,this); + titleLabel->setStyleSheet("QLabel {color:white;}"); + + setStyleSheet(QString("QLineEdit {" + "border:none; background-color: #2E2E2E; color : white; padding-left: %1; padding-bottom: 1px; margin-bottom: 0px;" + "}").arg(titleLabel->sizeHint().width()+6)); + + setFixedHeight(22); +} + +void ScrapperLineEdit::resizeEvent(QResizeEvent *) +{ + QSize szl = titleLabel->sizeHint(); + titleLabel->move(6,(rect().bottom() + 1 - szl.height())/2); +} diff --git a/YACReaderLibrary/comic_vine/scrapper_lineedit.h b/YACReaderLibrary/comic_vine/scrapper_lineedit.h new file mode 100644 index 00000000..d8e7b780 --- /dev/null +++ b/YACReaderLibrary/comic_vine/scrapper_lineedit.h @@ -0,0 +1,19 @@ +#ifndef SCRAPPER_LINEEDIT_H +#define SCRAPPER_LINEEDIT_H + +#include + +class QLabel; + +class ScrapperLineEdit : public QLineEdit +{ + Q_OBJECT +public: + ScrapperLineEdit(const QString & title, QWidget * widget = 0); +protected: + void resizeEvent(QResizeEvent *); +private: + QLabel * titleLabel; +}; + +#endif // SCRAPPER_LINEEDIT_H diff --git a/YACReaderLibrary/comic_vine/search_single_comic.cpp b/YACReaderLibrary/comic_vine/search_single_comic.cpp new file mode 100644 index 00000000..ae881fe0 --- /dev/null +++ b/YACReaderLibrary/comic_vine/search_single_comic.cpp @@ -0,0 +1,54 @@ +#include "search_single_comic.h" + +#include "scrapper_lineedit.h" + +#include +#include +#include + +SearchSingleComic::SearchSingleComic(QWidget * parent) + :QWidget(parent) +{ + + QLabel * label = new QLabel(tr("No results found, please provide some aditional information. At least one field is needed.")); + label->setStyleSheet("QLabel {color:white; font-size:12px;font-family:Arial;}"); + + titleEdit = new ScrapperLineEdit(tr("Title:")); + numberEdit = new ScrapperLineEdit(tr("Number:")); + volumeEdit = new ScrapperLineEdit(tr("Series:")); + + numberEdit->setMaximumWidth(126); + + QVBoxLayout * l = new QVBoxLayout; + QHBoxLayout * hl = new QHBoxLayout; + hl->addWidget(titleEdit); + hl->addWidget(numberEdit); + + l->addSpacing(35); + l->addWidget(label); + l->addLayout(hl); + l->addWidget(volumeEdit); + l->addStretch(); + + l->setContentsMargins(0,0,0,0); + setLayout(l); + setContentsMargins(0,0,0,0); +} + +QString SearchSingleComic::getVolumeInfo() +{ + return volumeEdit->text(); +} + +QString SearchSingleComic::getComicInfo() +{ + return titleEdit->text(); +} + +int SearchSingleComic::getComicNumber() +{ + QString numberText = numberEdit->text(); + if(numberText.isEmpty()) + return -1; + return numberText.toInt(); +} diff --git a/YACReaderLibrary/comic_vine/search_single_comic.h b/YACReaderLibrary/comic_vine/search_single_comic.h new file mode 100644 index 00000000..b6f5f925 --- /dev/null +++ b/YACReaderLibrary/comic_vine/search_single_comic.h @@ -0,0 +1,21 @@ +#ifndef SEARCH_SINGLE_COMIC_H +#define SEARCH_SINGLE_COMIC_H + +#include + +class ScrapperLineEdit; + +class SearchSingleComic : public QWidget +{ + Q_OBJECT +public: + SearchSingleComic(QWidget * parent = 0); + QString getVolumeInfo(); + QString getComicInfo(); + int getComicNumber(); +private: + ScrapperLineEdit * titleEdit; + ScrapperLineEdit * numberEdit; + ScrapperLineEdit * volumeEdit; +}; +#endif // SEARCH_SINGLE_COMIC_H diff --git a/YACReaderLibrary/comic_vine/search_volume.cpp b/YACReaderLibrary/comic_vine/search_volume.cpp new file mode 100644 index 00000000..6924f5b3 --- /dev/null +++ b/YACReaderLibrary/comic_vine/search_volume.cpp @@ -0,0 +1,31 @@ +#include "search_volume.h" + +#include "scrapper_lineedit.h" + +#include +#include + +SearchVolume::SearchVolume(QWidget * parent) + :QWidget(parent) +{ + QLabel * label = new QLabel(tr("No results found, please provide some aditional information.")); + label->setStyleSheet("QLabel {color:white; font-size:12px;font-family:Arial;}"); + + volumeEdit = new ScrapperLineEdit(tr("Series:")); + + QVBoxLayout * l = new QVBoxLayout; + + l->addSpacing(35); + l->addWidget(label); + l->addWidget(volumeEdit); + l->addStretch(); + + l->setContentsMargins(0,0,0,0); + setLayout(l); + setContentsMargins(0,0,0,0); +} + +QString SearchVolume::getVolumeInfo() +{ + return volumeEdit->text(); +} diff --git a/YACReaderLibrary/comic_vine/search_volume.h b/YACReaderLibrary/comic_vine/search_volume.h new file mode 100644 index 00000000..21ad8482 --- /dev/null +++ b/YACReaderLibrary/comic_vine/search_volume.h @@ -0,0 +1,20 @@ +#ifndef SEARCH_VOLUME_H +#define SEARCH_VOLUME_H + +#include + +class ScrapperLineEdit; + + +class SearchVolume : public QWidget +{ + Q_OBJECT +public: + SearchVolume(QWidget * parent = 0); +public slots: + QString getVolumeInfo(); +private: + ScrapperLineEdit * volumeEdit; +}; + +#endif // SEARCH_VOLUME_H diff --git a/YACReaderLibrary/comic_vine/select_comic.cpp b/YACReaderLibrary/comic_vine/select_comic.cpp new file mode 100644 index 00000000..111936b3 --- /dev/null +++ b/YACReaderLibrary/comic_vine/select_comic.cpp @@ -0,0 +1,8 @@ +#include "select_comic.h" + + +SelectComic::SelectComic(QWidget *parent) + :QWidget(parent) +{} + +SelectComic::~SelectComic() {} diff --git a/YACReaderLibrary/comic_vine/select_comic.h b/YACReaderLibrary/comic_vine/select_comic.h new file mode 100644 index 00000000..c4ad4588 --- /dev/null +++ b/YACReaderLibrary/comic_vine/select_comic.h @@ -0,0 +1,14 @@ +#ifndef SELECT_COMIC_H +#define SELECT_COMIC_H + +#include + +class SelectComic : public QWidget +{ + Q_OBJECT +public: + SelectComic(QWidget * parent = 0); + virtual ~SelectComic(); +}; + +#endif // SELECT_COMIC_H diff --git a/YACReaderLibrary/comic_vine/select_volume.cpp b/YACReaderLibrary/comic_vine/select_volume.cpp new file mode 100644 index 00000000..52a4d9f0 --- /dev/null +++ b/YACReaderLibrary/comic_vine/select_volume.cpp @@ -0,0 +1,72 @@ +#include "select_volume.h" + +#include +#include +#include +#include + +#include "volumes_model.h" + +SelectVolume::SelectVolume(QWidget *parent) + :QWidget(parent) +{ + QString labelStylesheet = "QLabel {color:white; font-size:12px;font-family:Arial;}"; + QString tableStylesheet = "" + "QTableView {alternate-background-color: #333333;background-color: #2B2B2B; outline: 0px;}"// border: 1px solid #999999; border-right:none; border-bottom:none;}" + "QTableCornerButton::section {background-color:#F5F5F5; border:none; border-bottom:1px solid #B8BDC4; border-right:1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #D1D1D1, stop: 1 #B8BDC4);}" + "QTableView::item {outline: 0px; border: 0px color:#FFFFFF;}" + "QTableView {border-top:1px solid #B8B8B8;border-bottom:none;border-left:1px solid #B8B8B8;border-right:none;}" + "QTableView::item:selected {outline: 0px; border-bottom: 1px solid #D4D4D4;border-top: 1px solid #D4D4D4; padding-bottom:1px; background-color: #D4D4D4; }" + "QHeaderView::section:horizontal {background-color:#F5F5F5; border-bottom:1px solid #B8BDC4; border-right:1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #D1D1D1, stop: 1 #B8BDC4); border-left:none; border-top:none; padding:4px; color:#313232;}" + "QHeaderView::section:vertical {border-bottom: 1px solid #DFDFDF;border-top: 1px solid #FEFEFE;}" + //"QTableView::item:hover {border-bottom: 1px solid #A3A3A3;border-top: 1px solid #A3A3A3; padding-bottom:1px; background-color: #A3A3A3; color: #FFFFFF; }" + + //scrollbar + + "QScrollBar:vertical { border: none; background: #404040; width: 3px; margin: 0; }" + "QScrollBar::handle:vertical { background: #DDDDDD; width: 7px; min-height: 20px; }" + "QScrollBar::add-line:vertical { border: none; background: #404040; height: 10px; subcontrol-position: bottom; subcontrol-origin: margin; margin: 0 3px 0 0;}" + + "QScrollBar::sub-line:vertical { border: none; background: #404040; height: 10px; subcontrol-position: top; subcontrol-origin: margin; margin: 0 3px 0 0;}" + "QScrollBar::up-arrow:vertical {border:none;width: 9px;height: 6px;background: url(':/images/folders_view/line-up.png') center top no-repeat;}" + "QScrollBar::down-arrow:vertical {border:none;width: 9px;height: 6px;background: url(':/images/folders_view/line-down.png') center top no-repeat;}" + + "QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {background: none; }" + ""; + + QLabel * label = new QLabel(tr("Please, select the right series for your comic.")); + label->setStyleSheet(labelStylesheet); + + QVBoxLayout * l = new QVBoxLayout; + QWidget * leftWidget = new QWidget; + QVBoxLayout * left = new QVBoxLayout; + QHBoxLayout * content = new QHBoxLayout; + + //widgets + cover = new QLabel(); + detailLabel = new QLabel(); + detailLabel->setStyleSheet(labelStylesheet); + tableVolumes = new QTableView(); + tableVolumes->setStyleSheet(tableStylesheet); + + left->addWidget(cover); + left->addWidget(detailLabel); + left->addStretch(); + leftWidget->setMaximumWidth(168); + leftWidget->setLayout(left); + + content->addWidget(leftWidget); + content->addWidget(tableVolumes); + + l->addSpacing(15); + l->addWidget(label); + l->addLayout(content); + l->addStretch(); + + l->setContentsMargins(0,0,0,0); + setLayout(l); + setContentsMargins(0,0,0,0); +} + + +SelectVolume::~SelectVolume() {} diff --git a/YACReaderLibrary/comic_vine/select_volume.h b/YACReaderLibrary/comic_vine/select_volume.h new file mode 100644 index 00000000..3c5d2d64 --- /dev/null +++ b/YACReaderLibrary/comic_vine/select_volume.h @@ -0,0 +1,23 @@ +#ifndef SELECT_VOLUME_H +#define SELECT_VOLUME_H + +#include + +class QLabel; +class QTableView; +class VolumesModel; + +class SelectVolume : public QWidget +{ + Q_OBJECT +public: + SelectVolume(QWidget * parent = 0); + virtual ~SelectVolume(); +private: + QLabel * cover; + QLabel * detailLabel; + QTableView * tableVolumes; + VolumesModel * model; +}; + +#endif // SELECT_VOLUME_H diff --git a/YACReaderLibrary/comic_vine/series_question.cpp b/YACReaderLibrary/comic_vine/series_question.cpp new file mode 100644 index 00000000..dc442798 --- /dev/null +++ b/YACReaderLibrary/comic_vine/series_question.cpp @@ -0,0 +1,41 @@ +#include "series_question.h" + +#include +#include +#include + + +SeriesQuestion::SeriesQuestion(QWidget * parent) + :QWidget(parent) +{ + QVBoxLayout * l = new QVBoxLayout; + + QLabel * questionLabel = new QLabel(tr("You are trying to get information for various comics at once, are they part of the same series?")); + questionLabel->setStyleSheet("QLabel {color:white; font-size:12px;font-family:Arial;}"); + yes = new QRadioButton(tr("yes")); + no = new QRadioButton(tr("no")); + + QString rbStyle = "QRadioButton {margin-left:27px; margin-top:5px; color:white;font-size:12px;font-family:Arial;}" + "QRadioButton::indicator {width:11px;height:11px;}" + "QRadioButton::indicator::unchecked {image : url(:/images/comic_vine/radioUnchecked.png);}" + "QRadioButton::indicator::checked {image : url(:/images/comic_vine/radioChecked.png);}"; + yes->setStyleSheet(rbStyle); + no->setStyleSheet(rbStyle); + + yes->setChecked(true); + + l->addSpacing(35); + l->addWidget(questionLabel); + l->addWidget(yes); + l->addWidget(no); + l->addStretch(); + + l->setContentsMargins(0,0,0,0); + setLayout(l); + setContentsMargins(0,0,0,0); +} + +bool SeriesQuestion::getYes() +{ + return yes->isChecked(); +} diff --git a/YACReaderLibrary/comic_vine/series_question.h b/YACReaderLibrary/comic_vine/series_question.h new file mode 100644 index 00000000..8f46f12e --- /dev/null +++ b/YACReaderLibrary/comic_vine/series_question.h @@ -0,0 +1,22 @@ +#ifndef SERIES_QUESTION_H +#define SERIES_QUESTION_H + +#include + +class QRadioButton; + +class SeriesQuestion : public QWidget +{ + Q_OBJECT + +public: + SeriesQuestion(QWidget * parent = 0); + bool getYes(); + +private: + QRadioButton * yes; + QRadioButton * no; +}; + + +#endif // SERIES_QUESTION_H diff --git a/YACReaderLibrary/comic_vine/title_header.cpp b/YACReaderLibrary/comic_vine/title_header.cpp new file mode 100644 index 00000000..cebc0d6f --- /dev/null +++ b/YACReaderLibrary/comic_vine/title_header.cpp @@ -0,0 +1,53 @@ +#include "title_header.h" + +#include +#include +#include + +TitleHeader::TitleHeader(QWidget * parent ) + :QWidget(parent) +{ + mainTitleLabel = new QLabel(); + subTitleLabel = new QLabel(); + + mainTitleLabel->setStyleSheet("QLabel {color:white; font-size:18px;font-family:Arial;}"); + subTitleLabel->setStyleSheet("QLabel {color:white; font-size:12px;font-family:Arial;}"); + + QHBoxLayout * titleLayout = new QHBoxLayout; + QVBoxLayout * titleLabelsLayout = new QVBoxLayout; + + titleLabelsLayout->addWidget(mainTitleLabel); + titleLabelsLayout->addWidget(subTitleLabel); + titleLabelsLayout->setSpacing(0); + + titleLayout->addLayout(titleLabelsLayout); + titleLayout->setContentsMargins(0,0,0,0); + + setLayout(titleLayout); + + setContentsMargins(0,0,0,0); + + setTitle(tr("SEARCH")); +} + +void TitleHeader::setTitle(const QString & title) +{ + mainTitleLabel->setText(title); +} + +void TitleHeader::setSubTitle(const QString & title) +{ + subTitleLabel->setText(title); +} + +void TitleHeader::showButtons(bool show) +{ + if(show) + { + + } + else + { + + } +} diff --git a/YACReaderLibrary/comic_vine/title_header.h b/YACReaderLibrary/comic_vine/title_header.h new file mode 100644 index 00000000..a4e62e98 --- /dev/null +++ b/YACReaderLibrary/comic_vine/title_header.h @@ -0,0 +1,22 @@ +#ifndef TITLE_HEADER_H +#define TITLE_HEADER_H + +#include + +class QLabel; + +class TitleHeader : public QWidget +{ + Q_OBJECT +public: + TitleHeader(QWidget * parent = 0); +public slots: + void setTitle(const QString & title); + void setSubTitle(const QString & title); + void showButtons(bool show); +private: + QLabel * mainTitleLabel; + QLabel * subTitleLabel; +}; + +#endif // TITLE_HEADER_H diff --git a/YACReaderLibrary/comic_vine_dialog.h b/YACReaderLibrary/comic_vine_dialog.h deleted file mode 100644 index 36af2ca8..00000000 --- a/YACReaderLibrary/comic_vine_dialog.h +++ /dev/null @@ -1,158 +0,0 @@ -#ifndef COMIC_VINE_DIALOG_H -#define COMIC_VINE_DIALOG_H - -#include -#include - -#include "comic_db.h" - -class QPushButton; -class QStackedWidget; -class QLabel; -class QRadioButton; -class ComicVineClient; - -class ScrapperLineEdit : public QLineEdit -{ - Q_OBJECT -public: - ScrapperLineEdit(const QString & title, QWidget * widget = 0); -protected: - void resizeEvent(QResizeEvent *); -private: - QLabel * titleLabel; -}; - -//---------------------------------------- -class TitleHeader : public QWidget -{ - Q_OBJECT -public: - TitleHeader(QWidget * parent = 0); -public slots: - void setTitle(const QString & title); - void setSubTitle(const QString & title); - void showButtons(bool show); -private: - QLabel * mainTitleLabel; - QLabel * subTitleLabel; -}; - -//---------------------------------------- -class SeriesQuestion : public QWidget -{ - Q_OBJECT -public: - SeriesQuestion(QWidget * parent = 0); - inline bool getYes(); -private: - QRadioButton * yes; - QRadioButton * no; -}; - -//---------------------------------------- -class SearchSingleComic : public QWidget -{ - Q_OBJECT -public: - SearchSingleComic(QWidget * parent = 0); -private: - ScrapperLineEdit * titleEdit; - ScrapperLineEdit * numberEdit; - ScrapperLineEdit * volumeEdit; -}; - -//--------------------------------------- -class SearchVolume : public QWidget -{ - Q_OBJECT -public: - SearchVolume(QWidget * parent = 0); -public slots: - QString getVolumeInfo() {return volumeEdit->text();} -private: - ScrapperLineEdit * volumeEdit; -}; - -//--------------------------------------- -class SelectComic : public QWidget -{ - Q_OBJECT -public: - SelectComic(QWidget * parent = 0); - virtual ~SelectComic(); -}; - -//--------------------------------------- -class SelectVolume : public QWidget -{ - Q_OBJECT -public: - SelectVolume(QWidget * parent = 0); - virtual ~SelectVolume(); -}; - -//---------------------------------------- -class ComicVineDialog : public QDialog -{ - Q_OBJECT -public: - explicit ComicVineDialog(QWidget *parent = 0); - QString databasePath; - QString basePath; - void setComics(const QList & comics); -signals: - -public slots: - void show(); -protected slots: - void goNext(); - void debugClientResults(const QString & string); - //show widget methods - void showSeriesQuestion(); - void showSearchSingleComic(); - void showSearchVolume(); - void showLoading(); - void search(); -private: - - enum ScrapperStatus - { - SingleComic, - Volume, - SingleComicInSeries - }; - - ScrapperStatus status; - - ComicVineClient * comicVineClient; - - int currentIndex; - - TitleHeader * titleHeader; - - QPushButton * skipButton; - QPushButton * backButton; - QPushButton * nextButton; - QPushButton * searchButton; - QPushButton * closeButton; - - //stacked widgets - QStackedWidget * content; - - QWidget * infoNotFound; - QWidget * singleComicBrowser; - - void doLayout(); - void doStackedWidgets(); - void doLoading(); - void doConnections(); - - QList comics; - - SeriesQuestion * seriesQuestion; - SearchSingleComic * searchSingleComic; - SearchVolume * searchVolume; -}; - -#endif // COMIC_VINE_DIALOG_H