1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215 | /* ============================================================
*
* This file is a part of digiKam project
* https://www.digikam.org
*
* Date : 2006-01-16
* Description : image file IO threaded interface.
*
* SPDX-FileCopyrightText: 2005-2013 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
* SPDX-FileCopyrightText: 2005-2025 by Gilles Caulier <caulier dot gilles at gmail dot com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* ============================================================ */
#pragma once
// Local includes
#include "loadsavethread.h"
namespace Digikam
{
class LoadingTask;
class LoadSaveTask;
class DIGIKAM_EXPORT ManagedLoadSaveThread : public LoadSaveThread
{
Q_OBJECT
public:
enum LoadingPolicy
{
/**
* Load image immediately, remove and stop all previous loading tasks.
*/
LoadingPolicyFirstRemovePrevious,
/**
* Prepend loading in front of all other tasks, but wait for the current task to finish.
* No other tasks will be removed, preloading tasks will be stopped and postponed.
*/
LoadingPolicyPrepend,
/**
* Prepend in front of all other tasks (not touching the current task).
* Do not check for duplicate tasks, do not check for preloading tasks.
*/
LoadingPolicySimplePrepend,
/**
* Append loading task to the end of the list, but in front of all preloading tasks.
* No other tasks will be removed, preloading tasks will be stopped and postponed.
* This is similar to the simple load() operation from LoadSaveThread, except for the
* special care taken for preloading.
*/
LoadingPolicyAppend,
/**
* Append to the lists of tasks.
* Do not check for duplicate tasks, do not check for preloading tasks.
*/
LoadingPolicySimpleAppend,
/**
* Preload image, i.e. load it with low priority when no other tasks are scheduled.
* All other tasks will take precedence, and preloading tasks will be stopped and
* postponed when another task is added.
* No progress info will be sent for preloaded images
*/
LoadingPolicyPreload
};
enum TerminationPolicy
{
/**
* Wait for saving tasks, stop and remove loading tasks
* This is the default.
*/
TerminationPolicyTerminateLoading,
/**
* Wait for loading and saving tasks, stop and remove preloading tasks
*/
TerminationPolicyTerminatePreloading,
/**
* Wait for all pending tasks
*/
TerminationPolicyWait,
/**
* Stop all pending tasks
*/
TerminationPolicyTerminateAll
};
enum LoadingTaskFilter
{
/**
* filter all loading tasks
*/
LoadingTaskFilterAll,
/**
* filter only tasks with preloading policy
*/
LoadingTaskFilterPreloading
};
/**
* used by SharedLoadSaveThread only
*/
enum LoadingMode
{
/**
* no sharing of loading process, no caching of image
*/
LoadingModeNormal,
/**
* loading process is shared, image is cached
*/
LoadingModeShared
};
public:
/**
* Termination is controlled by setting the TerminationPolicy
* Default is TerminationPolicyTerminateLoading
*/
explicit ManagedLoadSaveThread(QObject* const parent = nullptr);
~ManagedLoadSaveThread() override;
/**
* Append a task to load the given file to the task list.
* If there is already a task for the given file, it will possibly be rescheduled,
* but no second task will be added.
* Only loading tasks will - if required by the policy - be stopped or removed,
* saving tasks will not be touched.
*/
void load(const LoadingDescription& description);<--- Derived function 'ManagedLoadSaveThread::load'<--- Derived function 'ManagedLoadSaveThread::load'
void load(const LoadingDescription& description, LoadingPolicy policy);
/**
* Stop and remove tasks filtered by filePath and policy.
* If filePath isNull, applies to all file paths.
*/
void stopLoading(const QString& filePath = QString(),
LoadingTaskFilter filter = LoadingTaskFilterAll);
/**
* Same than previous method, but Stop and remove tasks filtered by LoadingDescription.
*/
void stopLoading(const LoadingDescription& desc,
LoadingTaskFilter filter = LoadingTaskFilterAll);
/**
* Stop and remove saving tasks filtered by filePath.
* If filePath isNull, applies to all file paths.
*/
void stopSaving(const QString& filePath = QString());
void stopAllTasks();
/**
* Append a task to save the image to the task list
*/
void save(const DImg& image, const QString& filePath, const QString& format);<--- Derived function 'ManagedLoadSaveThread::save'<--- Derived function 'ManagedLoadSaveThread::save'
void setTerminationPolicy(TerminationPolicy terminationPolicy);
TerminationPolicy terminationPolicy() const;
/**
* Set the loading policy.
* Default is LoadingPolicyAppend.
* You can override the default value for each operation.
*/
void setLoadingPolicy(LoadingPolicy policy);
LoadingPolicy loadingPolicy() const;
protected:
void shutDown();<--- Derived function 'ManagedLoadSaveThread::shutDown'
void load(const LoadingDescription& description, LoadingMode loadingMode,
AccessMode mode = AccessModeReadWrite);
void load(const LoadingDescription& description, LoadingMode loadingMode,
LoadingPolicy policy, AccessMode mode = AccessModeReadWrite);
void loadPreview(const LoadingDescription& description, LoadingPolicy policy);
void loadThumbnail(const LoadingDescription& description);
void preloadThumbnail(const LoadingDescription& description);
void preloadThumbnailGroup(const QList<LoadingDescription>& descriptions);
void prependThumbnailGroup(const QList<LoadingDescription>& descriptions);
protected:
LoadingPolicy m_loadingPolicy = LoadingPolicyAppend;
TerminationPolicy m_terminationPolicy = TerminationPolicyTerminateLoading;
private:
LoadingTask* checkLoadingTask(LoadSaveTask* const task, LoadingTaskFilter filter) const;
LoadingTask* findExistingTask(const LoadingDescription& description) const;
LoadingTask* createLoadingTask(const LoadingDescription& description,
bool preloading,
LoadingMode loadingMode,
AccessMode accessMode);
void removeLoadingTasks(const LoadingDescription& description, LoadingTaskFilter filter);
private:
// Disable
ManagedLoadSaveThread(const ManagedLoadSaveThread&) = delete;
ManagedLoadSaveThread& operator=(const ManagedLoadSaveThread&) = delete;
};
} // namespace Digikam
|