mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-22 18:32:17 -07:00
Address pull request comments (nullptr checks and additional comments, mostly.)
This commit is contained in:
parent
7f48d4e676
commit
e70533a9bc
2 changed files with 57 additions and 57 deletions
|
|
@ -175,8 +175,8 @@ void PictureLoaderWorker::processLoadQueue()
|
||||||
QString cardName = cardBeingLoaded.getCard()->getName();
|
QString cardName = cardBeingLoaded.getCard()->getName();
|
||||||
QString correctedCardName = cardBeingLoaded.getCard()->getCorrectedName();
|
QString correctedCardName = cardBeingLoaded.getCard()->getCorrectedName();
|
||||||
|
|
||||||
//qDebug().nospace() << "PictureLoader: [card: " << cardName << " set: " << setName
|
qDebug().nospace() << "PictureLoader: [card: " << cardName << " set: " << setName
|
||||||
// << "]: Trying to load picture";
|
<< "]: Trying to load picture";
|
||||||
|
|
||||||
if (CardDatabaseManager::getInstance()->isUuidForPreferredPrinting(
|
if (CardDatabaseManager::getInstance()->isUuidForPreferredPrinting(
|
||||||
cardName, cardBeingLoaded.getCard()->getPixmapCacheKey())) {
|
cardName, cardBeingLoaded.getCard()->getPixmapCacheKey())) {
|
||||||
|
|
@ -185,8 +185,8 @@ void PictureLoaderWorker::processLoadQueue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//qDebug().nospace() << "PictureLoader: [card: " << cardName << " set: " << setName
|
qDebug().nospace() << "PictureLoader: [card: " << cardName << " set: " << setName
|
||||||
// << "]: No custom picture, trying to download";
|
<< "]: No custom picture, trying to download";
|
||||||
cardsToDownload.append(cardBeingLoaded);
|
cardsToDownload.append(cardBeingLoaded);
|
||||||
cardBeingLoaded.clear();
|
cardBeingLoaded.clear();
|
||||||
if (!downloadRunning) {
|
if (!downloadRunning) {
|
||||||
|
|
@ -228,22 +228,22 @@ bool PictureLoaderWorker::cardImageExistsOnDisk(QString &setName, QString &corre
|
||||||
for (const auto &_picsPath : picsPaths) {
|
for (const auto &_picsPath : picsPaths) {
|
||||||
imgReader.setFileName(_picsPath);
|
imgReader.setFileName(_picsPath);
|
||||||
if (imgReader.read(&image)) {
|
if (imgReader.read(&image)) {
|
||||||
//qDebug().nospace() << "PictureLoader: [card: " << correctedCardname << " set: " << setName
|
qDebug().nospace() << "PictureLoader: [card: " << correctedCardname << " set: " << setName
|
||||||
// << "]: Picture found on disk.";
|
<< "]: Picture found on disk.";
|
||||||
imageLoaded(cardBeingLoaded.getCard(), image);
|
imageLoaded(cardBeingLoaded.getCard(), image);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
imgReader.setFileName(_picsPath + ".full");
|
imgReader.setFileName(_picsPath + ".full");
|
||||||
if (imgReader.read(&image)) {
|
if (imgReader.read(&image)) {
|
||||||
//qDebug().nospace() << "PictureLoader: [card: " << correctedCardname << " set: " << setName
|
qDebug().nospace() << "PictureLoader: [card: " << correctedCardname << " set: " << setName
|
||||||
// << "]: Picture.full found on disk.";
|
<< "]: Picture.full found on disk.";
|
||||||
imageLoaded(cardBeingLoaded.getCard(), image);
|
imageLoaded(cardBeingLoaded.getCard(), image);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
imgReader.setFileName(_picsPath + ".xlhq");
|
imgReader.setFileName(_picsPath + ".xlhq");
|
||||||
if (imgReader.read(&image)) {
|
if (imgReader.read(&image)) {
|
||||||
//qDebug().nospace() << "PictureLoader: [card: " << correctedCardname << " set: " << setName
|
qDebug().nospace() << "PictureLoader: [card: " << correctedCardname << " set: " << setName
|
||||||
// << "]: Picture.xlhq found on disk.";
|
<< "]: Picture.xlhq found on disk.";
|
||||||
imageLoaded(cardBeingLoaded.getCard(), image);
|
imageLoaded(cardBeingLoaded.getCard(), image);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -259,8 +259,6 @@ static int parse(const QString &urlTemplate,
|
||||||
std::function<QString(const QString &)> getProperty,
|
std::function<QString(const QString &)> getProperty,
|
||||||
QMap<QString, QString> &transformMap)
|
QMap<QString, QString> &transformMap)
|
||||||
{
|
{
|
||||||
(void) cardName;
|
|
||||||
(void) setName;
|
|
||||||
static const QRegularExpression rxFillWith("^(.+)_fill_with_(.+)$");
|
static const QRegularExpression rxFillWith("^(.+)_fill_with_(.+)$");
|
||||||
static const QRegularExpression rxSubStr("^(.+)_substr_(\\d+)_(\\d+)$");
|
static const QRegularExpression rxSubStr("^(.+)_substr_(\\d+)_(\\d+)$");
|
||||||
|
|
||||||
|
|
@ -291,18 +289,18 @@ static int parse(const QString &urlTemplate,
|
||||||
}
|
}
|
||||||
QString propertyValue = getProperty(cardPropertyName);
|
QString propertyValue = getProperty(cardPropertyName);
|
||||||
if (propertyValue.isEmpty()) {
|
if (propertyValue.isEmpty()) {
|
||||||
//qDebug().nospace() << "PictureLoader: [card: " << cardName << " set: " << setName << "]: Requested "
|
qDebug().nospace() << "PictureLoader: [card: " << cardName << " set: " << setName << "]: Requested "
|
||||||
// << propType << "property (" << cardPropertyName << ") for Url template (" << urlTemplate
|
<< propType << "property (" << cardPropertyName << ") for Url template (" << urlTemplate
|
||||||
// << ") is not available";
|
<< ") is not available";
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
int propLength = propertyValue.length();
|
int propLength = propertyValue.length();
|
||||||
if (subStrLen > 0) {
|
if (subStrLen > 0) {
|
||||||
if (subStrPos + subStrLen > propLength) {
|
if (subStrPos + subStrLen > propLength) {
|
||||||
//qDebug().nospace() << "PictureLoader: [card: " << cardName << " set: " << setName << "]: Requested "
|
qDebug().nospace() << "PictureLoader: [card: " << cardName << " set: " << setName << "]: Requested "
|
||||||
// << propType << " property (" << cardPropertyName << ") for Url template ("
|
<< propType << " property (" << cardPropertyName << ") for Url template ("
|
||||||
// << urlTemplate << ") is smaller than substr specification (" << subStrPos
|
<< urlTemplate << ") is smaller than substr specification (" << subStrPos
|
||||||
// << " + " << subStrLen << " > " << propLength << ")";
|
<< " + " << subStrLen << " > " << propLength << ")";
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
propertyValue = propertyValue.mid(subStrPos, subStrLen);
|
propertyValue = propertyValue.mid(subStrPos, subStrLen);
|
||||||
|
|
@ -313,9 +311,9 @@ static int parse(const QString &urlTemplate,
|
||||||
if (!fillWith.isEmpty()) {
|
if (!fillWith.isEmpty()) {
|
||||||
int fillLength = fillWith.length();
|
int fillLength = fillWith.length();
|
||||||
if (fillLength < propLength) {
|
if (fillLength < propLength) {
|
||||||
//qDebug().nospace() << "PictureLoader: [card: " << cardName << " set: " << setName << "]: Requested "
|
qDebug().nospace() << "PictureLoader: [card: " << cardName << " set: " << setName << "]: Requested "
|
||||||
// << propType << " property (" << cardPropertyName << ") for Url template ("
|
<< propType << " property (" << cardPropertyName << ") for Url template ("
|
||||||
// << urlTemplate << ") is longer than fill specification (" << fillWith << ")";
|
<< urlTemplate << ") is longer than fill specification (" << fillWith << ")";
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|
@ -382,9 +380,9 @@ QString PictureToLoad::transformUrl(const QString &urlTemplate) const
|
||||||
* populated in this card, so it should return an empty string,
|
* populated in this card, so it should return an empty string,
|
||||||
* indicating an invalid Url.
|
* indicating an invalid Url.
|
||||||
*/
|
*/
|
||||||
//qDebug().nospace() << "PictureLoader: [card: " << cardName << " set: " << setName
|
qDebug().nospace() << "PictureLoader: [card: " << cardName << " set: " << setName
|
||||||
// << "]: Requested information (" << prop << ") for Url template (" << urlTemplate
|
<< "]: Requested information (" << prop << ") for Url template (" << urlTemplate
|
||||||
// << ") is not available";
|
<< ") is not available";
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -412,9 +410,9 @@ void PictureLoaderWorker::startNextPicDownload()
|
||||||
picDownloadFailed();
|
picDownloadFailed();
|
||||||
} else {
|
} else {
|
||||||
QUrl url(picUrl);
|
QUrl url(picUrl);
|
||||||
//qDebug().nospace() << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getCorrectedName()
|
qDebug().nospace() << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getCorrectedName()
|
||||||
// << " set: " << cardBeingDownloaded.getSetName() << "]: Trying to fetch picture from url "
|
<< " set: " << cardBeingDownloaded.getSetName() << "]: Trying to fetch picture from url "
|
||||||
// << url.toDisplayString();
|
<< url.toDisplayString();
|
||||||
makeRequest(url);
|
makeRequest(url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -430,10 +428,10 @@ void PictureLoaderWorker::picDownloadFailed()
|
||||||
loadQueue.prepend(cardBeingDownloaded);
|
loadQueue.prepend(cardBeingDownloaded);
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
} else {
|
} else {
|
||||||
//qDebug().nospace() << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getCorrectedName()
|
qDebug().nospace() << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getCorrectedName()
|
||||||
// << " set: " << cardBeingDownloaded.getSetName() << "]: Picture NOT found, "
|
<< " set: " << cardBeingDownloaded.getSetName() << "]: Picture NOT found, "
|
||||||
// << (picDownload ? "download failed" : "downloads disabled")
|
<< (picDownload ? "download failed" : "downloads disabled")
|
||||||
// << ", no more url combinations to try: BAILING OUT";
|
<< ", no more url combinations to try: BAILING OUT";
|
||||||
imageLoaded(cardBeingDownloaded.getCard(), QImage());
|
imageLoaded(cardBeingDownloaded.getCard(), QImage());
|
||||||
cardBeingDownloaded.clear();
|
cardBeingDownloaded.clear();
|
||||||
}
|
}
|
||||||
|
|
@ -461,19 +459,19 @@ void PictureLoaderWorker::picDownloadFinished(QNetworkReply *reply)
|
||||||
|
|
||||||
if (reply->error()) {
|
if (reply->error()) {
|
||||||
if (isFromCache) {
|
if (isFromCache) {
|
||||||
//qDebug().nospace() << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getName()
|
qDebug().nospace() << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getName()
|
||||||
// << " set: " << cardBeingDownloaded.getSetName()
|
<< " set: " << cardBeingDownloaded.getSetName()
|
||||||
// << "]: Removing corrupted cache file for url " << reply->url().toDisplayString()
|
<< "]: Removing corrupted cache file for url " << reply->url().toDisplayString()
|
||||||
// << " and retrying (" << reply->errorString() << ")";
|
<< " and retrying (" << reply->errorString() << ")";
|
||||||
|
|
||||||
networkManager->cache()->remove(reply->url());
|
networkManager->cache()->remove(reply->url());
|
||||||
|
|
||||||
makeRequest(reply->url());
|
makeRequest(reply->url());
|
||||||
} else {
|
} else {
|
||||||
//qDebug().nospace() << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getName()
|
qDebug().nospace() << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getName()
|
||||||
// << " set: " << cardBeingDownloaded.getSetName()
|
<< " set: " << cardBeingDownloaded.getSetName()
|
||||||
// << "]: " << (picDownload ? "Download" : "Cache search") << " failed for url "
|
<< "]: " << (picDownload ? "Download" : "Cache search") << " failed for url "
|
||||||
// << reply->url().toDisplayString() << " (" << reply->errorString() << ")";
|
<< reply->url().toDisplayString() << " (" << reply->errorString() << ")";
|
||||||
|
|
||||||
picDownloadFailed();
|
picDownloadFailed();
|
||||||
startNextPicDownload();
|
startNextPicDownload();
|
||||||
|
|
@ -488,9 +486,9 @@ void PictureLoaderWorker::picDownloadFinished(QNetworkReply *reply)
|
||||||
if (statusCode == 301 || statusCode == 302 || statusCode == 303 || statusCode == 305 || statusCode == 307 ||
|
if (statusCode == 301 || statusCode == 302 || statusCode == 303 || statusCode == 305 || statusCode == 307 ||
|
||||||
statusCode == 308) {
|
statusCode == 308) {
|
||||||
QUrl redirectUrl = reply->header(QNetworkRequest::LocationHeader).toUrl();
|
QUrl redirectUrl = reply->header(QNetworkRequest::LocationHeader).toUrl();
|
||||||
//qDebug().nospace() << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getName()
|
qDebug().nospace() << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getName()
|
||||||
// << " set: " << cardBeingDownloaded.getSetName() << "]: following "
|
<< " set: " << cardBeingDownloaded.getSetName() << "]: following "
|
||||||
// << (isFromCache ? "cached redirect" : "redirect") << " to " << redirectUrl.toDisplayString();
|
<< (isFromCache ? "cached redirect" : "redirect") << " to " << redirectUrl.toDisplayString();
|
||||||
makeRequest(redirectUrl);
|
makeRequest(redirectUrl);
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
return;
|
return;
|
||||||
|
|
@ -500,9 +498,9 @@ void PictureLoaderWorker::picDownloadFinished(QNetworkReply *reply)
|
||||||
const QByteArray &picData = reply->peek(reply->size());
|
const QByteArray &picData = reply->peek(reply->size());
|
||||||
|
|
||||||
if (imageIsBlackListed(picData)) {
|
if (imageIsBlackListed(picData)) {
|
||||||
//qDebug().nospace() << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getName()
|
qDebug().nospace() << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getName()
|
||||||
// << " set: " << cardBeingDownloaded.getSetName()
|
<< " set: " << cardBeingDownloaded.getSetName()
|
||||||
// << "]: Picture found, but blacklisted, will consider it as not found";
|
<< "]: Picture found, but blacklisted, will consider it as not found";
|
||||||
|
|
||||||
picDownloadFailed();
|
picDownloadFailed();
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
@ -535,19 +533,19 @@ void PictureLoaderWorker::picDownloadFinished(QNetworkReply *reply)
|
||||||
imageLoaded(cardBeingDownloaded.getCard(), testImage);
|
imageLoaded(cardBeingDownloaded.getCard(), testImage);
|
||||||
logSuccessMessage = true;
|
logSuccessMessage = true;
|
||||||
} else {
|
} else {
|
||||||
//qDebug().nospace() << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getName()
|
qDebug().nospace() << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getName()
|
||||||
// << " set: " << cardBeingDownloaded.getSetName() << "]: Possible "
|
<< " set: " << cardBeingDownloaded.getSetName() << "]: Possible "
|
||||||
// << (isFromCache ? "cached" : "downloaded") << " picture at "
|
<< (isFromCache ? "cached" : "downloaded") << " picture at "
|
||||||
// << reply->url().toDisplayString() << " could not be loaded: " << reply->errorString();
|
<< reply->url().toDisplayString() << " could not be loaded: " << reply->errorString();
|
||||||
|
|
||||||
picDownloadFailed();
|
picDownloadFailed();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logSuccessMessage) {
|
if (logSuccessMessage) {
|
||||||
//qDebug().nospace() << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getName()
|
qDebug().nospace() << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getName()
|
||||||
// << " set: " << cardBeingDownloaded.getSetName() << "]: Image successfully "
|
<< " set: " << cardBeingDownloaded.getSetName() << "]: Image successfully "
|
||||||
// << (isFromCache ? "loaded from cached" : "downloaded from") << " url "
|
<< (isFromCache ? "loaded from cached" : "downloaded from") << " url "
|
||||||
// << reply->url().toDisplayString();
|
<< reply->url().toDisplayString();
|
||||||
}
|
}
|
||||||
|
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
@ -614,7 +612,7 @@ void PictureLoader::getCardBackPixmap(QPixmap &pixmap, QSize size)
|
||||||
{
|
{
|
||||||
QString backCacheKey = "_trice_card_back_" + QString::number(size.width()) + QString::number(size.height());
|
QString backCacheKey = "_trice_card_back_" + QString::number(size.width()) + QString::number(size.height());
|
||||||
if (!QPixmapCache::find(backCacheKey, &pixmap)) {
|
if (!QPixmapCache::find(backCacheKey, &pixmap)) {
|
||||||
//qDebug() << "PictureLoader: cache fail for" << backCacheKey;
|
qDebug() << "PictureLoader: cache fail for" << backCacheKey;
|
||||||
pixmap = QPixmap("theme:cardback").scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
pixmap = QPixmap("theme:cardback").scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||||
QPixmapCache::insert(backCacheKey, pixmap);
|
QPixmapCache::insert(backCacheKey, pixmap);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -160,8 +160,10 @@ AbstractDecklistNode *InnerDecklistNode::findChild(const QString &_name)
|
||||||
AbstractDecklistNode *InnerDecklistNode::findCardChildByNameAndUUID(const QString &_name, const QString &_uuid)
|
AbstractDecklistNode *InnerDecklistNode::findCardChildByNameAndUUID(const QString &_name, const QString &_uuid)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < size(); i++) {
|
for (int i = 0; i < size(); i++) {
|
||||||
if (at(i)->getName() == _name && at(i)->getCardUuid() == _uuid) {
|
if (at(i) != nullptr) {
|
||||||
return at(i);
|
if (at(i)->getName() == _name && at(i)->getCardUuid() == _uuid) {
|
||||||
|
return at(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue