digiKam
loadsavetask.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-20
7  * Description : image file IO threaded interface.
8  *
9  * Copyright (C) 2005-2013 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_TASK_H
26 #define DIGIKAM_LOAD_SAVE_TASK_H
27 
28 // Qt includes
29 
30 #include <QList>
31 #include <QEvent>
32 
33 // Local includes
34 
35 #include "dimg.h"
36 #include "dimgloaderobserver.h"
37 #include "loadingdescription.h"
38 #include "loadingcache.h"
39 
40 namespace Digikam
41 {
42 
43 class LoadSaveThread;
44 
46 {
47 public:
48 
49  enum TaskType
50  {
53  };
54 
55 public:
56 
57  explicit LoadSaveTask(LoadSaveThread* const thread);
58  virtual ~LoadSaveTask();
59 
60 public:
61 
62  virtual void execute() = 0;
63  virtual TaskType type() = 0;
64 
65  virtual void progressInfo(float progress) = 0;
66  virtual bool continueQuery() = 0;
67 
68 protected:
69 
71 
72 private:
73 
74  // Disable
75  LoadSaveTask(const LoadSaveTask&) = delete;
76  LoadSaveTask& operator=(const LoadSaveTask&) = delete;
77 };
78 
79 //---------------------------------------------------------------------------------------------------
80 
81 class LoadingTask : public LoadSaveTask,
82  public DImgLoaderObserver
83 {
84 public:
85 
87  {
91  };
92 
93 public:
94 
95  explicit LoadingTask(LoadSaveThread* const thread,
96  const LoadingDescription& description,
97  LoadingTaskStatus loadingTaskStatus = LoadingTaskStatusLoading);
98  ~LoadingTask() override;
99 
100  LoadingTaskStatus status() const;
101  QString filePath() const;
102 
103  const LoadingDescription& loadingDescription() const;
104 
105  // LoadSaveTask
106 
107  void execute() override;
108  TaskType type() override;
109 
110  // DImgLoaderObserver
111 
112  void progressInfo(float progress) override;
113  bool continueQuery() override;
114 
116 
117 protected:
118 
121 
122 private:
123 
124  // Disable
125  LoadingTask(const LoadingTask&) = delete;
126  LoadingTask& operator=(const LoadingTask&) = delete;
127 };
128 
129 //---------------------------------------------------------------------------------------------------
130 
132  public LoadingProcess,
134 {
135 public:
136 
137  explicit SharedLoadingTask(LoadSaveThread* const thread,
138  const LoadingDescription& description,
140  LoadingTaskStatus loadingTaskStatus = LoadingTaskStatusLoading);
141 
142  void execute() override;
143  void progressInfo(float progress) override;
144 
145  bool needsPostProcessing() const;
146  virtual void postProcess();
147 
148  // LoadingProcess
149 
150  bool completed() const override;
151  QString cacheKey() const override;
152  void addListener(LoadingProcessListener* const listener) override;
153  void removeListener(LoadingProcessListener* const listener) override;
154  void notifyNewLoadingProcess(LoadingProcess* const process,
155  const LoadingDescription& description) override;
156 
157  // LoadingProcessListener
158 
159  bool querySendNotifyEvent() const override;
161  const DImg& img) override;
162  LoadSaveNotifier* loadSaveNotifier() const override;
163  LoadSaveThread::AccessMode accessMode() const override;
164 
165  DImg img() const;
166 
167 protected:
168 
169  volatile bool m_completed;
173 
174 private:
175 
176  // Disable
177  SharedLoadingTask(const SharedLoadingTask&) = delete;
178  SharedLoadingTask& operator=(const SharedLoadingTask&) = delete;
179 };
180 
181 //---------------------------------------------------------------------------------------------------
182 
183 class SavingTask : public LoadSaveTask,
184  public DImgLoaderObserver
185 {
186 public:
187 
189  {
192  };
193 
194 public:
195 
196  explicit SavingTask(LoadSaveThread* const thread,
197  const DImg& img,
198  const QString& filePath,
199  const QString& format);
200 
201  SavingTaskStatus status() const;
202  QString filePath() const;
203 
204 public:
205 
206  void execute() override;
207  TaskType type() override;
208 
209  void progressInfo(float progress) override;
210  bool continueQuery() override;
211 
213 
214 private:
215 
216  QString m_filePath;
217  QString m_format;
218  DImg m_img;
219  volatile SavingTaskStatus m_savingTaskStatus;
220 
221 private:
222 
223  // Disable
224  SavingTask(const SavingTask&) = delete;
225  SavingTask& operator=(const SavingTask&) = delete;
226 };
227 
228 } // namespace Digikam
229 
230 #endif // DIGIKAM_LOAD_SAVE_TASK_H
Definition: dimgloaderobserver.h:41
Definition: dimg.h:62
Definition: loadsavethread.h:51
Definition: loadsavetask.h:46
virtual bool continueQuery()=0
TaskType
Definition: loadsavetask.h:50
@ TaskTypeLoading
Definition: loadsavetask.h:51
@ TaskTypeSaving
Definition: loadsavetask.h:52
virtual ~LoadSaveTask()
Definition: loadsavetask.cpp:45
virtual void progressInfo(float progress)=0
LoadSaveThread * m_thread
Definition: loadsavetask.h:70
LoadSaveTask(LoadSaveThread *const thread)
Definition: loadsavetask.cpp:40
virtual TaskType type()=0
virtual void execute()=0
Definition: loadsavethread.h:103
AccessMode
Definition: loadsavethread.h:127
@ AccessModeReadWrite
Definition: loadsavethread.h:135
Definition: loadingdescription.h:45
Definition: loadingcache.h:43
Definition: loadingcache.h:63
Definition: loadsavetask.h:83
LoadingTaskStatus status() const
Definition: loadsavetask.cpp:64
QString filePath() const
Definition: loadsavetask.cpp:69
bool continueQuery() override
Definition: loadsavetask.cpp:109
const LoadingDescription & loadingDescription() const
Definition: loadsavetask.cpp:74
void setStatus(LoadingTaskStatus status)
Definition: loadsavetask.cpp:114
LoadingTask(LoadSaveThread *const thread, const LoadingDescription &description, LoadingTaskStatus loadingTaskStatus=LoadingTaskStatusLoading)
Definition: loadsavetask.cpp:51
TaskType type() override
Definition: loadsavetask.cpp:93
~LoadingTask() override
Definition: loadsavetask.cpp:60
LoadingTaskStatus
Definition: loadsavetask.h:87
@ LoadingTaskStatusPreloading
Definition: loadsavetask.h:89
@ LoadingTaskStatusLoading
Definition: loadsavetask.h:88
@ LoadingTaskStatusStopping
Definition: loadsavetask.h:90
void execute() override
Definition: loadsavetask.cpp:79
volatile LoadingTaskStatus m_loadingTaskStatus
Definition: loadsavetask.h:120
LoadingDescription m_loadingDescription
Definition: loadsavetask.h:119
void progressInfo(float progress) override
Definition: loadsavetask.cpp:98
Definition: loadsavetask.h:185
SavingTaskStatus status() const
Definition: loadsavetask.cpp:488
SavingTask(LoadSaveThread *const thread, const DImg &img, const QString &filePath, const QString &format)
Definition: loadsavetask.cpp:476
QString filePath() const
Definition: loadsavetask.cpp:493
TaskType type() override
Definition: loadsavetask.cpp:506
void setStatus(SavingTaskStatus status)
Definition: loadsavetask.cpp:524
bool continueQuery() override
Definition: loadsavetask.cpp:519
void progressInfo(float progress) override
Definition: loadsavetask.cpp:511
void execute() override
Definition: loadsavetask.cpp:498
SavingTaskStatus
Definition: loadsavetask.h:189
@ SavingTaskStatusSaving
Definition: loadsavetask.h:190
@ SavingTaskStatusStopping
Definition: loadsavetask.h:191
Definition: loadsavetask.h:134
LoadSaveNotifier * loadSaveNotifier() const override
Definition: loadsavetask.cpp:459
QString cacheKey() const override
Definition: loadsavetask.cpp:413
void progressInfo(float progress) override
Definition: loadsavetask.cpp:388
void removeListener(LoadingProcessListener *const listener) override
Definition: loadsavetask.cpp:423
bool querySendNotifyEvent() const override
Definition: loadsavetask.cpp:454
void execute() override
Definition: loadsavetask.cpp:133
SharedLoadingTask(LoadSaveThread *const thread, const LoadingDescription &description, LoadSaveThread::AccessMode mode=LoadSaveThread::AccessModeReadWrite, LoadingTaskStatus loadingTaskStatus=LoadingTaskStatusLoading)
Definition: loadsavetask.cpp:121
LoadSaveThread::AccessMode accessMode() const override
Definition: loadsavetask.cpp:464
DImg m_img
Definition: loadsavetask.h:172
bool completed() const override
Definition: loadsavetask.cpp:408
LoadSaveThread::AccessMode m_accessMode
Definition: loadsavetask.h:170
bool needsPostProcessing() const
Definition: loadsavetask.cpp:336
QList< LoadingProcessListener * > m_listeners
Definition: loadsavetask.h:171
DImg img() const
Definition: loadsavetask.cpp:469
void addListener(LoadingProcessListener *const listener) override
Definition: loadsavetask.cpp:418
void setResult(const LoadingDescription &loadingDescription, const DImg &img) override
Definition: loadsavetask.cpp:322
virtual void postProcess()
Definition: loadsavetask.cpp:341
volatile bool m_completed
Definition: loadsavetask.h:169
void notifyNewLoadingProcess(LoadingProcess *const process, const LoadingDescription &description) override
Definition: loadsavetask.cpp:428
Definition: piwigotalker.h:48
Definition: datefolderview.cpp:43