MythTV  master
mythuithemecache.h
Go to the documentation of this file.
1 #ifndef MYTHUICACHE_H
2 #define MYTHUICACHE_H
3 
4 // Qt
5 #include <QMap>
6 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
7 #include <QMutex>
8 #else
9 #include <QRecursiveMutex>
10 #endif
11 
12 // MythTV
13 #include "mythchrono.h"
14 #include "mythimage.h"
15 
17 {
18  kCacheNormal = 0x0,
22 };
23 
24 class MThreadPool;
25 
27 {
28  public:
31 
32  void UpdateImageCache();
33  void SetScreenSize(QSize Size);
34  void ClearThemeCacheDir();
35  QString GetThemeCacheDir();
36  MythImage* LoadCacheImage(QString File, const QString& Label,
37  MythPainter* Painter, ImageCacheMode cacheMode = kCacheNormal);
38  MythImage* CacheImage(const QString& URL, MythImage* Image, bool NoDisk = false);
39  void RemoveFromCacheByFile(const QString& File);
40  bool IsImageInCache(const QString& URL);
41  void IncludeInCacheSize(MythImage* Image);
42  void ExcludeFromCacheSize(MythImage* Image);
43  MThreadPool* GetImageThreadPool();
44 
45  private:
46  QString GetCacheDirByUrl(const QString& URL);
47  void RemoveFromCacheByURL(const QString& URL);
48  MythImage* GetImageFromCache(const QString& URL);
49  void ClearOldImageCache();
50  void RemoveCacheDir(const QString& Dir);
51  static void PruneCacheDir(const QString& Dir);
52 
53  QMap<QString, MythImage *> m_imageCache;
54  QMap<QString, SystemTime> m_cacheTrack;
55 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
56  QMutex m_cacheLock { QMutex::Recursive };
57 #else
58  QRecursiveMutex m_cacheLock;
59 #endif
60 #if QT_VERSION < QT_VERSION_CHECK(5,10,0)
61  QAtomicInt m_cacheSize { 0 };
62  QAtomicInt m_maxCacheSize { 30 * 1024 * 1024 };
63 #else
64  QAtomicInteger<qint64> m_cacheSize { 0 };
65  QAtomicInteger<qint64> m_maxCacheSize { 30 * 1024 * 1024 };
66 #endif
67  QString m_themecachedir;
69  MThreadPool* m_imageThreadPool { nullptr };
70 };
71 
72 #endif
MUI_PUBLIC
#define MUI_PUBLIC
Definition: mythuiexp.h:9
MythUIThemeCache::m_cacheScreenSize
QSize m_cacheScreenSize
Definition: mythuithemecache.h:68
MythUIThemeCache::m_imageCache
QMap< QString, MythImage * > m_imageCache
Definition: mythuithemecache.h:53
MythUIThemeCache
Definition: mythuithemecache.h:26
MythUIThemeCache::m_themecachedir
QString m_themecachedir
Definition: mythuithemecache.h:67
kCacheCheckMemoryOnly
@ kCacheCheckMemoryOnly
Definition: mythuithemecache.h:20
ImageCacheMode
ImageCacheMode
Definition: mythuithemecache.h:16
MythUIThemeCache::m_cacheLock
QRecursiveMutex m_cacheLock
Definition: mythuithemecache.h:58
kCacheNormal
@ kCacheNormal
Definition: mythuithemecache.h:18
kCacheForceStat
@ kCacheForceStat
Definition: mythuithemecache.h:21
kCacheIgnoreDisk
@ kCacheIgnoreDisk
Definition: mythuithemecache.h:19
MThreadPool
Definition: mthreadpool.h:18
mythimage.h
MythPainter
Definition: mythpainter.h:32
MythImage
Definition: mythimage.h:36
mythchrono.h
MythUIThemeCache::m_cacheTrack
QMap< QString, SystemTime > m_cacheTrack
Definition: mythuithemecache.h:54