Branch 'kolab/integration/4.13.0' - kcalcore/attendee.cpp kcalcore/attendee.h kcalcore/tests

Sandro Knauß knauss at kolabsys.com
Wed Apr 30 17:45:56 CEST 2014


 kcalcore/attendee.cpp           |   87 ++++++++++++++++++++++++++++++++++++++++
 kcalcore/attendee.h             |   51 +++++++++++++++++++++++
 kcalcore/tests/testattendee.cpp |   75 ++++++++++++++++++++++++++++++++++
 kcalcore/tests/testattendee.h   |    2 
 4 files changed, 214 insertions(+), 1 deletion(-)

New commits:
commit f80252ca600bb43b01652b93cf618081c3c88654
Author: Sandro Knauß <knauss at kolabsys.com>
Date:   Tue Apr 29 16:35:48 2014 +0200

    Added handling for cutype of an Attendee
    
    REVIEW: 117875

diff --git a/kcalcore/attendee.cpp b/kcalcore/attendee.cpp
index a31827c..da51441 100644
--- a/kcalcore/attendee.cpp
+++ b/kcalcore/attendee.cpp
@@ -45,6 +45,11 @@ using namespace KCalCore;
 class KCalCore::Attendee::Private
 {
 public:
+    void setCuType(CuType cuType);
+    void setCuType(const QString &cuType);
+    CuType cuType() const;
+    QString cuTypeStr() const;
+
     bool mRSVP;
     Role mRole;
     PartStat mStatus;
@@ -52,9 +57,65 @@ public:
     QString mDelegate;
     QString mDelegator;
     CustomProperties mCustomProperties;
+private:
+    QString sCuType;
+    CuType mCuType;
 };
 //@endcond
 
+void KCalCore::Attendee::Private::setCuType(Attendee::CuType cuType)
+{
+    mCuType = cuType;
+    sCuType.clear();
+}
+
+void KCalCore::Attendee::Private::setCuType(const QString &cuType)
+{
+    const QString upper = cuType.toUpper();
+    if (upper == QLatin1String("INDIVIDUAL")) {
+        setCuType(Attendee::Individual);
+    } else if (upper == QLatin1String("GROUP")) {
+        setCuType(Attendee::Group);
+    } else if (upper == QLatin1String("RESOURCE")) {
+        setCuType(Attendee::Resource);
+    } else if (upper == QLatin1String("ROOM")) {
+        setCuType(Attendee::Room);
+    } else {
+        setCuType(Attendee::Unknown);
+        if (upper.startsWith(QLatin1String("X-")) || upper.startsWith(QLatin1String("IANA-"))) {
+            sCuType = upper;
+        }
+    }
+}
+
+Attendee::CuType KCalCore::Attendee::Private::cuType() const
+{
+    return mCuType;
+}
+
+QString KCalCore::Attendee::Private::cuTypeStr() const
+{
+    switch (mCuType) {
+    case Attendee::Individual:
+        return QLatin1String("INDIVIDUAL");
+    case Attendee::Group:
+        return QLatin1String("GROUP");
+    case Attendee::Resource:
+        return QLatin1String("RESOURCE");
+    case Attendee::Room:
+        return QLatin1String("ROOM");
+    case Attendee::Unknown:
+        if (sCuType.isEmpty()) {
+            return QLatin1String("UNKNOWN");
+        } else {
+            return sCuType;
+        }
+    }
+    return QLatin1String("UNKNOWN");
+}
+
+
+
 Attendee::Attendee(const QString &name, const QString &email, bool rsvp,
                    Attendee::PartStat status, Attendee::Role role, const QString &uid)
     : d(new Attendee::Private)
@@ -65,6 +126,7 @@ Attendee::Attendee(const QString &name, const QString &email, bool rsvp,
     d->mStatus = status;
     d->mRole = role;
     d->mUid = uid;
+    d->setCuType(Attendee::Individual);
 }
 
 Attendee::Attendee(const Attendee &attendee)
@@ -87,6 +149,7 @@ bool KCalCore::Attendee::operator==(const Attendee &attendee) const
         d->mStatus == attendee.d->mStatus &&
         d->mDelegate == attendee.d->mDelegate &&
         d->mDelegator == attendee.d->mDelegator &&
+        d->cuTypeStr() == attendee.d->cuTypeStr() &&
         (const Person &)*this == (const Person &)attendee;
 }
 
@@ -128,6 +191,26 @@ Attendee::PartStat Attendee::status() const
     return d->mStatus;
 }
 
+void Attendee::setCuType(Attendee::CuType cuType)
+{
+    d->setCuType(cuType);
+}
+
+void Attendee::setCuType(const QString &cuType)
+{
+    d->setCuType(cuType);
+}
+
+Attendee::CuType Attendee::cuType() const
+{
+    return d->cuType();
+}
+
+QString Attendee::cuTypeStr() const
+{
+    return d->cuTypeStr();
+}
+
 void Attendee::setRole(Attendee::Role role)
 {
     d->mRole = role;
@@ -193,6 +276,7 @@ QDataStream &KCalCore::operator<<(QDataStream &stream, const KCalCore::Attendee:
            << attendee->d->mUid
            << attendee->d->mDelegate
            << attendee->d->mDelegator
+           << attendee->d->cuTypeStr()
            << attendee->d->mCustomProperties;
 }
 
@@ -204,6 +288,7 @@ QDataStream &KCalCore::operator>>(QDataStream &stream, KCalCore::Attendee::Ptr &
     QString uid;
     QString delegate;
     QString delegator;
+    QString cuType;
     CustomProperties customProperties;
     uint role_int;
     uint status_int;
@@ -216,6 +301,7 @@ QDataStream &KCalCore::operator>>(QDataStream &stream, KCalCore::Attendee::Ptr &
            >> uid
            >> delegate
            >> delegator
+           >> cuType
            >> customProperties;
 
     role = Attendee::Role(role_int);
@@ -225,6 +311,7 @@ QDataStream &KCalCore::operator>>(QDataStream &stream, KCalCore::Attendee::Ptr &
                            RSVP, status, role, uid));
     att_temp->setDelegate(delegate);
     att_temp->setDelegator(delegator);
+    att_temp->setCuType(cuType);
     att_temp->d->mCustomProperties = customProperties;
     attendee.swap(att_temp);
     return stream;
diff --git a/kcalcore/attendee.h b/kcalcore/attendee.h
index 226b2ac..9ebea8c 100644
--- a/kcalcore/attendee.h
+++ b/kcalcore/attendee.h
@@ -88,6 +88,23 @@ public:
         Chair            /**< Chairperson */
     };
 
+
+    /**
+     * The different types of a participant.
+     */
+    enum CuType {
+        Individual,       /**< An individual (default) */
+        Group,            /**< A group of individuals */
+        Resource,         /**< A physical resource */
+        Room,             /**< A room resource */
+        Unknown           /**< Otherwise not known */
+        /**
+         * Parameters that have to set via the QString variant of @setCuType() and @cuType()
+         * x-name         ; Experimental cuType
+         * iana-token     ; Other IANA-registered
+         */
+    };
+
     /**
       A shared pointer to an Attendee object.
     */
@@ -175,6 +192,40 @@ public:
     PartStat status() const;
 
     /**
+      Sets the #CuType of the attendee to @p cuType.
+
+      @param cuType is the #CuType to use for the attendee.
+
+      @see cuType()
+    */
+    void setCuType(CuType cuType);
+
+    /**
+      Sets the #CuType of the attendee to @p cuType.
+
+      @param cuType is the #CuType to use for the attendee.
+
+      @see cuType()
+    */
+    void setCuType(const QString &cuType);
+
+
+    /**
+      Returns the #CuType of the attendee.
+
+      @see setCuType()
+    */
+    CuType cuType() const;
+
+    /**
+      Returns the #CuType of the attendee.
+
+      @see setCuType()
+    */
+    QString cuTypeStr() const;
+
+
+    /**
       Sets the @acronym RSVP flag of the attendee to @p rsvp.
 
       @param rsvp if set (true), the attendee is requested to reply to
diff --git a/kcalcore/tests/testattendee.cpp b/kcalcore/tests/testattendee.cpp
index 3648a35..7581c51 100644
--- a/kcalcore/tests/testattendee.cpp
+++ b/kcalcore/tests/testattendee.cpp
@@ -37,6 +37,60 @@ void AttendeeTest::testValidity()
     QVERIFY(attendee.role() == Attendee::Chair);
 }
 
+void AttendeeTest::testType()
+{
+    Attendee attendee("fred", "fred at flintstone.com");
+    QCOMPARE(attendee.cuType(), Attendee::Individual);
+    QCOMPARE(attendee.cuTypeStr(), QLatin1String("INDIVIDUAL"));
+
+    attendee.setCuType(attendee.cuTypeStr());
+    QCOMPARE(attendee.cuType(), Attendee::Individual);
+
+    attendee.setCuType(QLatin1String("INVALID"));
+    QCOMPARE(attendee.cuType(), Attendee::Unknown);
+    QCOMPARE(attendee.cuTypeStr(), QLatin1String("UNKNOWN"));
+
+    attendee.setCuType(QLatin1String("group"));
+    QCOMPARE(attendee.cuType(), Attendee::Group);
+    QCOMPARE(attendee.cuTypeStr(), QLatin1String("GROUP"));
+
+    attendee.setCuType(QLatin1String("resource"));
+    QCOMPARE(attendee.cuType(), Attendee::Resource);
+    QCOMPARE(attendee.cuTypeStr(), QLatin1String("RESOURCE"));
+
+    attendee.setCuType(QLatin1String("ROOM"));
+    QCOMPARE(attendee.cuType(), Attendee::Room);
+    QCOMPARE(attendee.cuTypeStr(), QLatin1String("ROOM"));
+
+    attendee.setCuType(QLatin1String("UNKNOWN"));
+    QCOMPARE(attendee.cuType(), Attendee::Unknown);
+    QCOMPARE(attendee.cuTypeStr(), QLatin1String("UNKNOWN"));
+
+    attendee.setCuType(QLatin1String("X-test"));
+    QCOMPARE(attendee.cuType(), Attendee::Unknown);
+    QCOMPARE(attendee.cuTypeStr(), QLatin1String("X-TEST"));
+
+    attendee.setCuType(QLatin1String("IANA-TEST"));
+    QCOMPARE(attendee.cuType(), Attendee::Unknown);
+    QCOMPARE(attendee.cuTypeStr(), QLatin1String("IANA-TEST"));
+
+    attendee.setCuType(Attendee::Individual);
+    QCOMPARE(attendee.cuType(), Attendee::Individual);
+
+    attendee.setCuType(Attendee::Group);
+    QCOMPARE(attendee.cuType(), Attendee::Group);
+
+    attendee.setCuType(Attendee::Resource);
+    QCOMPARE(attendee.cuType(), Attendee::Resource);
+
+    attendee.setCuType(Attendee::Room);
+    QCOMPARE(attendee.cuType(), Attendee::Room);
+
+    attendee.setCuType(Attendee::Unknown);
+    QCOMPARE(attendee.cuType(), Attendee::Unknown);
+}
+
+
 void AttendeeTest::testCompare()
 {
     Attendee attendee1("fred", "fred at flintstone.com");
@@ -49,6 +103,19 @@ void AttendeeTest::testCompare()
     QVERIFY(attendee1.name() == "fred");
 }
 
+void AttendeeTest::testCompareType()
+{
+    Attendee attendee1("fred", "fred at flintstone.com");
+    attendee1.setCuType(Attendee::Resource);
+    Attendee attendee2 = attendee1;
+
+    QCOMPARE(attendee2.cuType(), Attendee::Resource);
+    QVERIFY(attendee1 == attendee2);
+
+    attendee2.setCuType(Attendee::Individual);
+    QVERIFY(!(attendee1 == attendee2));
+}
+
 void AttendeeTest::testAssign()
 {
     Attendee attendee1("fred", "fred at flintstone.com");
@@ -70,6 +137,7 @@ void AttendeeTest::testDataStreamOut()
     attendee1->setUid("Shooby Doo Bop");
     attendee1->setDelegate("I AM THE Delegate");
     attendee1->setDelegator("AND I AM THE Delegator");
+    attendee1->setCuType(QLatin1String("X-SPECIAL"));
     attendee1->setCustomProperty("name", "value");
     attendee1->setCustomProperty("foo", "bar");
 
@@ -82,7 +150,7 @@ void AttendeeTest::testDataStreamOut()
 
     Person::Ptr person;
     bool rsvp;
-    QString name, email, delegate, delegator, uid;
+    QString name, email, delegate, delegator, cuType, uid;
     CustomProperties customProperties;
     Attendee::Role role;
     Attendee::PartStat status;
@@ -112,6 +180,9 @@ void AttendeeTest::testDataStreamOut()
     in_stream >> delegator;
     QVERIFY(delegator == attendee1->delegator());
 
+    in_stream >> cuType;
+    QVERIFY(cuType == attendee1->cuTypeStr());
+
     in_stream >> customProperties;
     QVERIFY(customProperties == attendee1->customProperties());
 }
@@ -121,6 +192,7 @@ void AttendeeTest::testDataStreamIn()
     Attendee::Ptr attendee1(new Attendee("fred", "fred at flintstone.com"));
     attendee1->setRSVP(true);
     attendee1->setRole(Attendee::Chair);
+    attendee1->setCuType(QLatin1String("IANA-FOO"));
     attendee1->setUid("Shooby Doo Bop");
     attendee1->setDelegate("I AM THE Delegate");
     attendee1->setDelegator("AND I AM THE Delegator");
@@ -141,6 +213,7 @@ void AttendeeTest::testDataStreamIn()
     QVERIFY(attendee2->uid() == attendee1->uid());
     QVERIFY(attendee2->RSVP() == attendee1->RSVP());
     QVERIFY(attendee2->role() == attendee1->role());
+    QVERIFY(attendee2->cuTypeStr() == attendee1->cuTypeStr());
     QVERIFY(attendee2->status() == attendee1->status());
     QVERIFY(attendee2->delegate() == attendee1->delegate());
     QVERIFY(attendee2->delegator() == attendee1->delegator());
diff --git a/kcalcore/tests/testattendee.h b/kcalcore/tests/testattendee.h
index 35a224f..05c9291 100644
--- a/kcalcore/tests/testattendee.h
+++ b/kcalcore/tests/testattendee.h
@@ -30,7 +30,9 @@ class AttendeeTest : public QObject
     Q_OBJECT
 private Q_SLOTS:
     void testValidity();
+    void testType();
     void testCompare();
+    void testCompareType();
     void testAssign();
     void testDataStreamOut();
     void testDataStreamIn();




More information about the commits mailing list