From b9cb61abd05f83c67740aafa5e1e6939143547e4 Mon Sep 17 00:00:00 2001 From: Daenyth Date: Sun, 29 Jun 2014 23:00:58 -0400 Subject: [PATCH] First draft of better pic url error handling --- cockatrice/src/carddatabase.cpp | 27 ++++++++++++++++++++++----- cockatrice/src/carddatabasemodel.cpp | 4 ++-- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/cockatrice/src/carddatabase.cpp b/cockatrice/src/carddatabase.cpp index eff101f94..4ac4d3eb1 100644 --- a/cockatrice/src/carddatabase.cpp +++ b/cockatrice/src/carddatabase.cpp @@ -151,14 +151,28 @@ void PictureLoader::processLoadQueue() QString PictureLoader::getPicUrl(CardInfo *card) { - if (!picDownload) return 0; + if (!picDownload) return QString(""); QString picUrl = picDownloadHq ? settingsCache->getPicUrlHq() : settingsCache->getPicUrl(); + picUrl.replace("!name!", QUrl::toPercentEncoding(card->getCorrectedName())); + CardSet *set = card->getPreferredSet(); - 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(card->getPreferredMuId()))); + + 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; } @@ -175,8 +189,11 @@ 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(); + return; + } QUrl url(picUrl); diff --git a/cockatrice/src/carddatabasemodel.cpp b/cockatrice/src/carddatabasemodel.cpp index e62664be6..4dc8ec602 100644 --- a/cockatrice/src/carddatabasemodel.cpp +++ b/cockatrice/src/carddatabasemodel.cpp @@ -70,11 +70,11 @@ void CardDatabaseModel::updateCardList() { for (int i = 0; i < cardList.size(); ++i) disconnect(cardList[i], 0, this, 0); - + cardList = db->getCardList(); for (int i = 0; i < cardList.size(); ++i) connect(cardList[i], SIGNAL(cardInfoChanged(CardInfo *)), this, SLOT(cardInfoChanged(CardInfo *))); - + reset(); }