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] 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