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

« back to all changes in this revision

Viewing changes to libs/threadimageio/thumbnailloadthread.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:
144
144
K_GLOBAL_STATIC(ThumbnailLoadThread, defaultThumbBarObject)
145
145
 
146
146
ThumbnailLoadThread::ThumbnailLoadThread()
147
 
                   : d(new ThumbnailLoadThreadPriv)
 
147
    : d(new ThumbnailLoadThreadPriv)
148
148
{
149
149
    static_d->firstThreadCreated = true;
150
150
    d->creator = new ThumbnailCreator(static_d->storageMethod);
 
151
 
151
152
    if (static_d->provider)
 
153
    {
152
154
        d->creator->setThumbnailInfoProvider(static_d->provider);
 
155
    }
 
156
 
153
157
    d->creator->setOnlyLargeThumbnails(true);
154
158
    d->creator->setRemoveAlphaChannel(true);
155
159
 
192
196
    if (static_d->firstThreadCreated)
193
197
    {
194
198
        kError() << "Call initializeThumbnailDatabase at application start. "
195
 
                    "There are already thumbnail loading threads created, "
196
 
                    "and these will not be switched to use the database. ";
 
199
                 "There are already thumbnail loading threads created, "
 
200
                 "and these will not be switched to use the database. ";
197
201
    }
 
202
 
198
203
    ThumbnailDatabaseAccess::setParameters(params);
 
204
 
199
205
    if (ThumbnailDatabaseAccess::checkReadyForUse(0))
200
206
    {
201
207
        kDebug() << "Thumbnail db ready for use";
227
233
int ThumbnailLoadThread::maximumThumbnailPixmapSize(bool highlight)
228
234
{
229
235
    if (highlight)
 
236
    {
230
237
        return ThumbnailSize::Huge;
 
238
    }
231
239
    else
232
 
        return ThumbnailSize::Huge + 2; // see slotThumbnailLoaded
 
240
    {
 
241
        return ThumbnailSize::Huge + 2;    // see slotThumbnailLoaded
 
242
    }
233
243
}
234
244
 
235
245
void ThumbnailLoadThread::setExifRotate(int exifRotate)
257
267
    d->highlight = highlight;
258
268
}
259
269
 
260
 
ThumbnailCreator *ThumbnailLoadThread::thumbnailCreator() const
 
270
ThumbnailCreator* ThumbnailLoadThread::thumbnailCreator() const
261
271
{
262
272
    return d->creator;
263
273
}
275
285
int ThumbnailLoadThread::thumbnailPixmapSize(bool withHighlight, int size)
276
286
{
277
287
    if (withHighlight && size >= 10)
 
288
    {
278
289
        return size + 2;
 
290
    }
 
291
 
279
292
    return size;
280
293
}
281
294
 
287
300
int ThumbnailLoadThread::ThumbnailLoadThreadPriv::pixmapSizeForThumbnailSize(int thumbnailSize) const
288
301
{
289
302
    if (hasHighlightingBorder())
 
303
    {
290
304
        return thumbnailSize + 2;
 
305
    }
 
306
 
291
307
    return thumbnailSize;
292
308
}
293
309
 
295
311
{
296
312
    // bug #206666: Do not cut off one-pixel line for highlighting border
297
313
    if (hasHighlightingBorder())
 
314
    {
298
315
        return pixmapSize - 2;
 
316
    }
 
317
 
299
318
    return pixmapSize;
300
319
}
301
320
 
323
342
    {
324
343
        LoadingCache* cache = LoadingCache::cache();
325
344
        LoadingCache::CacheLock lock(cache);
 
345
 
326
346
        if (cache->hasThumbnailPixmap(cacheKey))
 
347
        {
327
348
            return false;
 
349
        }
328
350
    }
329
351
 
330
352
    {
331
353
        QMutexLocker lock(&resultsMutex);
 
354
 
332
355
        if (collectedResults.contains(cacheKey))
 
356
        {
333
357
            return false;
 
358
        }
334
359
    }
335
360
    return true;
336
361
}
337
362
 
338
363
QList<LoadingDescription> ThumbnailLoadThread::ThumbnailLoadThreadPriv::makeDescriptions(const QStringList& filePaths,
339
 
                                                                                         int size)
 
364
        int size)
340
365
{
341
366
    QList<LoadingDescription> descriptions;
342
367
    {
344
369
        foreach(const QString& filePath, filePaths)
345
370
        {
346
371
            description.filePath = filePath;
 
372
 
347
373
            if (!checkDescription(description))
 
374
            {
348
375
                continue;
 
376
            }
 
377
 
349
378
            descriptions << description;
350
379
        }
351
380
    }
359
388
    QString cacheKey               = description.cacheKey();
360
389
 
361
390
    {
362
 
        LoadingCache *cache = LoadingCache::cache();
 
391
        LoadingCache* cache = LoadingCache::cache();
363
392
        LoadingCache::CacheLock lock(cache);
364
393
        pix = cache->retrieveThumbnailPixmap(cacheKey);
365
394
    }
373
402
    {
374
403
        // If there is a result waiting for conversion to pixmap, return false - pixmap will come shortly
375
404
        QMutexLocker lock(&d->resultsMutex);
 
405
 
376
406
        if (d->collectedResults.contains(cacheKey))
 
407
        {
377
408
            return false;
 
409
        }
378
410
    }
379
411
 
380
412
    load(description);
407
439
    {
408
440
        // If there is a result waiting for conversion to pixmap, return false - pixmap will come shortly
409
441
        QMutexLocker lock(&d->resultsMutex);
 
442
 
410
443
        if (d->collectedResults.contains(cacheKey))
411
444
        {
412
445
            return;
440
473
void ThumbnailLoadThread::preloadGroup(const QStringList& filePaths, int size)
441
474
{
442
475
    if (!checkSize(size))
 
476
    {
443
477
        return;
 
478
    }
444
479
 
445
480
    QList<LoadingDescription> descriptions = d->makeDescriptions(filePaths, size);
446
481
    ManagedLoadSaveThread::preloadThumbnailGroup(descriptions);
454
489
void ThumbnailLoadThread::preload(const QString& filePath, int size)
455
490
{
456
491
    LoadingDescription description = d->createLoadingDescription(filePath, size);
 
492
 
457
493
    if (d->checkDescription(description))
 
494
    {
458
495
        load(description, true);
 
496
    }
459
497
}
460
498
 
461
499
void ThumbnailLoadThread::load(const LoadingDescription& desc)
466
504
void ThumbnailLoadThread::load(const LoadingDescription& description, bool preload)
467
505
{
468
506
    if (!checkSize(description.previewParameters.size))
 
507
    {
469
508
        return;
 
509
    }
470
510
 
471
511
    if (preload)
 
512
    {
472
513
        ManagedLoadSaveThread::preloadThumbnail(description);
 
514
    }
473
515
    else
 
516
    {
474
517
        ManagedLoadSaveThread::loadThumbnail(description);
 
518
    }
475
519
}
476
520
 
477
521
bool ThumbnailLoadThread::checkSize(int size)
478
522
{
479
523
    size = d->thumbnailSizeForPixmapSize(size);
 
524
 
480
525
    if (size <= 0)
481
526
    {
482
527
        kError() << "ThumbnailLoadThread::load: No thumbnail size specified. Refusing to load thumbnail.";
488
533
                 << " is larger than " << ThumbnailSize::Huge << ". Refusing to load.";
489
534
        return false;
490
535
    }
 
536
 
491
537
    return true;
492
538
}
493
539
 
499
545
    ManagedLoadSaveThread::thumbnailLoaded(loadingDescription, img);
500
546
 
501
547
    if (!d->wantPixmap)
 
548
    {
502
549
        return;
 
550
    }
503
551
 
504
552
    // Store result in our list and fire one signal
505
553
    // This means there can be several results per pixmap,
506
554
    // to speed up cases where inter-thread communication is the limiting factor
507
555
    QMutexLocker lock(&d->resultsMutex);
508
556
    d->collectedResults.insert(loadingDescription.cacheKey(), ThumbnailResult(loadingDescription, img));
 
557
 
509
558
    // only sent signal when flag indicates there is no signal on the way currently
510
559
    if (!d->notifiedForResults)
511
560
    {
535
584
void ThumbnailLoadThread::slotThumbnailLoaded(const LoadingDescription& description, const QImage& thumb)
536
585
{
537
586
    if (thumb.isNull())
 
587
    {
538
588
        loadWithKDE(description);
 
589
    }
539
590
 
540
591
    QPixmap pix;
541
592
 
576
627
void ThumbnailLoadThread::startKdePreviewJob()
577
628
{
578
629
    if (d->kdeJob || d->kdeTodo.isEmpty())
 
630
    {
579
631
        return;
 
632
    }
580
633
 
581
634
    KUrl::List list;
582
635
    foreach (const LoadingDescription& description, d->kdeTodo)
588
641
    d->kdeTodo.clear();
589
642
    d->kdeJob = KIO::filePreview(list, d->creator->storedSize()); // dont know if size 0 is allowed
590
643
 
591
 
    connect(d->kdeJob, SIGNAL(gotPreview(const KFileItem &, const QPixmap &)),
592
 
            this, SLOT(gotKDEPreview(const KFileItem &, const QPixmap &)));
 
644
    connect(d->kdeJob, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)),
 
645
            this, SLOT(gotKDEPreview(const KFileItem&, const QPixmap&)));
593
646
 
594
 
    connect(d->kdeJob, SIGNAL(failed(const KFileItem &)),
595
 
            this, SLOT(failedKDEPreview(const KFileItem &)));
 
647
    connect(d->kdeJob, SIGNAL(failed(const KFileItem&)),
 
648
            this, SLOT(failedKDEPreview(const KFileItem&)));
596
649
 
597
650
    connect(d->kdeJob, SIGNAL(finished(KJob*)),
598
651
            this, SLOT(kdePreviewFinished(KJob*)));
641
694
    QPixmap pix;
642
695
 
643
696
    KMimeType::Ptr mimeType = KMimeType::findByPath(description.filePath);
 
697
 
644
698
    if (mimeType)
645
699
    {
646
700
        pix = DesktopIcon(mimeType->iconName(), KIconLoader::SizeEnormous);
684
738
 
685
739
    QSize size(pix.size());
686
740
    size.scale(description.previewParameters.size, description.previewParameters.size, Qt::KeepAspectRatio);
 
741
 
687
742
    if (!pix.isNull() && size.width() < pix.width() && size.height() < pix.height())
688
743
    {
689
744
        // only scale down
708
763
    }
709
764
 
710
765
    ThumbnailCreator creator(static_d->storageMethod);
 
766
 
711
767
    if (static_d->provider)
712
768
    {
713
769
        creator.setThumbnailInfoProvider(static_d->provider);
714
770
    }
 
771
 
715
772
    creator.deleteThumbnailsFromDisk(filePath);
716
773
}
717
774