From 93bc6919986dd85c0bea6051a7b11ab87e2c4011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Sat, 5 Oct 2013 23:37:20 +0200 Subject: [PATCH] comic vine search query working --- YACReaderLibrary/comic_vine_client.cpp | 22 ++++++++-------- YACReaderLibrary/comic_vine_client.h | 12 +++------ YACReaderLibrary/comic_vine_dialog.cpp | 36 +++++++++++++++++--------- YACReaderLibrary/comic_vine_dialog.h | 8 +++++- common/comic_db.cpp | 12 ++++++++- common/comic_db.h | 5 +++- 6 files changed, 60 insertions(+), 35 deletions(-) diff --git a/YACReaderLibrary/comic_vine_client.cpp b/YACReaderLibrary/comic_vine_client.cpp index 8d711c98..c7c1a0a8 100644 --- a/YACReaderLibrary/comic_vine_client.cpp +++ b/YACReaderLibrary/comic_vine_client.cpp @@ -4,13 +4,14 @@ //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"; +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" "&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 //gets the detail for a volume %1 static const QString CV_SERIES_DETAIL = CV_WEB_ADDRESS + "/volume/4050-%1/?api_key=" + CV_API_KEY + @@ -42,16 +43,22 @@ ComicVineClient::ComicVineClient(QObject *parent) : //CV_SEARCH void ComicVineClient::search(const QString & query, int page) { - CVSearch * search = new CVSearch(CV_SEARCH.arg(query).arg(page)); - connect(search,SIGNAL(dataReady(const QByteArry &)),this,SLOT(proccessVolumesSearchData(const QByteArry &))); + HttpWorker * search = new HttpWorker(CV_SEARCH.arg(query).arg(page)); + connect(search,SIGNAL(dataReady(const QByteArray &)),this,SLOT(proccessVolumesSearchData(const QByteArray &))); + connect(search,SIGNAL(timeout()),this,SLOT(queryTimeOut())); connect(search,SIGNAL(finished()),search,SLOT(deleteLater())); search->get(); } - //CV_SEARCH result void ComicVineClient::proccessVolumesSearchData(const QByteArray & data) { QString xml(data); + emit searchResult(xml); +} + +void ComicVineClient::queryTimeOut() +{ + } //CV_SERIES_DETAIL @@ -83,10 +90,3 @@ void ComicVineClient::getCoverURL(const QString & id) { } - -//CVSearch -CVSearch::CVSearch(const QString & URL) - :HttpWorker(URL) -{ - -} \ No newline at end of file diff --git a/YACReaderLibrary/comic_vine_client.h b/YACReaderLibrary/comic_vine_client.h index 41806317..4d2c91ad 100644 --- a/YACReaderLibrary/comic_vine_client.h +++ b/YACReaderLibrary/comic_vine_client.h @@ -12,7 +12,7 @@ public: explicit ComicVineClient(QObject *parent = 0); signals: - + void searchResult(QString); public slots: void search(const QString & query, int page = 0); void getSeriesDetail(const QString & id); @@ -20,15 +20,9 @@ public slots: void getComicId(const QString & id, int comicNumber); void getComicDetail(const QString & id); void getCoverURL(const QString & id); -private slots: +protected slots: void proccessVolumesSearchData(const QByteArray & data); + void queryTimeOut(); }; - -class CVSearch : public HttpWorker -{ -public: - CVSearch(const QString & URL); -}; - #endif // COMIC_VINE_CLIENT_H diff --git a/YACReaderLibrary/comic_vine_dialog.cpp b/YACReaderLibrary/comic_vine_dialog.cpp index 1fc7344a..fff73fdb 100644 --- a/YACReaderLibrary/comic_vine_dialog.cpp +++ b/YACReaderLibrary/comic_vine_dialog.cpp @@ -5,12 +5,13 @@ #include #include #include -#include +#include #include "yacreader_busy_widget.h" +#include "comic_vine_client.h" ComicVineDialog::ComicVineDialog(QWidget *parent) : - QDialog(parent) + QDialog(parent),comicVineClient(new ComicVineClient) { doLayout(); doStackedWidgets(); @@ -65,6 +66,8 @@ void ComicVineDialog::doConnections() { connect(closeButton,SIGNAL(pressed()),this,SLOT(close())); connect(nextButton,SIGNAL(pressed()),this,SLOT(goNext())); + + connect(comicVineClient,SIGNAL(searchResult(QString)),this,SLOT(debugClientResults(QString))); } void ComicVineDialog::goNext() @@ -78,9 +81,13 @@ void ComicVineDialog::goNext() } else { - //titleHeader->setSubtitle + ComicDB comic = comics[currentIndex]; + QString title = comic.getTitleOrPath(); + titleHeader->setSubTitle(tr("comic %1 of %2 - %3").arg(currentIndex+1).arg(comics.length()).arg(title)); content->setCurrentWidget(searchSingleComic); } + } + else if (content->currentWidget() == searchSingleComic) { } } @@ -92,19 +99,19 @@ void ComicVineDialog::setComics(const QList & comics) void ComicVineDialog::show() { + currentIndex = 0; + if(comics.length() == 1) { ComicDB singleComic = comics[0]; - - if(singleComic.info.title != 0) - titleHeader->setSubtitle(*singleComic.info.title); - else - titleHeader->setSubtitle(QFileInfo(singleComic.path).fileName()); - + QString title = singleComic.getTitleOrPath(); + titleHeader->setSubTitle(title); content->setCurrentWidget(searchSingleComic); + + comicVineClient->search(title); }else if(comics.length()>1) { - titleHeader->setSubtitle(tr("%1 comics selected").arg(comics.length())); + titleHeader->setSubTitle(tr("%1 comics selected").arg(comics.length())); content->setCurrentWidget(seriesQuestion); } QDialog::show(); @@ -127,6 +134,11 @@ void ComicVineDialog::doLoading() content->addWidget(w); } +void ComicVineDialog::debugClientResults(const QString & string) +{ + QMessageBox::information(0,"-Response-", string); +} + //--------------------------------------- //TitleHeader //--------------------------------------- @@ -161,7 +173,7 @@ void TitleHeader::setTitle(const QString & title) mainTitleLabel->setText(title); } -void TitleHeader::setSubtitle(const QString & title) +void TitleHeader::setSubTitle(const QString & title) { subTitleLabel->setText(title); } @@ -290,4 +302,4 @@ SearchVolume::SearchVolume(QWidget * parent) l->setContentsMargins(0,0,0,0); setLayout(l); setContentsMargins(0,0,0,0); -} \ No newline at end of file +} diff --git a/YACReaderLibrary/comic_vine_dialog.h b/YACReaderLibrary/comic_vine_dialog.h index 16460370..ab8a21ad 100644 --- a/YACReaderLibrary/comic_vine_dialog.h +++ b/YACReaderLibrary/comic_vine_dialog.h @@ -10,6 +10,7 @@ class QPushButton; class QStackedWidget; class QLabel; class QRadioButton; +class ComicVineClient; class ScrapperLineEdit : public QLineEdit { @@ -30,7 +31,7 @@ public: TitleHeader(QWidget * parent = 0); public slots: void setTitle(const QString & title); - void setSubtitle(const QString & title); + void setSubTitle(const QString & title); void showButtons(bool show); private: QLabel * mainTitleLabel; @@ -86,7 +87,12 @@ public slots: void show(); protected slots: void goNext(); + void debugClientResults(const QString & string); private: + ComicVineClient * comicVineClient; + + int currentIndex; + TitleHeader * titleHeader; QPushButton * nextButton; QPushButton * closeButton; diff --git a/common/comic_db.cpp b/common/comic_db.cpp index 4c985006..10e4dc22 100644 --- a/common/comic_db.cpp +++ b/common/comic_db.cpp @@ -1,6 +1,7 @@ #include "comic_db.h" #include +#include //----------------------------------------------------------------------------- //COMIC------------------------------------------------------------------------ @@ -106,6 +107,15 @@ QString ComicDB::toTXT() return txt; } + +QString ComicDB::getTitleOrPath() +{ + if(info.title && info.title->isEmpty()) + return *(info.title); + else + return QFileInfo(path).fileName(); +} + //----------------------------------------------------------------------------- //COMIC_INFO------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -618,4 +628,4 @@ QDataStream &operator>>(QDataStream & stream, ComicInfo & comicInfo) deserializeField(stream,comicInfo.characters); deserializeField(stream,comicInfo.notes); return stream; -} \ No newline at end of file +} diff --git a/common/comic_db.h b/common/comic_db.h index c5e521e1..7931258c 100644 --- a/common/comic_db.h +++ b/common/comic_db.h @@ -132,6 +132,9 @@ public: bool hasCover() {return _hasCover;}; + //returns comic title if it isn't null or empty, in other case returns fileName + QString getTitleOrPath(); + QString toTXT(); ComicInfo info; @@ -144,4 +147,4 @@ public: Q_DECLARE_METATYPE(ComicDB); -#endif \ No newline at end of file +#endif