summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Kurtz <denis.kurtz@posteo.de>2016-08-26 13:20:30 (GMT)
committerDaniel Vrátil <dvratil@kde.org>2016-08-26 13:21:36 (GMT)
commitc527e0a0e1ffec9892fa30c9510aeb8cc3639757 (patch)
treeb3f2fed7b51ccdb61b9a05823d04b1476efda7e1
parentcf7947b13360bfc3dce30fe4b734574e4ba1a5c8 (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.12 Differential Revision: https://phabricator.kde.org/D2434
-rw-r--r--CMakeLists.txt2
-rw-r--r--src/kcalprefs.cpp4
-rw-r--r--src/tagcache.cpp7
-rw-r--r--src/tagcache.h2
4 files changed, 12 insertions, 3 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7ddbae8..b79204d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,7 +19,7 @@ include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE)
include(ECMQtDeclareLoggingCategory)
include(ECMAddTests)
-set(PIM_VERSION "5.3.42")
+set(PIM_VERSION "5.3.43")
set(CALENDARSUPPORT_LIB_VERSION ${PIM_VERSION})
set(AKONADI_MIMELIB_VERSION "5.3.40")
diff --git a/src/kcalprefs.cpp b/src/kcalprefs.cpp
index ef58ab6..117c807 100644
--- a/src/kcalprefs.cpp
+++ b/src/kcalprefs.cpp
@@ -312,7 +312,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);
@@ -323,7 +323,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;
};