diff --git a/cockatrice/src/carddatabase.cpp b/cockatrice/src/carddatabase.cpp index 9e7b38dc..79a225ec 100644 --- a/cockatrice/src/carddatabase.cpp +++ b/cockatrice/src/carddatabase.cpp @@ -176,7 +176,7 @@ void PictureLoader::processLoadQueue() QString PictureLoader::getPicUrl(CardInfo *card) { - if (!picDownload) return 0; + if (!picDownload) return QString(""); CardSet *set = card->getPreferredSet(); QString picUrl = QString(""); @@ -201,9 +201,22 @@ QString PictureLoader::getPicUrl(CardInfo *card) // otherwise, fallback to the default url picUrl = picDownloadHq ? settingsCache->getPicUrlHq() : settingsCache->getPicUrl(); picUrl.replace("!name!", QUrl::toPercentEncoding(card->getCorrectedName())); - picUrl.replace("!setcode!", QUrl::toPercentEncoding(set->getShortName())); - picUrl.replace("!setname!", QUrl::toPercentEncoding(set->getLongName())); - picUrl.replace("!cardid!", QUrl::toPercentEncoding(QString::number(card->getPreferredMuId()))); + + if (set) { + 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; } @@ -220,8 +233,13 @@ void PictureLoader::startNextPicDownload() cardBeingDownloaded = cardsToDownload.takeFirst(); - // TODO: Do something useful when picUrl is 0 or empty, etc QString picUrl = getPicUrl(cardBeingDownloaded.getCard()); + if (picUrl.isEmpty()) { + qDebug() << "No url for" << cardBeingDownloaded.getCard()->getName(); + cardBeingDownloaded = 0; + downloadRunning = false; + return; + } QUrl url(picUrl);