Merged: First draft of better pic url error handling
Cherry-picked b9cb61abd05f83c67740aafa5e1e6939143547e4
This commit is contained in:
parent
bba8184d37
commit
42f1c6938f
1 changed files with 21 additions and 5 deletions
|
@ -176,7 +176,7 @@ void PictureLoader::processLoadQueue()
|
||||||
|
|
||||||
QString PictureLoader::getPicUrl(CardInfo *card)
|
QString PictureLoader::getPicUrl(CardInfo *card)
|
||||||
{
|
{
|
||||||
if (!picDownload) return 0;
|
if (!picDownload) return QString("");
|
||||||
|
|
||||||
CardSet *set = card->getPreferredSet();
|
CardSet *set = card->getPreferredSet();
|
||||||
QString picUrl = QString("");
|
QString picUrl = QString("");
|
||||||
|
@ -201,9 +201,22 @@ QString PictureLoader::getPicUrl(CardInfo *card)
|
||||||
// otherwise, fallback to the default url
|
// otherwise, fallback to the default url
|
||||||
picUrl = picDownloadHq ? settingsCache->getPicUrlHq() : settingsCache->getPicUrl();
|
picUrl = picDownloadHq ? settingsCache->getPicUrlHq() : settingsCache->getPicUrl();
|
||||||
picUrl.replace("!name!", QUrl::toPercentEncoding(card->getCorrectedName()));
|
picUrl.replace("!name!", QUrl::toPercentEncoding(card->getCorrectedName()));
|
||||||
picUrl.replace("!setcode!", QUrl::toPercentEncoding(set->getShortName()));
|
|
||||||
picUrl.replace("!setname!", QUrl::toPercentEncoding(set->getLongName()));
|
if (set) {
|
||||||
picUrl.replace("!cardid!", QUrl::toPercentEncoding(QString::number(card->getPreferredMuId())));
|
picUrl.replace("!setcode!", QUrl::toPercentEncoding(set->getShortName()));
|
||||||
|
picUrl.replace("!setname!", QUrl::toPercentEncoding(set->getLongName()));
|
||||||
|
}
|
||||||
|
int muid = card->getPreferredMuId();
|
||||||
|
if (muid)
|
||||||
|
picUrl.replace("!cardid!", QUrl::toPercentEncoding(QString::number(muid)));
|
||||||
|
|
||||||
|
if (picUrl.contains("!name!") ||
|
||||||
|
picUrl.contains("!setcode!") ||
|
||||||
|
picUrl.contains("!setname!") ||
|
||||||
|
picUrl.contains("!cardid!")) {
|
||||||
|
qDebug() << "Insufficient card data to download" << card->getName() << "Url:" << picUrl;
|
||||||
|
return QString("");
|
||||||
|
}
|
||||||
|
|
||||||
return picUrl;
|
return picUrl;
|
||||||
}
|
}
|
||||||
|
@ -220,8 +233,11 @@ void PictureLoader::startNextPicDownload()
|
||||||
|
|
||||||
cardBeingDownloaded = cardsToDownload.takeFirst();
|
cardBeingDownloaded = cardsToDownload.takeFirst();
|
||||||
|
|
||||||
// TODO: Do something useful when picUrl is 0 or empty, etc
|
|
||||||
QString picUrl = getPicUrl(cardBeingDownloaded.getCard());
|
QString picUrl = getPicUrl(cardBeingDownloaded.getCard());
|
||||||
|
if (picUrl.isEmpty()) {
|
||||||
|
qDebug() << "No url for" << cardBeingDownloaded.getCard()->getName();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QUrl url(picUrl);
|
QUrl url(picUrl);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue