From 9d7a554ab353df0c2a03cbf6c08aec6500646253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Sun, 4 May 2025 17:26:05 +0200 Subject: [PATCH 01/11] Convert ScraperMode and ScraperStatus into enum class --- .../comic_vine/comic_vine_dialog.cpp | 74 +++++++++---------- .../comic_vine/comic_vine_dialog.h | 4 +- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp index 025b9b76..0e6e63d8 100644 --- a/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp +++ b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp @@ -130,12 +130,12 @@ void ComicVineDialog::goNext() if (content->currentWidget() == seriesQuestionWidget) { if (seriesQuestionWidget->getYes()) { QString volumeSearchString = comics[0].getParentFolderName(); - mode = Volume; + mode = ScraperMode::Volume; showSearchVolume(volumeSearchString); } else { - status = AutoSearching; - mode = SingleComicInList; + status = ScraperStatus::AutoSearching; + mode = ScraperMode::SingleComicInList; ComicDB comic = comics[currentIndex]; QString title = comic.getTitleOrFileName(); titleHeader->setSubTitle(tr("comic %1 of %2 - %3").arg(currentIndex + 1).arg(comics.length()).arg(title)); @@ -179,27 +179,27 @@ void ComicVineDialog::goBack() clearState(); switch (status) { - case SelectingSeries: - if (mode == Volume) + case ScraperStatus::SelectingSeries: + if (mode == ScraperMode::Volume) showSearchVolume(); else showSearchSingleComic(); break; - case SortingComics: + case ScraperStatus::SortingComics: showSelectVolume(); break; - case SelectingComic: - if (mode == SingleComic) + case ScraperStatus::SelectingComic: + if (mode == ScraperMode::SingleComic) showSelectVolume(); break; - case AutoSearching: - if (mode == Volume) + case ScraperStatus::AutoSearching: + if (mode == ScraperMode::Volume) showSearchVolume(); else showSearchSingleComic(); break; default: - if (mode == Volume) + if (mode == ScraperMode::Volume) showSearchVolume(); else showSearchSingleComic(); @@ -248,8 +248,8 @@ void ComicVineDialog::show() searchVolumeWidget->clean(); if (comics.length() == 1) { - status = AutoSearching; - mode = SingleComic; + status = ScraperStatus::AutoSearching; + mode = ScraperMode::SingleComic; ComicDB singleComic = comics[0]; QString title = singleComic.getTitleOrFileName(); @@ -296,16 +296,16 @@ void ComicVineDialog::debugClientResults(const QString &string) goBack(); } else { switch (mode) { - case SingleComic: - case SingleComicInList: + case ScraperMode::SingleComic: + case ScraperMode::SingleComicInList: if (p.getNumResults() == 0) showSearchSingleComic(); - else if (status == SearchingVolume) + else if (status == ScraperStatus::SearchingVolume) showSelectVolume(string); else showSelectComic(string); break; - case Volume: + case ScraperMode::Volume: if (p.getNumResults() == 0) showSearchVolume(); else @@ -317,7 +317,7 @@ void ComicVineDialog::debugClientResults(const QString &string) void ComicVineDialog::showSeriesQuestion() { - status = AskingForInfo; + status = ScraperStatus::AskingForInfo; content->setCurrentWidget(seriesQuestionWidget); backButton->setHidden(true); skipButton->setHidden(true); @@ -332,7 +332,7 @@ void ComicVineDialog::showSeriesQuestion() void ComicVineDialog::showSearchSingleComic() { - status = AskingForInfo; + status = ScraperStatus::AskingForInfo; content->setCurrentWidget(searchSingleComicWidget); backButton->setHidden(true); skipButton->setHidden(true); @@ -349,7 +349,7 @@ void ComicVineDialog::showSearchVolume(const QString &volume) { searchVolumeWidget->setVolumeInfo(volume); - status = AskingForInfo; + status = ScraperStatus::AskingForInfo; content->setCurrentWidget(searchVolumeWidget); backButton->setHidden(true); nextButton->setHidden(true); @@ -369,7 +369,7 @@ void ComicVineDialog::showSelectVolume(const QString &json) void ComicVineDialog::showSelectVolume() { - status = SelectingSeries; + status = ScraperStatus::SelectingSeries; content->setCurrentWidget(selectVolumeWidget); @@ -385,7 +385,7 @@ void ComicVineDialog::showSelectVolume() void ComicVineDialog::showSelectComic(const QString &json) { - status = SelectingComic; + status = ScraperStatus::SelectingComic; content->setCurrentWidget(selectComicWidget); selectComicWidget->load(json, currentVolumeId); @@ -402,7 +402,7 @@ void ComicVineDialog::showSelectComic(const QString &json) void ComicVineDialog::showSortVolumeComics(const QString &json) { - status = SortingComics; + status = ScraperStatus::SortingComics; content->setCurrentWidget(sortVolumeComicsWidget); @@ -423,22 +423,22 @@ void ComicVineDialog::queryTimeOut() QMessageBox::warning(this, "Comic Vine error", "Time out connecting to Comic Vine"); switch (status) { - case AutoSearching: - if (mode == Volume) + case ScraperStatus::AutoSearching: + if (mode == ScraperMode::Volume) showSearchVolume(); else showSearchSingleComic(); break; - case SearchingVolume: - if (mode == Volume) + case ScraperStatus::SearchingVolume: + if (mode == ScraperMode::Volume) showSearchVolume(); else showSearchSingleComic(); break; - case SearchingSingleComic: + case ScraperStatus::SearchingSingleComic: showSearchSingleComic(); break; - case GettingVolumeComics: + case ScraperStatus::GettingVolumeComics: showSelectVolume(); break; default: @@ -481,7 +481,7 @@ void ComicVineDialog::getComicInfo(const QString &comicId, int count, const QStr QByteArray result = comicVineClient->getComicDetail(comicId, error, timeout); // TODO check timeOut or Connection error if (error || timeout) { // TODO - if (mode == SingleComic || currentIndex == (comics.count() - 1)) { + if (mode == ScraperMode::SingleComic || currentIndex == (comics.count() - 1)) { emit accepted(); } else { goToNextComic(); @@ -504,7 +504,7 @@ void ComicVineDialog::getComicInfo(const QString &comicId, int count, const QStr } QSqlDatabase::removeDatabase(connectionName); - if (mode == SingleComic || currentIndex == (comics.count() - 1)) { + if (mode == ScraperMode::SingleComic || currentIndex == (comics.count() - 1)) { emit accepted(); } else { goToNextComic(); @@ -513,7 +513,7 @@ void ComicVineDialog::getComicInfo(const QString &comicId, int count, const QStr void ComicVineDialog::toggleSkipButton() { - if (mode == SingleComicInList) + if (mode == ScraperMode::SingleComicInList) skipButton->setVisible(true); else skipButton->setHidden(true); @@ -521,7 +521,7 @@ void ComicVineDialog::toggleSkipButton() void ComicVineDialog::goToNextComic() { - if (mode == SingleComic || currentIndex == (comics.count() - 1)) { + if (mode == ScraperMode::SingleComic || currentIndex == (comics.count() - 1)) { emit accepted(); return; } @@ -559,7 +559,7 @@ void ComicVineDialog::setLoadingMessage(const QString &message) void ComicVineDialog::search() { switch (mode) { - case Volume: + case ScraperMode::Volume: launchSearchVolume(); break; default: @@ -580,17 +580,17 @@ void ComicVineDialog::searchVolume(const QString &v, int page) connect(comicVineClient, &ComicVineClient::finished, comicVineClient, &QObject::deleteLater); comicVineClient->search(v, page); - status = SearchingVolume; + status = ScraperStatus::SearchingVolume; } void ComicVineDialog::getVolumeComicsInfo(const QString &vID, int /* page */) { showLoading(tr("Retrieving volume info...")); - status = GettingVolumeComics; + status = ScraperStatus::GettingVolumeComics; auto comicVineClient = new ComicVineClient; - if (mode == Volume) + if (mode == ScraperMode::Volume) connect(comicVineClient, &ComicVineClient::volumeComicsInfo, this, &ComicVineDialog::showSortVolumeComics); else connect(comicVineClient, &ComicVineClient::volumeComicsInfo, this, &ComicVineDialog::showSelectComic); diff --git a/YACReaderLibrary/comic_vine/comic_vine_dialog.h b/YACReaderLibrary/comic_vine/comic_vine_dialog.h index fa686150..02cb1182 100644 --- a/YACReaderLibrary/comic_vine/comic_vine_dialog.h +++ b/YACReaderLibrary/comic_vine/comic_vine_dialog.h @@ -66,13 +66,13 @@ private: void toggleSkipButton(); - enum ScraperMode { + enum class ScraperMode { SingleComic, // the scraper has been opened for a single comic Volume, // the scraper is trying to get comics info for a whole volume SingleComicInList // the scraper has been opened for a list of unrelated comics }; - enum ScraperStatus { + enum class ScraperStatus { AutoSearching, AskingForInfo, SelectingComic, From 1b4116db1af127fed6970b7a8c6289a4bc03dc13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Sun, 4 May 2025 17:33:39 +0200 Subject: [PATCH 02/11] Remove default cases from switches using enum class --- .../comic_vine/comic_vine_dialog.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp index 0e6e63d8..15282ed0 100644 --- a/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp +++ b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp @@ -198,7 +198,11 @@ void ComicVineDialog::goBack() else showSearchSingleComic(); break; - default: + + case ScraperStatus::AskingForInfo: + case ScraperStatus::SearchingSingleComic: + case ScraperStatus::SearchingVolume: + case ScraperStatus::GettingVolumeComics: if (mode == ScraperMode::Volume) showSearchVolume(); else @@ -441,7 +445,11 @@ void ComicVineDialog::queryTimeOut() case ScraperStatus::GettingVolumeComics: showSelectVolume(); break; - default: + + case ScraperStatus::AskingForInfo: + case ScraperStatus::SelectingComic: + case ScraperStatus::SelectingSeries: + case ScraperStatus::SortingComics: break; } } @@ -562,7 +570,9 @@ void ComicVineDialog::search() case ScraperMode::Volume: launchSearchVolume(); break; - default: + + case ScraperMode::SingleComic: + case ScraperMode::SingleComicInList: launchSearchComic(); break; } From fca1e2004e782f1091f375454e37258eb13e807f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Sun, 4 May 2025 17:46:50 +0200 Subject: [PATCH 03/11] Add new ScraperStatus for exact volume searches --- YACReaderLibrary/comic_vine/comic_vine_dialog.cpp | 2 ++ YACReaderLibrary/comic_vine/comic_vine_dialog.h | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp index 15282ed0..32a14470 100644 --- a/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp +++ b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp @@ -202,6 +202,7 @@ void ComicVineDialog::goBack() case ScraperStatus::AskingForInfo: case ScraperStatus::SearchingSingleComic: case ScraperStatus::SearchingVolume: + case ScraperStatus::SearchingExactVolume: case ScraperStatus::GettingVolumeComics: if (mode == ScraperMode::Volume) showSearchVolume(); @@ -434,6 +435,7 @@ void ComicVineDialog::queryTimeOut() showSearchSingleComic(); break; case ScraperStatus::SearchingVolume: + case ScraperStatus::SearchingExactVolume: if (mode == ScraperMode::Volume) showSearchVolume(); else diff --git a/YACReaderLibrary/comic_vine/comic_vine_dialog.h b/YACReaderLibrary/comic_vine/comic_vine_dialog.h index 02cb1182..0ba3ccb7 100644 --- a/YACReaderLibrary/comic_vine/comic_vine_dialog.h +++ b/YACReaderLibrary/comic_vine/comic_vine_dialog.h @@ -73,12 +73,13 @@ private: }; enum class ScraperStatus { - AutoSearching, - AskingForInfo, + AutoSearching, // Searching for volumes maching a single comic + AskingForInfo, // The dialog is showing some UI to ask the user for some info SelectingComic, SelectingSeries, SearchingSingleComic, SearchingVolume, + SearchingExactVolume, SortingComics, GettingVolumeComics }; From 51590aaa4f740833da4b3ca77cb5efc65815aedc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Sun, 4 May 2025 18:12:37 +0200 Subject: [PATCH 04/11] Rename method --- YACReaderLibrary/comic_vine/comic_vine_dialog.cpp | 2 +- YACReaderLibrary/comic_vine/comic_vine_dialog.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp index 32a14470..2d6f4e77 100644 --- a/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp +++ b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp @@ -291,7 +291,7 @@ void ComicVineDialog::doLoading() content->addWidget(w); } -void ComicVineDialog::debugClientResults(const QString &string) +void ComicVineDialog::processClientResults(const QString &string) { ResponseParser p; p.loadJSONResponse(string); diff --git a/YACReaderLibrary/comic_vine/comic_vine_dialog.h b/YACReaderLibrary/comic_vine/comic_vine_dialog.h index 0ba3ccb7..1afb4181 100644 --- a/YACReaderLibrary/comic_vine/comic_vine_dialog.h +++ b/YACReaderLibrary/comic_vine/comic_vine_dialog.h @@ -42,7 +42,7 @@ public slots: protected slots: void goNext(); void goBack(); - void debugClientResults(const QString &string); + void processClientResults(const QString &string); // show widget methods void showSeriesQuestion(); void showSearchSingleComic(); From e7652355dea3c5d6f347cbabe8855a8d1796a573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Sun, 4 May 2025 18:13:33 +0200 Subject: [PATCH 05/11] Fix status check --- YACReaderLibrary/comic_vine/comic_vine_dialog.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp index 2d6f4e77..6e2f727f 100644 --- a/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp +++ b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp @@ -305,7 +305,7 @@ void ComicVineDialog::processClientResults(const QString &string) case ScraperMode::SingleComicInList: if (p.getNumResults() == 0) showSearchSingleComic(); - else if (status == ScraperStatus::SearchingVolume) + else if (status == ScraperStatus::SearchingVolume || status == ScraperStatus::SearchingExactVolume) showSelectVolume(string); else showSelectComic(string); @@ -587,7 +587,7 @@ void ComicVineDialog::searchVolume(const QString &v, int page) currentVolumeSearchString = v; auto comicVineClient = new ComicVineClient; - connect(comicVineClient, &ComicVineClient::searchResult, this, &ComicVineDialog::debugClientResults); + 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); From e5f02bebe5754c0845c7ba5309f4a051cab44daa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Sun, 4 May 2025 21:50:36 +0200 Subject: [PATCH 06/11] Try to always get some description for single volume issues If the issue doesn't have a description it will get the volume description. --- YACReaderLibrary/comic_vine/comic_vine.pri | 1 + .../comic_vine/comic_vine_dialog.cpp | 27 +++++++------- .../comic_vine/comic_vine_dialog.h | 5 ++- .../comic_vine/comic_vine_json_parser.cpp | 13 +++++-- .../comic_vine/comic_vine_json_parser.h | 4 +- .../comic_vine/model/selected_volume_info.h | 13 +++++++ YACReaderLibrary/comic_vine/select_comic.cpp | 17 +++++++-- YACReaderLibrary/comic_vine/select_volume.cpp | 37 ++++++++++++------- YACReaderLibrary/comic_vine/select_volume.h | 6 +-- 9 files changed, 83 insertions(+), 40 deletions(-) create mode 100644 YACReaderLibrary/comic_vine/model/selected_volume_info.h diff --git a/YACReaderLibrary/comic_vine/comic_vine.pri b/YACReaderLibrary/comic_vine/comic_vine.pri index 1c84f938..3ac1410b 100644 --- a/YACReaderLibrary/comic_vine/comic_vine.pri +++ b/YACReaderLibrary/comic_vine/comic_vine.pri @@ -1,6 +1,7 @@ HEADERS += \ $$PWD/comic_vine_json_parser.h \ + $$PWD/model/selected_volume_info.h \ comic_vine/comic_vine_dialog.h \ comic_vine/comic_vine_client.h \ comic_vine/scraper_lineedit.h \ diff --git a/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp index 6e2f727f..32e7d301 100644 --- a/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp +++ b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp @@ -22,6 +22,7 @@ #include "search_volume.h" #include "select_comic.h" #include "select_volume.h" +#include "selected_volume_info.h" #include "sort_volume_comics.h" #include "db_helper.h" #include "response_parser.h" @@ -144,7 +145,7 @@ void ComicVineDialog::goNext() searchVolume(title); } } else if (content->currentWidget() == selectVolumeWidget) { - currentVolumeId = selectVolumeWidget->getSelectedVolumeId(); + currentVolumeId = selectVolumeWidget->getSelectedVolumeInfo().id; getVolumeComicsInfo(currentVolumeId); } else if (content->currentWidget() == sortVolumeComicsWidget) { @@ -152,24 +153,23 @@ void ComicVineDialog::goNext() // ComicDB-ComicVineID QList> matchingInfo = sortVolumeComicsWidget->getMatchingInfo(); - int count = selectVolumeWidget->getSelectedVolumeNumIssues(); - QString publisher = selectVolumeWidget->getSelectedVolumePublisher(); + auto volumeInfo = selectVolumeWidget->getSelectedVolumeInfo(); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - QtConcurrent::run(&ComicVineDialog::getComicsInfo, this, matchingInfo, count, publisher); + QtConcurrent::run(&ComicVineDialog::getComicsInfo, this, matchingInfo, volumeInfo); #else - QtConcurrent::run(this, &ComicVineDialog::getComicsInfo, matchingInfo, count, publisher); + QtConcurrent::run(this, &ComicVineDialog::getComicsInfo, matchingInfo, volumeInfo); #endif } else if (content->currentWidget() == selectComicWidget) { showLoading(); QString comicId = selectComicWidget->getSelectedComicId(); - int count = selectVolumeWidget->getSelectedVolumeNumIssues(); - QString publisher = selectVolumeWidget->getSelectedVolumePublisher(); + auto volumeInfo = selectVolumeWidget->getSelectedVolumeInfo(); + #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - QtConcurrent::run(&ComicVineDialog::getComicInfo, this, comicId, count, publisher); + QtConcurrent::run(&ComicVineDialog::getComicInfo, this, comicId, volumeInfo); #else - QtConcurrent::run(this, &ComicVineDialog::getComicInfo, comicId, count, publisher); + QtConcurrent::run(this, &ComicVineDialog::getComicInfo, comicId, volumeInfo); #endif } } @@ -300,6 +300,7 @@ void ComicVineDialog::processClientResults(const QString &string) QMessageBox::critical(0, tr("Error connecting to ComicVine"), p.errorDescription()); goBack(); } else { + switch (mode) { case ScraperMode::SingleComic: case ScraperMode::SingleComicInList: @@ -456,7 +457,7 @@ void ComicVineDialog::queryTimeOut() } } -void ComicVineDialog::getComicsInfo(QList> matchingInfo, int count, const QString &publisher) +void ComicVineDialog::getComicsInfo(QList> matchingInfo, const SelectedVolumeInfo &volumeInfo) { QPair p; QList comics; @@ -470,7 +471,7 @@ void ComicVineDialog::getComicsInfo(QList> matchingInfo, QByteArray result = comicVineClient->getComicDetail(p.second, error, timeout); // TODO check timeOut or Connection error if (error || timeout) continue; // TODO - ComicDB comic = YACReader::parseCVJSONComicInfo(p.first, result, count, publisher); // TODO check result error + ComicDB comic = YACReader::parseCVJSONComicInfo(p.first, result, volumeInfo); // TODO check result error comic.info.comicVineID = p.second; comics.push_back(comic); @@ -482,7 +483,7 @@ void ComicVineDialog::getComicsInfo(QList> matchingInfo, emit accepted(); } -void ComicVineDialog::getComicInfo(const QString &comicId, int count, const QString &publisher) +void ComicVineDialog::getComicInfo(const QString &comicId, const SelectedVolumeInfo &volumeInfo) { auto comicVineClient = new ComicVineClient; @@ -498,7 +499,7 @@ void ComicVineDialog::getComicInfo(const QString &comicId, int count, const QStr } } - ComicDB comic = YACReader::parseCVJSONComicInfo(comics[currentIndex], result, count, publisher); // TODO check result error + ComicDB comic = YACReader::parseCVJSONComicInfo(comics[currentIndex], result, volumeInfo); // TODO check result error comic.info.comicVineID = comicId; setLoadingMessage(tr("Retrieving tags for : %1").arg(comics[currentIndex].getFileName())); QString connectionName = ""; diff --git a/YACReaderLibrary/comic_vine/comic_vine_dialog.h b/YACReaderLibrary/comic_vine/comic_vine_dialog.h index 1afb4181..b0f71c79 100644 --- a/YACReaderLibrary/comic_vine/comic_vine_dialog.h +++ b/YACReaderLibrary/comic_vine/comic_vine_dialog.h @@ -17,6 +17,7 @@ class SearchSingleComic; class SearchVolume; class SelectComic; class SelectVolume; +struct SelectedVolumeInfo; class SortVolumeComics; // TODO this should use a QStateMachine @@ -31,8 +32,8 @@ public: void setComics(const QList &comics); QSize sizeHint() const override; QSize minimumSizeHint() const override; - void getComicsInfo(QList> matchingInfo, int count, const QString &publisher); - void getComicInfo(const QString &comicId, int count, const QString &publisher); + void getComicsInfo(QList> matchingInfo, const SelectedVolumeInfo &volumeInfo); + void getComicInfo(const QString &comicId, const SelectedVolumeInfo &volumeInfo); void closeEvent(QCloseEvent *event) override; signals: diff --git a/YACReaderLibrary/comic_vine/comic_vine_json_parser.cpp b/YACReaderLibrary/comic_vine/comic_vine_json_parser.cpp index f6a03813..90ac8244 100644 --- a/YACReaderLibrary/comic_vine/comic_vine_json_parser.cpp +++ b/YACReaderLibrary/comic_vine/comic_vine_json_parser.cpp @@ -2,6 +2,7 @@ #include "comic_vine_json_parser.h" #include "comic_vine_client.h" +#include "selected_volume_info.h" #include #include @@ -12,7 +13,7 @@ QPair getFirstStoryArcIdAndName(const QVariant &json_story_arc QPair getArcNumberAndArcCount(const QString &storyArcId, const QString &comicId); QList getNamesFromList(const QVariant &json_list); -ComicDB YACReader::parseCVJSONComicInfo(ComicDB &comic, const QString &json, int count, const QString &publisher) +ComicDB YACReader::parseCVJSONComicInfo(ComicDB &comic, const QString &json, const SelectedVolumeInfo &volumeInfo) { QJsonParseError Err; @@ -61,8 +62,12 @@ ComicDB YACReader::parseCVJSONComicInfo(ComicDB &comic, const QString &json, int } } - if (result.contains("description") && !result.value("description").isNull()) { + if (result.contains("description") && !result.value("description").isNull() && !result.value("description").toString().trimmed().isEmpty()) { comic.info.synopsis = result.value("description"); + } else if (result.contains("deck") && !result.value("deck").isNull() && !result.value("deck").toString().trimmed().isEmpty()) { + comic.info.synopsis = result.value("deck"); + } else if (!volumeInfo.description.trimmed().isEmpty() && volumeInfo.numIssues < 2) { + comic.info.synopsis = volumeInfo.description.trimmed(); } if (result.contains("character_credits") && !result.value("character_credits").isNull()) { @@ -101,9 +106,9 @@ ComicDB YACReader::parseCVJSONComicInfo(ComicDB &comic, const QString &json, int comic.info.characters = getNamesFromList(result.value("character_credits")).join("\n"); } - comic.info.count = count; + comic.info.count = volumeInfo.numIssues; - comic.info.publisher = publisher; + comic.info.publisher = volumeInfo.publisher; comic.info.edited = true; } diff --git a/YACReaderLibrary/comic_vine/comic_vine_json_parser.h b/YACReaderLibrary/comic_vine/comic_vine_json_parser.h index 6b7bf4c1..8f395759 100644 --- a/YACReaderLibrary/comic_vine/comic_vine_json_parser.h +++ b/YACReaderLibrary/comic_vine/comic_vine_json_parser.h @@ -4,9 +4,11 @@ #include "comic_db.h" +struct SelectedVolumeInfo; + namespace YACReader { -ComicDB parseCVJSONComicInfo(ComicDB &comic, const QString &json, int count, const QString &publisher); +ComicDB parseCVJSONComicInfo(ComicDB &comic, const QString &json, const SelectedVolumeInfo &volumeInfo); } diff --git a/YACReaderLibrary/comic_vine/model/selected_volume_info.h b/YACReaderLibrary/comic_vine/model/selected_volume_info.h new file mode 100644 index 00000000..7bf76b40 --- /dev/null +++ b/YACReaderLibrary/comic_vine/model/selected_volume_info.h @@ -0,0 +1,13 @@ +#ifndef SELECTED_VOLUME_INFO_H +#define SELECTED_VOLUME_INFO_H + +#include + +struct SelectedVolumeInfo { + QString id; + int numIssues; + QString publisher; + QString description; +}; + +#endif // SELECTED_VOLUME_INFO_H diff --git a/YACReaderLibrary/comic_vine/select_comic.cpp b/YACReaderLibrary/comic_vine/select_comic.cpp index 68b568e6..c01cfb68 100644 --- a/YACReaderLibrary/comic_vine/select_comic.cpp +++ b/YACReaderLibrary/comic_vine/select_comic.cpp @@ -130,9 +130,20 @@ void SelectComic::setDescription(const QString &jsonDetail) return; } - QVariant descriptionValues = sc.value("results").toMap().value("description"); - bool valid = !descriptionValues.isNull() && descriptionValues.isValid(); - detailLabel->setText(valid ? descriptionValues.toString().replace("setText(description.replace("setText(deck.replace("setText(tr("comic description unavailable")); + } } QString SelectComic::getSelectedComicId() diff --git a/YACReaderLibrary/comic_vine/select_volume.cpp b/YACReaderLibrary/comic_vine/select_volume.cpp index d934d4fc..d466af29 100644 --- a/YACReaderLibrary/comic_vine/select_volume.cpp +++ b/YACReaderLibrary/comic_vine/select_volume.cpp @@ -24,6 +24,8 @@ #include "response_parser.h" #include "scraper_results_paginator.h" +#include "selected_volume_info.h" + SelectVolume::SelectVolume(QWidget *parent) : ScraperSelector(parent), model(0) { @@ -176,22 +178,29 @@ void SelectVolume::setDescription(const QString &jsonDetail) return; } - QVariant descriptionValues = sc.value("results").toMap().value("description"); - bool valid = !descriptionValues.isNull() && descriptionValues.isValid(); - detailLabel->setText(valid ? descriptionValues.toString().replace("setText(description.replace("setText(deck.replace("setText(tr("volume description unavailable")); + } } -QString SelectVolume::getSelectedVolumeId() +SelectedVolumeInfo SelectVolume::getSelectedVolumeInfo() { - return model->getVolumeId(proxyModel->mapToSource(tableVolumes->currentIndex())); -} + auto volumeId = model->getVolumeId(proxyModel->mapToSource(tableVolumes->currentIndex())); + auto numIssues = model->getNumIssues(proxyModel->mapToSource(tableVolumes->currentIndex())); + auto publisher = model->getPublisher(proxyModel->mapToSource(tableVolumes->currentIndex())); -int SelectVolume::getSelectedVolumeNumIssues() -{ - return model->getNumIssues(proxyModel->mapToSource(tableVolumes->currentIndex())); -} - -QString SelectVolume::getSelectedVolumePublisher() -{ - return model->getPublisher(proxyModel->mapToSource(tableVolumes->currentIndex())); + return { volumeId, numIssues, publisher, selectedVolumeDescription }; } diff --git a/YACReaderLibrary/comic_vine/select_volume.h b/YACReaderLibrary/comic_vine/select_volume.h index e6e00d00..81231f8e 100644 --- a/YACReaderLibrary/comic_vine/select_volume.h +++ b/YACReaderLibrary/comic_vine/select_volume.h @@ -2,6 +2,7 @@ #define SELECT_VOLUME_H #include "scraper_selector.h" +#include "selected_volume_info.h" class QLabel; class VolumesModel; @@ -26,9 +27,7 @@ public slots: void loadVolumeInfo(const QModelIndex &mi); void setCover(const QByteArray &); void setDescription(const QString &jsonDetail); - QString getSelectedVolumeId(); - int getSelectedVolumeNumIssues(); - QString getSelectedVolumePublisher(); + SelectedVolumeInfo getSelectedVolumeInfo(); private: QLabel *cover; @@ -37,6 +36,7 @@ private: VolumesModel *model; QSortFilterProxyModel *proxyModel; ScraperLineEdit *filterEdit; + QString selectedVolumeDescription; }; #endif // SELECT_VOLUME_H From 868de856a7ae2baf9a2ce7b84b574d24e41a016a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Mon, 5 May 2025 18:35:07 +0200 Subject: [PATCH 07/11] Add support for exact match searches It will be enabled by default. --- YACReaderLibrary/comic_vine/comic_vine.pri | 5 +- .../comic_vine/comic_vine_client.cpp | 20 ++++- .../comic_vine/comic_vine_client.h | 1 + .../comic_vine/comic_vine_dialog.cpp | 81 +++++++++++-------- .../comic_vine/comic_vine_dialog.h | 8 +- .../comic_vine/model/volume_search_query.h | 12 +++ .../comic_vine/scraper_checkbox.cpp | 27 +++++++ .../comic_vine/scraper_checkbox.h | 12 +++ .../comic_vine/scraper_selector.cpp | 25 ------ .../comic_vine/scraper_selector.h | 28 ------- .../comic_vine/search_single_comic.cpp | 14 +++- .../comic_vine/search_single_comic.h | 13 ++- YACReaderLibrary/comic_vine/search_volume.cpp | 6 ++ YACReaderLibrary/comic_vine/search_volume.h | 6 +- YACReaderLibrary/comic_vine/select_comic.cpp | 20 ++++- YACReaderLibrary/comic_vine/select_comic.h | 17 +++- YACReaderLibrary/comic_vine/select_volume.cpp | 20 ++++- YACReaderLibrary/comic_vine/select_volume.h | 18 ++++- .../comic_vine/sort_volume_comics.cpp | 18 ++++- .../comic_vine/sort_volume_comics.h | 18 +++-- images/comic_vine/checkBoxTick.svg | 14 ++++ 21 files changed, 265 insertions(+), 118 deletions(-) create mode 100644 YACReaderLibrary/comic_vine/model/volume_search_query.h create mode 100644 YACReaderLibrary/comic_vine/scraper_checkbox.cpp create mode 100644 YACReaderLibrary/comic_vine/scraper_checkbox.h delete mode 100644 YACReaderLibrary/comic_vine/scraper_selector.cpp delete mode 100644 YACReaderLibrary/comic_vine/scraper_selector.h create mode 100644 images/comic_vine/checkBoxTick.svg 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 From 73bde73fdbe63b8bcada5831ace4e4cce92f8397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Mon, 5 May 2025 18:35:44 +0200 Subject: [PATCH 08/11] Add some minimum width to the scraper table view columns --- YACReaderLibrary/comic_vine/scraper_tableview.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/YACReaderLibrary/comic_vine/scraper_tableview.cpp b/YACReaderLibrary/comic_vine/scraper_tableview.cpp index 08f23296..eec6da83 100644 --- a/YACReaderLibrary/comic_vine/scraper_tableview.cpp +++ b/YACReaderLibrary/comic_vine/scraper_tableview.cpp @@ -54,6 +54,8 @@ ScraperTableView::ScraperTableView(QWidget *parent) setAlternatingRowColors(true); + horizontalHeader()->setMinimumSectionSize(85); + verticalHeader()->hide(); setSelectionMode(QAbstractItemView::SingleSelection); From dfb1cb9b70fa2855dfe17e99769b029edf484a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Mon, 5 May 2025 18:36:17 +0200 Subject: [PATCH 09/11] Include missing image in qrc --- YACReaderLibrary/images.qrc | 1 + 1 file changed, 1 insertion(+) diff --git a/YACReaderLibrary/images.qrc b/YACReaderLibrary/images.qrc index 2685121c..8ae9df1c 100644 --- a/YACReaderLibrary/images.qrc +++ b/YACReaderLibrary/images.qrc @@ -10,6 +10,7 @@ ../images/comic_vine/rowDown.png ../images/comic_vine/rowUp.png ../images/comic_vine/upArrow.png + ../images/comic_vine/checkBoxTick.svg ../images/comics_view_toolbar/asignNumber.svg ../images/comics_view_toolbar/big_size_grid_zoom.svg ../images/comics_view_toolbar/editComic.svg From 6b1987a16af8cea886802e72e8c02dc076758f20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Mon, 5 May 2025 19:20:51 +0200 Subject: [PATCH 10/11] Use a better default search string from comic files --- .../comic_vine/comic_vine_dialog.cpp | 30 +++++++++++++++---- .../comic_vine/comic_vine_dialog.h | 2 +- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp index 468ff2f2..1faa0aae 100644 --- a/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp +++ b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp @@ -143,9 +143,7 @@ void ComicVineDialog::goNext() showLoading(tr("Looking for volume...")); - // TODO: option to handle exact matches? - // TODO: parse the file name to create better searches - searchVolume({ title, 1, true }); + searchVolume({ volumeSearchStringFromComic(comic), 1, true }); } } else if (content->currentWidget() == selectVolumeWidget) { currentVolumeId = selectVolumeWidget->getSelectedVolumeInfo().id; @@ -260,10 +258,11 @@ void ComicVineDialog::show() mode = ScraperMode::SingleComic; ComicDB singleComic = comics[0]; + QString title = singleComic.getTitleOrFileName(); titleHeader->setSubTitle(title); - showSearchSingleComic(singleComic.getParentFolderName()); + showSearchSingleComic(volumeSearchStringFromComic(singleComic)); } else if (comics.length() > 1) { titleHeader->setSubTitle(tr("%1 comics selected").arg(comics.length())); showSeriesQuestion(); @@ -533,6 +532,25 @@ void ComicVineDialog::toggleSkipButton() skipButton->setHidden(true); } +QString ComicVineDialog::volumeSearchStringFromComic(const ComicDB &comic) +{ + auto volume = comic.info.volume.toString().trimmed(); + if (!volume.isEmpty()) + return volume; + + auto series = comic.info.series.toString().trimmed(); + if (!series.isEmpty()) + return series; + + auto alternateSeries = comic.info.alternateSeries.toString().trimmed(); + if (!alternateSeries.isEmpty()) + return alternateSeries; + + // extract information from file name + auto parentFolderName = comic.getParentFolderName(); + return parentFolderName; +} + void ComicVineDialog::goToNextComic() { if (mode == ScraperMode::SingleComic || currentIndex == (comics.count() - 1)) { @@ -543,11 +561,11 @@ void ComicVineDialog::goToNextComic() currentIndex++; 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); + showSearchSingleComic(volumeSearchStringFromComic(comic)); } void ComicVineDialog::clearState() diff --git a/YACReaderLibrary/comic_vine/comic_vine_dialog.h b/YACReaderLibrary/comic_vine/comic_vine_dialog.h index 39bbc3c2..e6ccfc78 100644 --- a/YACReaderLibrary/comic_vine/comic_vine_dialog.h +++ b/YACReaderLibrary/comic_vine/comic_vine_dialog.h @@ -66,8 +66,8 @@ protected slots: private: void clearState(); - void toggleSkipButton(); + QString volumeSearchStringFromComic(const ComicDB &comic); enum class ScraperMode { SingleComic, // the scraper has been opened for a single comic From 879d3163911a1327364be1a9644d14acd5cfb8fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Mon, 5 May 2025 19:29:17 +0200 Subject: [PATCH 11/11] Update CHANGELOG --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c99c4d2..a67a2cc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ Version counting is based on semantic versioning (Major.Feature.Patch) * Fix setting the comic rating in the table view. * Log libraries validation when the app starts. * New toolbar on macos. +* New setting in Comic Vine scraper to force exact volume matches. +* Better default search query in the Comic Vine scraper. +* Improved navigation in Comic Vine scraper, including keeping the current query around to make edits and refined searches easier. ### YACReaderLibraryServer * Log libraries validation when the app starts.