Merge pull request #1770 from ctrlaltca/fix_pixmaps
Fix pixmap usage in pictureloader
This commit is contained in:
commit
7ec3968c02
2 changed files with 78 additions and 43 deletions
|
@ -88,10 +88,10 @@ CardSet *PictureToLoad::getCurrentSet() const
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList PictureLoader::md5Blacklist = QStringList()
|
QStringList PictureLoaderWorker::md5Blacklist = QStringList()
|
||||||
<< "db0c48db407a907c16ade38de048a441"; // card back returned by gatherer when card is not found
|
<< "db0c48db407a907c16ade38de048a441"; // card back returned by gatherer when card is not found
|
||||||
|
|
||||||
PictureLoader::PictureLoader()
|
PictureLoaderWorker::PictureLoaderWorker()
|
||||||
: QObject(0),
|
: QObject(0),
|
||||||
downloadRunning(false), loadQueueRunning(false)
|
downloadRunning(false), loadQueueRunning(false)
|
||||||
{
|
{
|
||||||
|
@ -110,12 +110,12 @@ PictureLoader::PictureLoader()
|
||||||
moveToThread(pictureLoaderThread);
|
moveToThread(pictureLoaderThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
PictureLoader::~PictureLoader()
|
PictureLoaderWorker::~PictureLoaderWorker()
|
||||||
{
|
{
|
||||||
pictureLoaderThread->deleteLater();
|
pictureLoaderThread->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PictureLoader::processLoadQueue()
|
void PictureLoaderWorker::processLoadQueue()
|
||||||
{
|
{
|
||||||
if (loadQueueRunning)
|
if (loadQueueRunning)
|
||||||
return;
|
return;
|
||||||
|
@ -160,7 +160,7 @@ void PictureLoader::processLoadQueue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PictureLoader::cardImageExistsOnDisk(QString & setName, QString & correctedCardname)
|
bool PictureLoaderWorker::cardImageExistsOnDisk(QString & setName, QString & correctedCardname)
|
||||||
{
|
{
|
||||||
QImage image;
|
QImage image;
|
||||||
QImageReader imgReader;
|
QImageReader imgReader;
|
||||||
|
@ -194,7 +194,7 @@ bool PictureLoader::cardImageExistsOnDisk(QString & setName, QString & corrected
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PictureLoader::getPicUrl()
|
QString PictureLoaderWorker::getPicUrl()
|
||||||
{
|
{
|
||||||
if (!picDownload) return QString("");
|
if (!picDownload) return QString("");
|
||||||
|
|
||||||
|
@ -242,7 +242,7 @@ QString PictureLoader::getPicUrl()
|
||||||
return picUrl;
|
return picUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PictureLoader::startNextPicDownload()
|
void PictureLoaderWorker::startNextPicDownload()
|
||||||
{
|
{
|
||||||
if (cardsToDownload.isEmpty()) {
|
if (cardsToDownload.isEmpty()) {
|
||||||
cardBeingDownloaded = 0;
|
cardBeingDownloaded = 0;
|
||||||
|
@ -267,7 +267,7 @@ void PictureLoader::startNextPicDownload()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PictureLoader::picDownloadFailed()
|
void PictureLoaderWorker::picDownloadFailed()
|
||||||
{
|
{
|
||||||
if (cardBeingDownloaded.nextSet())
|
if (cardBeingDownloaded.nextSet())
|
||||||
{
|
{
|
||||||
|
@ -283,13 +283,13 @@ void PictureLoader::picDownloadFailed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PictureLoader::imageIsBlackListed(const QByteArray &picData)
|
bool PictureLoaderWorker::imageIsBlackListed(const QByteArray &picData)
|
||||||
{
|
{
|
||||||
QString md5sum = QCryptographicHash::hash(picData, QCryptographicHash::Md5).toHex();
|
QString md5sum = QCryptographicHash::hash(picData, QCryptographicHash::Md5).toHex();
|
||||||
return md5Blacklist.contains(md5sum);
|
return md5Blacklist.contains(md5sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PictureLoader::picDownloadFinished(QNetworkReply *reply)
|
void PictureLoaderWorker::picDownloadFinished(QNetworkReply *reply)
|
||||||
{
|
{
|
||||||
if (reply->error()) {
|
if (reply->error()) {
|
||||||
qDebug() << "Download failed:" << reply->errorString();
|
qDebug() << "Download failed:" << reply->errorString();
|
||||||
|
@ -349,7 +349,7 @@ void PictureLoader::picDownloadFinished(QNetworkReply *reply)
|
||||||
startNextPicDownload();
|
startNextPicDownload();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PictureLoader::enqueueImageLoad(CardInfo *card)
|
void PictureLoaderWorker::enqueueImageLoad(CardInfo *card)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&mutex);
|
QMutexLocker locker(&mutex);
|
||||||
|
|
||||||
|
@ -367,20 +367,31 @@ void PictureLoader::enqueueImageLoad(CardInfo *card)
|
||||||
emit startLoadQueue();
|
emit startLoadQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PictureLoader::picDownloadChanged()
|
void PictureLoaderWorker::picDownloadChanged()
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&mutex);
|
QMutexLocker locker(&mutex);
|
||||||
picDownload = settingsCache->getPicDownload();
|
picDownload = settingsCache->getPicDownload();
|
||||||
|
|
||||||
QPixmapCache::clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PictureLoader::picsPathChanged()
|
void PictureLoaderWorker::picsPathChanged()
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&mutex);
|
QMutexLocker locker(&mutex);
|
||||||
picsPath = settingsCache->getPicsPath();
|
picsPath = settingsCache->getPicsPath();
|
||||||
|
}
|
||||||
|
|
||||||
QPixmapCache::clear();
|
PictureLoader::PictureLoader()
|
||||||
|
: QObject(0)
|
||||||
|
{
|
||||||
|
worker = new PictureLoaderWorker;
|
||||||
|
connect(settingsCache, SIGNAL(picsPathChanged()), this, SLOT(picsPathChanged()));
|
||||||
|
connect(settingsCache, SIGNAL(picDownloadChanged()), this, SLOT(picDownloadChanged()));
|
||||||
|
|
||||||
|
connect(worker, SIGNAL(imageLoaded(CardInfo *, const QImage &)), this, SLOT(imageLoaded(CardInfo *, const QImage &)));
|
||||||
|
}
|
||||||
|
|
||||||
|
PictureLoader::~PictureLoader()
|
||||||
|
{
|
||||||
|
worker->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PictureLoader::internalGetCardBackPixmap(QPixmap &pixmap, QSize size)
|
void PictureLoader::internalGetCardBackPixmap(QPixmap &pixmap, QSize size)
|
||||||
|
@ -388,7 +399,7 @@ void PictureLoader::internalGetCardBackPixmap(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() << "cache fail for" << backCacheKey;
|
qDebug() << "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);
|
||||||
}
|
}
|
||||||
|
@ -425,7 +436,7 @@ void PictureLoader::getPixmap(QPixmap &pixmap, CardInfo *card, QSize size)
|
||||||
if(card)
|
if(card)
|
||||||
{
|
{
|
||||||
// add the card to the load queue
|
// add the card to the load queue
|
||||||
getInstance().enqueueImageLoad(card);
|
getInstance().worker->enqueueImageLoad(card);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -471,6 +482,16 @@ void PictureLoader::cacheCardPixmaps(QList<CardInfo *> cards)
|
||||||
if(QPixmapCache::find(key, &tmp))
|
if(QPixmapCache::find(key, &tmp))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
getInstance().enqueueImageLoad(card);
|
getInstance().worker->enqueueImageLoad(card);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PictureLoader::picDownloadChanged()
|
||||||
|
{
|
||||||
|
QPixmapCache::clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PictureLoader::picsPathChanged()
|
||||||
|
{
|
||||||
|
QPixmapCache::clear();
|
||||||
|
}
|
|
@ -28,6 +28,42 @@ public:
|
||||||
bool nextSet();
|
bool nextSet();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class PictureLoaderWorker : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
PictureLoaderWorker();
|
||||||
|
~PictureLoaderWorker();
|
||||||
|
|
||||||
|
void enqueueImageLoad(CardInfo *card);
|
||||||
|
private:
|
||||||
|
static QStringList md5Blacklist;
|
||||||
|
|
||||||
|
QThread *pictureLoaderThread;
|
||||||
|
QString picsPath;
|
||||||
|
QList<PictureToLoad> loadQueue;
|
||||||
|
QMutex mutex;
|
||||||
|
QNetworkAccessManager *networkManager;
|
||||||
|
QList<PictureToLoad> cardsToDownload;
|
||||||
|
PictureToLoad cardBeingLoaded;
|
||||||
|
PictureToLoad cardBeingDownloaded;
|
||||||
|
bool picDownload, downloadRunning, loadQueueRunning;
|
||||||
|
void startNextPicDownload();
|
||||||
|
QString getPicUrl();
|
||||||
|
bool cardImageExistsOnDisk(QString & setName, QString & correctedCardname);
|
||||||
|
bool imageIsBlackListed(const QByteArray &picData);
|
||||||
|
private slots:
|
||||||
|
void picDownloadFinished(QNetworkReply *reply);
|
||||||
|
void picDownloadFailed();
|
||||||
|
|
||||||
|
void picDownloadChanged();
|
||||||
|
void picsPathChanged();
|
||||||
|
public slots:
|
||||||
|
void processLoadQueue();
|
||||||
|
signals:
|
||||||
|
void startLoadQueue();
|
||||||
|
void imageLoaded(CardInfo *card, const QImage &image);
|
||||||
|
};
|
||||||
|
|
||||||
class PictureLoader : public QObject {
|
class PictureLoader : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
@ -43,24 +79,8 @@ private:
|
||||||
PictureLoader(PictureLoader const&);
|
PictureLoader(PictureLoader const&);
|
||||||
void operator=(PictureLoader const&);
|
void operator=(PictureLoader const&);
|
||||||
|
|
||||||
static QStringList md5Blacklist;
|
PictureLoaderWorker * worker;
|
||||||
|
|
||||||
QThread *pictureLoaderThread;
|
|
||||||
QString picsPath;
|
|
||||||
QList<PictureToLoad> loadQueue;
|
|
||||||
QMutex mutex;
|
|
||||||
QNetworkAccessManager *networkManager;
|
|
||||||
QList<PictureToLoad> cardsToDownload;
|
|
||||||
PictureToLoad cardBeingLoaded;
|
|
||||||
PictureToLoad cardBeingDownloaded;
|
|
||||||
bool picDownload, downloadRunning, loadQueueRunning;
|
|
||||||
void startNextPicDownload();
|
|
||||||
void imageLoaded(CardInfo *card, const QImage &image);
|
|
||||||
QString getPicUrl();
|
|
||||||
bool cardImageExistsOnDisk(QString & setName, QString & correctedCardname);
|
|
||||||
bool imageIsBlackListed(const QByteArray &picData);
|
|
||||||
public:
|
public:
|
||||||
void enqueueImageLoad(CardInfo *card);
|
|
||||||
static void getPixmap(QPixmap &pixmap, CardInfo *card, QSize size);
|
static void getPixmap(QPixmap &pixmap, CardInfo *card, QSize size);
|
||||||
static void clearPixmapCache(CardInfo *card);
|
static void clearPixmapCache(CardInfo *card);
|
||||||
static void clearPixmapCache();
|
static void clearPixmapCache();
|
||||||
|
@ -68,15 +88,9 @@ public:
|
||||||
protected:
|
protected:
|
||||||
static void internalGetCardBackPixmap(QPixmap &pixmap, QSize size);
|
static void internalGetCardBackPixmap(QPixmap &pixmap, QSize size);
|
||||||
private slots:
|
private slots:
|
||||||
void picDownloadFinished(QNetworkReply *reply);
|
|
||||||
void picDownloadFailed();
|
|
||||||
|
|
||||||
void picDownloadChanged();
|
void picDownloadChanged();
|
||||||
void picsPathChanged();
|
void picsPathChanged();
|
||||||
public slots:
|
public slots:
|
||||||
void processLoadQueue();
|
void imageLoaded(CardInfo *card, const QImage &image);
|
||||||
signals:
|
|
||||||
void startLoadQueue();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue