summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2013-04-11 17:26:13 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2013-04-11 17:26:13 (GMT)
commita220c403e31f9e102d28d8cc5dfa94ae090cba4c (patch)
tree13d1f7c1b26c8f34bbfdd61d15987bb536800d92
parent1ac387f8e8f9606b9892cfe6b7a69b33a9557abb (diff)
downloadlibkolab-a220c403e31f9e102d28d8cc5dfa94ae090cba4c.tar.gz
Support for uid's in kolabv2
-rw-r--r--kolabformatV2/distributionlist.cpp26
-rw-r--r--kolabformatV2/distributionlist.h1
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/legacyformattest.cpp58
-rw-r--r--tests/legacyformattest.h31
-rw-r--r--tests/testfiles/v2/contacts/distlistWithUID.xml21
6 files changed, 132 insertions, 6 deletions
diff --git a/kolabformatV2/distributionlist.cpp b/kolabformatV2/distributionlist.cpp
index 34379ef..6fe6873 100644
--- a/kolabformatV2/distributionlist.cpp
+++ b/kolabformatV2/distributionlist.cpp
@@ -78,6 +78,8 @@ void KolabV2::DistributionList::loadDistrListMember( const QDomElement& element
member.displayName = e.text();
else if ( tagName == "smtp-address" )
member.email = e.text();
+ else if ( tagName == "uid" )
+ member.uid = e.text();
}
}
mDistrListMembers.append( member );
@@ -90,8 +92,12 @@ void DistributionList::saveDistrListMembers( QDomElement& element ) const
QDomElement e = element.ownerDocument().createElement( "member" );
element.appendChild( e );
const Member& m = *it;
- writeString( e, "display-name", m.displayName );
- writeString( e, "smtp-address", m.email );
+ if (!m.uid.isEmpty()) {
+ writeString( e, "uid", m.uid );
+ } else {
+ writeString( e, "display-name", m.displayName );
+ writeString( e, "smtp-address", m.email );
+ }
}
}
@@ -192,8 +198,13 @@ void DistributionList::setFields( const KABC::ContactGroup* contactGroup )
mDistrListMembers.append( m );
}
- if (contactGroup->contactReferenceCount() > 0) {
- kWarning() << "Tried to save contact references, which should have been resolved already";
+ for ( uint index = 0; index < contactGroup->contactReferenceCount(); ++index ) {
+ const KABC::ContactGroup::ContactReference& data = contactGroup->contactReference( index );
+
+ Member m;
+ m.uid = data.uid();
+
+ mDistrListMembers.append( m );
}
if (contactGroup->contactGroupReferenceCount() > 0) {
kWarning() << "Tried to save contact group references, which should have been resolved already";
@@ -209,8 +220,11 @@ void DistributionList::saveTo( KABC::ContactGroup* contactGroup )
QList<Member>::ConstIterator mit = mDistrListMembers.constBegin();
for ( ; mit != mDistrListMembers.constEnd(); ++mit ) {
- const KABC::ContactGroup::Data data( (*mit).displayName, (*mit).email );
- contactGroup->append( data );
+ if (!(*mit).uid.isEmpty()) {
+ contactGroup->append(KABC::ContactGroup::ContactReference( (*mit).uid ));
+ } else {
+ contactGroup->append(KABC::ContactGroup::Data( (*mit).displayName, (*mit).email ));
+ }
}
}
diff --git a/kolabformatV2/distributionlist.h b/kolabformatV2/distributionlist.h
index c0a42e0..f646540 100644
--- a/kolabformatV2/distributionlist.h
+++ b/kolabformatV2/distributionlist.h
@@ -86,6 +86,7 @@ private:
struct Member {
QString displayName;
QString email;
+ QString uid;
};
QList<Member> mDistrListMembers;
};
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 6e53353..ef7a37f 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -24,6 +24,7 @@ addTest(timezonetest)
addTest(mimeobjecttest)
addTest(xmlobjecttest)
addTest(debugstreamtest)
+addTest(legacyformattest)
if(PHP_BINDINGS)
find_path(PHP_KOLABFORMAT_PATH NAMES kolabformat.php PATHS /usr/local/lib/php/modules /usr/lib/php/modules PATH_SUFFIXES lib/php/modules lib64/php/modules)
diff --git a/tests/legacyformattest.cpp b/tests/legacyformattest.cpp
new file mode 100644
index 0000000..dfb0a61
--- /dev/null
+++ b/tests/legacyformattest.cpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "legacyformattest.h"
+#include "kolabformat/xmlobject.h"
+#include "kolabformat/errorhandler.h"
+#include "testutils.h"
+
+#include <QTest>
+#include <fstream>
+#include <sstream>
+
+void V2Test::testReadDistlistUID()
+{
+ std::ifstream t((TESTFILEDIR.toStdString()+"v2/contacts/distlistWithUID.xml").c_str());
+ std::stringstream buffer;
+ buffer << t.rdbuf();
+
+ Kolab::XMLObject xo;
+ const Kolab::DistList distlist = xo.readDistlist(buffer.str(), Kolab::KolabV2);
+ foreach (const Kolab::ContactReference &contact, distlist.members()) {
+ QVERIFY(!contact.uid().empty());
+ }
+ QVERIFY(!Kolab::ErrorHandler::errorOccured());
+}
+
+void V2Test::testWriteDistlistUID()
+{
+ Kolab::DistList distlist;
+ distlist.setUid("uid");
+ distlist.setName("name");
+ std::vector<Kolab::ContactReference> members;
+ members.push_back(Kolab::ContactReference(Kolab::ContactReference::UidReference, "memberuid", "membername"));
+ distlist.setMembers(members);
+
+ Kolab::XMLObject xo;
+ const std::string xml = xo.writeDistlist(distlist, Kolab::KolabV2);
+ QVERIFY(QString::fromStdString(xml).contains("memberuid"));
+ QVERIFY(!Kolab::ErrorHandler::errorOccured());
+}
+
+QTEST_MAIN( V2Test )
+
+#include "legacyformattest.moc" \ No newline at end of file
diff --git a/tests/legacyformattest.h b/tests/legacyformattest.h
new file mode 100644
index 0000000..42c6de3
--- /dev/null
+++ b/tests/legacyformattest.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef V2TEST_H
+#define V2TEST_H
+
+#include <QObject>
+
+class V2Test: public QObject
+{
+ Q_OBJECT
+private slots:
+ void testReadDistlistUID();
+ void testWriteDistlistUID();
+};
+
+#endif // V2TEST_H
diff --git a/tests/testfiles/v2/contacts/distlistWithUID.xml b/tests/testfiles/v2/contacts/distlistWithUID.xml
new file mode 100644
index 0000000..74a41b9
--- /dev/null
+++ b/tests/testfiles/v2/contacts/distlistWithUID.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<distribution-list version="1.0">
+ <uid>ebb1774429a2e03afafb31f233e23b42</uid>
+ <body></body>
+ <categories></categories>
+ <creation-date>2010-11-25T18:02:32Z</creation-date>
+ <last-modification-date>2011-07-23T09:06:38Z</last-modification-date>
+ <sensitivity>public</sensitivity>
+ <product-id>Horde::Kolab</product-id>
+ <display-name>Another lista</display-name>
+ <member>
+ <display-name>Another User</display-name>
+ <smtp-address>other@debian-vm.local</smtp-address>
+ <uid>a2cfdc52365ef429042413bf7717dc85</uid>
+ </member>
+ <member>
+ <display-name>Sample A. User Jr.</display-name>
+ <smtp-address>sample@debian-vm.local</smtp-address>
+ <uid>f538c7e9ad5a63e4452b7db3bc291231</uid>
+ </member>
+</distribution-list> \ No newline at end of file