~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to libs/threadimageio/loadsavetask.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-12-21 23:19:11 UTC
  • mfrom: (1.2.33 upstream) (3.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20101221231911-z9jip7s5aht1jqn9
Tags: 2:1.7.0-1ubuntu1
* Merge from Debian Experimental. Remaining Ubuntu changes:
  - Export .pot name and copy to plugins in debian/rules
  - Version build-depends on kipi-plugins-dev to ensure build is against the
    same version on all archs
* Drop debian/patches/kubuntu_01_linker.diff, incoporated upstream
* Remove patches directory and unused patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
void LoadingTask::execute()
45
45
{
46
46
    if (m_loadingTaskStatus == LoadingTaskStatusStopping)
 
47
    {
47
48
        return;
 
49
    }
 
50
 
48
51
    DImg img(m_loadingDescription.filePath, this, m_loadingDescription.rawDecodingSettings);
49
52
    m_thread->taskHasFinished();
50
53
    m_thread->imageLoaded(m_loadingDescription, img);
55
58
    return TaskTypeLoading;
56
59
}
57
60
 
58
 
void LoadingTask::progressInfo(const DImg *, float progress)
 
61
void LoadingTask::progressInfo(const DImg*, float progress)
59
62
{
60
63
    if (m_loadingTaskStatus == LoadingTaskStatusLoading)
61
64
    {
62
65
        if (m_thread->querySendNotifyEvent())
 
66
        {
63
67
            m_thread->loadingProgress(m_loadingDescription, progress);
 
68
        }
64
69
    }
65
70
}
66
71
 
67
 
bool LoadingTask::continueQuery(const DImg *)
 
72
bool LoadingTask::continueQuery(const DImg*)
68
73
{
69
74
    return m_loadingTaskStatus != LoadingTaskStatusStopping;
70
75
}
78
83
 
79
84
SharedLoadingTask::SharedLoadingTask(LoadSaveThread* thread, LoadingDescription description,
80
85
                                     LoadSaveThread::AccessMode mode, LoadingTaskStatus loadingTaskStatus)
81
 
                  : LoadingTask(thread, description, loadingTaskStatus),
82
 
                   m_completed(false), m_accessMode(mode), m_usedProcess(0), m_resultLoadingDescription(description)
 
86
    : LoadingTask(thread, description, loadingTaskStatus),
 
87
      m_completed(false), m_accessMode(mode), m_usedProcess(0), m_resultLoadingDescription(description)
83
88
{
84
89
    if (m_accessMode == LoadSaveThread::AccessModeRead && needsPostProcessing())
 
90
    {
85
91
        m_accessMode = LoadSaveThread::AccessModeReadWrite;
 
92
    }
86
93
}
87
94
 
88
95
void SharedLoadingTask::execute()
89
96
{
90
97
    if (m_loadingTaskStatus == LoadingTaskStatusStopping)
 
98
    {
91
99
        return;
 
100
    }
 
101
 
92
102
    // send StartedLoadingEvent from each single Task, not via LoadingProcess list
93
103
    m_thread->imageStartedLoading(m_loadingDescription);
94
104
 
95
 
    LoadingCache *cache = LoadingCache::cache();
 
105
    LoadingCache* cache = LoadingCache::cache();
96
106
    {
97
107
        LoadingCache::CacheLock lock(cache);
98
108
 
99
109
        // find possible cached images
100
 
        DImg *cachedImg = 0;
 
110
        DImg* cachedImg = 0;
101
111
        QStringList lookupKeys = m_loadingDescription.lookupCacheKeys();
102
112
        foreach (const QString& key, lookupKeys)
103
113
        {
106
116
                if (m_loadingDescription.needCheckRawDecoding())
107
117
                {
108
118
                    if (cachedImg->rawDecodingSettings() == m_loadingDescription.rawDecodingSettings)
 
119
                    {
109
120
                        break;
 
121
                    }
110
122
                    else
 
123
                    {
111
124
                        cachedImg = 0;
 
125
                    }
112
126
                }
113
127
                else
114
128
                {
121
135
        {
122
136
            // image is found in image cache, loading is successful
123
137
            m_img = *cachedImg;
 
138
 
124
139
            if (accessMode() == LoadSaveThread::AccessModeReadWrite)
 
140
            {
125
141
                m_img = m_img.copy();
 
142
            }
 
143
 
126
144
            // continues after else clause...
127
145
        }
128
146
        else
129
147
        {
130
148
            // find possible running loading process
131
149
            m_usedProcess = 0;
132
 
            for ( QStringList::Iterator it = lookupKeys.begin(); it != lookupKeys.end(); ++it ) {
 
150
 
 
151
            for ( QStringList::Iterator it = lookupKeys.begin(); it != lookupKeys.end(); ++it )
 
152
            {
133
153
                if ( (m_usedProcess = cache->retrieveLoadingProcess(*it)) )
134
154
                {
135
155
                    break;
143
163
                // attach this thread to the other thread, wait until loading
144
164
                // has finished.
145
165
                m_usedProcess->addListener(this);
 
166
 
146
167
                // break loop when either the loading has completed, or this task is being stopped
147
168
                while ( m_loadingTaskStatus != LoadingTaskStatusStopping && m_usedProcess && !m_usedProcess->completed() )
 
169
                {
148
170
                    lock.timedWait();
 
171
                }
 
172
 
149
173
                // remove listener from process
150
174
                if (m_usedProcess)
 
175
                {
151
176
                    m_usedProcess->removeListener(this);
 
177
                }
 
178
 
152
179
                // wake up the process which is waiting until all listeners have removed themselves
153
180
                lock.wakeAll();
154
181
                // set to 0, as checked in setStatus
187
214
    bool isCached = false;
188
215
    {
189
216
        LoadingCache::CacheLock lock(cache);
 
217
 
190
218
        // put (valid) image into cache of loaded images
191
219
        if (!m_img.isNull())
 
220
        {
192
221
            isCached = cache->putImage(m_loadingDescription.cacheKey(), new DImg(m_img), m_loadingDescription.filePath);
 
222
        }
 
223
 
193
224
        // remove this from the list of loading processes in cache
194
225
        cache->removeLoadingProcess(this);
195
226
    }
203
234
        // dispatch image to all listeners, including this
204
235
        for (int i=0; i<m_listeners.count(); ++i)
205
236
        {
206
 
            LoadingProcessListener *l = m_listeners[i];
 
237
            LoadingProcessListener* l = m_listeners[i];
 
238
 
207
239
            if (l->accessMode() == LoadSaveThread::AccessModeReadWrite)
208
240
            {
209
241
                // If a listener requested ReadWrite access, it gets a deep copy.
221
253
        removeListener(this);
222
254
        // wake all listeners waiting on cache condVar, so that they remove themselves
223
255
        lock.wakeAll();
 
256
 
224
257
        // wait until all listeners have removed themselves
225
258
        while (m_listeners.count() != 0)
 
259
        {
226
260
            lock.timedWait();
 
261
        }
 
262
 
227
263
        // set to 0, as checked in setStatus
228
264
        m_usedProcess = 0;
229
265
    }
296
332
    removeListener(this);
297
333
}
298
334
 
299
 
void SharedLoadingTask::progressInfo(const DImg *, float progress)
 
335
void SharedLoadingTask::progressInfo(const DImg*, float progress)
300
336
{
301
337
    if (m_loadingTaskStatus == LoadingTaskStatusLoading)
302
338
    {
303
 
        LoadingCache *cache = LoadingCache::cache();
 
339
        LoadingCache* cache = LoadingCache::cache();
304
340
        LoadingCache::CacheLock lock(cache);
305
341
 
306
342
        for (int i=0; i<m_listeners.size(); ++i)
307
343
        {
308
 
            LoadingProcessListener *l = m_listeners[i];
 
344
            LoadingProcessListener* l = m_listeners[i];
 
345
 
309
346
            if (l->querySendNotifyEvent())
 
347
            {
310
348
                l->loadSaveNotifier()->loadingProgress(m_loadingDescription, progress);
 
349
            }
311
350
        }
312
351
    }
313
352
}
314
353
 
315
 
bool SharedLoadingTask::continueQuery(const DImg *)
 
354
bool SharedLoadingTask::continueQuery(const DImg*)
316
355
{
317
356
    // If this is called, the thread is currently loading an image.
318
357
    // In shared loading, we cannot stop until all listeners have been removed as well
322
361
void SharedLoadingTask::setStatus(LoadingTaskStatus status)
323
362
{
324
363
    m_loadingTaskStatus = status;
 
364
 
325
365
    if (m_loadingTaskStatus == LoadingTaskStatusStopping)
326
366
    {
327
 
        LoadingCache *cache = LoadingCache::cache();
 
367
        LoadingCache* cache = LoadingCache::cache();
328
368
        LoadingCache::CacheLock lock(cache);
329
369
 
330
370
        // check for m_usedProcess, to avoid race condition that it has finished before
355
395
    return m_loadingDescription.cacheKey();
356
396
}
357
397
 
358
 
void SharedLoadingTask::addListener(LoadingProcessListener *listener)
 
398
void SharedLoadingTask::addListener(LoadingProcessListener* listener)
359
399
{
360
400
    m_listeners << listener;
361
401
}
362
402
 
363
 
void SharedLoadingTask::removeListener(LoadingProcessListener *listener)
 
403
void SharedLoadingTask::removeListener(LoadingProcessListener* listener)
364
404
{
365
405
    m_listeners.removeAll(listener);
366
406
}
367
407
 
368
 
void SharedLoadingTask::notifyNewLoadingProcess(LoadingProcess *process, LoadingDescription description)
 
408
void SharedLoadingTask::notifyNewLoadingProcess(LoadingProcess* process, LoadingDescription description)
369
409
{
370
410
    // Ok, we are notified that another task has been started in another thread.
371
411
    // We are of course only interested if the task loads the same file,
391
431
    return m_thread->querySendNotifyEvent();
392
432
}
393
433
 
394
 
LoadSaveNotifier *SharedLoadingTask::loadSaveNotifier()
 
434
LoadSaveNotifier* SharedLoadingTask::loadSaveNotifier()
395
435
{
396
436
    return m_thread;
397
437
}
416
456
    return TaskTypeSaving;
417
457
}
418
458
 
419
 
void SavingTask::progressInfo(const DImg *, float progress)
 
459
void SavingTask::progressInfo(const DImg*, float progress)
420
460
{
421
461
    if (m_thread->querySendNotifyEvent())
 
462
    {
422
463
        m_thread->savingProgress(m_filePath, progress);
 
464
    }
423
465
}
424
466
 
425
 
bool SavingTask::continueQuery(const DImg *)
 
467
bool SavingTask::continueQuery(const DImg*)
426
468
{
427
469
    return m_savingTaskStatus != SavingTaskStatusStopping;
428
470
}