Git commit 01c8829fe881926c5aa6abb08b63b5d8aadfec5f by Marcel Wiesweg. Committed on 08/02/11 at 19:53. Pushed by mwiesweg into branch 'development/2.0'. The call in DigikamApp is probably too late for the collection scanner. - use built-in flag to populate color tags at first use - remove global call - pour in thread-safety - ensure tags a reread when db changes etc. M +0 -3 digikam/digikamapp.cpp M +38 -25 libs/database/tagscache.cpp M +0 -5 libs/database/tagscache.h http://commits.kde.org/digikam/01c8829fe881926c5aa6abb08b63b5d8aadfec5f diff --git a/digikam/digikamapp.cpp b/digikam/digikamapp.cpp index 8083b9f..5c69fc2 100644 --- a/digikam/digikamapp.cpp +++ b/digikam/digikamapp.cpp @@ -215,9 +215,6 @@ DigikamApp::DigikamApp() IccSettings::instance()->loadAllProfilesProperties(); ThumbnailLoadThread::setDisplayingWidget(this); - // FIXME : This is a temporally fix to register Color Label Tags. This must be done at a better place. - TagsCache::instance()->registerColorLabelTagsToDb(); - connect(AlbumSettings::instance(), SIGNAL(setupChanged()), this, SLOT(slotSetupChanged())); diff --git a/libs/database/tagscache.cpp b/libs/database/tagscache.cpp index 0abffe1..6e243b3 100644 --- a/libs/database/tagscache.cpp +++ b/libs/database/tagscache.cpp @@ -65,12 +65,14 @@ class TagsCache::TagsCachePriv { public: - TagsCachePriv() : + TagsCachePriv(TagsCache* q) : initialized(false), needUpdateInfos(true), needUpdateHash(true), needUpdateProperties(true), - changingDB(false) + needUpdateColorLabelTags(true), + changingDB(false), + q(q) { } @@ -78,6 +80,7 @@ public: bool needUpdateInfos; bool needUpdateHash; bool needUpdateProperties; + bool needUpdateColorLabelTags; bool changingDB; QReadWriteLock lock; @@ -89,6 +92,8 @@ public: QSet internalTags; QMap colorLabelsTags; // Map between color Id and tag label Id created in DB. + TagsCache* const q; + void checkInfos() { if (needUpdateInfos && initialized) @@ -191,6 +196,29 @@ public: { return qBinaryFind(list, value) != list.end(); } + + void checkColorLabelTags() + { + if (needUpdateColorLabelTags && initialized) + { + QMap map; + map.insert(NoneLabel, q->getOrCreateInternalTag(InternalTagName::colorLabelNone())); + map.insert(RedLabel, q->getOrCreateInternalTag(InternalTagName::colorLabelRed())); + map.insert(OrangeLabel, q->getOrCreateInternalTag(InternalTagName::colorLabelOrange())); + map.insert(YellowLabel, q->getOrCreateInternalTag(InternalTagName::colorLabelYellow())); + map.insert(GreenLabel, q->getOrCreateInternalTag(InternalTagName::colorLabelGreen())); + map.insert(BlueLabel, q->getOrCreateInternalTag(InternalTagName::colorLabelBlue())); + map.insert(MagentaLabel, q->getOrCreateInternalTag(InternalTagName::colorLabelMagenta())); + map.insert(GrayLabel, q->getOrCreateInternalTag(InternalTagName::colorLabelGray())); + map.insert(BlackLabel, q->getOrCreateInternalTag(InternalTagName::colorLabelBlack())); + map.insert(WhiteLabel, q->getOrCreateInternalTag(InternalTagName::colorLabelWhite())); + + QWriteLocker locker(&lock); + needUpdateColorLabelTags = false; + colorLabelsTags = map; + } + } + }; // ------------------------------------------------------------------------------------------ @@ -229,7 +257,7 @@ TagsCache* TagsCache::instance() } TagsCache::TagsCache() - : d(new TagsCachePriv) + : d(new TagsCachePriv(this)) { } @@ -252,27 +280,12 @@ void TagsCache::initialize() d->initialized = true; } -void TagsCache::registerColorLabelTagsToDb() -{ - d->colorLabelsTags.insert(NoneLabel, getOrCreateInternalTag(InternalTagName::colorLabelNone())); - d->colorLabelsTags.insert(RedLabel, getOrCreateInternalTag(InternalTagName::colorLabelRed())); - d->colorLabelsTags.insert(OrangeLabel, getOrCreateInternalTag(InternalTagName::colorLabelOrange())); - d->colorLabelsTags.insert(YellowLabel, getOrCreateInternalTag(InternalTagName::colorLabelYellow())); - d->colorLabelsTags.insert(GreenLabel, getOrCreateInternalTag(InternalTagName::colorLabelGreen())); - d->colorLabelsTags.insert(BlueLabel, getOrCreateInternalTag(InternalTagName::colorLabelBlue())); - d->colorLabelsTags.insert(MagentaLabel, getOrCreateInternalTag(InternalTagName::colorLabelMagenta())); - d->colorLabelsTags.insert(GrayLabel, getOrCreateInternalTag(InternalTagName::colorLabelGray())); - d->colorLabelsTags.insert(BlackLabel, getOrCreateInternalTag(InternalTagName::colorLabelBlack())); - d->colorLabelsTags.insert(WhiteLabel, getOrCreateInternalTag(InternalTagName::colorLabelWhite())); - - kDebug() << "Color Label Tags: " << d->colorLabelsTags; -} - void TagsCache::invalidate() { - d->needUpdateInfos = true; - d->needUpdateHash = true; - d->needUpdateProperties = true; + d->needUpdateInfos = true; + d->needUpdateHash = true; + d->needUpdateProperties = true; + d->needUpdateColorLabelTags = true; } QLatin1String TagsCache::tagPathOfDigikamInternalTags(LeadingSlashPolicy slashPolicy) @@ -833,9 +846,7 @@ void TagsCache::slotTagChanged(const TagChangeset& changeset) { if (!d->changingDB && changeset.operation() != TagChangeset::IconChanged) { - d->needUpdateInfos = true; - d->needUpdateHash = true; - d->needUpdateProperties = true; + invalidate(); } if (changeset.operation() == TagChangeset::Added) @@ -853,6 +864,8 @@ int TagsCache::getTagForColorLabel(ColorLabel label) if (label < NoneLabel || label > WhiteLabel) return 0; + d->checkColorLabelTags(); + QReadLocker locker(&d->lock); return d->colorLabelsTags[label]; } diff --git a/libs/database/tagscache.h b/libs/database/tagscache.h index 37e922a..5614d9f 100644 --- a/libs/database/tagscache.h +++ b/libs/database/tagscache.h @@ -194,11 +194,6 @@ public: */ int getTagForColorLabel(ColorLabel label); - /** - * Register Color Label tags in database. If tags do not exists, create it as well. - */ - void registerColorLabelTagsToDb(); - static QLatin1String tagPathOfDigikamInternalTags(LeadingSlashPolicy slashPolicy = IncludeLeadingSlash); static QLatin1String propertyNameDigikamInternalTag(); static QLatin1String propertyNameExcludedFromWriting();