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

« back to all changes in this revision

Viewing changes to digikam/metadatamanager.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:
48
48
namespace Digikam
49
49
{
50
50
 
51
 
class MetadataManagerCreator { public: MetadataManager object; };
 
51
class MetadataManagerCreator
 
52
{
 
53
public:
 
54
    MetadataManager object;
 
55
};
52
56
K_GLOBAL_STATIC(MetadataManagerCreator, metadataManagercreator)
53
57
 
54
58
MetadataManager* MetadataManager::instance()
57
61
}
58
62
 
59
63
MetadataManager::MetadataManager()
60
 
               : d(new MetadataManagerPriv(this))
 
64
    : d(new MetadataManagerPriv(this))
61
65
{
62
 
    connect(d, SIGNAL(progressMessageChanged(const QString &)),
63
 
            this, SIGNAL(progressMessageChanged(const QString &)));
 
66
    connect(d, SIGNAL(progressMessageChanged(const QString&)),
 
67
            this, SIGNAL(progressMessageChanged(const QString&)));
64
68
 
65
69
    connect(d, SIGNAL(progressValueChanged(float)),
66
70
            this, SIGNAL(progressValueChanged(float)));
68
72
    connect(d, SIGNAL(progressFinished()),
69
73
            this, SIGNAL(progressFinished()));
70
74
 
71
 
    connect(d->fileWorker, SIGNAL(orientationChangeFailed(const QStringList &)),
72
 
            this, SIGNAL(orientationChangeFailed(const QStringList &)));
 
75
    connect(d->fileWorker, SIGNAL(orientationChangeFailed(const QStringList&)),
 
76
            this, SIGNAL(orientationChangeFailed(const QStringList&)));
73
77
}
74
78
 
75
79
MetadataManager::~MetadataManager()
96
100
    foreach (int id, ids)
97
101
    {
98
102
        ImageInfo info(id);
 
103
 
99
104
        if (!info.isNull())
100
105
        {
101
106
            infos << info;
178
183
// --------------------------------------------------------------------------------------
179
184
 
180
185
MetadataManager::MetadataManagerPriv::MetadataManagerPriv(MetadataManager* q)
181
 
                                    : q(q)
 
186
    : q(q)
182
187
{
183
188
    dbWorker   = new MetadataManagerDatabaseWorker(this);
184
189
    fileWorker = new MetadataManagerFileWorker(this);
237
242
bool MetadataManager::MetadataManagerPriv::shallSendForWriting(qlonglong id)
238
243
{
239
244
    QMutexLocker lock(&mutex);
 
245
 
240
246
    if (scheduledToWrite.contains(id))
 
247
    {
241
248
        return false;
 
249
    }
 
250
 
242
251
    scheduledToWrite << id;
243
252
    return true;
244
253
}
246
255
void MetadataManager::MetadataManagerPriv::dbProcessedOne()
247
256
{
248
257
    if ( (dbDone++ % 10) == 0)
 
258
    {
249
259
        updateProgress();
 
260
    }
250
261
}
251
262
 
252
263
void MetadataManager::MetadataManagerPriv::dbProcessed(int numberOfInfos)
307
318
void MetadataManager::MetadataManagerPriv::updateProgressMessage()
308
319
{
309
320
    QString message;
 
321
 
310
322
    if (dbTodo && writerTodo)
 
323
    {
311
324
        message = dbMessage;
 
325
    }
312
326
    else if (dbTodo)
 
327
    {
313
328
        message = dbMessage;
 
329
    }
314
330
    else if (writerTodo)
 
331
    {
315
332
        message = writerMessage;
 
333
    }
 
334
 
316
335
    emit progressMessageChanged(message);
317
336
}
318
337
 
323
342
        emit progressFinished();
324
343
        return;
325
344
    }
 
345
 
326
346
    // we use a weighting factor of 10 for file writing
327
347
    float allTodo = dbTodo + 10*writerTodo;
328
348
    float allDone = dbDone + 10*writerDone;
330
350
    emit progressValueChanged(percent);
331
351
}
332
352
 
333
 
void MetadataManager::MetadataManagerPriv::slotImageDataChanged(const QString &path, bool removeThumbnails, bool notifyCache)
 
353
void MetadataManager::MetadataManagerPriv::slotImageDataChanged(const QString& path, bool removeThumbnails, bool notifyCache)
334
354
{
335
355
    // must be done from the UI thread, touches pixmaps
336
356
    if (removeThumbnails)
 
357
    {
337
358
        ThumbnailLoadThread::deleteThumbnail(path);
 
359
    }
338
360
 
339
361
    if (notifyCache)
 
362
    {
340
363
        LoadingCacheInterface::fileChanged(path);
 
364
    }
341
365
}
342
366
 
343
367
// -------------------------------------------------------------------------------
355
379
}
356
380
 
357
381
void MetadataManagerDatabaseWorker::changeTags(const QList<ImageInfo>& infos,
358
 
                                                                const QList<int>& tagIDs, bool addOrRemove)
 
382
        const QList<int>& tagIDs, bool addOrRemove)
359
383
{
360
384
    MetadataHub      hub;
361
385
    QList<ImageInfo> forWriting;
376
400
            hub.write(info, MetadataHub::PartialWrite);
377
401
 
378
402
            if (hub.willWriteMetadata(MetadataHub::FullWriteIfChanged) && d->shallSendForWriting(info.id()))
 
403
            {
379
404
                forWriting << info;
 
405
            }
380
406
 
381
407
            d->dbProcessedOne();
382
408
        }
411
437
            hub.write(info, MetadataHub::PartialWrite);
412
438
 
413
439
            if (hub.willWriteMetadata(MetadataHub::FullWriteIfChanged) && d->shallSendForWriting(info.id()))
 
440
            {
414
441
                forWriting << info;
 
442
            }
415
443
 
416
444
            d->dbProcessedOne();
417
445
        }
438
466
    d->dbFinished(infos.size());
439
467
}
440
468
 
441
 
void MetadataManagerDatabaseWorker::applyMetadata(const QList<ImageInfo>& infos, MetadataHub *hub)
 
469
void MetadataManagerDatabaseWorker::applyMetadata(const QList<ImageInfo>& infos, MetadataHub* hub)
442
470
{
443
471
    d->setDBAction(i18n("Applying metadata. Please wait..."));
444
472
 
493
521
    }
494
522
 
495
523
    if (!failedItems.isEmpty())
 
524
    {
496
525
        emit orientationChangeFailed(failedItems);
 
526
    }
497
527
 
498
528
    d->finishedWriting(infos.size());
499
529
}
512
542
        hub.load(info);
513
543
        QString filePath = info.filePath();
514
544
        bool fileChanged = hub.write(filePath, MetadataHub::FullWrite);
 
545
 
515
546
        if (fileChanged)
 
547
        {
516
548
            ScanController::instance()->scanFileDirectly(filePath);
517
 
            // hub emits fileMetadataChanged
 
549
        }
 
550
 
 
551
        // hub emits fileMetadataChanged
518
552
 
519
553
        d->writtenToOne();
520
554
    }
523
557
    d->finishedWriting(infos.size());
524
558
}
525
559
 
526
 
void MetadataManagerFileWorker::writeMetadata(const QList<ImageInfo>& infos, MetadataHub *hub)
 
560
void MetadataManagerFileWorker::writeMetadata(const QList<ImageInfo>& infos, MetadataHub* hub)
527
561
{
528
562
    d->setWriterAction(i18n("Writing metadata to files. Please wait..."));
529
563
    d->startingToWrite(infos);
540
574
 
541
575
        // trigger db scan (to update file size etc.)
542
576
        if (fileChanged)
 
577
        {
543
578
            ScanController::instance()->scanFileDirectly(filePath);
544
 
            // hub emits fileMetadataChanged
 
579
        }
 
580
 
 
581
        // hub emits fileMetadataChanged
545
582
 
546
583
        d->writtenToOne();
547
584
    }