mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-04 04:23:55 -07:00
[PictureLoader] Periodically refresh the local images index (#5997)
This commit is contained in:
parent
b69091a51a
commit
c1f12f52ae
2 changed files with 15 additions and 5 deletions
|
|
@ -7,6 +7,8 @@
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
#include <QMovie>
|
#include <QMovie>
|
||||||
|
|
||||||
|
static constexpr int REFRESH_INTERVAL_MS = 10 * 1000;
|
||||||
|
|
||||||
PictureLoaderLocal::PictureLoaderLocal(QObject *parent)
|
PictureLoaderLocal::PictureLoaderLocal(QObject *parent)
|
||||||
: QObject(parent), picsPath(SettingsCache::instance().getPicsPath()),
|
: QObject(parent), picsPath(SettingsCache::instance().getPicsPath()),
|
||||||
customPicsPath(SettingsCache::instance().getCustomPicsPath()),
|
customPicsPath(SettingsCache::instance().getCustomPicsPath()),
|
||||||
|
|
@ -17,11 +19,17 @@ PictureLoaderLocal::PictureLoaderLocal(QObject *parent)
|
||||||
connect(&SettingsCache::instance(), &SettingsCache::overrideAllCardArtWithPersonalPreferenceChanged, this,
|
connect(&SettingsCache::instance(), &SettingsCache::overrideAllCardArtWithPersonalPreferenceChanged, this,
|
||||||
&PictureLoaderLocal::setOverrideAllCardArtWithPersonalPreference);
|
&PictureLoaderLocal::setOverrideAllCardArtWithPersonalPreference);
|
||||||
|
|
||||||
createIndex();
|
refreshIndex();
|
||||||
|
|
||||||
|
refreshTimer = new QTimer(this);
|
||||||
|
connect(refreshTimer, &QTimer::timeout, this, &PictureLoaderLocal::refreshIndex);
|
||||||
|
refreshTimer->start(REFRESH_INTERVAL_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PictureLoaderLocal::createIndex()
|
void PictureLoaderLocal::refreshIndex()
|
||||||
{
|
{
|
||||||
|
customFolderIndex.clear();
|
||||||
|
|
||||||
QDirIterator it(customPicsPath, QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);
|
QDirIterator it(customPicsPath, QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);
|
||||||
|
|
||||||
// Recursively check all subdirectories of the CUSTOM folder
|
// Recursively check all subdirectories of the CUSTOM folder
|
||||||
|
|
@ -37,8 +45,8 @@ void PictureLoaderLocal::createIndex()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qCInfo(PictureLoaderLocalLog) << "Finished indexing local image folder CUSTOM; map now has"
|
qCDebug(PictureLoaderLocalLog) << "Finished indexing local image folder CUSTOM; map now has"
|
||||||
<< customFolderIndex.size() << "entries.";
|
<< customFolderIndex.size() << "entries.";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
inline Q_LOGGING_CATEGORY(PictureLoaderLocalLog, "picture_loader.local");
|
inline Q_LOGGING_CATEGORY(PictureLoaderLocalLog, "picture_loader.local");
|
||||||
|
|
||||||
|
|
@ -26,8 +27,9 @@ private:
|
||||||
bool overrideAllCardArtWithPersonalPreference;
|
bool overrideAllCardArtWithPersonalPreference;
|
||||||
|
|
||||||
QMultiHash<QString, QString> customFolderIndex; // multimap of cardName to picPaths
|
QMultiHash<QString, QString> customFolderIndex; // multimap of cardName to picPaths
|
||||||
|
QTimer *refreshTimer;
|
||||||
|
|
||||||
void createIndex();
|
void refreshIndex();
|
||||||
|
|
||||||
QImage
|
QImage
|
||||||
tryLoadCardImageFromDisk(const QString &setName, const QString &correctedCardName, bool searchCustomPics) const;
|
tryLoadCardImageFromDisk(const QString &setName, const QString &correctedCardName, bool searchCustomPics) const;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue