Merge pull request #271 from ctrlaltca/picurl_handling

Picurl handling
This commit is contained in:
Gavin Bisesi 2014-08-07 17:25:38 -04:00
commit e12d66df4f
2 changed files with 52 additions and 26 deletions

View file

@ -93,6 +93,14 @@ bool PictureToLoad::nextSet()
return true;
}
QString PictureToLoad::getSetName() const
{
if (setIndex < sortedSets.size())
return sortedSets[setIndex]->getCorrectedShortName();
else
return QString("");
}
PictureLoader::PictureLoader(const QString &__picsPath, bool _picDownload, bool _picDownloadHq, QObject *parent)
: QObject(parent),
_picsPath(__picsPath), picDownload(_picDownload), picDownloadHq(_picDownloadHq),
@ -127,9 +135,15 @@ void PictureLoader::processLoadQueue()
mutex.unlock();
//The list of paths to the folders in which to search for images
QList<QString> picsPaths = QList<QString>() << _picsPath + "/CUSTOM/" + ptl.getCard()->getCorrectedName() + ".full"
<< _picsPath + "/" + ptl.getSetName() + "/" + ptl.getCard()->getCorrectedName() + ".full"
<< _picsPath + "/downloadedPics/" + ptl.getSetName() + "/" + ptl.getCard()->getCorrectedName() + ".full";
QList<QString> picsPaths = QList<QString>() << _picsPath + "/CUSTOM/" + ptl.getCard()->getCorrectedName() + ".full";
QString setName=ptl.getSetName();
if(!setName.isEmpty())
{
picsPaths << _picsPath + "/" + setName + "/" + ptl.getCard()->getCorrectedName() + ".full"
<< _picsPath + "/downloadedPics/" + setName + "/" + ptl.getCard()->getCorrectedName() + ".full";
}
QImage image;
QImageReader imgReader;
@ -166,19 +180,24 @@ QString PictureLoader::getPicUrl(CardInfo *card)
CardSet *set = card->getPreferredSet();
QString picUrl = QString("");
// first check if Hq is enabled and a custom Hq card url exists in cards.xml
if(picDownloadHq)
// if sets have been defined for the card, they can contain custom picUrls
if(set)
{
picUrl = card->getCustomPicURLHq(set->getShortName());
// first check if Hq is enabled and a custom Hq card url exists in cards.xml
if(picDownloadHq)
{
picUrl = card->getCustomPicURLHq(set->getShortName());
if (!picUrl.isEmpty())
return picUrl;
}
// then, test for a custom, non-Hq card url in cards.xml
picUrl = card->getCustomPicURL(set->getShortName());
if (!picUrl.isEmpty())
return picUrl;
}
// then, test for a custom, non-Hq card url in cards.xml
picUrl = card->getCustomPicURL(set->getShortName());
if (!picUrl.isEmpty())
return picUrl;
// otherwise, fallback to the default url
picUrl = picDownloadHq ? settingsCache->getPicUrlHq() : settingsCache->getPicUrl();
picUrl.replace("!name!", QUrl::toPercentEncoding(card->getCorrectedName()));
@ -229,21 +248,25 @@ void PictureLoader::picDownloadFinished(QNetworkReply *reply)
extension = ".jpg";
if (imgReader.read(&testImage)) {
if (!QDir().mkpath(picsPath + "/downloadedPics/" + cardBeingDownloaded.getSetName())) {
qDebug() << picsPath + "/downloadedPics/" + cardBeingDownloaded.getSetName() + " could not be created.";
return;
QString setName = cardBeingDownloaded.getSetName();
if(!setName.isEmpty())
{
if (!QDir().mkpath(picsPath + "/downloadedPics/" + setName)) {
qDebug() << picsPath + "/downloadedPics/" + setName + " could not be created.";
return;
}
QString suffix;
if (!cardBeingDownloaded.getStripped())
suffix = ".full";
QFile newPic(picsPath + "/downloadedPics/" + setName + "/" + cardBeingDownloaded.getCard()->getCorrectedName() + suffix + extension);
if (!newPic.open(QIODevice::WriteOnly))
return;
newPic.write(picData);
newPic.close();
}
QString suffix;
if (!cardBeingDownloaded.getStripped())
suffix = ".full";
QFile newPic(picsPath + "/downloadedPics/" + cardBeingDownloaded.getSetName() + "/" + cardBeingDownloaded.getCard()->getCorrectedName() + suffix + extension);
if (!newPic.open(QIODevice::WriteOnly))
return;
newPic.write(picData);
newPic.close();
emit imageLoaded(cardBeingDownloaded.getCard(), testImage);
} else if (cardBeingDownloaded.getHq()) {
qDebug() << "HQ: received invalid picture. URL:" << reply->request().url();
@ -456,6 +479,8 @@ void CardInfo::updatePixmapCache()
CardSet* CardInfo::getPreferredSet()
{
if(sets.isEmpty())
return 0;
SetList sortedSets = sets;
sortedSets.sortByKey();
return sortedSets.first();
@ -463,7 +488,8 @@ CardSet* CardInfo::getPreferredSet()
int CardInfo::getPreferredMuId()
{
return muIds[getPreferredSet()->getShortName()];
CardSet *set = getPreferredSet();
return set ? muIds[set->getShortName()] : 0;
}
QString CardInfo::simplifyName(const QString &name) {

View file

@ -55,7 +55,7 @@ public:
PictureToLoad(CardInfo *_card = 0, bool _stripped = false, bool _hq = true);
CardInfo *getCard() const { return card; }
bool getStripped() const { return stripped; }
QString getSetName() const { return sortedSets[setIndex]->getCorrectedShortName(); }
QString getSetName() const;
bool nextSet();
bool getHq() const { return hq; }
void setHq(bool _hq) { hq = _hq; }