summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Seigo <aseigo@kde.org>2014-10-21 15:23:57 (GMT)
committerAaron Seigo <aseigo@kde.org>2014-10-22 09:44:27 (GMT)
commit8b06c46eaaf70fc70af3abff8f7fbfa7f3116a19 (patch)
tree2b29ecfeed7f7d7441ba8775ceebf57b995fbe16
parent220162c184995bdd2b1a662612c33e102831ca3b (diff)
downloadlibkolab-feature/relations.tar.gz
add Relation support to KolabObject: read, write and getfeature/relations
-rw-r--r--kolabformat/kolabobject.cpp80
-rw-r--r--kolabformat/kolabobject.h4
2 files changed, 66 insertions, 18 deletions
diff --git a/kolabformat/kolabobject.cpp b/kolabformat/kolabobject.cpp
index 3d41c5c..3cf3f86 100644
--- a/kolabformat/kolabobject.cpp
+++ b/kolabformat/kolabobject.cpp
@@ -134,7 +134,7 @@ public:
ObjectType readKolabV2(const KMime::Message::Ptr &msg, Kolab::ObjectType objectType);
ObjectType readKolabV3(const KMime::Message::Ptr &msg, Kolab::ObjectType objectType);
-
+
KCalCore::Incidence::Ptr mIncidence;
KABC::Addressee mAddressee;
KABC::ContactGroup mContactGroup;
@@ -144,13 +144,15 @@ public:
ObjectType mObjectType;
Version mVersion;
Kolab::Freebusy mFreebusy;
+ ObjectType mOverrideObjectType;
+ Version mOverrideVersion;
+ bool mDoOverrideVersion;
+
#ifdef HAVE_TAG_H
+ Akonadi::Relation mRelation;
Akonadi::Tag mTag;
QStringList mTagMembers;
#endif
- ObjectType mOverrideObjectType;
- Version mOverrideVersion;
- bool mDoOverrideVersion;
};
//@endcond
@@ -397,16 +399,31 @@ ObjectType KolabObjectReader::Private::readKolabV3(const KMime::Message::Ptr &ms
const Kolab::Configuration &configuration = Kolab::readConfiguration(xml, false);
const Kolab::Relation &relation = configuration.relation();
- mTag = Akonadi::Tag();
- mTag.setName(Conversion::fromStdString(relation.name()));
- mTag.setGid(Conversion::fromStdString(configuration.uid()).toLatin1());
- mTag.setType(Akonadi::Tag::PLAIN);
-
- mTagMembers.reserve(relation.members().size());
- foreach (const std::string &member, relation.members()) {
- mTagMembers << Conversion::fromStdString(member);
+ if (relation.type() == "tag") {
+ mTag = Akonadi::Tag();
+ mTag.setName(Conversion::fromStdString(relation.name()));
+ mTag.setGid(Conversion::fromStdString(configuration.uid()).toLatin1());
+ mTag.setType(Akonadi::Tag::PLAIN);
+
+ mTagMembers.reserve(relation.members().size());
+ foreach (const std::string &member, relation.members()) {
+ mTagMembers << Conversion::fromStdString(member);
+ }
+ } else if (relation.type() == "generic") {
+ if (relation.members().size() == 2) {
+ mRelation = Akonadi::Relation();
+ mRelation.setRemoteId(Conversion::fromStdString(configuration.uid()).toLatin1());
+ mRelation.setType(Akonadi::Relation::GENERIC);
+ mRelation.setLeft(Akonadi::Item(Conversion::fromStdString(relation.members()[0]).toLongLong()));
+ mRelation.setRight(Akonadi::Item(Conversion::fromStdString(relation.members()[1]).toLongLong()));
+ } else {
+ Critical() << "generic relation had wrong number of members:" << relation.members().size();
+ printMessageDebugInfo(msg);
+ }
+ } else {
+ Critical() << "unknown configuration object type" << relation.type();
+ printMessageDebugInfo(msg);
}
-
}
break;
#endif
@@ -537,6 +554,11 @@ Freebusy KolabObjectReader::getFreebusy() const
}
#ifdef HAVE_TAG_H
+Akonadi::Relation KolabObjectReader::getRelation() const
+{
+ return d->mRelation;
+}
+
Akonadi::Tag KolabObjectReader::getTag() const
{
return d->mTag;
@@ -727,6 +749,32 @@ KMime::Message::Ptr KolabObjectWriter::writeFreebusy(const Freebusy &freebusy, V
}
#ifdef HAVE_TAG_H
+KMime::Message::Ptr writeRelationHelper(const Kolab::Relation &relation, const QByteArray &uid, const QString &productId)
+{
+ Kolab::Configuration configuration(relation); //TODO preserve creation/lastModified date
+ configuration.setUid(uid.constData());
+ const std::string &v3String = Kolab::writeConfiguration(configuration, Conversion::toStdString(getProductId(productId)));
+ ErrorHandler::handleLibkolabxmlErrors();
+ return Mime::createMessage(Conversion::fromStdString(configuration.uid()), kolabMimeType(), relationKolabType(), Conversion::fromStdString(v3String).toUtf8(), true, getProductId(productId));
+}
+
+KMime::Message::Ptr KolabObjectWriter::writeRelation(const Akonadi::Relation &relation, Version v, const QString &productId)
+{
+ ErrorHandler::clearErrors();
+ if (v != KolabV3) {
+ Critical() << "only v3 implementation available";
+ }
+
+ Kolab::Relation kolabRelation(std::string(), "generic");
+ std::vector<std::string> m;
+ m.reserve(2);
+ m.push_back(Conversion::toStdString(QString::number(relation.left().id())));
+ m.push_back(Conversion::toStdString(QString::number(relation.right().id())));
+ kolabRelation.setMembers(m);
+
+ return writeRelationHelper(kolabRelation, relation.remoteId(), productId);
+}
+
KMime::Message::Ptr KolabObjectWriter::writeTag(const Akonadi::Tag &tag, const QStringList &members, Version v, const QString &productId)
{
ErrorHandler::clearErrors();
@@ -742,11 +790,7 @@ KMime::Message::Ptr KolabObjectWriter::writeTag(const Akonadi::Tag &tag, const Q
}
relation.setMembers(m);
- Kolab::Configuration configuration(relation); //TODO preserve creation/lastModified date
- configuration.setUid(tag.gid().constData());
- const std::string &v3String = Kolab::writeConfiguration(configuration, Conversion::toStdString(getProductId(productId)));
- ErrorHandler::handleLibkolabxmlErrors();
- return Mime::createMessage(Conversion::fromStdString(configuration.uid()), kolabMimeType(), relationKolabType(), Conversion::fromStdString(v3String).toUtf8(), true, getProductId(productId));
+ return writeRelationHelper(relation, tag.gid(), productId);
}
#endif
diff --git a/kolabformat/kolabobject.h b/kolabformat/kolabobject.h
index 9edbfd3..0b56fe8 100644
--- a/kolabformat/kolabobject.h
+++ b/kolabformat/kolabobject.h
@@ -23,7 +23,9 @@
#include <libkolab_config.h>
#ifdef HAVE_TAG_H
+#include <akonadi/item.h>
#include <akonadi/tag.h>
+#include <akonadi/relation.h>
#endif
#include <kabc/addressee.h>
#include <kabc/contactgroup.h>
@@ -104,6 +106,7 @@ public:
QStringList getDictionary(QString &lang) const;
Freebusy getFreebusy() const;
#ifdef HAVE_TAG_H
+ Akonadi::Relation getRelation() const;
Akonadi::Tag getTag() const;
QStringList getTagMembers() const;
#endif
@@ -132,6 +135,7 @@ public:
static KMime::Message::Ptr writeDictionary(const QStringList &, const QString &lang, Version v = KolabV3, const QString &productId = QString());
static KMime::Message::Ptr writeFreebusy(const Kolab::Freebusy &, Version v = KolabV3, const QString &productId = QString());
#ifdef HAVE_TAG_H
+ static KMime::Message::Ptr writeRelation(const Akonadi::Relation &, Version v = KolabV3, const QString &productId = QString());
static KMime::Message::Ptr writeTag(const Akonadi::Tag &, const QStringList &items, Version v = KolabV3, const QString &productId = QString());
#endif