mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
Try to always get some description for single volume issues
If the issue doesn't have a description it will get the volume description.
This commit is contained in:
parent
e7652355de
commit
e5f02bebe5
@ -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 \
|
||||
|
@ -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<QPair<ComicDB, QString>> 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<QPair<ComicDB, QString>> matchingInfo, int count, const QString &publisher)
|
||||
void ComicVineDialog::getComicsInfo(QList<QPair<ComicDB, QString>> matchingInfo, const SelectedVolumeInfo &volumeInfo)
|
||||
{
|
||||
QPair<ComicDB, QString> p;
|
||||
QList<ComicDB> comics;
|
||||
@ -470,7 +471,7 @@ void ComicVineDialog::getComicsInfo(QList<QPair<ComicDB, QString>> 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<QPair<ComicDB, QString>> 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 = "";
|
||||
|
@ -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<ComicDB> &comics);
|
||||
QSize sizeHint() const override;
|
||||
QSize minimumSizeHint() const override;
|
||||
void getComicsInfo(QList<QPair<ComicDB, QString>> matchingInfo, int count, const QString &publisher);
|
||||
void getComicInfo(const QString &comicId, int count, const QString &publisher);
|
||||
void getComicsInfo(QList<QPair<ComicDB, QString>> matchingInfo, const SelectedVolumeInfo &volumeInfo);
|
||||
void getComicInfo(const QString &comicId, const SelectedVolumeInfo &volumeInfo);
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
signals:
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "comic_vine_json_parser.h"
|
||||
|
||||
#include "comic_vine_client.h"
|
||||
#include "selected_volume_info.h"
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonParseError>
|
||||
@ -12,7 +13,7 @@ QPair<QString, QString> getFirstStoryArcIdAndName(const QVariant &json_story_arc
|
||||
QPair<QString, QString> getArcNumberAndArcCount(const QString &storyArcId, const QString &comicId);
|
||||
QList<QString> 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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
13
YACReaderLibrary/comic_vine/model/selected_volume_info.h
Normal file
13
YACReaderLibrary/comic_vine/model/selected_volume_info.h
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef SELECTED_VOLUME_INFO_H
|
||||
#define SELECTED_VOLUME_INFO_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
struct SelectedVolumeInfo {
|
||||
QString id;
|
||||
int numIssues;
|
||||
QString publisher;
|
||||
QString description;
|
||||
};
|
||||
|
||||
#endif // SELECTED_VOLUME_INFO_H
|
@ -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("<a", "<a style = 'color:#827A68; text-decoration:none;'") : tr("description unavailable"));
|
||||
auto resultMap = sc.value("results").toMap();
|
||||
QVariant descriptionValues = resultMap.value("description");
|
||||
auto description = descriptionValues.toString().trimmed();
|
||||
QVariant deckValues = resultMap.value("deck");
|
||||
auto deck = deckValues.toString().trimmed();
|
||||
bool valid = !descriptionValues.isNull() && descriptionValues.isValid() && !description.isEmpty();
|
||||
bool validDeck = !deckValues.isNull() && deckValues.isValid() && !deck.isEmpty();
|
||||
if (valid) {
|
||||
detailLabel->setText(description.replace("<a", "<a style = 'color:#827A68; text-decoration:none;'"));
|
||||
} else if (validDeck) {
|
||||
detailLabel->setText(deck.replace("<a", "<a style = 'color:#827A68; text-decoration:none;'"));
|
||||
} else {
|
||||
detailLabel->setText(tr("comic description unavailable"));
|
||||
}
|
||||
}
|
||||
|
||||
QString SelectComic::getSelectedComicId()
|
||||
|
@ -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("<a", "<a style = 'color:#827A68; text-decoration:none;'") : tr("description unavailable"));
|
||||
auto resultMap = sc.value("results").toMap();
|
||||
QVariant descriptionValues = resultMap.value("description");
|
||||
auto description = descriptionValues.toString().trimmed();
|
||||
QVariant deckValues = resultMap.value("deck");
|
||||
auto deck = deckValues.toString().trimmed();
|
||||
bool valid = !descriptionValues.isNull() && descriptionValues.isValid() && !description.isEmpty();
|
||||
bool validDeck = !deckValues.isNull() && deckValues.isValid() && !deck.isEmpty();
|
||||
if (valid) {
|
||||
selectedVolumeDescription = description;
|
||||
detailLabel->setText(description.replace("<a", "<a style = 'color:#827A68; text-decoration:none;'"));
|
||||
} else if (validDeck) {
|
||||
selectedVolumeDescription = deck;
|
||||
detailLabel->setText(deck.replace("<a", "<a style = 'color:#827A68; text-decoration:none;'"));
|
||||
} else {
|
||||
detailLabel->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 };
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user