Commit c527e0a0 authored by Denis Kurtz's avatar Denis Kurtz 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.12

Differential Revision: https://phabricator.kde.org/D2434
parent cf7947b1
......@@ -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")
......
......@@ -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();
}
......
......@@ -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()
......
......@@ -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;
};
......
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