digiKam
loadsavethread.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 : 2005-12-17
7  * Description : image file IO threaded interface.
8  *
9  * Copyright (C) 2005-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  * Copyright (C) 2005-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * ============================================================ */
24 
25 #ifndef DIGIKAM_LOAD_SAVE_THREAD_H
26 #define DIGIKAM_LOAD_SAVE_THREAD_H
27 
28 // Qt includes
29 
30 #include <QThread>
31 #include <QMutex>
32 #include <QList>
33 #include <QDateTime>
34 #include <QWaitCondition>
35 #include <QEvent>
36 
37 // Local includes
38 
39 #include "dimg.h"
40 #include "digikam_export.h"
41 #include "dynamicthread.h"
42 #include "loadingdescription.h"
43 
44 namespace Digikam
45 {
46 
47 class DMetadata;
48 class LoadSaveTask;
49 
50 class DIGIKAM_EXPORT LoadSaveNotifier
51 {
52 public:
53 
55  virtual ~LoadSaveNotifier();
56 
57  virtual void imageStartedLoading(const LoadingDescription& loadingDescription) = 0;
58  virtual void loadingProgress(const LoadingDescription& loadingDescription, float progress) = 0;
59  virtual void imageLoaded(const LoadingDescription& loadingDescription, const DImg& img) = 0;
60  virtual void moreCompleteLoadingAvailable(const LoadingDescription& oldLoadingDescription,
61  const LoadingDescription& newLoadingDescription) = 0;
62  virtual void imageStartedSaving(const QString& filePath) = 0;
63  virtual void savingProgress(const QString& filePath, float progress) = 0;
64  virtual void imageSaved(const QString& filePath, bool success) = 0;
65  virtual void thumbnailLoaded(const LoadingDescription& loadingDescription, const QImage& img) = 0;
66 
67 private:
68 
69  Q_DISABLE_COPY(LoadSaveNotifier)
70 };
71 
72 // -------------------------------------------------------------------------------------------------------
73 
74 class DIGIKAM_EXPORT LoadSaveFileInfoProvider
75 {
76 public:
77 
79  virtual ~LoadSaveFileInfoProvider();
80 
86  virtual int orientationHint(const QString& path) = 0;
87 
92  virtual QSize dimensionsHint(const QString& path) = 0;
93 
94 private:
95 
96  Q_DISABLE_COPY(LoadSaveFileInfoProvider)
97 };
98 
99 // -------------------------------------------------------------------------------------------------------
100 
101 class DIGIKAM_EXPORT LoadSaveThread : public DynamicThread,
102  public LoadSaveNotifier
103 {
104  Q_OBJECT
105 
106 public:
107 
109  {
120  NotificationPolicyTimeLimited
121  };
122 
127  {
135  AccessModeReadWrite
136  };
137 
138 public:
139 
140  explicit LoadSaveThread(QObject* const parent = nullptr);
141 
146  ~LoadSaveThread() override;
147 
151  void load(const LoadingDescription& description);
152 
156  void save(const DImg& image, const QString& filePath, const QString& format);
157 
158  void setNotificationPolicy(NotificationPolicy notificationPolicy);
159 
160 public:
161 
162  static void setInfoProvider(LoadSaveFileInfoProvider* const infoProvider);
163  static LoadSaveFileInfoProvider* infoProvider();
164 
169  static int exifOrientation(const QString& filePath,
170  const DMetadata& metadata,
171  bool isRaw,
172  bool fromRawEmbeddedPreview);
173 
174 Q_SIGNALS:
175 
185  void signalImageStartedLoading(const LoadingDescription& loadingDescription);
186 
192  void signalLoadingProgress(const LoadingDescription& loadingDescription, float progress);
193 
198  void signalImageLoaded(const LoadingDescription& loadingDescription, const DImg& img);
199 
208  void signalMoreCompleteLoadingAvailable(const LoadingDescription& oldLoadingDescription,
209  const LoadingDescription& newLoadingDescription);
210 
211  void signalImageStartedSaving(const QString& filePath);
212  void signalSavingProgress(const QString& filePath, float progress);
213  void signalImageSaved(const QString& filePath, bool success);
214 
215  void signalThumbnailLoaded(const LoadingDescription& loadingDescription, const QImage& img);
216 
217 public:
218 
219  void imageStartedLoading(const LoadingDescription& loadingDescription) override;
220  void loadingProgress(const LoadingDescription& loadingDescription, float progress) override;
221  void imageLoaded(const LoadingDescription& loadingDescription, const DImg& img) override;
222  void moreCompleteLoadingAvailable(const LoadingDescription& oldLoadingDescription,
223  const LoadingDescription& newLoadingDescription) override;
224  void imageStartedSaving(const QString& filePath) override;
225  void savingProgress(const QString& filePath, float progress) override;
226  void imageSaved(const QString& filePath, bool success) override;
227  void thumbnailLoaded(const LoadingDescription& loadingDescription, const QImage& img) override;
228 
229  virtual bool querySendNotifyEvent() const;
230  virtual void taskHasFinished();
231 
232 protected:
233 
234  void run() override;
235 
236  void notificationReceived();
237 
238 protected:
239 
240  QMutex m_mutex;
241 
243 
245 
247 
248 private:
249 
250  // Disable
251  LoadSaveThread(const LoadSaveThread&) = delete;
252  LoadSaveThread& operator=(const LoadSaveThread&) = delete;
253 
254 private:
255 
256  class Private;
257  Private* const d;
258 };
259 
260 } // namespace Digikam
261 
262 #endif // DIGIKAM_LOAD_SAVE_THREAD_H
Definition: dimg.h:62
Definition: dmetadata.h:55
Definition: dynamicthread.h:43
Definition: loadsavethread.h:75
virtual QSize dimensionsHint(const QString &path)=0
virtual int orientationHint(const QString &path)=0
Definition: loadsavethread.h:51
virtual void savingProgress(const QString &filePath, float progress)=0
virtual void moreCompleteLoadingAvailable(const LoadingDescription &oldLoadingDescription, const LoadingDescription &newLoadingDescription)=0
virtual void imageSaved(const QString &filePath, bool success)=0
virtual void loadingProgress(const LoadingDescription &loadingDescription, float progress)=0
virtual void imageStartedSaving(const QString &filePath)=0
virtual void imageLoaded(const LoadingDescription &loadingDescription, const DImg &img)=0
virtual void thumbnailLoaded(const LoadingDescription &loadingDescription, const QImage &img)=0
virtual void imageStartedLoading(const LoadingDescription &loadingDescription)=0
Definition: loadsavetask.h:46
Definition: loadsavethread.h:103
void signalSavingProgress(const QString &filePath, float progress)
AccessMode
Definition: loadsavethread.h:127
@ AccessModeRead
Definition: loadsavethread.h:131
NotificationPolicy m_notificationPolicy
Definition: loadsavethread.h:246
NotificationPolicy
Definition: loadsavethread.h:109
@ NotificationPolicyDirect
Definition: loadsavethread.h:113
QList< LoadSaveTask * > m_todo
Definition: loadsavethread.h:242
void signalImageStartedLoading(const LoadingDescription &loadingDescription)
LoadSaveTask * m_currentTask
Definition: loadsavethread.h:244
void signalImageStartedSaving(const QString &filePath)
void signalImageLoaded(const LoadingDescription &loadingDescription, const DImg &img)
QMutex m_mutex
Definition: loadsavethread.h:240
void signalThumbnailLoaded(const LoadingDescription &loadingDescription, const QImage &img)
void signalLoadingProgress(const LoadingDescription &loadingDescription, float progress)
void signalImageSaved(const QString &filePath, bool success)
void signalMoreCompleteLoadingAvailable(const LoadingDescription &oldLoadingDescription, const LoadingDescription &newLoadingDescription)
Definition: loadingdescription.h:45
Definition: piwigotalker.h:48
Definition: datefolderview.cpp:43