summaryrefslogtreecommitdiffstats
path: root/src/libs/threadimageio/loadsavetask.h
blob: 833f86fa47c05c347dcb0fd106f8afabbf4edfeb (plain)
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/* ============================================================
 *
 * This file is a part of digiKam project
 * http://www.digikam.org
 *
 * Date        : 2006-01-20
 * Description : image file IO threaded interface.
 *
 * Copyright (C) 2005-2007 by Marcel Wiesweg <marcel.wiesweg@gmx.de>
 * Copyright (C) 2005-2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
 *
 * This program is free software; you can redistribute it
 * and/or modify it under the terms of the GNU General
 * Public License as published by the Free Software Foundation;
 * either version 2, or (at your option)
 * any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * ============================================================ */


#ifndef LOAD_SAVE_TASK_H
#define LOAD_SAVE_TASK_H

// TQt includes.

#include <tqevent.h>

// Local includes.

#include "dimg.h"
#include "dimgloaderobserver.h"
#include "loadingdescription.h"
#include "loadingcache.h"

namespace Digikam
{

class LoadSaveThread;

class LoadSaveTask
{
public:

    LoadSaveTask(LoadSaveThread* thread)
        : m_thread(thread)
        {};
    virtual ~LoadSaveTask() {};

    virtual void execute() = 0;

    enum TaskType
    {
        TaskTypeLoading,
        TaskTypeSaving
    };

    virtual TaskType type() = 0;

protected:

    LoadSaveThread *m_thread;
};

//---------------------------------------------------------------------------------------------------

class NotifyEvent : public TQCustomEvent
{
public:

    static TQEvent::Type notifyEventId()
        { return TQEvent::User; };

    NotifyEvent() : TQCustomEvent(notifyEventId()) {};

    virtual void notify(LoadSaveThread *thread) = 0;
};

//---------------------------------------------------------------------------------------------------

class ProgressEvent : public NotifyEvent
{
public:

    ProgressEvent(float progress)
        : m_progress(progress)
        {};

protected:

    float m_progress;
};

//---------------------------------------------------------------------------------------------------

class LoadingProgressEvent : public ProgressEvent
{
public:

    LoadingProgressEvent(const LoadingDescription &loadingDescription, float progress)
        : ProgressEvent(progress),
          m_loadingDescription(loadingDescription)
        {};

    virtual void notify(LoadSaveThread *thread);

private:

    LoadingDescription m_loadingDescription;
};

//---------------------------------------------------------------------------------------------------

class SavingProgressEvent : public ProgressEvent
{
public:

    SavingProgressEvent(const TQString& filePath, float progress)
        : ProgressEvent(progress),
          m_filePath(filePath)
        {};

    virtual void notify(LoadSaveThread *thread);

private:

    TQString m_filePath;
};

//---------------------------------------------------------------------------------------------------

class StartedLoadingEvent : public NotifyEvent
{
public:

    StartedLoadingEvent(const LoadingDescription &loadingDescription)
        : m_loadingDescription(loadingDescription)
        {};

    virtual void notify(LoadSaveThread *thread);

private:

    LoadingDescription m_loadingDescription;
};

//---------------------------------------------------------------------------------------------------

class StartedSavingEvent : public NotifyEvent
{
public:

    StartedSavingEvent(const TQString& filePath)
    : m_filePath(filePath)
    {};

    virtual void notify(LoadSaveThread *thread);

private:

    TQString m_filePath;
};

//---------------------------------------------------------------------------------------------------

class LoadedEvent : public NotifyEvent
{
public:

    LoadedEvent(const LoadingDescription &loadingDescription, DImg &img)
        : m_loadingDescription(loadingDescription), m_img(img)
        {};

    virtual void notify(LoadSaveThread *thread);

private:

    LoadingDescription m_loadingDescription;
    DImg    m_img;
};

//---------------------------------------------------------------------------------------------------

class MoreCompleteLoadingAvailableEvent : public NotifyEvent
{
public:

    MoreCompleteLoadingAvailableEvent(const LoadingDescription &oldLoadingDescription,
                                      const LoadingDescription &newLoadingDescription)
        : m_oldDescription(oldLoadingDescription), m_newDescription(newLoadingDescription)
        {};

    virtual void notify(LoadSaveThread *thread);

private:

    LoadingDescription m_oldDescription;
    LoadingDescription m_newDescription;
};

//---------------------------------------------------------------------------------------------------

class LoadingTask : public LoadSaveTask, public DImgLoaderObserver
{
public:

    enum LoadingTaskStatus
    {
        LoadingTaskStatusLoading,
        LoadingTaskStatusPreloading,
        LoadingTaskStatusStopping
    };

    LoadingTask(LoadSaveThread* thread, LoadingDescription description,
                LoadingTaskStatus loadingTaskStatus = LoadingTaskStatusLoading)
        : LoadSaveTask(thread), m_loadingDescription(description), m_loadingTaskStatus(loadingTaskStatus)
        {}

    // LoadSaveTask

    virtual void execute();
    virtual TaskType type();

    // DImgLoaderObserver

    virtual void progressInfo(const DImg *, float progress);
    virtual bool continueQuery(const DImg *);
    virtual bool isShuttingDown();

    virtual void setStatus(LoadingTaskStatus status);

    LoadingTaskStatus status() const
    {
        return m_loadingTaskStatus;
    }

    TQString filePath() const
    {
        return m_loadingDescription.filePath;
    }

    LoadingDescription loadingDescription() const
    {
        return m_loadingDescription;
    }

protected:

    LoadingDescription m_loadingDescription;
    LoadingTaskStatus m_loadingTaskStatus;
};

//---------------------------------------------------------------------------------------------------

class SharedLoadingTask : public LoadingTask, public LoadingProcess, public LoadingProcessListener
{
public:

    SharedLoadingTask(LoadSaveThread* thread, LoadingDescription description,
                      LoadSaveThread::AccessMode mode = LoadSaveThread::AccessModeReadWrite,
                      LoadingTaskStatus loadingTaskStatus = LoadingTaskStatusLoading)
        : LoadingTask(thread, description, loadingTaskStatus),
          m_accessMode(mode), m_completed(false), m_usedProcess(0)
        {}

    virtual void execute();
    virtual void progressInfo(const DImg *, float progress);
    virtual bool continueQuery(const DImg *);
    virtual void setStatus(LoadingTaskStatus status);

    // LoadingProcess

    virtual bool completed();
    virtual TQString filePath();
    virtual TQString cacheKey();
    virtual void addListener(LoadingProcessListener *listener);
    virtual void removeListener(LoadingProcessListener *listener);
    virtual void notifyNewLoadingProcess(LoadingProcess *process, LoadingDescription description);

    // LoadingProcessListener

    virtual bool querySendNotifyEvent();
    virtual TQObject *eventReceiver();
    virtual LoadSaveThread::AccessMode accessMode();

protected:

    LoadSaveThread::AccessMode m_accessMode;
    bool m_completed;
    LoadingProcess *m_usedProcess;
    TQPtrList<LoadingProcessListener> m_listeners;
};

//---------------------------------------------------------------------------------------------------

class SavedEvent : public NotifyEvent
{
public:

    SavedEvent(const TQString &filePath, bool success)
        : m_filePath(filePath), m_success(success)
        {};

    virtual void notify(LoadSaveThread *thread);

private:

    TQString m_filePath;
    bool m_success;
};

//---------------------------------------------------------------------------------------------------

class SavingTask : public LoadSaveTask, public DImgLoaderObserver
{
public:

    enum SavingTaskStatus
    {
        SavingTaskStatusSaving,
        SavingTaskStatusStopping
    };

    SavingTask(LoadSaveThread* thread, DImg &img, const TQString &filePath, const TQString &format)
        : LoadSaveTask(thread), m_img(img), m_filePath(filePath), m_format(format)
        {};

    virtual void execute();
    virtual TaskType type();

    virtual void progressInfo(const DImg *, float progress);
    virtual bool continueQuery(const DImg *);

    virtual void setStatus(SavingTaskStatus status);

    SavingTaskStatus status() const
    {
        return m_savingTaskStatus;
    }

    TQString filePath() const
    {
        return m_filePath;
    }

private:

    DImg        m_img;
    TQString     m_filePath;
    TQString     m_format;
    SavingTaskStatus m_savingTaskStatus;
};

}   // namespace Digikam

#endif // LOAD_SAVE_TASK_H