* 2479: Running clang-format Reformatting files to be in line with style guidelines. * 2479: Updates to remove set/url indices This change removes set and Url indices in favor of check for empty lists and removing items from them instead. * 2479: TransformUrl will now error on missing fields If transformUrl is called with a template, and the card/set is missing something required by that template, it will now return an empty string, instead of the template with an empty string substituted in. * 2479: clang-format updates * 2479: Fixing omission of ! from two properties * 2479: Adding prefix on debug messages Adding PictureLoader: to the front of each debug message from this file, so that it can be more easily filtered out by grep in the log of a running application. * 2479: Remove outdated comment * 2479: Remove unused method from intermediate work * 2479: Updating QDebug messages to be more consistent * 2479: clang-format updates * 2479: Remove repeated code, replace with call to nextUrl This removes some redundant code that is better replaced with a call to nextUrl, in case the code needed to populate the nextUrl changes significantly. * 2479: Adding more detailed comments * 2479: Refactor transformUrl Refactor transformUrl to do everything in a single loop instead of two almost identical loops. set information is populated if present, but is added with empty strings if absent.
119 lines
2.8 KiB
C++
119 lines
2.8 KiB
C++
#ifndef PICTURELOADER_H
|
|
#define PICTURELOADER_H
|
|
|
|
#include <QList>
|
|
#include <QMap>
|
|
#include <QMutex>
|
|
#include <QNetworkRequest>
|
|
|
|
#include "carddatabase.h"
|
|
class QNetworkAccessManager;
|
|
class QNetworkReply;
|
|
class QThread;
|
|
|
|
class PictureToLoad
|
|
{
|
|
private:
|
|
class SetDownloadPriorityComparator;
|
|
|
|
CardInfoPtr card;
|
|
QList<CardSetPtr> sortedSets;
|
|
QList<QString> urlTemplates;
|
|
QList<QString> currentSetUrls;
|
|
QString currentUrl;
|
|
CardSetPtr currentSet;
|
|
|
|
public:
|
|
PictureToLoad(CardInfoPtr _card = CardInfoPtr());
|
|
CardInfoPtr getCard() const
|
|
{
|
|
return card;
|
|
}
|
|
void clear()
|
|
{
|
|
card.clear();
|
|
}
|
|
QString getCurrentUrl() const
|
|
{
|
|
return currentUrl;
|
|
}
|
|
CardSetPtr getCurrentSet() const
|
|
{
|
|
return currentSet;
|
|
}
|
|
QString getSetName() const;
|
|
QString transformUrl(QString urlTemplate) const;
|
|
bool nextSet();
|
|
bool nextUrl();
|
|
void populateSetUrls();
|
|
};
|
|
|
|
class PictureLoaderWorker : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
PictureLoaderWorker();
|
|
~PictureLoaderWorker();
|
|
|
|
void enqueueImageLoad(CardInfoPtr card);
|
|
|
|
private:
|
|
static QStringList md5Blacklist;
|
|
|
|
QThread *pictureLoaderThread;
|
|
QString picsPath, customPicsPath;
|
|
QList<PictureToLoad> loadQueue;
|
|
QMutex mutex;
|
|
QNetworkAccessManager *networkManager;
|
|
QList<PictureToLoad> cardsToDownload;
|
|
PictureToLoad cardBeingLoaded;
|
|
PictureToLoad cardBeingDownloaded;
|
|
bool picDownload, downloadRunning, loadQueueRunning;
|
|
void startNextPicDownload();
|
|
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(CardInfoPtr card, const QImage &image);
|
|
};
|
|
|
|
class PictureLoader : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
static PictureLoader &getInstance()
|
|
{
|
|
static PictureLoader instance;
|
|
return instance;
|
|
}
|
|
|
|
private:
|
|
PictureLoader();
|
|
~PictureLoader();
|
|
// Singleton - Don't implement copy constructor and assign operator
|
|
PictureLoader(PictureLoader const &);
|
|
void operator=(PictureLoader const &);
|
|
|
|
PictureLoaderWorker *worker;
|
|
|
|
public:
|
|
static void getPixmap(QPixmap &pixmap, CardInfoPtr card, QSize size);
|
|
static void getCardBackPixmap(QPixmap &pixmap, QSize size);
|
|
static void clearPixmapCache(CardInfoPtr card);
|
|
static void clearPixmapCache();
|
|
static void cacheCardPixmaps(QList<CardInfoPtr> cards);
|
|
private slots:
|
|
void picDownloadChanged();
|
|
void picsPathChanged();
|
|
public slots:
|
|
void imageLoaded(CardInfoPtr card, const QImage &image);
|
|
};
|
|
#endif
|