diff --git a/autotests/testattendee.cpp b/autotests/testattendee.cpp --- a/autotests/testattendee.cpp +++ b/autotests/testattendee.cpp @@ -22,6 +22,7 @@ #include "testattendee.h" #include "attendee.h" +#include "person.h" #include #include diff --git a/src/attendee.h b/src/attendee.h --- a/src/attendee.h +++ b/src/attendee.h @@ -30,10 +30,10 @@ #define KCALCORE_ATTENDEE_H #include +#include #include "kcalcore_export.h" #include "customproperties.h" -#include "person.h" namespace KCalCore { @@ -55,15 +55,9 @@ (unique identifier) derived from a Calendar Incidence, Email Message, or any other thing you want. */ -class KCALCORE_EXPORT Attendee : private Person +class KCALCORE_EXPORT Attendee { public: - using Person::setEmail; - using Person::email; - using Person::setName; - using Person::name; - using Person::fullName; - /** The different types of participant status. The meaning is specific to the incidence type in context. @@ -118,7 +112,7 @@ typedef QVector List; /** - Constructs an attendee consisting of a Person name (@p name) and + Constructs an attendee consisting of a person name (@p name) and email address (@p email); invitation status and #Role; an optional @acronym RSVP flag and @acronym UID. @@ -145,6 +139,31 @@ */ ~Attendee(); + /** + Returns the name of the attendee. + */ + Q_REQUIRED_RESULT QString name() const; + /** + Sets the name of the attendee to @p name. + */ + void setName(const QString &name); + + /** + Returns the full name and email address of this attendee + @return A QString containing the person's full name in the form + "FirstName LastName \". + */ + Q_REQUIRED_RESULT QString fullName() const; + + /** + Returns the email address for this attendee. + */ + Q_REQUIRED_RESULT QString email() const; + /** + Sets the email address for this attendee to @p email. + */ + void setEmail(const QString &email); + /** Sets the Role of the attendee to @p role. diff --git a/src/attendee.cpp b/src/attendee.cpp --- a/src/attendee.cpp +++ b/src/attendee.cpp @@ -32,6 +32,8 @@ */ #include "attendee.h" +#include "person.h" +#include "person_p.h" #include @@ -57,6 +59,8 @@ QString mDelegate; QString mDelegator; CustomProperties mCustomProperties; + QString mName; + QString mEmail; private: QString sCuType; CuType mCuType; @@ -128,8 +132,7 @@ } Attendee::Attendee(const Attendee &attendee) - : Person(attendee), - d(new Attendee::Private(*attendee.d)) + : d(new Attendee::Private(*attendee.d)) { } @@ -148,7 +151,8 @@ d->mDelegate == attendee.d->mDelegate && d->mDelegator == attendee.d->mDelegator && d->cuTypeStr() == attendee.d->cuTypeStr() && - (const Person &) * this == (const Person &)attendee; + d->mName == attendee.d->mName && + d->mEmail == attendee.d->mEmail; } bool KCalCore::Attendee::operator!=(const Attendee &attendee) const @@ -164,11 +168,34 @@ } *d = *attendee.d; - setName(attendee.name()); - setEmail(attendee.email()); return *this; } +QString Attendee::name() const +{ + return d->mName; +} + +void Attendee::setName(const QString &name) +{ + d->mName = name; +} + +QString Attendee::fullName() const +{ + return fullNameHelper(d->mName, d->mEmail); +} + +QString Attendee::email() const +{ + return d->mEmail; +} + +void Attendee::setEmail(const QString &email) +{ + d->mEmail = email; +} + void Attendee::setRSVP(bool r) { d->mRSVP = r; @@ -266,7 +293,7 @@ QDataStream &KCalCore::operator<<(QDataStream &stream, const KCalCore::Attendee::Ptr &attendee) { - KCalCore::Person::Ptr p(new KCalCore::Person(*((Person *)attendee.data()))); + KCalCore::Person::Ptr p(new KCalCore::Person(attendee->name(), attendee->email())); stream << p; return stream << attendee->d->mRSVP << int(attendee->d->mRole) diff --git a/src/incidencebase.h b/src/incidencebase.h --- a/src/incidencebase.h +++ b/src/incidencebase.h @@ -59,6 +59,7 @@ #include "attendee.h" #include "customproperties.h" #include "duration.h" +#include "person.h" #include diff --git a/src/person.h b/src/person.h --- a/src/person.h +++ b/src/person.h @@ -178,7 +178,6 @@ Private *const d; //@endcond - // TODO_KDE5: FIXME: This operator does slicing,if the object is in fact one of the derived classes (Attendee) friend KCALCORE_EXPORT QDataStream &operator<<(QDataStream &s, const KCalCore::Person::Ptr &person); friend KCALCORE_EXPORT QDataStream &operator>>(QDataStream &s, diff --git a/src/person.cpp b/src/person.cpp --- a/src/person.cpp +++ b/src/person.cpp @@ -34,6 +34,7 @@ */ #include "person.h" +#include "person_p.h" #include #include @@ -97,29 +98,32 @@ return *this; } -QString Person::fullName() const +QString KCalCore::fullNameHelper(const QString &name, const QString &email) { - if (d->mName.isEmpty()) { - return d->mEmail; - } else { - if (d->mEmail.isEmpty()) { - return d->mName; - } else { - // Taken from KContacts::Addressee::fullEmail - QString name = d->mName; - QRegExp needQuotes(QStringLiteral("[^ 0-9A-Za-z\\x0080-\\xFFFF]")); - bool weNeedToQuote = name.indexOf(needQuotes) != -1; - if (weNeedToQuote) { - if (name[0] != QLatin1Char('"')) { - name.prepend(QLatin1Char('"')); - } - if (name[ name.length() - 1 ] != QLatin1Char('"')) { - name.append(QLatin1Char('"')); - } - } - return name + QStringLiteral(" <") + d->mEmail + QLatin1Char('>'); + if (name.isEmpty()) { + return email; + } + if (email.isEmpty()) { + return name; + } + // Taken from KContacts::Addressee::fullEmail + QString fullName = name; + QRegExp needQuotes(QStringLiteral("[^ 0-9A-Za-z\\x0080-\\xFFFF]")); + bool weNeedToQuote = name.indexOf(needQuotes) != -1; + if (weNeedToQuote) { + if (fullName[0] != QLatin1Char('"')) { + fullName.prepend(QLatin1Char('"')); + } + if (fullName[ fullName.length() - 1 ] != QLatin1Char('"')) { + fullName.append(QLatin1Char('"')); } } + return fullName + QStringLiteral(" <") + email + QLatin1Char('>'); +} + +QString Person::fullName() const +{ + return fullNameHelper(d->mName, d->mEmail); } QString Person::name() const diff --git a/src/person_p.h b/src/person_p.h new file mode 100644 --- /dev/null +++ b/src/person_p.h @@ -0,0 +1,32 @@ +/* + This file is part of the kcalcore library. + + Copyright (c) 2019 Volker Krause + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KCALCORE_PERSON_P_H +#define KCALCORE_PERSON_P_H + +class QString; + +namespace KCalCore +{ + QString fullNameHelper(const QString &name, const QString &email); +} + +#endif