diff --git a/cockatrice/src/client/ui/picture_loader/picture_loader_local.cpp b/cockatrice/src/client/ui/picture_loader/picture_loader_local.cpp index c3ccc747e..0b8d48995 100644 --- a/cockatrice/src/client/ui/picture_loader/picture_loader_local.cpp +++ b/cockatrice/src/client/ui/picture_loader/picture_loader_local.cpp @@ -7,6 +7,8 @@ #include #include +static constexpr int REFRESH_INTERVAL_MS = 10 * 1000; + PictureLoaderLocal::PictureLoaderLocal(QObject *parent) : QObject(parent), picsPath(SettingsCache::instance().getPicsPath()), customPicsPath(SettingsCache::instance().getCustomPicsPath()), @@ -17,11 +19,17 @@ PictureLoaderLocal::PictureLoaderLocal(QObject *parent) connect(&SettingsCache::instance(), &SettingsCache::overrideAllCardArtWithPersonalPreferenceChanged, this, &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); // 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" - << customFolderIndex.size() << "entries."; + qCDebug(PictureLoaderLocalLog) << "Finished indexing local image folder CUSTOM; map now has" + << customFolderIndex.size() << "entries."; } /** diff --git a/cockatrice/src/client/ui/picture_loader/picture_loader_local.h b/cockatrice/src/client/ui/picture_loader/picture_loader_local.h index cea4ae564..45312d570 100644 --- a/cockatrice/src/client/ui/picture_loader/picture_loader_local.h +++ b/cockatrice/src/client/ui/picture_loader/picture_loader_local.h @@ -5,6 +5,7 @@ #include #include +#include inline Q_LOGGING_CATEGORY(PictureLoaderLocalLog, "picture_loader.local"); @@ -26,8 +27,9 @@ private: bool overrideAllCardArtWithPersonalPreference; QMultiHash customFolderIndex; // multimap of cardName to picPaths + QTimer *refreshTimer; - void createIndex(); + void refreshIndex(); QImage tryLoadCardImageFromDisk(const QString &setName, const QString &correctedCardName, bool searchCustomPics) const;