diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.5) -set(PIM_VERSION "5.11.43") +set(PIM_VERSION "5.11.44") project(KCalCore VERSION ${PIM_VERSION}) diff --git a/autotests/testattendee.cpp b/autotests/testattendee.cpp --- a/autotests/testattendee.cpp +++ b/autotests/testattendee.cpp @@ -131,15 +131,15 @@ void AttendeeTest::testDataStreamOut() { - Attendee::Ptr attendee1(new Attendee(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com"))); - attendee1->setRSVP(true); - attendee1->setRole(Attendee::Chair); - attendee1->setUid(QStringLiteral("Shooby Doo Bop")); - attendee1->setDelegate(QStringLiteral("I AM THE Delegate")); - attendee1->setDelegator(QStringLiteral("AND I AM THE Delegator")); - attendee1->setCuType(QStringLiteral("X-SPECIAL")); - attendee1->setCustomProperty("name", QStringLiteral("value")); - attendee1->setCustomProperty("foo", QStringLiteral("bar")); + Attendee attendee1(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com")); + attendee1.setRSVP(true); + attendee1.setRole(Attendee::Chair); + attendee1.setUid(QStringLiteral("Shooby Doo Bop")); + attendee1.setDelegate(QStringLiteral("I AM THE Delegate")); + attendee1.setDelegator(QStringLiteral("AND I AM THE Delegator")); + attendee1.setCuType(QStringLiteral("X-SPECIAL")); + attendee1.setCustomProperty("name", QStringLiteral("value")); + attendee1.setCustomProperty("foo", QStringLiteral("bar")); QByteArray byteArray; QDataStream out_stream(&byteArray, QIODevice::WriteOnly); @@ -157,76 +157,77 @@ uint role_int, status_int; in_stream >> person; - QVERIFY(person.name() == attendee1->name()); - QVERIFY(person.email() == attendee1->email()); + QVERIFY(person.name() == attendee1.name()); + QVERIFY(person.email() == attendee1.email()); in_stream >> rsvp; - QVERIFY(rsvp == attendee1->RSVP()); + QVERIFY(rsvp == attendee1.RSVP()); in_stream >> role_int; role = Attendee::Role(role_int); - QVERIFY(role == attendee1->role()); + QVERIFY(role == attendee1.role()); in_stream >> status_int; status = Attendee::PartStat(status_int); - QVERIFY(status == attendee1->status()); + QVERIFY(status == attendee1.status()); in_stream >> uid; - QVERIFY(uid == attendee1->uid()); + QVERIFY(uid == attendee1.uid()); in_stream >> delegate; - QVERIFY(delegate == attendee1->delegate()); + QVERIFY(delegate == attendee1.delegate()); in_stream >> delegator; - QVERIFY(delegator == attendee1->delegator()); + QVERIFY(delegator == attendee1.delegator()); in_stream >> cuType; - QVERIFY(cuType == attendee1->cuTypeStr()); + QVERIFY(cuType == attendee1.cuTypeStr()); in_stream >> customProperties; - QVERIFY(customProperties == attendee1->customProperties()); + QVERIFY(customProperties == attendee1.customProperties()); } void AttendeeTest::testDataStreamIn() { - Attendee::Ptr attendee1(new Attendee(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com"))); - attendee1->setRSVP(true); - attendee1->setRole(Attendee::Chair); - attendee1->setCuType(QStringLiteral("IANA-FOO")); - attendee1->setUid(QStringLiteral("Shooby Doo Bop")); - attendee1->setDelegate(QStringLiteral("I AM THE Delegate")); - attendee1->setDelegator(QStringLiteral("AND I AM THE Delegator")); - attendee1->setCustomProperty("name", QStringLiteral("value")); - attendee1->setCustomProperty("foo", QStringLiteral("bar")); + Attendee attendee1(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com")); + attendee1.setRSVP(true); + attendee1.setRole(Attendee::Chair); + attendee1.setCuType(QStringLiteral("IANA-FOO")); + attendee1.setUid(QStringLiteral("Shooby Doo Bop")); + attendee1.setDelegate(QStringLiteral("I AM THE Delegate")); + attendee1.setDelegator(QStringLiteral("AND I AM THE Delegator")); + attendee1.setCustomProperty("name", QStringLiteral("value")); + attendee1.setCustomProperty("foo", QStringLiteral("bar")); + QVERIFY(!attendee1.isNull()); QByteArray byteArray; QDataStream out_stream(&byteArray, QIODevice::WriteOnly); out_stream << attendee1; - Attendee::Ptr attendee2; + Attendee attendee2; QDataStream in_stream(&byteArray, QIODevice::ReadOnly); in_stream >> attendee2; - QVERIFY(attendee2); - 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()); - QVERIFY(attendee2->customProperties() == attendee1->customProperties()); - QVERIFY(*attendee1 == *attendee2); + QVERIFY(!attendee2.isNull()); + 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()); + QVERIFY(attendee2.customProperties() == attendee1.customProperties()); + QVERIFY(attendee1 == attendee2); } void AttendeeTest::testUid() { - Attendee::Ptr a(new Attendee(QStringLiteral("me"), QStringLiteral("test@dev.null"))); - QVERIFY(!a->uid().isEmpty()); - a->setUid(QStringLiteral("42")); - QCOMPARE(a->uid(), QLatin1String("42")); - a->setUid({}); - QVERIFY(!a->uid().isEmpty()); + Attendee a(QStringLiteral("me"), QStringLiteral("test@dev.null")); + QVERIFY(!a.uid().isEmpty()); + a.setUid(QStringLiteral("42")); + QCOMPARE(a.uid(), QLatin1String("42")); + a.setUid({}); + QVERIFY(!a.uid().isEmpty()); } diff --git a/autotests/testevent.cpp b/autotests/testevent.cpp --- a/autotests/testevent.cpp +++ b/autotests/testevent.cpp @@ -181,13 +181,13 @@ QDateTime yesterday = today.addDays(-1); Event::Ptr event1 = Event::Ptr(new Event()); - Attendee::Ptr attendee1(new Attendee(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com"))); + Attendee attendee1(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com")); event1->addAttendee(attendee1); event1->setDtStart(yesterday); event1->setDtEnd(today); Event::Ptr event2 = Event::Ptr(new Event()); - Attendee::Ptr attendee2(new Attendee(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com"))); + Attendee attendee2(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com")); event2->addAttendee(attendee2); event2->setDtStart(yesterday); event2->setDtEnd(today); diff --git a/autotests/testicalformat.cpp b/autotests/testicalformat.cpp --- a/autotests/testicalformat.cpp +++ b/autotests/testicalformat.cpp @@ -130,8 +130,8 @@ event->setDtEnd(QDateTime(currentDate.addDays(1), {})); event->setAllDay(true); - Attendee::Ptr attendee(new Attendee(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com"))); - attendee->setCuType(Attendee::Resource); + Attendee attendee(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com")); + attendee.setCuType(Attendee::Resource); event->addAttendee(attendee); @@ -145,10 +145,10 @@ Incidence::Ptr event2 = format.fromString(serializedCalendar); QVERIFY(event2->attendeeCount() == 1); - Attendee::Ptr attendee2 = event2->attendees()[0]; - QVERIFY(attendee2->cuType() == attendee->cuType()); - QVERIFY(attendee2->name() == attendee->name()); - QVERIFY(attendee2->email() == attendee->email()); + Attendee attendee2 = event2->attendees()[0]; + QVERIFY(attendee2.cuType() == attendee.cuType()); + QVERIFY(attendee2.name() == attendee.name()); + QVERIFY(attendee2.email() == attendee.email()); } void ICalFormatTest::testAlarm() diff --git a/src/attendee.h b/src/attendee.h --- a/src/attendee.h +++ b/src/attendee.h @@ -30,7 +30,7 @@ #define KCALCORE_ATTENDEE_H #include -#include +#include #include "kcalcore_export.h" #include "customproperties.h" @@ -101,15 +101,13 @@ */ }; - /** - A shared pointer to an Attendee object. - */ - typedef QSharedPointer Ptr; - /** List of attendees. */ - typedef QVector List; + typedef QVector List; + + /** Create a null Attendee. */ + Attendee(); /** Constructs an attendee consisting of a person name (@p name) and @@ -139,6 +137,11 @@ */ ~Attendee(); + /** + * Returns @c true if this is a default-constructed Attendee instance. + */ + bool isNull() const; + /** Returns the name of the attendee. */ @@ -338,35 +341,35 @@ private: //@cond PRIVATE class Private; - Private *const d; + QSharedDataPointer d; //@endcond friend KCALCORE_EXPORT QDataStream &operator<<(QDataStream &s, - const KCalCore::Attendee::Ptr &attendee); + const KCalCore::Attendee &attendee); friend KCALCORE_EXPORT QDataStream &operator>>(QDataStream &s, - KCalCore::Attendee::Ptr &attendee); + KCalCore::Attendee &attendee); }; /** Serializes an Attendee object into a data stream. @param stream is a QDataStream. @param attendee is a pointer to a Attendee object to be serialized. */ KCALCORE_EXPORT QDataStream &operator<<(QDataStream &stream, - const KCalCore::Attendee::Ptr &attendee); + const KCalCore::Attendee &attendee); /** Initializes an Attendee object from a data stream. @param stream is a QDataStream. @param attendee is a pointer to a Attendee object to be initialized. */ KCALCORE_EXPORT QDataStream &operator>>(QDataStream &stream, - KCalCore::Attendee::Ptr &attendee); + KCalCore::Attendee &attendee); } //@cond PRIVATE -Q_DECLARE_TYPEINFO(KCalCore::Attendee::Ptr, Q_MOVABLE_TYPE); -Q_DECLARE_METATYPE(KCalCore::Attendee::Ptr) +Q_DECLARE_TYPEINFO(KCalCore::Attendee, Q_MOVABLE_TYPE); +Q_DECLARE_METATYPE(KCalCore::Attendee) //@endcond #endif diff --git a/src/attendee.cpp b/src/attendee.cpp --- a/src/attendee.cpp +++ b/src/attendee.cpp @@ -44,7 +44,7 @@ @internal */ //@cond PRIVATE -class Q_DECL_HIDDEN KCalCore::Attendee::Private +class Q_DECL_HIDDEN KCalCore::Attendee::Private : public QSharedData { public: void setCuType(CuType cuType); @@ -55,7 +55,7 @@ bool mRSVP = false; Role mRole; PartStat mStatus; - QString mUid; + mutable QString mUid; QString mDelegate; QString mDelegator; CustomProperties mCustomProperties; @@ -118,6 +118,11 @@ return QStringLiteral("UNKNOWN"); } +Attendee::Attendee() + : d(new Attendee::Private) +{ +} + Attendee::Attendee(const QString &name, const QString &email, bool rsvp, Attendee::PartStat status, Attendee::Role role, const QString &uid) : d(new Attendee::Private) @@ -132,13 +137,16 @@ } Attendee::Attendee(const Attendee &attendee) - : d(new Attendee::Private(*attendee.d)) + : d(attendee.d) { } -Attendee::~Attendee() +Attendee::~Attendee() = default; + +bool Attendee::isNull() const { - delete d; + // isNull rather than isEmpty, as user code is actually creating empty but non-null attendees... + return d->mName.isNull() && d->mEmail.isNull(); } bool KCalCore::Attendee::operator==(const Attendee &attendee) const @@ -167,7 +175,7 @@ return *this; } - *d = *attendee.d; + d = attendee.d; return *this; } @@ -270,7 +278,7 @@ * these will never hit disc though so faster generation speed is * more important than actually being forever unique.*/ if (d->mUid.isEmpty()) { - d->mUid = QString::number((qlonglong)this); + d->mUid = QString::number((qlonglong)d.constData()); } return d->mUid; @@ -311,21 +319,21 @@ return d->mCustomProperties; } -QDataStream &KCalCore::operator<<(QDataStream &stream, const KCalCore::Attendee::Ptr &attendee) +QDataStream &KCalCore::operator<<(QDataStream &stream, const KCalCore::Attendee &attendee) { - KCalCore::Person p(attendee->name(), attendee->email()); + KCalCore::Person p(attendee.name(), attendee.email()); stream << p; - return stream << attendee->d->mRSVP - << int(attendee->d->mRole) - << int(attendee->d->mStatus) - << attendee->d->mUid - << attendee->d->mDelegate - << attendee->d->mDelegator - << attendee->d->cuTypeStr() - << attendee->d->mCustomProperties; + return stream << attendee.d->mRSVP + << int(attendee.d->mRole) + << int(attendee.d->mStatus) + << attendee.d->mUid + << attendee.d->mDelegate + << attendee.d->mDelegator + << attendee.d->cuTypeStr() + << attendee.d->mCustomProperties; } -QDataStream &KCalCore::operator>>(QDataStream &stream, KCalCore::Attendee::Ptr &attendee) +QDataStream &KCalCore::operator>>(QDataStream &stream, KCalCore::Attendee &attendee) { bool RSVP; Attendee::Role role; @@ -352,12 +360,10 @@ role = Attendee::Role(role_int); status = Attendee::PartStat(status_int); - Attendee::Ptr att_temp(new KCalCore::Attendee(person.name(), person.email(), - 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); + attendee = Attendee(person.name(), person.email(), RSVP, status, role, uid); + attendee.setDelegate(delegate); + attendee.setDelegator(delegator); + attendee.setCuType(cuType); + attendee.d->mCustomProperties = customProperties; return stream; } diff --git a/src/calfilter.cpp b/src/calfilter.cpp --- a/src/calfilter.cpp +++ b/src/calfilter.cpp @@ -159,7 +159,7 @@ if (!todo->attendees().isEmpty()) { Attendee::List::ConstIterator it; for (it = attendees.begin(); it != attendees.end(); ++it) { - if (d->mEmailList.contains((*it)->email())) { + if (d->mEmailList.contains((*it).email())) { iAmOneOfTheAttendees = true; break; } diff --git a/src/icalformat_p.h b/src/icalformat_p.h --- a/src/icalformat_p.h +++ b/src/icalformat_p.h @@ -129,7 +129,7 @@ icalproperty *writeDescription(const QString &description, bool isRich = false); icalproperty *writeSummary(const QString &summary, bool isRich = false); icalproperty *writeLocation(const QString &location, bool isRich = false); - icalproperty *writeAttendee(const Attendee::Ptr &attendee); + icalproperty *writeAttendee(const Attendee &attendee); icalproperty *writeOrganizer(const Person &organizer); icalproperty *writeAttachment(const Attachment::Ptr &attach); icalproperty *writeRecurrenceRule(Recurrence *); @@ -141,7 +141,7 @@ Event::Ptr readEvent(icalcomponent *vevent, const ICalTimeZoneCache *tzList); FreeBusy::Ptr readFreeBusy(icalcomponent *vfreebusy); Journal::Ptr readJournal(icalcomponent *vjournal, const ICalTimeZoneCache *tzList); - Attendee::Ptr readAttendee(icalproperty *attendee); + Attendee readAttendee(icalproperty *attendee); Person readOrganizer(icalproperty *organizer); Attachment::Ptr readAttachment(icalproperty *attach); void readIncidence(icalcomponent *parent, const Incidence::Ptr &incidence, const ICalTimeZoneCache *tzList); diff --git a/src/icalformat_p.cpp b/src/icalformat_p.cpp --- a/src/icalformat_p.cpp +++ b/src/icalformat_p.cpp @@ -771,29 +771,29 @@ return p; } -icalproperty *ICalFormatImpl::writeAttendee(const Attendee::Ptr &attendee) +icalproperty *ICalFormatImpl::writeAttendee(const Attendee &attendee) { - if (attendee->email().isEmpty()) { + if (attendee.email().isEmpty()) { return nullptr; } icalproperty *p = - icalproperty_new_attendee(QByteArray(QByteArray("mailto:") + attendee->email().toUtf8()).constData()); + icalproperty_new_attendee(QByteArray(QByteArray("mailto:") + attendee.email().toUtf8()).constData()); - if (!attendee->name().isEmpty()) { + if (!attendee.name().isEmpty()) { icalproperty_add_parameter(p, #if defined(USE_ICAL_3) - icalparameter_new_cn(attendee->name().toUtf8().constData())); + icalparameter_new_cn(attendee.name().toUtf8().constData())); #else - icalparameter_new_cn(quoteForParam(attendee->name()).toUtf8().constData())); + icalparameter_new_cn(quoteForParam(attendee.name()).toUtf8().constData())); #endif } icalproperty_add_parameter( - p, icalparameter_new_rsvp(attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE)); + p, icalparameter_new_rsvp(attendee.RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE)); icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION; - switch (attendee->status()) { + switch (attendee.status()) { default: case Attendee::NeedsAction: status = ICAL_PARTSTAT_NEEDSACTION; @@ -820,7 +820,7 @@ icalproperty_add_parameter(p, icalparameter_new_partstat(status)); icalparameter_role role = ICAL_ROLE_REQPARTICIPANT; - switch (attendee->role()) { + switch (attendee.role()) { case Attendee::Chair: role = ICAL_ROLE_CHAIR; break; @@ -838,7 +838,7 @@ icalproperty_add_parameter(p, icalparameter_new_role(role)); icalparameter_cutype cutype = ICAL_CUTYPE_INDIVIDUAL; - switch (attendee->cuType()) { + switch (attendee.cuType()) { case Attendee::Unknown: cutype = ICAL_CUTYPE_UNKNOWN; break; @@ -858,22 +858,22 @@ } icalproperty_add_parameter(p, icalparameter_new_cutype(cutype)); - if (!attendee->uid().isEmpty()) { - icalparameter *icalparameter_uid = icalparameter_new_x(attendee->uid().toUtf8().constData()); + if (!attendee.uid().isEmpty()) { + icalparameter *icalparameter_uid = icalparameter_new_x(attendee.uid().toUtf8().constData()); icalparameter_set_xname(icalparameter_uid, "X-UID"); icalproperty_add_parameter(p, icalparameter_uid); } - if (!attendee->delegate().isEmpty()) { + if (!attendee.delegate().isEmpty()) { icalparameter *icalparameter_delegate = - icalparameter_new_delegatedto(attendee->delegate().toUtf8().constData()); + icalparameter_new_delegatedto(attendee.delegate().toUtf8().constData()); icalproperty_add_parameter(p, icalparameter_delegate); } - if (!attendee->delegator().isEmpty()) { + if (!attendee.delegator().isEmpty()) { icalparameter *icalparameter_delegator = - icalparameter_new_delegatedfrom(attendee->delegator().toUtf8().constData()); + icalparameter_new_delegatedfrom(attendee.delegator().toUtf8().constData()); icalproperty_add_parameter(p, icalparameter_delegator); } @@ -1411,12 +1411,12 @@ return journal; } -Attendee::Ptr ICalFormatImpl::readAttendee(icalproperty *attendee) +Attendee ICalFormatImpl::readAttendee(icalproperty *attendee) { // the following is a hack to support broken calendars (like WebCalendar 1.0.x) // that include non-RFC-compliant attendees. Otherwise libical 0.42 asserts. if (!icalproperty_get_value(attendee)) { - return Attendee::Ptr(); + return {}; } icalparameter *p = nullptr; @@ -1429,7 +1429,7 @@ // libical may return everything after ATTENDEE tag if the rest is // not meaningful. Verify the address to filter out these cases. if (!Person::isValidEmail(email)) { - return Attendee::Ptr(); + return {}; } QString name; @@ -1539,18 +1539,18 @@ p = icalproperty_get_next_parameter(attendee, ICAL_X_PARAMETER); } - Attendee::Ptr a(new Attendee(name, email, rsvp, status, role, uid)); - a->setCuType(cuType); - a->customProperties().setCustomProperties(custom); + Attendee a(name, email, rsvp, status, role, uid); + a.setCuType(cuType); + a.customProperties().setCustomProperties(custom); p = icalproperty_get_first_parameter(attendee, ICAL_DELEGATEDTO_PARAMETER); if (p) { - a->setDelegate(QLatin1String(icalparameter_get_delegatedto(p))); + a.setDelegate(QLatin1String(icalparameter_get_delegatedto(p))); } p = icalproperty_get_first_parameter(attendee, ICAL_DELEGATEDFROM_PARAMETER); if (p) { - a->setDelegator(QLatin1String(icalparameter_get_delegatedfrom(p))); + a.setDelegator(QLatin1String(icalparameter_get_delegatedfrom(p))); } return a; diff --git a/src/incidencebase.h b/src/incidencebase.h --- a/src/incidencebase.h +++ b/src/incidencebase.h @@ -62,7 +62,7 @@ #include "person.h" #include - +#include #include #include #include @@ -504,13 +504,12 @@ Q_REQUIRED_RESULT QStringList contacts() const; /** - Add Attendee to this incidence. IncidenceBase takes ownership of the - Attendee object. + Add Attendee to this incidence. - @param attendee a pointer to the attendee to add + @param attendee the attendee to add @param doUpdate If true the Observers are notified, if false they are not. */ - void addAttendee(const Attendee::Ptr &attendee, bool doUpdate = true); + void addAttendee(const Attendee &attendee, bool doUpdate = true); /** Removes all attendees from the incidence. @@ -544,7 +543,7 @@ form "FirstName LastName ". @see attendeeByMails(), attendeesByUid(). */ - Attendee::Ptr attendeeByMail(const QString &email) const; + Attendee attendeeByMail(const QString &email) const; /** Returns the first incidence attendee with one of the specified @@ -556,15 +555,15 @@ in addition to the list specified in @p emails. @see attendeeByMail(), attendeesByUid(). */ - Attendee::Ptr attendeeByMails(const QStringList &emails, const QString &email = QString()) const; + Attendee attendeeByMails(const QStringList &emails, const QString &email = QString()) const; /** Returns the incidence attendee with the specified attendee @acronym UID. @param uid is a QString containing an attendee @acronym UID. @see attendeeByMail(), attendeeByMails(). */ - Attendee::Ptr attendeeByUid(const QString &uid) const; + Attendee attendeeByUid(const QString &uid) const; /** Sets the incidences url. diff --git a/src/incidencebase.cpp b/src/incidencebase.cpp --- a/src/incidencebase.cpp +++ b/src/incidencebase.cpp @@ -112,13 +112,8 @@ mComments = other.mComments; mContacts = other.mContacts; - mAttendees.clear(); + mAttendees = other.mAttendees; mAttendees.reserve(other.mAttendees.count()); - for (Attendee::List::ConstIterator it = other.mAttendees.constBegin(), - end = other.mAttendees.constEnd(); - it != end; ++it) { - mAttendees.append(Attendee::Ptr(new Attendee(*(*it)))); - } mUrl = other.mUrl; } @@ -194,7 +189,7 @@ //TODO Does the order of attendees in the list really matter? //Please delete this comment if you know it's ok, kthx for (; a1 != al1.constEnd() && a2 != al2.constEnd(); ++a1, ++a2) { - if (!(**a1 == **a2)) { + if (!(*a1 == *a2)) { // qCDebug(KCALCORE_LOG) << "Attendees are different"; return false; } @@ -426,14 +421,12 @@ return d->mContacts; } -void IncidenceBase::addAttendee(const Attendee::Ptr &a, bool doupdate) +void IncidenceBase::addAttendee(const Attendee &a, bool doupdate) { - if (!a || mReadOnly) { + if (a.isNull() || mReadOnly) { return; } - - Q_ASSERT(!a->uid().isEmpty()); - Q_ASSERT(!d->mAttendees.contains(a)); + Q_ASSERT(!a.uid().isEmpty()); if (doupdate) { update(); @@ -488,19 +481,19 @@ d->mAttendees.clear(); } -Attendee::Ptr IncidenceBase::attendeeByMail(const QString &email) const +Attendee IncidenceBase::attendeeByMail(const QString &email) const { Attendee::List::ConstIterator it; for (it = d->mAttendees.constBegin(); it != d->mAttendees.constEnd(); ++it) { - if ((*it)->email() == email) { + if ((*it).email() == email) { return *it; } } - return Attendee::Ptr(); + return {}; } -Attendee::Ptr IncidenceBase::attendeeByMails(const QStringList &emails, const QString &email) const +Attendee IncidenceBase::attendeeByMails(const QStringList &emails, const QString &email) const { QStringList mails = emails; if (!email.isEmpty()) { @@ -510,25 +503,25 @@ Attendee::List::ConstIterator itA; for (itA = d->mAttendees.constBegin(); itA != d->mAttendees.constEnd(); ++itA) { for (QStringList::const_iterator it = mails.constBegin(); it != mails.constEnd(); ++it) { - if ((*itA)->email() == (*it)) { + if ((*itA).email() == (*it)) { return *itA; } } } - return Attendee::Ptr(); + return {}; } -Attendee::Ptr IncidenceBase::attendeeByUid(const QString &uid) const +Attendee IncidenceBase::attendeeByUid(const QString &uid) const { Attendee::List::ConstIterator it; for (it = d->mAttendees.constBegin(); it != d->mAttendees.constEnd(); ++it) { - if ((*it)->uid() == uid) { + if ((*it).uid() == uid) { return *it; } } - return Attendee::Ptr(); + return {}; } void IncidenceBase::setDuration(const Duration &duration) @@ -680,7 +673,7 @@ << i->d->mAllDay << i->d->mHasDuration << i->d->mComments << i->d->mContacts << i->d->mAttendees.count() << i->d->mUrl; - for (const Attendee::Ptr &attendee : qAsConst(i->d->mAttendees)) { + for (const Attendee &attendee : qAsConst(i->d->mAttendees)) { out << attendee; } @@ -725,7 +718,7 @@ i->d->mAttendees.clear(); i->d->mAttendees.reserve(attendeeCount); for (int it = 0; it < attendeeCount; it++) { - Attendee::Ptr attendee = Attendee::Ptr(new Attendee(QString(), QString())); + Attendee attendee; in >> attendee; i->d->mAttendees.append(attendee); } diff --git a/src/vcalformat.cpp b/src/vcalformat.cpp --- a/src/vcalformat.cpp +++ b/src/vcalformat.cpp @@ -227,7 +227,7 @@ while (moreIteration(&voi)) { vo = nextVObject(&voi); if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) { - Attendee::Ptr a; + Attendee a; VObject *vp; s = fakeCString(vObjectUStringZValue(vo)); QString tmpStr = QString::fromUtf8(s); @@ -237,26 +237,24 @@ if ((emailPos1 = tmpStr.indexOf(QLatin1Char('<'))) > 0) { // both email address and name int emailPos2 = tmpStr.lastIndexOf(QLatin1Char('>')); - a = Attendee::Ptr(new Attendee(tmpStr.left(emailPos1 - 1), - tmpStr.mid(emailPos1 + 1, - emailPos2 - (emailPos1 + 1)))); + a = Attendee(tmpStr.left(emailPos1 - 1), tmpStr.mid(emailPos1 + 1, emailPos2 - (emailPos1 + 1))); } else if (tmpStr.indexOf(QLatin1Char('@')) > 0) { // just an email address - a = Attendee::Ptr(new Attendee(QString(), tmpStr)); + a = Attendee(QString(), tmpStr); } else { // just a name // WTF??? Replacing the spaces of a name and using this as email? QString email = tmpStr.replace(QLatin1Char(' '), QLatin1Char('.')); - a = Attendee::Ptr(new Attendee(tmpStr, email)); + a = Attendee(tmpStr, email); } // is there an RSVP property? if ((vp = isAPropertyOf(vo, VCRSVPProp)) != nullptr) { - a->setRSVP(vObjectStringZValue(vp)); + a.setRSVP(vObjectStringZValue(vp)); } // is there a status property? if ((vp = isAPropertyOf(vo, VCStatusProp)) != nullptr) { - a->setStatus(readStatus(vObjectStringZValue(vp))); + a.setStatus(readStatus(vObjectStringZValue(vp))); } // add the attendee anEvent->addAttendee(a); @@ -704,7 +702,7 @@ while (moreIteration(&voi)) { vo = nextVObject(&voi); if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) { - Attendee::Ptr a; + Attendee a; VObject *vp = nullptr; s = fakeCString(vObjectUStringZValue(vo)); QString tmpStr = QString::fromUtf8(s); @@ -714,25 +712,23 @@ if ((emailPos1 = tmpStr.indexOf(QLatin1Char('<'))) > 0) { // both email address and name int emailPos2 = tmpStr.lastIndexOf(QLatin1Char('>')); - a = Attendee::Ptr(new Attendee(tmpStr.left(emailPos1 - 1), - tmpStr.mid(emailPos1 + 1, - emailPos2 - (emailPos1 + 1)))); + a = Attendee(tmpStr.left(emailPos1 - 1), tmpStr.mid(emailPos1 + 1, emailPos2 - (emailPos1 + 1))); } else if (tmpStr.indexOf(QLatin1Char('@')) > 0) { // just an email address - a = Attendee::Ptr(new Attendee(QString(), tmpStr)); + a = Attendee(QString(), tmpStr); } else { // just a name QString email = tmpStr.replace(QLatin1Char(' '), QLatin1Char('.')); - a = Attendee::Ptr(new Attendee(tmpStr, email)); + a = Attendee(tmpStr, email); } // is there an RSVP property? if ((vp = isAPropertyOf(vo, VCRSVPProp)) != nullptr) { - a->setRSVP(vObjectStringZValue(vp)); + a.setRSVP(vObjectStringZValue(vp)); } // is there a status property? if ((vp = isAPropertyOf(vo, VCStatusProp)) != nullptr) { - a->setStatus(readStatus(vObjectStringZValue(vp))); + a.setStatus(readStatus(vObjectStringZValue(vp))); } // add the attendee anEvent->addAttendee(a);