digiKam
loadingcache.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2006-01-11
7  * Description : shared image loading and caching
8  *
9  * Copyright (C) 2005-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_LOADING_CACHE_H
25 #define DIGIKAM_LOADING_CACHE_H
26 
27 // Qt includes
28 
29 #include <QPixmap>
30 
31 // Local includes
32 
33 #include "dimg.h"
34 #include "loadsavethread.h"
35 #include "digikam_export.h"
36 
37 namespace Digikam
38 {
39 
40 class ICCSettingsContainer;
41 
43 {
44 public:
45 
47  virtual ~LoadingProcessListener();
48  virtual bool querySendNotifyEvent() const = 0;
49  virtual void setResult(const LoadingDescription& loadingDescription, const DImg& img) = 0;
50  virtual LoadSaveNotifier* loadSaveNotifier() const = 0;
52 
53 private:
54 
55  // Disable
57  LoadingProcessListener& operator=(const LoadingProcessListener&) = delete;
58 };
59 
60 // --------------------------------------------------------------------------------------------------------------
61 
63 {
64 public:
65 
67  virtual ~LoadingProcess();
68  virtual bool completed() const = 0;
69  virtual QString cacheKey() const = 0;
70  virtual void addListener(LoadingProcessListener* const listener) = 0;
71  virtual void removeListener(LoadingProcessListener* const listener) = 0;
72  virtual void notifyNewLoadingProcess(LoadingProcess* const process, const LoadingDescription& description) = 0;
73 
74 private:
75 
76  // Disable
77  LoadingProcess(const LoadingProcess&) = delete;
78  LoadingProcess& operator=(const LoadingProcess&) = delete;
79 };
80 
81 // --------------------------------------------------------------------------------------------------------------
82 
83 class DIGIKAM_EXPORT LoadingCacheFileWatch : public QObject
84 {
85  Q_OBJECT
86 
87 public:
88 
90  ~LoadingCacheFileWatch() override;
91 
92  void addedImage(const QString& filePath);
93  void checkFileWatch(const QString& filePath);
94 
95 protected:
96 
103  void notifyFileChanged(const QString& filePath);
104 
105 protected:
106 
107  friend class LoadingCache;
108 
109  QMap<QString, QPair<qint64, QDateTime> > m_watchMap;
111 
112 private:
113 
114  // Disable
116  LoadingCacheFileWatch& operator=(const LoadingCacheFileWatch&) = delete;
117  LoadingCacheFileWatch(QObject*) = delete;
118 };
119 
120 // --------------------------------------------------------------------------------------------------------------
121 
122 class DIGIKAM_EXPORT LoadingCache : public QObject
123 {
124  Q_OBJECT
125 
126 public:
127 
132  class DIGIKAM_EXPORT CacheLock
133  {
134  public:
135 
136  explicit CacheLock(LoadingCache* const cache);
137  ~CacheLock();
138  void wakeAll();
139  void timedWait();
140 
141  private:
142 
143  LoadingCache* m_cache;
144  };
145 
146 public:
147 
148  static LoadingCache* cache();
149  static void cleanUp();
150 
155  DImg* retrieveImage(const QString& cacheKey) const;
156 
160  bool isCacheable(const DImg& img) const;
161 
170  bool putImage(const QString& cacheKey, const DImg& img, const QString& filePath) const;
171 
175  void removeImage(const QString& cacheKey);
176 
180  void removeImages();
181 
182  // ------- Loading process management -----------------------------------
183 
187  LoadingProcess* retrieveLoadingProcess(const QString& cacheKey) const;
188 
193  void addLoadingProcess(LoadingProcess* const process);
194 
198  void removeLoadingProcess(LoadingProcess* const process);
199 
203  void notifyNewLoadingProcess(LoadingProcess* const process, const LoadingDescription& description);
204 
209  void setCacheSize(int megabytes);
210 
211  // ------- Thumbnail cache -----------------------------------
212 
222  const QImage* retrieveThumbnail(const QString& cacheKey) const;
223  const QPixmap* retrieveThumbnailPixmap(const QString& cacheKey) const;
224  bool hasThumbnailPixmap(const QString& cacheKey) const;
225 
229  void putThumbnail(const QString& cacheKey, const QImage& thumb, const QString& filePath);
230  void putThumbnail(const QString& cacheKey, const QPixmap& thumb, const QString& filePath);
231 
235  void removeThumbnail(const QString& cacheKey);
236 
240  void removeThumbnails();
241 
255  void setThumbnailCacheSize(int numberOfQImages, int numberOfQPixmaps);
256 
257  // ------- File Watch Management -----------------------------------
258 
263  void setFileWatch(LoadingCacheFileWatch* const watch);
264 
268  QStringList imageFilePathsInCache() const;
269  QStringList thumbnailFilePathsInCache() const;
270 
275  void notifyFileChanged(const QString& filePath, bool notify = true);
276 
277 Q_SIGNALS:
278 
284  void fileChanged(const QString& filePath);
285 
286 private Q_SLOTS:
287 
288  void iccSettingsChanged(const ICCSettingsContainer& current, const ICCSettingsContainer& previous);
289 
290 private:
291 
292  // Disabled
293  LoadingCache();
294  explicit LoadingCache(QObject*) = delete;
295  ~LoadingCache() override;
296 
297  LoadingCache(const LoadingCache&) = delete;
298  LoadingCache& operator=(const LoadingCache&) = delete;
299 
300 private:
301 
302  friend class LoadingCacheFileWatch;
303  friend class CacheLock;
304 
305 private:
306 
307  static LoadingCache* m_instance;
308 
309  class Private;
310  Private* const d;
311 };
312 
313 } // namespace Digikam
314 
315 #endif // DIGIKAM_LOADING_CACHE_H
Definition: dimg.h:62
Definition: iccsettingscontainer.h:44
Definition: loadsavethread.h:51
AccessMode
Definition: loadsavethread.h:127
Definition: loadingcache.h:84
class LoadingCache * m_cache
Definition: loadingcache.h:110
QMap< QString, QPair< qint64, QDateTime > > m_watchMap
Definition: loadingcache.h:109
Definition: loadingcache.h:133
Definition: loadingcache.h:123
void fileChanged(const QString &filePath)
Definition: loadingdescription.h:45
Definition: loadingcache.h:43
virtual LoadSaveThread::AccessMode accessMode() const =0
virtual bool querySendNotifyEvent() const =0
LoadingProcessListener()
Definition: loadingcache.cpp:42
virtual LoadSaveNotifier * loadSaveNotifier() const =0
virtual void setResult(const LoadingDescription &loadingDescription, const DImg &img)=0
virtual ~LoadingProcessListener()
Definition: loadingcache.cpp:46
Definition: loadingcache.h:63
virtual QString cacheKey() const =0
virtual bool completed() const =0
virtual void notifyNewLoadingProcess(LoadingProcess *const process, const LoadingDescription &description)=0
virtual void removeListener(LoadingProcessListener *const listener)=0
virtual ~LoadingProcess()
Definition: loadingcache.cpp:56
virtual void addListener(LoadingProcessListener *const listener)=0
LoadingProcess()
Definition: loadingcache.cpp:52
Definition: datefolderview.cpp:43