summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSandro Knauß <mail@sandroknauss.de>2015-03-06 14:06:10 (GMT)
committerSandro Knauß <mail@sandroknauss.de>2015-03-06 14:06:10 (GMT)
commitd64945ad0babcca87b4c398e76bb8540c7dd3199 (patch)
tree7d62ec02a3b03aa706b474ca96443b57f683d479
parentfefdb55de34826c63e75ebfb46518c4eeaa1db14 (diff)
downloadlibkolab-dev/tag_color.tar.gz
Add color and icon sync support to tags.dev/tag_color
read&write color and icon setting from and to Kolab <-> Akonadi::Tag. KOLAB: 4808
-rw-r--r--kolabformat/kolabobject.cpp12
-rw-r--r--kolabformat/kolabobject.h1
-rw-r--r--tests/kolabobjecttest.cpp47
-rw-r--r--tests/kolabobjecttest.h6
4 files changed, 66 insertions, 0 deletions
diff --git a/kolabformat/kolabobject.cpp b/kolabformat/kolabobject.cpp
index e5c404d..95142c3 100644
--- a/kolabformat/kolabobject.cpp
+++ b/kolabformat/kolabobject.cpp
@@ -435,6 +435,12 @@ ObjectType KolabObjectReader::Private::readKolabV3(const KMime::Message::Ptr &ms
mTag = Akonadi::Tag();
mTag.setName(Conversion::fromStdString(relation.name()));
mTag.setGid(Conversion::fromStdString(configuration.uid()).toLatin1());
+
+ Akonadi::TagAttribute *attr = mTag.attribute<Akonadi::TagAttribute>(Akonadi::AttributeEntity::AddIfMissing);
+ attr->setBackgroundColor(QColor(Conversion::fromStdString(relation.color())));
+ attr->setIconName(Conversion::fromStdString(relation.iconName()));
+ attr->setPriority(relation.priority());
+
#ifdef KDEPIMLIBS_HAS_GENERIC_TAG
mTag.setType(Akonadi::Tag::GENERIC);
#else
@@ -818,6 +824,12 @@ KMime::Message::Ptr KolabObjectWriter::writeTag(const Akonadi::Tag &tag, const Q
}
Kolab::Relation relation(Conversion::toStdString(tag.name()), "tag");
+ const Akonadi::TagAttribute *const attr = tag.attribute<Akonadi::TagAttribute>();
+ if (attr) {
+ relation.setColor(Conversion::toStdString(attr->backgroundColor().name()));
+ relation.setIconName(Conversion::toStdString(attr->iconName()));
+ relation.setPriority(attr->priority());
+ }
std::vector<std::string> m;
m.reserve(members.count());
foreach (const QString &member, members) {
diff --git a/kolabformat/kolabobject.h b/kolabformat/kolabobject.h
index b3ec9c0..376ac6b 100644
--- a/kolabformat/kolabobject.h
+++ b/kolabformat/kolabobject.h
@@ -25,6 +25,7 @@
#ifdef HAVE_TAG_H
#include <akonadi/item.h>
#include <akonadi/tag.h>
+#include <akonadi/tagattribute.h>
#endif
#ifdef HAVE_RELATION_H
#include <akonadi/relation.h>
diff --git a/tests/kolabobjecttest.cpp b/tests/kolabobjecttest.cpp
index 5840760..b254f79 100644
--- a/tests/kolabobjecttest.cpp
+++ b/tests/kolabobjecttest.cpp
@@ -22,6 +22,13 @@
#include "kolabformat/kolabobject.h"
#include <kdebug.h>
#include <kolabformat/errorhandler.h>
+#include <kolabconfiguration.h>
+
+#ifdef HAVE_TAG_H
+#include <akonadi/item.h>
+#include <akonadi/tag.h>
+#include <akonadi/tagattribute.h>
+#endif
void KolabObjectTest::preserveLatin1()
{
@@ -167,7 +174,47 @@ void KolabObjectTest::parseRelationMembers()
}
}
+#ifdef HAVE_TAG_H
+void KolabObjectTest::convertTag()
+{
+ Akonadi::Tag tag;
+ tag.setName("tagName");
+ Akonadi::TagAttribute *attr = tag.attribute<Akonadi::TagAttribute>(Akonadi::AttributeEntity::AddIfMissing);
+ attr->setBackgroundColor(QColor("#123456"));
+ attr->setIconName("qwertz");
+ attr->setPriority(2);
+
+ QStringList members;
+ members << "member1";
+
+ KMime::Message::Ptr msg = Kolab::KolabObjectWriter::writeTag(tag, members);
+ qDebug() << msg->encodedContent();
+
+ Kolab::KolabObjectReader reader;
+ Kolab::ObjectType t = reader.parseMimeMessage(msg);
+ QCOMPARE(t, Kolab::RelationConfigurationObject);
+ QCOMPARE(reader.getVersion(), Kolab::KolabV3);
+ QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug);
+ QCOMPARE(reader.getTagMembers(), members);
+ Akonadi::Tag readTag = reader.getTag();
+ Akonadi::TagAttribute *readAttr = readTag.attribute<Akonadi::TagAttribute>();
+ QVERIFY(readAttr);
+ QCOMPARE(readTag.name(), tag.name());
+ QCOMPARE(readAttr->backgroundColor(), attr->backgroundColor());
+ QCOMPARE(readAttr->iconName(), attr->iconName());
+ QCOMPARE(readAttr->priority(), attr->priority());
+
+ //test no priority setting (aka default setting)
+ attr->setPriority(-1);
+ msg = Kolab::KolabObjectWriter::writeTag(tag, members);
+ reader.parseMimeMessage(msg);
+ readTag = reader.getTag();
+ readAttr = readTag.attribute<Akonadi::TagAttribute>();
+ QCOMPARE(readAttr->priority(), attr->priority());
+
+}
+#endif
QTEST_MAIN( KolabObjectTest )
diff --git a/tests/kolabobjecttest.h b/tests/kolabobjecttest.h
index 7cf3298..a37b0a4 100644
--- a/tests/kolabobjecttest.h
+++ b/tests/kolabobjecttest.h
@@ -19,6 +19,8 @@
#define KOLABOBJECTTEST_H
#include <QObject>
+#include <libkolab_config.h>
+
class KolabObjectTest: public QObject
{
Q_OBJECT
@@ -28,6 +30,10 @@ private slots:
void dontCrashWithEmptyOrganizer();
void dontCrashWithEmptyIncidence();
void parseRelationMembers();
+
+#ifdef HAVE_TAG_H
+ void convertTag();
+#endif
};
#endif // KOLABOBJECTTEST_H