First draft of better pic url error handling

This commit is contained in:
Daenyth 2014-06-29 23:00:58 -04:00
parent 4d6f46b06e
commit b9cb61abd0
2 changed files with 24 additions and 7 deletions

View file

@ -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);

View file

@ -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();
}