diff --git a/YACReaderLibrary/comic_vine/comic_vine.pri b/YACReaderLibrary/comic_vine/comic_vine.pri index 3ac1410b..97836023 100644 --- a/YACReaderLibrary/comic_vine/comic_vine.pri +++ b/YACReaderLibrary/comic_vine/comic_vine.pri @@ -2,6 +2,8 @@ HEADERS += \ $$PWD/comic_vine_json_parser.h \ $$PWD/model/selected_volume_info.h \ + $$PWD/model/volume_search_query.h \ + $$PWD/scraper_checkbox.h \ comic_vine/comic_vine_dialog.h \ comic_vine/comic_vine_client.h \ comic_vine/scraper_lineedit.h \ @@ -21,12 +23,12 @@ HEADERS += \ comic_vine/model/volume_comics_model.h \ comic_vine/scraper_scroll_label.h \ comic_vine/scraper_results_paginator.h \ - comic_vine/scraper_selector.h \ comic_vine/api_key_dialog.h \ $$PWD/comic_vine_all_volume_comics_retriever.h SOURCES += \ $$PWD/comic_vine_json_parser.cpp \ + $$PWD/scraper_checkbox.cpp \ comic_vine/comic_vine_dialog.cpp \ comic_vine/comic_vine_client.cpp \ comic_vine/scraper_lineedit.cpp \ @@ -46,6 +48,5 @@ SOURCES += \ comic_vine/model/volume_comics_model.cpp \ comic_vine/scraper_scroll_label.cpp \ comic_vine/scraper_results_paginator.cpp \ - comic_vine/scraper_selector.cpp \ comic_vine/api_key_dialog.cpp \ $$PWD/comic_vine_all_volume_comics_retriever.cpp diff --git a/YACReaderLibrary/comic_vine/comic_vine_client.cpp b/YACReaderLibrary/comic_vine/comic_vine_client.cpp index 10bae8fe..75e2dde9 100644 --- a/YACReaderLibrary/comic_vine/comic_vine_client.cpp +++ b/YACReaderLibrary/comic_vine/comic_vine_client.cpp @@ -18,6 +18,13 @@ static const QString CV_SEARCH = CV_WEB_ADDRESS + "/search/?api_key=" + CV_API_K "&query=%1&page=%2"; // 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,deck&query=superman +// look for exact match volumes +static const QString CV_EXACT_VOLUME_SEARCH = CV_WEB_ADDRESS + "/volumes/?api_key=" + CV_API_KEY + + "&format=json&limit=100" + "&field_list=name,start_year,publisher,id,image,count_of_issues,deck" + "&sort=name:asc" + "&filter=name:%1&offset=%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=json&field_list=name,start_year,publisher,image,count_of_issues,id,description"; @@ -69,6 +76,17 @@ void ComicVineClient::search(const QString &query, int page) connect(search, &QThread::finished, search, &QObject::deleteLater); search->get(); } + +// CV_EXACT_VOLUME_SEARCH +void ComicVineClient::searchExactVolume(const QString &query, int page) +{ + HttpWorker *search = new HttpWorker(QString(CV_EXACT_VOLUME_SEARCH).replace(CV_WEB_ADDRESS, baseURL).replace(CV_API_KEY, settings->value(COMIC_VINE_API_KEY, CV_API_KEY_DEFAULT).toString()).arg(query).arg((page - 1) * 100)); + connect(search, &HttpWorker::dataReady, this, &ComicVineClient::proccessVolumesSearchData); + connect(search, &HttpWorker::timeout, this, &ComicVineClient::timeOut); + connect(search, &QThread::finished, search, &QObject::deleteLater); + search->get(); +} + // CV_SEARCH result void ComicVineClient::proccessVolumesSearchData(const QByteArray &data) { @@ -120,7 +138,7 @@ void ComicVineClient::getSeriesCover(const QString &url) // CV_COMIC_IDS void ComicVineClient::getVolumeComicsInfo(const QString &idVolume, int page) { - HttpWorker *search = new HttpWorker(QString(CV_COMICS_INFO).replace(CV_WEB_ADDRESS, baseURL).replace(CV_API_KEY, settings->value(COMIC_VINE_API_KEY, CV_API_KEY_DEFAULT).toString()).arg(idVolume).arg((page - 1) * 100)); // page doesn't work for search, using offset instead + HttpWorker *search = new HttpWorker(QString(CV_COMICS_INFO).replace(CV_WEB_ADDRESS, baseURL).replace(CV_API_KEY, settings->value(COMIC_VINE_API_KEY, CV_API_KEY_DEFAULT).toString()).arg(idVolume).arg((page - 1) * 100)); connect(search, &HttpWorker::dataReady, this, &ComicVineClient::processVolumeComicsInfo); connect(search, &HttpWorker::timeout, this, &ComicVineClient::timeOut); // TODO connect(search, &QThread::finished, search, &QObject::deleteLater); diff --git a/YACReaderLibrary/comic_vine/comic_vine_client.h b/YACReaderLibrary/comic_vine/comic_vine_client.h index 6b36806e..43c4ba5b 100644 --- a/YACReaderLibrary/comic_vine/comic_vine_client.h +++ b/YACReaderLibrary/comic_vine/comic_vine_client.h @@ -24,6 +24,7 @@ signals: void finished(); public slots: void search(const QString &query, int page = 1); + void searchExactVolume(const QString &query, int page = 1); void getSeriesDetail(const QString &id); void getSeriesCover(const QString &url); void getVolumeComicsInfo(const QString &idVolume, int page = 1); diff --git a/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp index 32e7d301..468ff2f2 100644 --- a/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp +++ b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp @@ -94,7 +94,7 @@ void ComicVineDialog::doLayout() setLayout(mainLayout); - setWindowTitle("Comic Vine Scraper (beta)"); + setWindowTitle("Comic Vine Scraper"); } void ComicVineDialog::doStackedWidgets() @@ -116,9 +116,9 @@ void ComicVineDialog::doConnections() connect(searchButton, &QAbstractButton::clicked, this, &ComicVineDialog::search); connect(skipButton, &QAbstractButton::clicked, this, &ComicVineDialog::goToNextComic); - connect(selectVolumeWidget, &ScraperSelector::loadPage, this, &ComicVineDialog::searchVolume); - connect(selectComicWidget, &ScraperSelector::loadPage, this, &ComicVineDialog::getVolumeComicsInfo); - connect(sortVolumeComicsWidget, &ScraperSelector::loadPage, this, &ComicVineDialog::getVolumeComicsInfo); + connect(selectVolumeWidget, &SelectVolume::loadPage, this, &ComicVineDialog::searchVolume); + connect(selectComicWidget, &SelectComic::loadPage, this, &ComicVineDialog::getVolumeComicsInfo); + connect(sortVolumeComicsWidget, &SortVolumeComics::loadPage, this, &ComicVineDialog::getVolumeComicsInfo); connect(this, &QDialog::accepted, this, &QWidget::close, Qt::QueuedConnection); } @@ -142,7 +142,10 @@ void ComicVineDialog::goNext() titleHeader->setSubTitle(tr("comic %1 of %2 - %3").arg(currentIndex + 1).arg(comics.length()).arg(title)); showLoading(tr("Looking for volume...")); - searchVolume(title); + + // TODO: option to handle exact matches? + // TODO: parse the file name to create better searches + searchVolume({ title, 1, true }); } } else if (content->currentWidget() == selectVolumeWidget) { currentVolumeId = selectVolumeWidget->getSelectedVolumeInfo().id; @@ -181,9 +184,9 @@ void ComicVineDialog::goBack() switch (status) { case ScraperStatus::SelectingSeries: if (mode == ScraperMode::Volume) - showSearchVolume(); + showSearchVolume(currentVolumeSearchQuery.volume); else - showSearchSingleComic(); + showSearchSingleComic(currentVolumeSearchQuery.volume); break; case ScraperStatus::SortingComics: showSelectVolume(); @@ -194,9 +197,9 @@ void ComicVineDialog::goBack() break; case ScraperStatus::AutoSearching: if (mode == ScraperMode::Volume) - showSearchVolume(); + showSearchVolume(currentVolumeSearchQuery.volume); else - showSearchSingleComic(); + showSearchSingleComic(currentVolumeSearchQuery.volume); break; case ScraperStatus::AskingForInfo: @@ -205,9 +208,9 @@ void ComicVineDialog::goBack() case ScraperStatus::SearchingExactVolume: case ScraperStatus::GettingVolumeComics: if (mode == ScraperMode::Volume) - showSearchVolume(); + showSearchVolume(currentVolumeSearchQuery.volume); else - showSearchSingleComic(); + showSearchSingleComic(currentVolumeSearchQuery.volume); break; } } @@ -253,16 +256,14 @@ void ComicVineDialog::show() searchVolumeWidget->clean(); if (comics.length() == 1) { - status = ScraperStatus::AutoSearching; + status = ScraperStatus::AskingForInfo; mode = ScraperMode::SingleComic; ComicDB singleComic = comics[0]; QString title = singleComic.getTitleOrFileName(); titleHeader->setSubTitle(title); - showLoading(tr("Looking for volume...")); - searchVolume(singleComic.getParentFolderName()); - QLOG_TRACE() << singleComic.getParentFolderName(); + showSearchSingleComic(singleComic.getParentFolderName()); } else if (comics.length() > 1) { titleHeader->setSubTitle(tr("%1 comics selected").arg(comics.length())); showSeriesQuestion(); @@ -305,7 +306,7 @@ void ComicVineDialog::processClientResults(const QString &string) case ScraperMode::SingleComic: case ScraperMode::SingleComicInList: if (p.getNumResults() == 0) - showSearchSingleComic(); + showSearchSingleComic(currentVolumeSearchQuery.volume); else if (status == ScraperStatus::SearchingVolume || status == ScraperStatus::SearchingExactVolume) showSelectVolume(string); else @@ -313,7 +314,7 @@ void ComicVineDialog::processClientResults(const QString &string) break; case ScraperMode::Volume: if (p.getNumResults() == 0) - showSearchVolume(); + showSearchVolume(currentVolumeSearchQuery.volume); else showSelectVolume(string); break; @@ -336,8 +337,10 @@ void ComicVineDialog::showSeriesQuestion() toggleSkipButton(); } -void ComicVineDialog::showSearchSingleComic() +void ComicVineDialog::showSearchSingleComic(const QString &volume) { + searchSingleComicWidget->setVolumeInfo(volume); + status = ScraperStatus::AskingForInfo; content->setCurrentWidget(searchSingleComicWidget); backButton->setHidden(true); @@ -370,7 +373,7 @@ void ComicVineDialog::showSearchVolume(const QString &volume) void ComicVineDialog::showSelectVolume(const QString &json) { showSelectVolume(); - selectVolumeWidget->load(json, currentVolumeSearchString); + selectVolumeWidget->load(json, currentVolumeSearchQuery); } void ComicVineDialog::showSelectVolume() @@ -431,19 +434,19 @@ void ComicVineDialog::queryTimeOut() switch (status) { case ScraperStatus::AutoSearching: if (mode == ScraperMode::Volume) - showSearchVolume(); + showSearchVolume(currentVolumeSearchQuery.volume); else - showSearchSingleComic(); + showSearchSingleComic(currentVolumeSearchQuery.volume); break; case ScraperStatus::SearchingVolume: case ScraperStatus::SearchingExactVolume: if (mode == ScraperMode::Volume) - showSearchVolume(); + showSearchVolume(currentVolumeSearchQuery.volume); else - showSearchSingleComic(); + showSearchSingleComic(currentVolumeSearchQuery.volume); break; case ScraperStatus::SearchingSingleComic: - showSearchSingleComic(); + showSearchSingleComic(currentVolumeSearchQuery.volume); break; case ScraperStatus::GettingVolumeComics: showSelectVolume(); @@ -539,11 +542,12 @@ void ComicVineDialog::goToNextComic() currentIndex++; - showSearchSingleComic(); - ComicDB comic = comics[currentIndex]; QString title = comic.getTitleOrFileName(); titleHeader->setSubTitle(tr("comic %1 of %2 - %3").arg(currentIndex + 1).arg(comics.length()).arg(title)); + + // TODO: parse title + showSearchSingleComic(title); } void ComicVineDialog::clearState() @@ -581,19 +585,23 @@ void ComicVineDialog::search() } } -void ComicVineDialog::searchVolume(const QString &v, int page) +void ComicVineDialog::searchVolume(const VolumeSearchQuery &query) { showLoading(tr("Looking for volume...")); - currentVolumeSearchString = v; + currentVolumeSearchQuery = query; auto comicVineClient = new ComicVineClient; connect(comicVineClient, &ComicVineClient::searchResult, this, &ComicVineDialog::processClientResults); connect(comicVineClient, &ComicVineClient::timeOut, this, &ComicVineDialog::queryTimeOut); connect(comicVineClient, &ComicVineClient::finished, comicVineClient, &QObject::deleteLater); - comicVineClient->search(v, page); - - status = ScraperStatus::SearchingVolume; + if (query.exactMatch) { + status = ScraperStatus::SearchingExactVolume; + comicVineClient->searchExactVolume(query.volume, query.page); + } else { + status = ScraperStatus::SearchingVolume; + comicVineClient->search(query.volume, query.page); + } } void ComicVineDialog::getVolumeComicsInfo(const QString &vID, int /* page */) @@ -615,21 +623,28 @@ void ComicVineDialog::getVolumeComicsInfo(const QString &vID, int /* page */) comicVineClient->getAllVolumeComicsInfo(vID); } +// TODO: get the search configuration for exact match or not void ComicVineDialog::launchSearchVolume() { showLoading(tr("Looking for volume...")); // TODO: check if volume info is empty. - searchVolume(searchVolumeWidget->getVolumeInfo()); + + QString volumeInfo = searchVolumeWidget->getVolumeInfo(); + bool exactMatch = searchVolumeWidget->getExactMatch(); + + searchVolume({ volumeInfo, 1, exactMatch }); } +// TODO: get the search configuration for exact match or not void ComicVineDialog::launchSearchComic() { showLoading(tr("Looking for comic...")); QString volumeInfo = searchSingleComicWidget->getVolumeInfo(); + bool exactMatch = searchSingleComicWidget->getExactMatch(); // QString comicInfo = searchSingleComicWidget->getComicInfo(); // int comicNumber = searchSingleComicWidget->getComicNumber(); // if(comicInfo.isEmpty() && comicNumber == -1) - searchVolume(volumeInfo); + searchVolume({ volumeInfo, 1, exactMatch }); } diff --git a/YACReaderLibrary/comic_vine/comic_vine_dialog.h b/YACReaderLibrary/comic_vine/comic_vine_dialog.h index b0f71c79..39bbc3c2 100644 --- a/YACReaderLibrary/comic_vine/comic_vine_dialog.h +++ b/YACReaderLibrary/comic_vine/comic_vine_dialog.h @@ -4,6 +4,7 @@ #include #include "comic_db.h" +#include "volume_search_query.h" class QPushButton; class QStackedWidget; @@ -19,6 +20,7 @@ class SelectComic; class SelectVolume; struct SelectedVolumeInfo; class SortVolumeComics; +struct VolumeSearchQuery; // TODO this should use a QStateMachine //---------------------------------------- @@ -46,11 +48,11 @@ protected slots: void processClientResults(const QString &string); // show widget methods void showSeriesQuestion(); - void showSearchSingleComic(); + void showSearchSingleComic(const QString &volume = ""); void showSearchVolume(const QString &volume = ""); void showLoading(const QString &message = ""); void search(); - void searchVolume(const QString &v, int page = 1); + void searchVolume(const VolumeSearchQuery &query); void getVolumeComicsInfo(const QString &vID, int page = 1); void launchSearchVolume(); void launchSearchComic(); @@ -120,7 +122,7 @@ private: SelectComic *selectComicWidget; SortVolumeComics *sortVolumeComicsWidget; - QString currentVolumeSearchString; + VolumeSearchQuery currentVolumeSearchQuery; QString currentVolumeId; }; diff --git a/YACReaderLibrary/comic_vine/model/volume_search_query.h b/YACReaderLibrary/comic_vine/model/volume_search_query.h new file mode 100644 index 00000000..d93c7233 --- /dev/null +++ b/YACReaderLibrary/comic_vine/model/volume_search_query.h @@ -0,0 +1,12 @@ +#ifndef VOLUME_SEARCH_QUERY_H +#define VOLUME_SEARCH_QUERY_H + +#include + +struct VolumeSearchQuery { + QString volume; + int page; + bool exactMatch; +}; + +#endif // VOLUME_SEARCH_QUERY_H diff --git a/YACReaderLibrary/comic_vine/scraper_checkbox.cpp b/YACReaderLibrary/comic_vine/scraper_checkbox.cpp new file mode 100644 index 00000000..9a538121 --- /dev/null +++ b/YACReaderLibrary/comic_vine/scraper_checkbox.cpp @@ -0,0 +1,27 @@ +#include "scraper_checkbox.h" +#include "qwidget.h" + +ScraperCheckBox::ScraperCheckBox(const QString &text, QWidget *parent) + : QCheckBox(text, parent) +{ + setStyleSheet( + "QCheckBox {" + " color: white;" + " font-size: 12px;" + " font-family: Arial;" + " spacing: 10px;" + "}" + "QCheckBox::indicator {" + " width: 13px;" + " height: 13px;" + " border: 1px solid #242424;" + " background: #2e2e2e;" + "}" + "QCheckBox::indicator:checked {" + " image: url(:/images/comic_vine/checkBoxTick.svg);" + " background: #2e2e2e;" + "}" + "QCheckBox::indicator:unchecked {" + " background: #2e2e2e;" + "}"); +} diff --git a/YACReaderLibrary/comic_vine/scraper_checkbox.h b/YACReaderLibrary/comic_vine/scraper_checkbox.h new file mode 100644 index 00000000..ad684670 --- /dev/null +++ b/YACReaderLibrary/comic_vine/scraper_checkbox.h @@ -0,0 +1,12 @@ +#ifndef SCRAPER_CHECKBOX_H +#define SCRAPER_CHECKBOX_H + +#include + +class ScraperCheckBox : public QCheckBox +{ +public: + ScraperCheckBox(const QString &text, QWidget *parent = nullptr); +}; + +#endif // SCRAPER_CHECKBOX_H diff --git a/YACReaderLibrary/comic_vine/scraper_selector.cpp b/YACReaderLibrary/comic_vine/scraper_selector.cpp deleted file mode 100644 index 8e84a311..00000000 --- a/YACReaderLibrary/comic_vine/scraper_selector.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "scraper_selector.h" - -ScraperSelector::ScraperSelector(QWidget *parent) - : QWidget(parent) -{ - paginator = new ScraperResultsPaginator; - connect(paginator, &ScraperResultsPaginator::loadNextPage, this, &ScraperSelector::loadNextPage); - connect(paginator, &ScraperResultsPaginator::loadPreviousPage, this, &ScraperSelector::loadPreviousPage); -} - -void ScraperSelector::load(const QString &json, const QString &searchString) -{ - currentSearchString = searchString; - paginator->update(json); -} - -void ScraperSelector::loadNextPage() -{ - emit loadPage(currentSearchString, paginator->getCurrentPage() + 1); -} - -void ScraperSelector::loadPreviousPage() -{ - emit loadPage(currentSearchString, paginator->getCurrentPage() - 1); -} diff --git a/YACReaderLibrary/comic_vine/scraper_selector.h b/YACReaderLibrary/comic_vine/scraper_selector.h deleted file mode 100644 index 312dcb46..00000000 --- a/YACReaderLibrary/comic_vine/scraper_selector.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef SCRAPER_SELECTOR_H -#define SCRAPER_SELECTOR_H - -#include - -#include "scraper_results_paginator.h" - -class ScraperSelector : public QWidget -{ - Q_OBJECT -public: - explicit ScraperSelector(QWidget *parent = nullptr); - virtual void load(const QString &json, const QString &searchString); -public slots: - -signals: - void loadPage(QString, int); - -private slots: - void loadNextPage(); - void loadPreviousPage(); - -protected: - QString currentSearchString; - ScraperResultsPaginator *paginator; -}; - -#endif // SCRAPER_SELECTOR_H diff --git a/YACReaderLibrary/comic_vine/search_single_comic.cpp b/YACReaderLibrary/comic_vine/search_single_comic.cpp index de11a586..1d637990 100644 --- a/YACReaderLibrary/comic_vine/search_single_comic.cpp +++ b/YACReaderLibrary/comic_vine/search_single_comic.cpp @@ -11,12 +11,16 @@ SearchSingleComic::SearchSingleComic(QWidget *parent) { // QLabel * label = new QLabel(tr("Please provide some additional information. At least one field is needed.")); - QLabel *label = new QLabel(tr("Please provide some additional information.")); + QLabel *label = new QLabel(tr("Please provide some additional information for this comic.")); label->setStyleSheet("QLabel {color:white; font-size:12px;font-family:Arial;}"); // titleEdit = new ScraperLineEdit(tr("Title:")); // numberEdit = new ScraperLineEdit(tr("Number:")); volumeEdit = new ScraperLineEdit(tr("Series:")); + volumeEdit->setClearButtonEnabled(true); + + exactMatchCheckBox = new ScraperCheckBox(tr("Use exact match search. Disable if you want to find volumes that match some of the words in the name.")); + exactMatchCheckBox->setChecked(true); // numberEdit->setMaximumWidth(126); @@ -29,6 +33,7 @@ SearchSingleComic::SearchSingleComic(QWidget *parent) l->addWidget(label); // l->addLayout(hl); l->addWidget(volumeEdit); + l->addWidget(exactMatchCheckBox); l->addStretch(); l->setContentsMargins(0, 0, 0, 0); @@ -36,11 +41,16 @@ SearchSingleComic::SearchSingleComic(QWidget *parent) setContentsMargins(0, 0, 0, 0); } -QString SearchSingleComic::getVolumeInfo() +QString SearchSingleComic::getVolumeInfo() const { return volumeEdit->text(); } +void SearchSingleComic::setVolumeInfo(const QString &volume) +{ + volumeEdit->setText(volume); +} + QString SearchSingleComic::getComicInfo() { // return titleEdit->text(); diff --git a/YACReaderLibrary/comic_vine/search_single_comic.h b/YACReaderLibrary/comic_vine/search_single_comic.h index 58dfa44a..7a8d7c10 100644 --- a/YACReaderLibrary/comic_vine/search_single_comic.h +++ b/YACReaderLibrary/comic_vine/search_single_comic.h @@ -1,7 +1,9 @@ #ifndef SEARCH_SINGLE_COMIC_H #define SEARCH_SINGLE_COMIC_H -#include +#include + +#include "scraper_checkbox.h" class ScraperLineEdit; @@ -10,14 +12,17 @@ class SearchSingleComic : public QWidget Q_OBJECT public: SearchSingleComic(QWidget *parent = nullptr); - QString getVolumeInfo(); + QString getVolumeInfo() const; + bool getExactMatch() const { return exactMatchCheckBox->isChecked(); } + void setVolumeInfo(const QString &volume); QString getComicInfo(); int getComicNumber(); void clean(); private: - ScraperLineEdit *titleEdit; - ScraperLineEdit *numberEdit; + // ScraperLineEdit *titleEdit; + // ScraperLineEdit *numberEdit; ScraperLineEdit *volumeEdit; + ScraperCheckBox *exactMatchCheckBox; }; #endif // SEARCH_SINGLE_COMIC_H diff --git a/YACReaderLibrary/comic_vine/search_volume.cpp b/YACReaderLibrary/comic_vine/search_volume.cpp index 0e7fc11c..bace4425 100644 --- a/YACReaderLibrary/comic_vine/search_volume.cpp +++ b/YACReaderLibrary/comic_vine/search_volume.cpp @@ -1,6 +1,7 @@ #include "search_volume.h" #include "scraper_lineedit.h" +#include "scraper_checkbox.h" #include #include @@ -12,12 +13,17 @@ SearchVolume::SearchVolume(QWidget *parent) label->setStyleSheet("QLabel {color:white; font-size:12px;font-family:Arial;}"); volumeEdit = new ScraperLineEdit(tr("Series:")); + volumeEdit->setClearButtonEnabled(true); + + exactMatchCheckBox = new ScraperCheckBox(tr("Use exact match search. Disable if you want to find volumes that match some of the words in the name."), this); + exactMatchCheckBox->setChecked(true); QVBoxLayout *l = new QVBoxLayout; l->addSpacing(35); l->addWidget(label); l->addWidget(volumeEdit); + l->addWidget(exactMatchCheckBox); l->addStretch(); l->setContentsMargins(0, 0, 0, 0); diff --git a/YACReaderLibrary/comic_vine/search_volume.h b/YACReaderLibrary/comic_vine/search_volume.h index 6a9f1ee7..4ad8db80 100644 --- a/YACReaderLibrary/comic_vine/search_volume.h +++ b/YACReaderLibrary/comic_vine/search_volume.h @@ -1,9 +1,11 @@ #ifndef SEARCH_VOLUME_H #define SEARCH_VOLUME_H -#include +#include +#include "scraper_checkbox.h" class ScraperLineEdit; +class ScraperCheckBox; class SearchVolume : public QWidget { @@ -13,9 +15,11 @@ public: void clean(); void setVolumeInfo(const QString &volume); QString getVolumeInfo() const; + bool getExactMatch() const { return exactMatchCheckBox->isChecked(); } private: ScraperLineEdit *volumeEdit; + ScraperCheckBox *exactMatchCheckBox; }; #endif // SEARCH_VOLUME_H diff --git a/YACReaderLibrary/comic_vine/select_comic.cpp b/YACReaderLibrary/comic_vine/select_comic.cpp index c01cfb68..70b64359 100644 --- a/YACReaderLibrary/comic_vine/select_comic.cpp +++ b/YACReaderLibrary/comic_vine/select_comic.cpp @@ -11,7 +11,7 @@ #include SelectComic::SelectComic(QWidget *parent) - : ScraperSelector(parent), model(0) + : QWidget(parent), model(0) { QString labelStylesheet = "QLabel {color:white; font-size:12px;font-family:Arial;}"; @@ -35,6 +35,9 @@ SelectComic::SelectComic(QWidget *parent) // connections connect(tableComics, &QAbstractItemView::clicked, this, &SelectComic::loadComicInfo); + paginator = new ScraperResultsPaginator; + connect(paginator, &ScraperResultsPaginator::loadNextPage, this, &SelectComic::loadNextPage); + connect(paginator, &ScraperResultsPaginator::loadPreviousPage, this, &SelectComic::loadPreviousPage); paginator->setCustomLabel(tr("comics")); left->addWidget(cover); @@ -62,7 +65,7 @@ SelectComic::SelectComic(QWidget *parent) setContentsMargins(0, 0, 0, 0); } -void SelectComic::load(const QString &json, const QString &searchString) +void SelectComic::load(const QString &json, const QString &volumeId) { auto tempM = new VolumeComicsModel(); tempM->load(json); @@ -80,7 +83,18 @@ void SelectComic::load(const QString &json, const QString &searchString) tableComics->resizeColumnToContents(0); - ScraperSelector::load(json, searchString); + currentVolumeId = volumeId; + paginator->update(json); +} + +void SelectComic::loadNextPage() +{ + emit loadPage(currentVolumeId, paginator->getCurrentPage() + 1); +} + +void SelectComic::loadPreviousPage() +{ + emit loadPage(currentVolumeId, paginator->getCurrentPage() - 1); } SelectComic::~SelectComic() { } diff --git a/YACReaderLibrary/comic_vine/select_comic.h b/YACReaderLibrary/comic_vine/select_comic.h index 5a834378..427c3e29 100644 --- a/YACReaderLibrary/comic_vine/select_comic.h +++ b/YACReaderLibrary/comic_vine/select_comic.h @@ -1,7 +1,9 @@ #ifndef SELECT_COMIC_H #define SELECT_COMIC_H -#include "scraper_selector.h" +#include + +#include "scraper_results_paginator.h" class QLabel; class VolumeComicsModel; @@ -10,12 +12,12 @@ class QModelIndex; class ScraperScrollLabel; class ScraperTableView; -class SelectComic : public ScraperSelector +class SelectComic : public QWidget { Q_OBJECT public: SelectComic(QWidget *parent = nullptr); - void load(const QString &json, const QString &searchString) override; + void load(const QString &json, const QString &volumeId); virtual ~SelectComic(); public slots: @@ -24,11 +26,20 @@ public slots: void setDescription(const QString &jsonDetail); QString getSelectedComicId(); +signals: + void loadPage(QString, int); + +private slots: + void loadNextPage(); + void loadPreviousPage(); + private: QLabel *cover; ScraperScrollLabel *detailLabel; ScraperTableView *tableComics; VolumeComicsModel *model; + QString currentVolumeId; + ScraperResultsPaginator *paginator; }; #endif // SELECT_COMIC_H diff --git a/YACReaderLibrary/comic_vine/select_volume.cpp b/YACReaderLibrary/comic_vine/select_volume.cpp index d466af29..86bd49ac 100644 --- a/YACReaderLibrary/comic_vine/select_volume.cpp +++ b/YACReaderLibrary/comic_vine/select_volume.cpp @@ -27,7 +27,7 @@ #include "selected_volume_info.h" SelectVolume::SelectVolume(QWidget *parent) - : ScraperSelector(parent), model(0) + : QWidget(parent), model(0) { proxyModel = new QSortFilterProxyModel; proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); @@ -63,6 +63,9 @@ SelectVolume::SelectVolume(QWidget *parent) connect(tableVolumes->horizontalHeader(), qOverload(&QHeaderView::sortIndicatorChanged), tableVolumes, qOverload(&QTableView::sortByColumn)); connect(tableVolumes, &QAbstractItemView::clicked, this, &SelectVolume::loadVolumeInfo); + paginator = new ScraperResultsPaginator; + connect(paginator, &ScraperResultsPaginator::loadNextPage, this, &SelectVolume::loadNextPage); + connect(paginator, &ScraperResultsPaginator::loadPreviousPage, this, &SelectVolume::loadPreviousPage); paginator->setCustomLabel(tr("volumes")); top->addWidget(label); @@ -93,7 +96,7 @@ SelectVolume::SelectVolume(QWidget *parent) setContentsMargins(0, 0, 0, 0); } -void SelectVolume::load(const QString &json, const QString &searchString) +void SelectVolume::load(const QString &json, const VolumeSearchQuery &searchQuery) { auto tempM = new VolumesModel(); tempM->load(json); @@ -116,7 +119,18 @@ void SelectVolume::load(const QString &json, const QString &searchString) tableVolumes->setColumnWidth(0, 350); - ScraperSelector::load(json, searchString); + currentSearchQuery = searchQuery; + paginator->update(json); +} + +void SelectVolume::loadNextPage() +{ + emit loadPage({ currentSearchQuery.volume, paginator->getCurrentPage() + 1, currentSearchQuery.exactMatch }); +} + +void SelectVolume::loadPreviousPage() +{ + emit loadPage({ currentSearchQuery.volume, paginator->getCurrentPage() - 1, currentSearchQuery.exactMatch }); } void SelectVolume::clearFilter() diff --git a/YACReaderLibrary/comic_vine/select_volume.h b/YACReaderLibrary/comic_vine/select_volume.h index 81231f8e..944c833b 100644 --- a/YACReaderLibrary/comic_vine/select_volume.h +++ b/YACReaderLibrary/comic_vine/select_volume.h @@ -1,8 +1,11 @@ #ifndef SELECT_VOLUME_H #define SELECT_VOLUME_H -#include "scraper_selector.h" +#include + +#include "scraper_results_paginator.h" #include "selected_volume_info.h" +#include "volume_search_query.h" class QLabel; class VolumesModel; @@ -14,12 +17,12 @@ class ScraperScrollLabel; class ScraperTableView; class ScraperLineEdit; -class SelectVolume : public ScraperSelector +class SelectVolume : public QWidget { Q_OBJECT public: SelectVolume(QWidget *parent = nullptr); - void load(const QString &json, const QString &searchString) override; + void load(const QString &json, const VolumeSearchQuery &searchQuery); void clearFilter(); virtual ~SelectVolume(); @@ -29,6 +32,13 @@ public slots: void setDescription(const QString &jsonDetail); SelectedVolumeInfo getSelectedVolumeInfo(); +signals: + void loadPage(VolumeSearchQuery); + +private slots: + void loadNextPage(); + void loadPreviousPage(); + private: QLabel *cover; ScraperScrollLabel *detailLabel; @@ -37,6 +47,8 @@ private: QSortFilterProxyModel *proxyModel; ScraperLineEdit *filterEdit; QString selectedVolumeDescription; + VolumeSearchQuery currentSearchQuery; + ScraperResultsPaginator *paginator; }; #endif // SELECT_VOLUME_H diff --git a/YACReaderLibrary/comic_vine/sort_volume_comics.cpp b/YACReaderLibrary/comic_vine/sort_volume_comics.cpp index 3550de9b..fedd54a9 100644 --- a/YACReaderLibrary/comic_vine/sort_volume_comics.cpp +++ b/YACReaderLibrary/comic_vine/sort_volume_comics.cpp @@ -11,7 +11,7 @@ #include "volume_comics_model.h" SortVolumeComics::SortVolumeComics(QWidget *parent) - : ScraperSelector(parent) + : QWidget(parent) { QString labelStylesheet = "QLabel {color:white; font-size:12px;font-family:Arial;}"; @@ -55,6 +55,9 @@ SortVolumeComics::SortVolumeComics(QWidget *parent) // connect(tableVolumeComics, SIGNAL(pressed(QModelIndex)), tableFiles, SLOT(setCurrentIndex(QModelIndex))); // connect(tableFiles, SIGNAL(pressed(QModelIndex)), tableVolumeComics, SLOT(setCurrentIndex(QModelIndex))); + paginator = new ScraperResultsPaginator; + connect(paginator, &ScraperResultsPaginator::loadNextPage, this, &SortVolumeComics::loadNextPage); + connect(paginator, &ScraperResultsPaginator::loadPreviousPage, this, &SortVolumeComics::loadPreviousPage); paginator->setCustomLabel(tr("issues")); paginator->setMinimumWidth(422); @@ -119,7 +122,18 @@ void SortVolumeComics::setData(QList &comics, const QString &json, cons tableVolumeComics->resizeColumnToContents(0); - ScraperSelector::load(json, vID); + currentVolumeId = vID; + paginator->update(json); +} + +void SortVolumeComics::loadNextPage() +{ + emit loadPage(currentVolumeId, paginator->getCurrentPage() + 1); +} + +void SortVolumeComics::loadPreviousPage() +{ + emit loadPage(currentVolumeId, paginator->getCurrentPage() - 1); } void SortVolumeComics::synchronizeScroll(int pos) diff --git a/YACReaderLibrary/comic_vine/sort_volume_comics.h b/YACReaderLibrary/comic_vine/sort_volume_comics.h index bacadcb1..2a600341 100644 --- a/YACReaderLibrary/comic_vine/sort_volume_comics.h +++ b/YACReaderLibrary/comic_vine/sort_volume_comics.h @@ -1,13 +1,13 @@ #ifndef SORT_VOLUME_COMICS_H #define SORT_VOLUME_COMICS_H -#include "scraper_selector.h" - +#include #include #include #include #include "comic_db.h" +#include "scraper_results_paginator.h" class ScraperTableView; class LocalComicListModel; @@ -63,14 +63,12 @@ private: Appearance appearance; }; -class SortVolumeComics : public ScraperSelector +class SortVolumeComics : public QWidget { Q_OBJECT public: explicit SortVolumeComics(QWidget *parent = nullptr); -signals: - public slots: void setData(QList &comics, const QString &json, const QString &vID); QList> getMatchingInfo(); @@ -86,6 +84,13 @@ protected slots: void restoreAllComics(); void showRemovedComicsSelector(); +signals: + void loadPage(QString, int); + +private slots: + void loadNextPage(); + void loadPreviousPage(); + private: ScraperTableView *tableFiles; ScraperTableView *tableVolumeComics; @@ -97,6 +102,9 @@ private: ScrapperToolButton *moveDownButtonCL; ScrapperToolButton *moveUpButtonIL; ScrapperToolButton *moveDownButtonIL; + + QString currentVolumeId; + ScraperResultsPaginator *paginator; }; #endif // SORT_VOLUME_COMICS_H diff --git a/images/comic_vine/checkBoxTick.svg b/images/comic_vine/checkBoxTick.svg new file mode 100644 index 00000000..d6590f1b --- /dev/null +++ b/images/comic_vine/checkBoxTick.svg @@ -0,0 +1,14 @@ + + + + + + + \ No newline at end of file