From a18401c2fbada6272499a61af240ab796b4f00a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Mon, 9 Sep 2013 11:39:58 +0200 Subject: [PATCH] HttpWorker added, performs a http request in a background thread ComicVineDialog, work in progress... --- YACReader/YACReader.pri | 6 +- YACReaderLibrary/YACReaderLibrary.pro | 8 +- YACReaderLibrary/comic_vine_client.cpp | 79 +++++++++++++ YACReaderLibrary/comic_vine_client.h | 34 ++++++ YACReaderLibrary/comic_vine_dialog.cpp | 95 +++++++++++++++ YACReaderLibrary/comic_vine_dialog.h | 17 +++ YACReaderLibrary/images.qrc | 154 +++++++++++++------------ common/check_new_version.cpp | 73 +----------- common/check_new_version.h | 18 ++- common/http_worker.cpp | 47 ++++++++ common/http_worker.h | 29 +++++ images/comic_vine/radioChecked.png | Bin 0 -> 236 bytes images/comic_vine/radioUnchecked.png | Bin 0 -> 189 bytes 13 files changed, 400 insertions(+), 160 deletions(-) create mode 100644 YACReaderLibrary/comic_vine_client.cpp create mode 100644 YACReaderLibrary/comic_vine_client.h create mode 100644 common/http_worker.cpp create mode 100644 common/http_worker.h create mode 100644 images/comic_vine/radioChecked.png create mode 100644 images/comic_vine/radioUnchecked.png diff --git a/YACReader/YACReader.pri b/YACReader/YACReader.pri index 2b30df6b..95f78c38 100644 --- a/YACReader/YACReader.pri +++ b/YACReader/YACReader.pri @@ -59,7 +59,8 @@ HEADERS += $$PWD/comic.h \ $$PWD/../common/comic_db.h \ $$PWD/../common/folder.h \ $$PWD/../common/library_item.h \ - $$PWD/yacreader_local_client.h + $$PWD/yacreader_local_client.h \ + $$PWD/../common/http_worker.h SOURCES += $$PWD/comic.cpp \ $$PWD/configuration.cpp \ @@ -90,7 +91,8 @@ SOURCES += $$PWD/comic.cpp \ $$PWD/../common/comic_db.cpp \ $$PWD/../common/folder.cpp \ $$PWD/../common/library_item.cpp \ - $$PWD/yacreader_local_client.cpp + $$PWD/yacreader_local_client.cpp \ + $$PWD/../common/http_worker.cpp include($$PWD/../custom_widgets/custom_widgets_yacreader.pri) include($$PWD/../compressed_archive/wrapper.pri) diff --git a/YACReaderLibrary/YACReaderLibrary.pro b/YACReaderLibrary/YACReaderLibrary.pro index 7bb28134..de12152d 100644 --- a/YACReaderLibrary/YACReaderLibrary.pro +++ b/YACReaderLibrary/YACReaderLibrary.pro @@ -77,7 +77,9 @@ HEADERS += comic_flow.h \ yacreader_local_server.h \ yacreader_main_toolbar.h \ comics_remover.h \ - comic_vine_dialog.h + comic_vine_dialog.h \ + comic_vine_client.h \ + ../common/http_worker.h SOURCES += comic_flow.cpp \ create_library_dialog.cpp \ @@ -117,7 +119,9 @@ SOURCES += comic_flow.cpp \ yacreader_local_server.cpp \ yacreader_main_toolbar.cpp \ comics_remover.cpp \ - comic_vine_dialog.cpp + comic_vine_dialog.cpp \ + comic_vine_client.cpp \ + ../common/http_worker.cpp include(./server/server.pri) diff --git a/YACReaderLibrary/comic_vine_client.cpp b/YACReaderLibrary/comic_vine_client.cpp new file mode 100644 index 00000000..9054044a --- /dev/null +++ b/YACReaderLibrary/comic_vine_client.cpp @@ -0,0 +1,79 @@ +#include "comic_vine_client.h" + +//this is the API key used by YACReader to access Comic Vine +//please, do not use it in your own software, get one for free at Comic Vine +static const QString CV_API_KEY = "46680bebb358f1de690a5a365e15d325f9649f91"; + +static const QString CV_WEB_ADDRESS = "http://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" + "&field_list=name,start_year,publisher,id,image,count_of_issues" + "&query=%1&page=%2"; + +//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"; + +//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?? + +//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" + "&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"; + +//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"; + +//gets comics matching name %1 and number %2 +//http://comicvine.com/api/issues/?api_key=46680bebb358f1de690a5a365e15d325f9649f91&limit=20&filter=name:super,issue_number:15 + +ComicVineClient::ComicVineClient(QObject *parent) : + QObject(parent) +{ + +} + +void ComicVineClient::search(const QString & query, int page) +{ + CVSearch * search = new CVSearch(query,page); + connect(search,SIGNAL(dataReady(const QByteArry &)),this,SLOT(proccessVolumesSearchData(const QByteArry &))); + connect(search,SIGNAL(finished()),search,SLOT(deleteLater())); + search->get(); +} + +void ComicVineClient::proccessVolumesSearchData(const QByteArray & data) +{ + QString xml(data); +} + +void ComicVineClient::getSeriesDetail(const QString & id) +{ +} + +void ComicVineClient::getComicIds(const QString & id, int page) +{ +} + +void ComicVineClient::getComicId(const QString & id, int comicNumber) +{ +} + +void ComicVineClient::getComicDetail(const QString & id) +{ +} + +void ComicVineClient::getCoverURL(const QString & id) +{ +} + +//CVSearch +CVSearch::CVSearch(const QString & query, int page) + :HttpWorker(CV_SEARCH.arg(query).arg(page)) +{ +} \ No newline at end of file diff --git a/YACReaderLibrary/comic_vine_client.h b/YACReaderLibrary/comic_vine_client.h new file mode 100644 index 00000000..2f03b3af --- /dev/null +++ b/YACReaderLibrary/comic_vine_client.h @@ -0,0 +1,34 @@ +#ifndef COMIC_VINE_CLIENT_H +#define COMIC_VINE_CLIENT_H + +#include "http_worker.h" + +#include + +class ComicVineClient : public QObject +{ + Q_OBJECT +public: + explicit ComicVineClient(QObject *parent = 0); + +signals: + +public slots: + void search(const QString & query, int page = 0); + void getSeriesDetail(const QString & id); + void getComicIds(const QString & id, int page = 0); + void getComicId(const QString & id, int comicNumber); + void getComicDetail(const QString & id); + void getCoverURL(const QString & id); +private slots: + void proccessVolumesSearchData(const QByteArray & data); + +}; + +class CVSearch : public HttpWorker +{ +public: + CVSearch(const QString & query, int page=0); +}; + +#endif // COMIC_VINE_CLIENT_H diff --git a/YACReaderLibrary/comic_vine_dialog.cpp b/YACReaderLibrary/comic_vine_dialog.cpp index a824d7c1..00e9d4fe 100644 --- a/YACReaderLibrary/comic_vine_dialog.cpp +++ b/YACReaderLibrary/comic_vine_dialog.cpp @@ -1,10 +1,105 @@ #include "comic_vine_dialog.h" +#include +#include +#include +#include +#include +#include ComicVineDialog::ComicVineDialog(QWidget *parent) : QDialog(parent) +{ + doLayout(); + doStackedWidgets(); + doConnections(); +} + +void ComicVineDialog::doLayout() { setStyleSheet("" "QDialog {background-color: #404040; }" ""); + + QString dialogButtonsStyleSheet = "QPushButton {border: 1px solid #242424; background: #2e2e2e; color:white; padding: 5px 26px 5px 26px; font-size:12px;font-family:Arial; font-weight:bold;}"; + + QLabel * mainTitleLabel = new QLabel(tr("SEARCH")); + QLabel * subTitleLabel = new QLabel(tr("%1 comics selected")); + + mainTitleLabel->setStyleSheet("QLabel {color:white; font-size:18px;font-family:Arial;}"); + subTitleLabel->setStyleSheet("QLabel {color:white; font-size:12px;font-family:Arial;}"); + + nextButton = new QPushButton(tr("next")); + closeButton = new QPushButton(tr("close")); + + nextButton->setStyleSheet(dialogButtonsStyleSheet); + closeButton->setStyleSheet(dialogButtonsStyleSheet); + + content = new QStackedWidget(this); + // + + QVBoxLayout * mainLayout = new QVBoxLayout; + QHBoxLayout * titleLayout = new QHBoxLayout; + QVBoxLayout * titleLabelsLayout = new QVBoxLayout; + QHBoxLayout * buttonLayout = new QHBoxLayout; + + titleLabelsLayout->addWidget(mainTitleLabel); + titleLabelsLayout->addWidget(subTitleLabel); + titleLabelsLayout->setSpacing(0); + + titleLayout->addLayout(titleLabelsLayout); + + buttonLayout->addStretch(); + buttonLayout->addWidget(nextButton); + buttonLayout->addWidget(closeButton); + buttonLayout->setContentsMargins(0,0,0,0); + + mainLayout->addLayout(titleLayout); + mainLayout->addWidget(content); + mainLayout->addStretch(); + mainLayout->addLayout(buttonLayout); + + mainLayout->setContentsMargins(26,16,26,11); + + setLayout(mainLayout); setFixedSize(672,529); } + +void ComicVineDialog::doStackedWidgets() +{ + doSeriesQuestion(); +} +void ComicVineDialog::doSeriesQuestion() +{ + QWidget * w = new QWidget; + 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;}"); + QRadioButton * yes = new QRadioButton(tr("yes")); + QRadioButton * 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); + w->setLayout(l); + w->setContentsMargins(0,0,0,0); + content->addWidget(w); +} + +void ComicVineDialog::doConnections() +{ + connect(closeButton,SIGNAL(pressed()),this,SLOT(close())); +} \ No newline at end of file diff --git a/YACReaderLibrary/comic_vine_dialog.h b/YACReaderLibrary/comic_vine_dialog.h index 48208243..514c8d7e 100644 --- a/YACReaderLibrary/comic_vine_dialog.h +++ b/YACReaderLibrary/comic_vine_dialog.h @@ -3,6 +3,9 @@ #include +class QPushButton; +class QStackedWidget; + class ComicVineDialog : public QDialog { Q_OBJECT @@ -12,7 +15,21 @@ public: signals: public slots: + +private: + QPushButton * nextButton; + QPushButton * closeButton; + + //stacked widgets + QStackedWidget * content; + + QWidget * infoNotFound; + QWidget * singleComicBrowser; + void doLayout(); + void doStackedWidgets(); + void doSeriesQuestion(); + void doConnections(); }; #endif // COMIC_VINE_DIALOG_H diff --git a/YACReaderLibrary/images.qrc b/YACReaderLibrary/images.qrc index 5fe13260..ef3a5807 100644 --- a/YACReaderLibrary/images.qrc +++ b/YACReaderLibrary/images.qrc @@ -1,65 +1,65 @@ - - ../images/folder.png - ../images/icon.png - ../images/iconLibrary.png - ../images/new.png - ../images/openLibrary.png - ../images/removeLibraryIcon.png - ../images/updateLibraryIcon.png - ../images/comicFolder.png - ../images/notCover.png - ../images/edit.png - ../images/editIcon.png - ../images/flow1.png - ../images/flow2.png - ../images/flow3.png - ../images/flow4.png - ../images/flow5.png - ../images/importLibrary.png - ../images/importLibraryIcon.png - ../images/exportLibrary.png - ../images/exportLibraryIcon.png - ../images/open.png - ../images/coversPackage.png - ../images/setRead.png - - ../images/setUnread.png - - ../images/showMarks.png - ../images/editComic.png - ../images/selectAll.png - ../images/hideComicFlow.png - ../images/exportComicsInfo.png - ../images/importComicsInfo.png - ../images/exportComicsInfoIcon.png - ../images/importComicsInfoIcon.png - ../images/db.png - ../images/asignNumber.png - ../images/defaultCover.png - ../images/iphoneConfig.png - ../images/onStartFlowSelection.png - ../images/onStartFlowSelection_es.png - ../images/useNewFlowButton.png - ../images/useOldFlowButton.png - ../images/serverConfigBackground.png - ../images/noLibrariesIcon.png - ../images/noLibrariesLine.png - ../images/importingIcon.png - ../images/updatingIcon.png - ../images/importTopCoversDecoration.png - ../images/importBottomCoversDecoration.png - ../images/glowLine.png - ../images/clearSearch.png - ../images/iconSearch.png - ../images/readRibbon.png - ../images/readingRibbon.png - ../images/shownCovers.png - ../images/hiddenCovers.png - ../images/trash.png - ../images/setReadButton.png - ../images/openInYACReader.png - + ../images/setUnread.png + + ../images/showMarks.png + ../images/editComic.png + ../images/selectAll.png + ../images/hideComicFlow.png + ../images/exportComicsInfo.png + ../images/importComicsInfo.png + ../images/exportComicsInfoIcon.png + ../images/importComicsInfoIcon.png + ../images/db.png + ../images/asignNumber.png + ../images/defaultCover.png + ../images/iphoneConfig.png + ../images/onStartFlowSelection.png + ../images/onStartFlowSelection_es.png + ../images/useNewFlowButton.png + ../images/useOldFlowButton.png + ../images/serverConfigBackground.png + ../images/noLibrariesIcon.png + ../images/noLibrariesLine.png + ../images/importingIcon.png + ../images/updatingIcon.png + ../images/importTopCoversDecoration.png + ../images/importBottomCoversDecoration.png + ../images/glowLine.png + ../images/clearSearch.png + ../images/iconSearch.png + ../images/readRibbon.png + ../images/readingRibbon.png + ../images/shownCovers.png + ../images/hiddenCovers.png + ../images/trash.png + ../images/setReadButton.png + ../images/openInYACReader.png + - ../images/main_toolbar/divider.png - ../images/collapsed_branch_osx.png - ../images/expanded_branch_osx.png - ../images/folder_macosx.png - ../images/libraryIconSelected.png - ../images/libraryOptions.png - ../images/branch-open.png - ../images/branch-closed.png - ../images/expanded_branch_selected.png - ../images/collapsed_branch_selected.png - ../images/previousCoverPage.png - ../images/nextCoverPage.png - ../images/getInfo.png - - + ../images/main_toolbar/divider.png + ../images/collapsed_branch_osx.png + ../images/expanded_branch_osx.png + ../images/folder_macosx.png + ../images/libraryIconSelected.png + ../images/libraryOptions.png + ../images/branch-open.png + ../images/branch-closed.png + ../images/expanded_branch_selected.png + ../images/collapsed_branch_selected.png + ../images/previousCoverPage.png + ../images/nextCoverPage.png + ../images/getInfo.png + ../images/comic_vine/radioChecked.png + ../images/comic_vine/radioUnchecked.png + + diff --git a/common/check_new_version.cpp b/common/check_new_version.cpp index 86fb3b76..9bbb981b 100644 --- a/common/check_new_version.cpp +++ b/common/check_new_version.cpp @@ -13,80 +13,15 @@ #define PREVIOUS_VERSION "6.0.0" HttpVersionChecker::HttpVersionChecker() - :QThread() + :HttpWorker("https://bitbucket.org/luisangelsm/yacreader/wiki/Home") { - http = new QHttp(this); - - connect(http, SIGNAL(requestFinished(int, bool)), - this, SLOT(httpRequestFinished(int, bool))); - - connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)), - this, SLOT(readResponseHeader(const QHttpResponseHeader &))); - - connect(http, SIGNAL(readyRead(const QHttpResponseHeader &)), - this, SLOT(read(const QHttpResponseHeader &))); + connect(this,SIGNAL(dataReady(const QByteArray &)),this,SLOT(checkNewVersion(const QByteArray &))); } -void HttpVersionChecker::get() +void HttpVersionChecker::checkNewVersion(const QByteArray & data) { - this->start(); - + checkNewVersion(QString(data)); } - -void HttpVersionChecker::run() -{ - QNetworkAccessManager manager; - QEventLoop q; - QTimer tT; - - tT.setSingleShot(true); - connect(&tT, SIGNAL(timeout()), &q, SLOT(quit())); - connect(&manager, SIGNAL(finished(QNetworkReply*)),&q, SLOT(quit())); - QNetworkReply *reply = manager.get(QNetworkRequest( - QUrl("https://bitbucket.org/luisangelsm/yacreader/wiki/Home"))); - - tT.start(5000); // 5s timeout - q.exec(); - - if(tT.isActive()){ - // download complete - checkNewVersion(reply->readAll()); - tT.stop(); - } else { - // timeout - } - - /*QUrl url("http://code.google.com/p/yacreader/downloads/list"); - QHttp::ConnectionMode mode = QHttp::ConnectionModeHttp; - http->setHost(url.host(), mode, url.port() == -1 ? 0 : url.port()); - QByteArray path = QUrl::toPercentEncoding(url.path(), "!$&'()*+,;=:@/"); - if (path.isEmpty()) - path = "/"; - httpGetId = http->get(path, 0); - exec();*/ -} -void HttpVersionChecker::readResponseHeader(const QHttpResponseHeader &responseHeader) -{ - Q_UNUSED(responseHeader) -} - -void HttpVersionChecker::read(const QHttpResponseHeader &){ - content.append(http->readAll()); -} - -void HttpVersionChecker::httpRequestFinished(int requestId, bool error) -{ - Q_UNUSED(requestId) -#ifdef QT_DEBUG - QString response("YACReader-5.0.0 win32.exe"); -#else - QString response(content); -#endif - if(!error) - checkNewVersion(response); - exit(); -} - //TODO escribir prueba unitaria bool HttpVersionChecker::checkNewVersion(QString sourceContent) { diff --git a/common/check_new_version.h b/common/check_new_version.h index 341f2a6b..c8cb7f54 100644 --- a/common/check_new_version.h +++ b/common/check_new_version.h @@ -1,31 +1,27 @@ #ifndef __CHECKUPDATE_H #define __CHECKUPDATE_H +#include "http_worker.h" +#include "yacreader_global.h" + #include #include #include #include #include -#include "yacreader_global.h" - class HttpVersionChecker : public QThread + class HttpVersionChecker : public HttpWorker { Q_OBJECT public: HttpVersionChecker(); - bool thereIsNewVersion(); public slots: - void httpRequestFinished(int requestId, bool error); - void readResponseHeader(const QHttpResponseHeader &); - void read(const QHttpResponseHeader &); - void get(); + private: - void run(); - QHttp *http; - int httpGetId; - QByteArray content; bool found; + private slots: bool checkNewVersion(QString sourceContent); + void checkNewVersion(const QByteArray & data); signals: void newVersionDetected(); }; diff --git a/common/http_worker.cpp b/common/http_worker.cpp new file mode 100644 index 00000000..447bafe1 --- /dev/null +++ b/common/http_worker.cpp @@ -0,0 +1,47 @@ +#include "http_worker.h" +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#define PREVIOUS_VERSION "6.0.0" + +HttpWorker::HttpWorker(const QString & urlString) + :QThread(),url(urlString) +{ + +} + +void HttpWorker::get() +{ + this->start(); +} + +void HttpWorker::run() +{ + QNetworkAccessManager manager; + QEventLoop q; + QTimer tT; + + tT.setSingleShot(true); + connect(&tT, SIGNAL(timeout()), &q, SLOT(quit())); + connect(&manager, SIGNAL(finished(QNetworkReply*)),&q, SLOT(quit())); + QNetworkReply *reply = manager.get(QNetworkRequest(url)); + + tT.start(5000); // 5s timeout + q.exec(); + + if(tT.isActive()){ + // download complete + emit dataReady(reply->readAll()); + tT.stop(); + } else { + emit timeout(); + } +} \ No newline at end of file diff --git a/common/http_worker.h b/common/http_worker.h new file mode 100644 index 00000000..4ccc3785 --- /dev/null +++ b/common/http_worker.h @@ -0,0 +1,29 @@ +#ifndef __HTTP_WORKER_H +#define __HTTP_WORKER_H + +#include +#include +#include +#include +#include +#include +#include "yacreader_global.h" + + class HttpWorker : public QThread + { + Q_OBJECT + public: + HttpWorker(const QString & urlString); + public slots: + void get(); + private: + void run(); + QUrl url; + int httpGetId; + QByteArray content; + signals: + void dataReady(const QByteArray &); + void timeout(); + }; + +#endif diff --git a/images/comic_vine/radioChecked.png b/images/comic_vine/radioChecked.png new file mode 100644 index 0000000000000000000000000000000000000000..a6134f924de6a1dc1710d84cc4b5f168aad01258 GIT binary patch literal 236 zcmeAS@N?(olHy`uVBq!ia0vp^+#t-s1|(OmDOUqhk|nMYCBgY=CFO}lsSJ)O`AMk? zp1FzXsX?iUDV2pMQ*D5X`aE46Ln>}1r8G2Ee}Biyu(C?QEWx3H+u_cNB}=w29!YG` z%4yI#!s;L;C9zO#UAh7f)65CJHl?pboLyX4n*00tXY8x`sBsLo zkXl($ArZDFg7LYrVzz5oM{oZki4-9_J7JTG0}Hlo6I;jN(){DZL64{m2j)E!8=MM` g7)%msW?*DvSRHK{sNZls3g|KhPgg&ebxsLQ0Qe13)Bpeg literal 0 HcmV?d00001 diff --git a/images/comic_vine/radioUnchecked.png b/images/comic_vine/radioUnchecked.png new file mode 100644 index 0000000000000000000000000000000000000000..13c0a7bdf7d1c5a988313be4ee45e8b01f8f1f62 GIT binary patch literal 189 zcmeAS@N?(olHy`uVBq!ia0vp^+#t-s1|(OmDOUqhk|nMYCBgY=CFO}lsSJ)O`AMk? zp1FzXsX?iUDV2pMQ*D5X;yqm)Ln>}1r8G2Ee}Biyu(C?QEWx3H+u_cNB}=w29!YG` z%4yI#!s;L;C9zO#UAh7f(@c&T9XzjQUbxf2FJWLffx#oJrqN@oxI>q8XULrsEW8Cy jQU?SNdwB6Mu}Cnu8p&vLbnNp1TE*b$>gTe~DWM4fJ|;R~ literal 0 HcmV?d00001