3 commits - calendaring/calendaring.cpp calendaring/calendaring.h calendaring/calendaring.i calendaring/event.cpp calendaring/event.h CMakeLists.txt conversion/commonconversion.cpp conversion/commonconversion.h conversion/kcalconversion.cpp icalendar/icalendar.i tests/calendaringtest.cpp tests/kcalconversiontest.cpp tests/testhelpers.h
Christian Mollekopf
mollekopf at kolabsys.com
Thu May 31 15:45:32 CEST 2012
CMakeLists.txt | 2 -
calendaring/calendaring.cpp | 8 +++++-
calendaring/calendaring.h | 11 +++++++-
calendaring/calendaring.i | 2 +
calendaring/event.cpp | 10 ++++++-
calendaring/event.h | 5 ++-
conversion/commonconversion.cpp | 39 ++++++++++++++++++++++++++++++
conversion/commonconversion.h | 4 +++
conversion/kcalconversion.cpp | 32 +++++++++++++++++++++++++
icalendar/icalendar.i | 1
tests/calendaringtest.cpp | 6 +---
tests/kcalconversiontest.cpp | 19 ++++++++++----
tests/testhelpers.h | 51 ++++++++++++++++++++++++++++++++++++++++
13 files changed, 173 insertions(+), 17 deletions(-)
New commits:
commit 1f6d9622bcf84f550cc6cd9a4e7518eb3248de2b
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Thu May 31 15:44:55 2012 +0200
Cleanup, libkolab req. versionbump, fixed calendaring bindings.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 81ef942..567ba5d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,7 +46,7 @@ set(CMAKECONFIG_INSTALL_DIR ${LIB_INSTALL_DIR}/cmake/Libkolab )
find_package(Qt4 4.7.0 REQUIRED)
find_package(KDE4 4.8 REQUIRED)
find_package(KdepimLibs 4.8 REQUIRED)
-find_package(Libkolabxml 0.4 REQUIRED)
+find_package(Libkolabxml 0.6 REQUIRED)
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS} -fPIC" )
diff --git a/calendaring/calendaring.i b/calendaring/calendaring.i
index 5bb2fa6..4402f60 100644
--- a/calendaring/calendaring.i
+++ b/calendaring/calendaring.i
@@ -17,6 +17,7 @@
namespace std {
%template(vectordatetime) vector<Kolab::cDateTime>;
%template(vectorevent) vector<Kolab::Event>;
+ %template(vectorevent2) vector< vector<Kolab::Event> >;
};
/*%apply const std::string& {std::string* foo};*/
diff --git a/calendaring/event.cpp b/calendaring/event.cpp
index 4c18137..6efd1ec 100644
--- a/calendaring/event.cpp
+++ b/calendaring/event.cpp
@@ -32,6 +32,12 @@ Event::Event()
setUid(Kolab::generateUID());
}
+Event::~Event()
+{
+
+}
+
+
bool Event::read(const std::string &string)
{
const Kolab::Event &e = Kolab::readEvent(string, false);
@@ -47,7 +53,7 @@ std::string Event::write() const
return Kolab::writeEvent(*this);
}
-bool Event::fromIcal(const std::string &input)
+bool Event::fromICal(const std::string &input)
{
std::vector<Kolab::Event> list = fromICalEvents(input);
if (list.size() != 1) {
@@ -58,7 +64,7 @@ bool Event::fromIcal(const std::string &input)
return true;
}
-std::string Event::toIcal() const
+std::string Event::toICal() const
{
std::vector<Kolab::Event> list;
list.push_back(*this);
diff --git a/calendaring/event.h b/calendaring/event.h
index 35ac4f7..afb8e1a 100644
--- a/calendaring/event.h
+++ b/calendaring/event.h
@@ -34,12 +34,13 @@ class KOLAB_EXPORT Event: public Kolab::Event
{
public:
Event();
+ ~Event();
bool read(const std::string &);
std::string write() const;
- bool fromIcal(const std::string &);
- std::string toIcal() const;
+ bool fromICal(const std::string &);
+ std::string toICal() const;
/**
diff --git a/icalendar/icalendar.i b/icalendar/icalendar.i
index 44d8c81..9e2389b 100644
--- a/icalendar/icalendar.i
+++ b/icalendar/icalendar.i
@@ -14,6 +14,7 @@
namespace std {
%template(vectordatetime) vector<Kolab::cDateTime>;
%template(vectorevent) vector<Kolab::Event>;
+ %template(vectorevent2) vector< vector<Kolab::Event> >;
};
%include "icalendar.h"
\ No newline at end of file
diff --git a/tests/calendaringtest.cpp b/tests/calendaringtest.cpp
index 19935c6..6d94178 100644
--- a/tests/calendaringtest.cpp
+++ b/tests/calendaringtest.cpp
@@ -131,7 +131,6 @@ void CalendaringTest::testEventConflictSet()
events.push_back(createEvent(Kolab::cDateTime(2011,10,9,12,1,1,true), Kolab::cDateTime(2011,10,11,12,1,1,true)));
const std::vector< std::vector<Kolab::Event> > &result = Kolab::Calendaring::getConflictingSets(events);
-
std::vector< std::vector<Kolab::Event> > expectedResult;
std::vector<Kolab::Event> r1;
r1.push_back(createEvent(Kolab::cDateTime(2011,10,6,12,1,1,true), Kolab::cDateTime(2011,10,8,12,1,1,true)));
@@ -151,8 +150,6 @@ void CalendaringTest::testEventConflictSet()
}
compareEvents(result.at(i), expectedResult.at(i));
}
-
-
}
void CalendaringTest::testTimesInInterval_data()
commit c19087e67f4c2a9026ac5d8afcce81d28cc0257b
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Thu May 31 13:26:41 2012 +0200
Allow for conflict detection between two different lists, according to BUG 591.
diff --git a/calendaring/calendaring.cpp b/calendaring/calendaring.cpp
index 119d328..4579348 100644
--- a/calendaring/calendaring.cpp
+++ b/calendaring/calendaring.cpp
@@ -41,7 +41,7 @@ bool conflicts(const Kolab::Event &e1, const Kolab::Event &e2)
return true;
}
-std::vector< std::vector< Kolab::Event > > getConflictingSets(const std::vector< Event > &events)
+std::vector< std::vector< Event > > getConflictingSets(const std::vector< Event > &events, const std::vector< Event > &events2)
{
std::vector< std::vector< Kolab::Event > > ret;
for(int i = 0; i < events.size(); i++) {
@@ -54,6 +54,12 @@ std::vector< std::vector< Kolab::Event > > getConflictingSets(const std::vector<
set.push_back(e2);
}
}
+ for(int m = 0; m < events2.size(); m++) {
+ const Kolab::Event &e2 = events2.at(m);
+ if (conflicts(event, e2)) {
+ set.push_back(e2);
+ }
+ }
if (set.size() > 1) {
ret.push_back(set);
}
diff --git a/calendaring/calendaring.h b/calendaring/calendaring.h
index ffee9a6..b48c1d6 100644
--- a/calendaring/calendaring.h
+++ b/calendaring/calendaring.h
@@ -35,16 +35,23 @@ namespace Kolab {
/**
* Returns true if the events conflict (overlap)
* Start and end date/time is inclusive.
+ *
+ * Does not take recurrences into account.
*/
KOLAB_EXPORT bool conflicts(const Kolab::Event &, const Kolab::Event &);
/**
- * Returns sets of the events which are directly conflicting with each other
+ * Returns sets of the events which are directly conflicting with each other.
* The same event may appear in multiple sets.
* Non-conflicting events are not returned.
* conflicts() is used for conflict detection.
+ *
+ * If the second list is given, each event from the first list is additionally checked against each event of the second set.
+ * Conflicts within the second list are not detected.
+ *
+ * The checked event from the first list comes always first in the returned set.
*/
-KOLAB_EXPORT std::vector< std::vector<Kolab::Event> > getConflictingSets(const std::vector<Kolab::Event> &);
+KOLAB_EXPORT std::vector< std::vector<Kolab::Event> > getConflictingSets(const std::vector<Kolab::Event> &, const std::vector<Kolab::Event> & = std::vector<Kolab::Event>());
/**
* Returns the dates in which the event recurs within the specified timespan.
diff --git a/calendaring/calendaring.i b/calendaring/calendaring.i
index 2cedb2c..5bb2fa6 100644
--- a/calendaring/calendaring.i
+++ b/calendaring/calendaring.i
@@ -16,6 +16,7 @@
namespace std {
%template(vectordatetime) vector<Kolab::cDateTime>;
+ %template(vectorevent) vector<Kolab::Event>;
};
/*%apply const std::string& {std::string* foo};*/
commit 75bfe95e2d25957ab13e14c25ac99f29155512f2
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Wed May 30 17:44:18 2012 +0200
convert delagations
diff --git a/conversion/commonconversion.cpp b/conversion/commonconversion.cpp
index d91accf..60128f3 100644
--- a/conversion/commonconversion.cpp
+++ b/conversion/commonconversion.cpp
@@ -18,8 +18,10 @@
#include "commonconversion.h"
#include <kolabformat/errorhandler.h>
+#include <iostream>
#include <KDE/KSystemTimeZones>
#include <KDE/KDebug>
+#include <QUrl>
namespace Kolab {
namespace Conversion {
@@ -113,5 +115,42 @@ std::vector<std::string> fromStringList(const QStringList &l)
return list;
}
+QUrl toMailto(const std::string &email, const std::string &name)
+{
+ std::string mailto;
+ if (!name.empty()) {
+ mailto.append(name);
+ }
+ mailto.append("<");
+ mailto.append(email);
+ mailto.append(">");
+ return QUrl(QString::fromStdString(std::string("mailto:")+mailto));
+}
+
+std::string fromMailto(const QUrl &mailtoUri, std::string &name)
+{
+ const std::string &decoded = mailtoUri.toString().toStdString();
+ if (decoded.substr(0, 7).compare("mailto:")) {
+ WARNING("no mailto address");
+ std::cout << decoded << std::endl;
+ return decoded;
+ }
+ std::size_t begin = decoded.find('<',7);
+ if (begin == std::string::npos) {
+ WARNING("no mailto address");
+ std::cout << decoded << std::endl;
+ return decoded;
+ }
+ std::size_t end = decoded.find('>', begin);
+ if (end == std::string::npos) {
+ WARNING("no mailto address");
+ std::cout << decoded << std::endl;
+ return decoded;
+ }
+ name = decoded.substr(7, begin-7);
+ const std::string &email = decoded.substr(begin+1, end-begin-1);
+ return email;
+}
+
}
}
\ No newline at end of file
diff --git a/conversion/commonconversion.h b/conversion/commonconversion.h
index 7a3bc82..dda12ba 100644
--- a/conversion/commonconversion.h
+++ b/conversion/commonconversion.h
@@ -33,6 +33,10 @@ namespace Kolab {
* Returns a UTC, Floating Time or Timezone
*/
KDateTime::Spec getTimeSpec(bool isUtc, const std::string &timezone);
+
+ QUrl toMailto(const std::string &email, const std::string &name = std::string());
+ std::string fromMailto(const QUrl &mailtoUri, std::string &name);
+
};
};
diff --git a/conversion/kcalconversion.cpp b/conversion/kcalconversion.cpp
index e86b3ec..9f703cd 100644
--- a/conversion/kcalconversion.cpp
+++ b/conversion/kcalconversion.cpp
@@ -21,6 +21,7 @@
#include <QtCore/QBitArray>
#include <QtCore/QVector>
#include <QtCore/QDebug>
+#include <QUrl>
#include <vector>
#include "kolabformat/errorhandler.h"
@@ -31,6 +32,7 @@ namespace Kolab {
//The uid of a contact which refers to the uuid of a contact in the addressbook
#define CUSTOM_KOLAB_CONTACT_UUID "X_KOLAB_CONTACT_UUID"
+#define CUSTOM_KOLAB_CONTACT_CUTYPE "X_KOLAB_CONTACT_CUTYPE"
KCalCore::Duration toDuration(const Kolab::Duration &d)
{
@@ -291,6 +293,21 @@ void setIncidence(KCalCore::Incidence &i, const T &e)
if (!a.contact().uid().empty()) { //TODO Identify contact from addressbook based on uid
attendee->customProperties().setNonKDECustomProperty(CUSTOM_KOLAB_CONTACT_UUID, QString::fromStdString(a.contact().uid()));
}
+ if (!a.delegatedTo().empty()) {
+ if (a.delegatedTo().size() > 1) {
+ WARNING("multiple delegatees are not supported");
+ }
+ attendee->setDelegate(toMailto(a.delegatedTo().front().email(), a.delegatedTo().front().name()).toString());
+ }
+ if (!a.delegatedFrom().empty()) {
+ if (a.delegatedFrom().size() > 1) {
+ WARNING("multiple delegators are not supported");
+ }
+ attendee->setDelegator(toMailto(a.delegatedFrom().front().email(), a.delegatedFrom().front().name()).toString());
+ }
+ if (!a.cutype() != CutypeIndividual) {
+ attendee->customProperties().setNonKDECustomProperty(CUSTOM_KOLAB_CONTACT_CUTYPE, QString::number(a.cutype()));
+ }
i.addAttendee(attendee);
}
foreach (const Kolab::Attachment a, e.attachments()) {
@@ -330,6 +347,21 @@ void getIncidence(T &i, const I &e)
a.setRSVP(ptr->RSVP());
a.setPartStat(fromPartStat(ptr->status()));
a.setRole(fromRole(ptr->role()));
+ if (!ptr->delegate().isEmpty()) {
+ std::string name;
+ const std::string &email = fromMailto(ptr->delegate(), name);
+ a.setDelegatedTo(std::vector<Kolab::ContactReference>() << Kolab::ContactReference(email, name));
+ }
+ if (!ptr->delegator().isEmpty()) {
+ std::string name;
+ const std::string &email = fromMailto(ptr->delegator(), name);
+ a.setDelegatedFrom(std::vector<Kolab::ContactReference>() << Kolab::ContactReference(email, name));
+ }
+ const QString &cutype = ptr->customProperties().nonKDECustomProperty(CUSTOM_KOLAB_CONTACT_CUTYPE);
+ if (!cutype.isEmpty()) {
+ a.setCutype(static_cast<Kolab::Cutype>(cutype.toInt()));
+ }
+
attendees.push_back(a);
}
i.setAttendees(attendees);
diff --git a/tests/calendaringtest.cpp b/tests/calendaringtest.cpp
index fd88cd6..19935c6 100644
--- a/tests/calendaringtest.cpp
+++ b/tests/calendaringtest.cpp
@@ -21,7 +21,7 @@
#include <QTest>
#include <kolabevent.h>
-
+#include <iostream>
#include "calendaring/calendaring.h"
#include <calendaring/event.h>
@@ -312,6 +312,7 @@ void CalendaringTest::delegationTest()
event.setStart(Kolab::cDateTime("Europe/Zurich",2012,5,5,3,4,4));
Kolab::Attendee att1(Kolab::ContactReference("email1", "name1", "uid1"));
+ att1.setCutype(Kolab::CutypeIndividual);
Kolab::Attendee att2(Kolab::ContactReference("email2", "name2", "uid2"));
Kolab::Attendee att3(Kolab::ContactReference("email3", "name3", "uid3"));
Kolab::Attendee att4(Kolab::ContactReference("email4", "name4", "uid4"));
diff --git a/tests/kcalconversiontest.cpp b/tests/kcalconversiontest.cpp
index 29a7573..086b66a 100644
--- a/tests/kcalconversiontest.cpp
+++ b/tests/kcalconversiontest.cpp
@@ -166,8 +166,10 @@ void KCalConversionTest::testConversion_data()
kcal.setStatus(KCalCore::Incidence::StatusConfirmed);
kcal.setLocation("location");
kcal.setOrganizer(KCalCore::Person::Ptr(new KCalCore::Person("organizer", "organizer at email")));
- kcal.addAttendee(KCalCore::Attendee::Ptr(new KCalCore::Attendee("attendee", "attendee at email", false, KCalCore::Attendee::NeedsAction, KCalCore::Attendee::ReqParticipant)));
- //TODO KCalCore Delegate/Delegator
+ KCalCore::Attendee::Ptr att(new KCalCore::Attendee("attendee", "attendee at email", false, KCalCore::Attendee::NeedsAction, KCalCore::Attendee::ReqParticipant));
+ att->setDelegate("mailto:delegatee<delegatee at email>");
+ att->setDelegator("mailto:delegator<delegator at email>");
+ kcal.addAttendee(att);
kcal.addAttachment(KCalCore::Attachment::Ptr(new KCalCore::Attachment(QString("uri"), "mimetype/mime")));
KCalCore::Alarm::Ptr alarm = KCalCore::Alarm::Ptr(new KCalCore::Alarm(&kcal));
KCalCore::Person::List addressees;
@@ -214,6 +216,9 @@ void KCalConversionTest::testConversion_data()
kolab.setOrganizer(Kolab::ContactReference(Kolab::ContactReference::EmailReference,"organizer at email", "organizer")); //TODO uid
Kolab::Attendee a(Kolab::ContactReference(Kolab::ContactReference::EmailReference,"attendee at email", "attendee"));//TODO uid
+ a.setDelegatedTo(std::vector<Kolab::ContactReference>() << Kolab::ContactReference(Kolab::ContactReference::EmailReference,"delegatee at email", "delegatee"));
+ a.setDelegatedFrom(std::vector<Kolab::ContactReference>() << Kolab::ContactReference(Kolab::ContactReference::EmailReference,"delegator at email", "delegator"));
+ a.setCutype(Kolab::CutypeIndividual);
kolab.setAttendees(std::vector<Kolab::Attendee>() << a);
Kolab::Attachment attach;
@@ -315,9 +320,9 @@ void KCalConversionTest::testConversion()
// QCOMPARE(e->alarms(), kcal.alarms()); //TODO
//TODO custom properties
- QBENCHMARK {
- toKCalCore(kolab);
- }
+// QBENCHMARK {
+// toKCalCore(kolab);
+// }
const Kolab::Event &b = fromKCalCore(kcal);
QCOMPARE(b.uid(), kolab.uid());
@@ -339,6 +344,10 @@ void KCalConversionTest::testConversion()
QCOMPARE(b.summary(), kolab.summary());
QCOMPARE(b.description(), kolab.description());
QCOMPARE(b.status(), kolab.status());
+ QCOMPARE(b.location(), kolab.location());
+ QCOMPARE(b.organizer(), kolab.organizer());
+ QCOMPARE(b.attendees(), kolab.attendees());
+ QCOMPARE(b.attachments(), kolab.attachments());
}
diff --git a/tests/testhelpers.h b/tests/testhelpers.h
index 8dd7b35..d425686 100644
--- a/tests/testhelpers.h
+++ b/tests/testhelpers.h
@@ -197,6 +197,57 @@ namespace QTest {
return qstrdup(ba.data());
}
+ template<>
+ char *toString(const Kolab::ContactReference &a)
+ {
+ QByteArray ba = "Kolab::ContactReference(";
+ ba += QString::fromStdString(a.email()).toAscii()+ ", ";
+ ba += QString::fromStdString(a.name()).toAscii()+ ", ";
+ ba += QString::fromStdString(a.uid()).toAscii();
+ ba += ")";
+ return qstrdup(ba.data());
+ }
+
+ template<>
+ char *toString(const std::vector<Kolab::ContactReference> &v)
+ {
+ QByteArray ba = "vector<Kolab::ContactReference>(";
+ for (int i = 0; i < v.size(); i++) {
+ ba += QByteArray(toString(v.at(i)))+ "\n";
+ }
+ ba += ")";
+ return qstrdup(ba.data());
+ }
+
+ template<>
+ char *toString(const Kolab::Attendee &a)
+ {
+ QByteArray ba = "Kolab::Attendee(";
+ ba += QString::fromStdString(a.contact().email()).toAscii() + "\n";
+ ba += QString::fromStdString(a.contact().name()).toAscii()+ "\n";
+ ba += QByteArray::number(a.partStat()) + "\n";
+ ba += QByteArray::number(a.role()) + "\n";
+ ba += QByteArray::number(a.rsvp()) + "\n";
+ ba += QString::fromStdString(a.contact().uid()).toAscii()+"\n";
+ ba += QByteArray(toString(a.delegatedTo()))+"\n";
+ ba += QByteArray(toString(a.delegatedFrom()))+ "\n";
+ ba += QByteArray::number(a.cutype())+ "\n";
+ ba += ")";
+ return qstrdup(ba.data());
+ }
+
+ template<>
+ char *toString(const std::vector<Kolab::Attendee> &v)
+ {
+ QByteArray ba = "vector<Kolab::Attendee>(";
+ for (int i = 0; i < v.size(); i++) {
+ ba += QByteArray(toString(v.at(i)))+ "\n";
+ ba += QByteArray("#######################")+ "\n";
+ }
+ ba += ")";
+ return qstrdup(ba.data());
+ }
+
}
More information about the commits
mailing list