Commit a7e00390 authored by Denis Kurz's avatar Denis Kurz Committed by Daniel Vrátil

Cache tags by name instead of gid

To set and retrieve category colors, a TagCache is used, where tags
are stored by gid. So far, the utf8 encoding of a tag's name was used
to retrieve a tag from the cache. In general, however, the gid of a tag
is not the same as its name. Since the gid may be unknown when looking
for a tag's color, this change switches to the tags' names for keys.

BUG: 333754
FIXED-IN: 16.08.1

Differential Revision:
parent 851e4508
......@@ -310,7 +310,7 @@ bool KCalPrefs::thatIsMe(const QString &_email)
void KCalPrefs::setCategoryColor(const QString &cat, const QColor &color)
Akonadi::Tag tag = d->mTagCache.getTagByGid(cat.toUtf8());
Akonadi::Tag tag = d->mTagCache.getTagByName(cat);
Akonadi::TagAttribute *attr = tag.attribute<Akonadi::TagAttribute>(Akonadi::Tag::AddIfMissing);
new Akonadi::TagModifyJob(tag);
......@@ -321,7 +321,7 @@ QColor KCalPrefs::categoryColor(const QString &cat) const
QColor color;
if (!cat.isEmpty()) {
const Akonadi::Tag &tag = d->mTagCache.getTagByGid(cat.toUtf8());
const Akonadi::Tag &tag = d->mTagCache.getTagByName(cat);
if (Akonadi::TagAttribute *attr = tag.attribute<Akonadi::TagAttribute>()) {
color = attr->backgroundColor();
......@@ -47,10 +47,16 @@ Akonadi::Tag TagCache::getTagByGid(const QByteArray &gid) const
return mCache.value(mGidCache.value(gid));
Akonadi::Tag TagCache::getTagByName(const QString &name) const
return mCache.value(mNameCache.value(name));
void TagCache::onTagAdded(const Akonadi::Tag &tag)
mCache.insert(, tag);
void TagCache::onTagChanged(const Akonadi::Tag &tag)
......@@ -62,6 +68,7 @@ void TagCache::onTagRemoved(const Akonadi::Tag &tag)
void TagCache::retrieveTags()
......@@ -42,6 +42,7 @@ class TagCache : public QObject
Akonadi::Tag getTagByGid(const QByteArray &gid) const;
Akonadi::Tag getTagByName(const QString &name) const;
private Q_SLOTS:
void onTagAdded(const Akonadi::Tag &);
......@@ -54,6 +55,7 @@ private:
QHash<Akonadi::Tag::Id, Akonadi::Tag> mCache;
QHash<QByteArray, Akonadi::Tag::Id> mGidCache;
QHash<QString, Akonadi::Tag::Id> mNameCache;
Akonadi::Monitor *mMonitor;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment