summaryrefslogtreecommitdiff
path: root/src/iconfetcher.h
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2020-02-09 08:52:03 -0500
committerGitHub <noreply@github.com>2020-02-09 08:52:03 -0500
commit1f1f99f253f981ae3d11e9df177a144d00dbce0e (patch)
tree01d38125329508f5628f9221f797e303180c8fc3 /src/iconfetcher.h
parent718c2a56f91f824c5eab69d8cc16294f77243370 (diff)
parent3a80685189967fbf4cfa002ac2b8a4fa421306ca (diff)
Merge pull request #994 from isanae/generic-file-list
New file tree
Diffstat (limited to 'src/iconfetcher.h')
-rw-r--r--src/iconfetcher.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/iconfetcher.h b/src/iconfetcher.h
new file mode 100644
index 00000000..030bfb79
--- /dev/null
+++ b/src/iconfetcher.h
@@ -0,0 +1,76 @@
+#ifndef MODORGANIZER_ICONFETCHER_INCLUDED
+#define MODORGANIZER_ICONFETCHER_INCLUDED
+
+#include <QFileIconProvider>
+#include <mutex>
+
+class IconFetcher
+{
+public:
+ IconFetcher();
+ ~IconFetcher();
+
+ void stop();
+
+ QVariant icon(const QString& path) const;
+ QPixmap genericFileIcon() const;
+ QPixmap genericDirectoryIcon() const;
+
+private:
+ struct QuickCache
+ {
+ QPixmap file;
+ QPixmap directory;
+ };
+
+ struct Cache
+ {
+ std::map<QString, QPixmap, std::less<>> map;
+ std::mutex mapMutex;
+
+ std::set<QString> queue;
+ std::mutex queueMutex;
+ };
+
+ class Waiter
+ {
+ public:
+ void wait();
+ void wakeUp();
+
+ private:
+ mutable std::mutex m_wakeUpMutex;
+ std::condition_variable m_wakeUp;
+ bool m_queueAvailable = false;
+ };
+
+
+ const int m_iconSize;
+ QFileIconProvider m_provider;
+ std::thread m_thread;
+ std::atomic<bool> m_stop;
+
+ mutable QuickCache m_quickCache;
+ mutable Cache m_extensionCache;
+ mutable Cache m_fileCache;
+ mutable Waiter m_waiter;
+
+
+ bool hasOwnIcon(const QString& path) const;
+
+ template <class T>
+ QPixmap getPixmapIcon(T&& t) const
+ {
+ return m_provider.icon(t).pixmap({m_iconSize, m_iconSize});
+ }
+
+ void threadFun();
+
+ void checkCache(Cache& cache);
+ void queue(Cache& cache, QString path) const;
+
+ QVariant fileIcon(const QString& path) const;
+ QVariant extensionIcon(const QStringRef& ext) const;
+};
+
+#endif // MODORGANIZER_ICONFETCHER_INCLUDED