aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Kurz <denis.kurz@posteo.de>2016-08-26 13:20:30 (GMT)
committerDaniel Vrátil <dvratil@kde.org>2016-08-26 13:29:03 (GMT)
commita7e00390d31de4fb18c43f16afc21bfdbb460841 (patch)
treedaf7e155f0985deb315df6c28587cd01a08328e5
parent851e45085fb7925a00219a4c3a71dc1f3d149e2d (diff)
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: https://phabricator.kde.org/D2434
-rw-r--r--src/kcalprefs.cpp4
-rw-r--r--src/tagcache.cpp7
-rw-r--r--src/tagcache.h2
3 files changed, 11 insertions, 2 deletions
diff --git a/src/kcalprefs.cpp b/src/kcalprefs.cpp
index b31afec..eae4773 100644
--- a/src/kcalprefs.cpp
+++ b/src/kcalprefs.cpp
@@ -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);
attr->setBackgroundColor(color);
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();
}
diff --git a/src/tagcache.cpp b/src/tagcache.cpp
index 3d18098..e5aaaf9 100644
--- a/src/tagcache.cpp
+++ b/src/tagcache.cpp
@@ -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.id(), tag);
mGidCache.insert(tag.gid(), tag.id());
+ mNameCache.insert(tag.name(), tag.id());
}
void TagCache::onTagChanged(const Akonadi::Tag &tag)
@@ -62,6 +68,7 @@ void TagCache::onTagRemoved(const Akonadi::Tag &tag)
{
mCache.remove(tag.id());
mGidCache.remove(tag.gid());
+ mNameCache.remove(tag.name());
}
void TagCache::retrieveTags()
diff --git a/src/tagcache.h b/src/tagcache.h
index 044a138..4252f17 100644
--- a/src/tagcache.h
+++ b/src/tagcache.h
@@ -42,6 +42,7 @@ class TagCache : public QObject
public:
TagCache();
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;
};