diff --git a/CMakeLists.txt b/CMakeLists.txt index b75a1e3c3..941d58891 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,90 +1,90 @@ cmake_minimum_required(VERSION 3.5) -set(PIM_VERSION "5.11.42") +set(PIM_VERSION "5.11.43") project(KCalCore VERSION ${PIM_VERSION}) # ECM setup set(KF5_MIN_VERSION "5.58.0") find_package(ECM ${KF5_MIN_VERSION} CONFIG REQUIRED) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${KCalCore_SOURCE_DIR}/cmake) include(GenerateExportHeader) include(ECMGenerateHeaders) include(ECMGeneratePriFile) include(ECMSetupVersion) include(FeatureSummary) include(KDEInstallDirs) include(KDECMakeSettings) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) include(ECMQtDeclareLoggingCategory) if(POLICY CMP0053) cmake_policy(SET CMP0053 NEW) endif() set(QT_REQUIRED_VERSION "5.10.0") set(KCALENDARCORE_LIB_VERSION ${PIM_VERSION}) ecm_setup_version(PROJECT VARIABLE_PREFIX KCALCORE VERSION_HEADER "${KCalCore_BINARY_DIR}/kcalcore_version.h" PACKAGE_VERSION_FILE "${KCalCore_BINARY_DIR}/KF5CalendarCoreConfigVersion.cmake" SOVERSION 5 ) ########### Find packages ########### find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Core Gui) set(LibIcal_MIN_VERSION "2.0") find_package(LibIcal ${LibIcal_MIN_VERSION}) set_package_properties(LibIcal PROPERTIES TYPE REQUIRED) if(LibIcal_VERSION VERSION_GREATER "2.98") set(HAVE_ICAL_3 TRUE) add_definitions(-DUSE_ICAL_3) endif() ########### CMake Config Files ########### set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KF5CalendarCore") configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/KF5CalendarCoreConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/KF5CalendarCoreConfig.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000) add_definitions(-DQT_NO_FOREACH) ########### Targets ########### add_subdirectory(src) if(BUILD_TESTING) find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Test) add_subdirectory(autotests) endif() add_subdirectory(cmake) ########### Install Files ########### install(FILES "${CMAKE_CURRENT_BINARY_DIR}/KF5CalendarCoreConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/KF5CalendarCoreConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) install(EXPORT KF5CalendarCoreTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KF5CalendarCoreTargets.cmake NAMESPACE KF5:: ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kcalcore_version.h DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5} COMPONENT Devel ) install(FILES kcalcore.renamecategories kcalcore.categories DESTINATION ${KDE_INSTALL_CONFDIR}) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/src/incidencebase.cpp b/src/incidencebase.cpp index d444fbb34..8b5f278a2 100644 --- a/src/incidencebase.cpp +++ b/src/incidencebase.cpp @@ -1,742 +1,744 @@ /* This file is part of the kcalcore library. Copyright (c) 2001,2004 Cornelius Schumacher Copyright (C) 2003-2004 Reinhold Kainhofer Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. Contact: Alvaro Manera 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. */ /** @file This file is part of the API for handling calendar data and defines the IncidenceBase class. @brief An abstract base class that provides a common base for all calendar incidence classes. @author Cornelius Schumacher \ @author Reinhold Kainhofer \ */ #include "incidencebase.h" #include "calformat.h" #include "visitor.h" #include "utils.h" #include #include "kcalcore_debug.h" #include #include #define KCALCORE_MAGIC_NUMBER 0xCA1C012E #define KCALCORE_SERIALIZATION_VERSION 1 using namespace KCalCore; /** Private class that helps to provide binary compatibility between releases. @internal */ //@cond PRIVATE class Q_DECL_HIDDEN KCalCore::IncidenceBase::Private { public: Private() : mUpdateGroupLevel(0) , mUpdatedPending(false) , mAllDay(false) , mHasDuration(false) { } Private(const Private &other) : mUpdateGroupLevel(0) , mUpdatedPending(false) , mAllDay(true) , mHasDuration(false) { init(other); } ~Private() { } void init(const Private &other); QDateTime mLastModified; // incidence last modified date QDateTime mDtStart; // incidence start time Person mOrganizer; // incidence person (owner) QString mUid; // incidence unique id Duration mDuration; // incidence duration int mUpdateGroupLevel; // if non-zero, suppresses update() calls bool mUpdatedPending = false; // true if an update has occurred since startUpdates() bool mAllDay = false; // true if the incidence is all-day bool mHasDuration = false; // true if the incidence has a duration Attendee::List mAttendees; // list of incidence attendees QStringList mComments; // list of incidence comments QStringList mContacts; // list of incidence contacts QList mObservers; // list of incidence observers QSet mDirtyFields; // Fields that changed since last time the incidence was created // or since resetDirtyFlags() was called QUrl mUrl; // incidence url property }; void IncidenceBase::Private::init(const Private &other) { mLastModified = other.mLastModified; mDtStart = other.mDtStart; mOrganizer = other.mOrganizer; mUid = other.mUid; mDuration = other.mDuration; mAllDay = other.mAllDay; mHasDuration = other.mHasDuration; mComments = other.mComments; mContacts = other.mContacts; mAttendees.clear(); 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; } //@endcond IncidenceBase::IncidenceBase() : d(new KCalCore::IncidenceBase::Private) { mReadOnly = false; setUid(CalFormat::createUniqueId()); } IncidenceBase::IncidenceBase(const IncidenceBase &i) : CustomProperties(i) , d(new KCalCore::IncidenceBase::Private(*i.d)) { mReadOnly = i.mReadOnly; } IncidenceBase::~IncidenceBase() { delete d; } IncidenceBase &IncidenceBase::operator=(const IncidenceBase &other) { Q_ASSERT(type() == other.type()); startUpdates(); // assign is virtual, will call the derived class's IncidenceBase &ret = assign(other); endUpdates(); return ret; } IncidenceBase &IncidenceBase::assign(const IncidenceBase &other) { CustomProperties::operator=(other); d->init(*other.d); mReadOnly = other.mReadOnly; d->mDirtyFields.clear(); d->mDirtyFields.insert(FieldUnknown); return *this; } bool IncidenceBase::operator==(const IncidenceBase &i2) const { if (i2.type() != type()) { return false; } else { // equals is virtual, so here we're calling the derived class method return equals(i2); } } bool IncidenceBase::operator!=(const IncidenceBase &i2) const { return !operator==(i2); } bool IncidenceBase::equals(const IncidenceBase &i2) const { if (attendees().count() != i2.attendees().count()) { // qCDebug(KCALCORE_LOG) << "Attendee count is different"; return false; } Attendee::List al1 = attendees(); Attendee::List al2 = i2.attendees(); Attendee::List::ConstIterator a1 = al1.constBegin(); Attendee::List::ConstIterator a2 = al2.constBegin(); //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)) { // qCDebug(KCALCORE_LOG) << "Attendees are different"; return false; } } if (!CustomProperties::operator==(i2)) { // qCDebug(KCALCORE_LOG) << "Properties are different"; return false; } // Don't compare lastModified, otherwise the operator is not // of much use. We are not comparing for identity, after all. // no need to compare mObserver bool a = ((dtStart() == i2.dtStart()) || (!dtStart().isValid() && !i2.dtStart().isValid())); bool b = organizer() == i2.organizer(); bool c = uid() == i2.uid(); bool d = allDay() == i2.allDay(); bool e = duration() == i2.duration(); bool f = hasDuration() == i2.hasDuration(); bool g = url() == i2.url(); //qCDebug(KCALCORE_LOG) << a << b << c << d << e << f << g; return a && b && c && d && e && f && g; } bool IncidenceBase::accept(Visitor &v, const IncidenceBase::Ptr &incidence) { Q_UNUSED(v); Q_UNUSED(incidence); return false; } void IncidenceBase::setUid(const QString &uid) { if (d->mUid != uid) { update(); d->mUid = uid; d->mDirtyFields.insert(FieldUid); updated(); } } QString IncidenceBase::uid() const { return d->mUid; } void IncidenceBase::setLastModified(const QDateTime &lm) { // DON'T! updated() because we call this from // Calendar::updateEvent(). d->mDirtyFields.insert(FieldLastModified); // Convert to UTC and remove milliseconds part. QDateTime current = lm.toUTC(); QTime t = current.time(); t.setHMS(t.hour(), t.minute(), t.second(), 0); current.setTime(t); d->mLastModified = current; } QDateTime IncidenceBase::lastModified() const { return d->mLastModified; } void IncidenceBase::setOrganizer(const Person &organizer) { update(); // we don't check for readonly here, because it is // possible that by setting the organizer we are changing // the event's readonly status... d->mOrganizer = organizer; d->mDirtyFields.insert(FieldOrganizer); updated(); } void IncidenceBase::setOrganizer(const QString &o) { QString mail(o); if (mail.startsWith(QLatin1String("MAILTO:"), Qt::CaseInsensitive)) { mail = mail.remove(0, 7); } // split the string into full name plus email. const Person organizer = Person::fromFullName(mail); setOrganizer(organizer); } Person IncidenceBase::organizer() const { return d->mOrganizer; } void IncidenceBase::setReadOnly(bool readOnly) { mReadOnly = readOnly; } bool IncidenceBase::isReadOnly() const { return mReadOnly; } void IncidenceBase::setDtStart(const QDateTime &dtStart) { // if ( mReadOnly ) return; if (!dtStart.isValid() && type() != IncidenceBase::TypeTodo) { qCWarning(KCALCORE_LOG) << "Invalid dtStart"; } if (d->mDtStart != dtStart) { update(); d->mDtStart = dtStart; d->mDirtyFields.insert(FieldDtStart); updated(); } } QDateTime IncidenceBase::dtStart() const { return d->mDtStart; } bool IncidenceBase::allDay() const { return d->mAllDay; } void IncidenceBase::setAllDay(bool f) { if (mReadOnly || f == d->mAllDay) { return; } update(); d->mAllDay = f; if (d->mDtStart.isValid()) { d->mDirtyFields.insert(FieldDtStart); } updated(); } void IncidenceBase::shiftTimes(const QTimeZone &oldZone, const QTimeZone &newZone) { update(); d->mDtStart = d->mDtStart.toTimeZone(oldZone); d->mDtStart.setTimeZone(newZone); d->mDirtyFields.insert(FieldDtStart); d->mDirtyFields.insert(FieldDtEnd); updated(); } void IncidenceBase::addComment(const QString &comment) { d->mComments += comment; } bool IncidenceBase::removeComment(const QString &comment) { bool found = false; QStringList::Iterator i; for (i = d->mComments.begin(); !found && i != d->mComments.end(); ++i) { if ((*i) == comment) { found = true; d->mComments.erase(i); } } if (found) { d->mDirtyFields.insert(FieldComment); } return found; } void IncidenceBase::clearComments() { d->mDirtyFields.insert(FieldComment); d->mComments.clear(); } QStringList IncidenceBase::comments() const { return d->mComments; } void IncidenceBase::addContact(const QString &contact) { if (!contact.isEmpty()) { d->mContacts += contact; d->mDirtyFields.insert(FieldContact); } } bool IncidenceBase::removeContact(const QString &contact) { bool found = false; QStringList::Iterator i; for (i = d->mContacts.begin(); !found && i != d->mContacts.end(); ++i) { if ((*i) == contact) { found = true; d->mContacts.erase(i); } } if (found) { d->mDirtyFields.insert(FieldContact); } return found; } void IncidenceBase::clearContacts() { d->mDirtyFields.insert(FieldContact); d->mContacts.clear(); } QStringList IncidenceBase::contacts() const { return d->mContacts; } void IncidenceBase::addAttendee(const Attendee::Ptr &a, bool doupdate) { if (!a || mReadOnly) { return; } Q_ASSERT(!a->uid().isEmpty()); Q_ASSERT(!d->mAttendees.contains(a)); if (doupdate) { update(); } if (a->name().left(7).toUpper() == QLatin1String("MAILTO:")) { a->setName(a->name().remove(0, 7)); } d->mAttendees.append(a); if (doupdate) { d->mDirtyFields.insert(FieldAttendees); updated(); } } -void IncidenceBase::deleteAttendee(const Attendee::Ptr &a, bool doupdate) -{ - if (!a || mReadOnly) { - return; - } - - int index = d->mAttendees.indexOf(a); - if (index >= 0) { - if (doupdate) { - update(); - } - - d->mAttendees.remove(index); - - if (doupdate) { - d->mDirtyFields.insert(FieldAttendees); - updated(); - } - } -} - Attendee::List IncidenceBase::attendees() const { return d->mAttendees; } int IncidenceBase::attendeeCount() const { return d->mAttendees.count(); } +void IncidenceBase::setAttendees(const Attendee::List &attendees, bool doUpdate) +{ + if (mReadOnly) { + return; + } + + if (doUpdate) { + update(); + } + + // don't simply assign, we need the logic in addAttendee here too + clearAttendees(); + d->mAttendees.reserve(attendees.size()); + for (const auto &a : attendees) { + addAttendee(a, false); + } + + if (doUpdate) { + d->mDirtyFields.insert(FieldAttendees); + updated(); + } +} + void IncidenceBase::clearAttendees() { if (mReadOnly) { return; } d->mDirtyFields.insert(FieldAttendees); d->mAttendees.clear(); } Attendee::Ptr IncidenceBase::attendeeByMail(const QString &email) const { Attendee::List::ConstIterator it; for (it = d->mAttendees.constBegin(); it != d->mAttendees.constEnd(); ++it) { if ((*it)->email() == email) { return *it; } } return Attendee::Ptr(); } Attendee::Ptr IncidenceBase::attendeeByMails(const QStringList &emails, const QString &email) const { QStringList mails = emails; if (!email.isEmpty()) { mails.append(email); } 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)) { return *itA; } } } return Attendee::Ptr(); } Attendee::Ptr IncidenceBase::attendeeByUid(const QString &uid) const { Attendee::List::ConstIterator it; for (it = d->mAttendees.constBegin(); it != d->mAttendees.constEnd(); ++it) { if ((*it)->uid() == uid) { return *it; } } return Attendee::Ptr(); } void IncidenceBase::setDuration(const Duration &duration) { update(); d->mDuration = duration; setHasDuration(true); d->mDirtyFields.insert(FieldDuration); updated(); } Duration IncidenceBase::duration() const { return d->mDuration; } void IncidenceBase::setHasDuration(bool hasDuration) { d->mHasDuration = hasDuration; } bool IncidenceBase::hasDuration() const { return d->mHasDuration; } void IncidenceBase::setUrl(const QUrl &url) { d->mDirtyFields.insert(FieldUrl); d->mUrl = url; } QUrl IncidenceBase::url() const { return d->mUrl; } void IncidenceBase::registerObserver(IncidenceBase::IncidenceObserver *observer) { if (observer && !d->mObservers.contains(observer)) { d->mObservers.append(observer); } } void IncidenceBase::unRegisterObserver(IncidenceBase::IncidenceObserver *observer) { d->mObservers.removeAll(observer); } void IncidenceBase::update() { if (!d->mUpdateGroupLevel) { d->mUpdatedPending = true; const auto rid = recurrenceId(); for (IncidenceObserver *o : qAsConst(d->mObservers)) { o->incidenceUpdate(uid(), rid); } } } void IncidenceBase::updated() { if (d->mUpdateGroupLevel) { d->mUpdatedPending = true; } else { const auto rid = recurrenceId(); for (IncidenceObserver *o : qAsConst(d->mObservers)) { o->incidenceUpdated(uid(), rid); } } } void IncidenceBase::startUpdates() { update(); ++d->mUpdateGroupLevel; } void IncidenceBase::endUpdates() { if (d->mUpdateGroupLevel > 0) { if (--d->mUpdateGroupLevel == 0 && d->mUpdatedPending) { d->mUpdatedPending = false; updated(); } } } void IncidenceBase::customPropertyUpdate() { update(); } void IncidenceBase::customPropertyUpdated() { updated(); } QDateTime IncidenceBase::recurrenceId() const { return QDateTime(); } void IncidenceBase::resetDirtyFields() { d->mDirtyFields.clear(); } QSet IncidenceBase::dirtyFields() const { return d->mDirtyFields; } void IncidenceBase::setFieldDirty(IncidenceBase::Field field) { d->mDirtyFields.insert(field); } QUrl IncidenceBase::uri() const { return QUrl(QStringLiteral("urn:x-ical:") + uid()); } void IncidenceBase::setDirtyFields(const QSet &dirtyFields) { d->mDirtyFields = dirtyFields; } /** static */ quint32 IncidenceBase::magicSerializationIdentifier() { return KCALCORE_MAGIC_NUMBER; } QDataStream &KCalCore::operator<<(QDataStream &out, const KCalCore::IncidenceBase::Ptr &i) { if (!i) { return out; } out << static_cast(KCALCORE_MAGIC_NUMBER); // Magic number to identify KCalCore data out << static_cast(KCALCORE_SERIALIZATION_VERSION); out << static_cast(i->type()); out << *(static_cast(i.data())); serializeQDateTimeAsKDateTime(out, i->d->mLastModified); serializeQDateTimeAsKDateTime(out, i->d->mDtStart); out << i->organizer() << i->d->mUid << i->d->mDuration << 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)) { out << attendee; } // Serialize the sub-class data. In KDE5 we can add new virtuals. i->virtual_hook(KCalCore::IncidenceBase::SerializerHook, &out); return out; } QDataStream &KCalCore::operator>>(QDataStream &in, KCalCore::IncidenceBase::Ptr &i) { if (!i) { return in; } qint32 attendeeCount, type; quint32 magic, version; in >> magic; if (magic != KCALCORE_MAGIC_NUMBER) { qCWarning(KCALCORE_LOG) << "Invalid magic on serialized data"; return in; } in >> version; if (version > KCALCORE_MAGIC_NUMBER) { qCWarning(KCALCORE_LOG) << "Invalid version on serialized data"; return in; } in >> type; in >> *(static_cast(i.data())); deserializeKDateTimeAsQDateTime(in, i->d->mLastModified); deserializeKDateTimeAsQDateTime(in, i->d->mDtStart); in >> i->d->mOrganizer >> i->d->mUid >> i->d->mDuration >> i->d->mAllDay >> i->d->mHasDuration >> i->d->mComments >> i->d->mContacts >> attendeeCount >> i->d->mUrl; 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())); in >> attendee; i->d->mAttendees.append(attendee); } // Deserialize the sub-class data. In KDE5 we can add new virtuals. i->virtual_hook(KCalCore::IncidenceBase::DeserializerHook, &in); return in; } IncidenceBase::IncidenceObserver::~IncidenceObserver() { } diff --git a/src/incidencebase.h b/src/incidencebase.h index f663798f3..8305f1b43 100644 --- a/src/incidencebase.h +++ b/src/incidencebase.h @@ -1,785 +1,784 @@ /* This file is part of the kcalcore library. Copyright (c) 2001-2003 Cornelius Schumacher Copyright (c) 2003-2004 Reinhold Kainhofer Copyright (c) 2005 Rafal Rzepecki Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. Contact: Alvaro Manera 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. */ /** @file This file is part of the API for handling calendar data and defines the IncidenceBase class. @author Cornelius Schumacher \ @author Reinhold Kainhofer \ @author Rafal Rzepecki \ @glossary @anchor incidence @b incidence: General term for a calendar component. Examples are events, to-dos, and journals. @glossary @anchor event @b event: An @ref incidence that has a start and end time, typically representing some occurrence of social or personal importance. May be recurring. Examples are appointments, meetings, or holidays. @glossary @anchor to-do @b to-do: An @ref incidence that has an optional start time and an optional due time typically representing some undertaking to be performed. May be recurring. Examples are "fix the bug" or "pay the bills". @glossary @anchor todo @b todo: See @ref to-do. @glossary @anchor journal @b journal: An @ref incidence with a start date that represents a diary or daily record of one's activities. May @b not be recurring. */ #ifndef KCALCORE_INCIDENCEBASE_H #define KCALCORE_INCIDENCEBASE_H #include "attendee.h" #include "customproperties.h" #include "duration.h" #include "person.h" #include #include #include #include class QUrl; class QDate; class QTimeZone; namespace KCalCore { /** List of dates */ typedef QList DateList; /** List of times */ typedef QList DateTimeList; class Event; class Todo; class Journal; class FreeBusy; class Visitor; /** @brief An abstract class that provides a common base for all calendar incidence classes. define: organizer (person) define: uid (same as the attendee uid?) Several properties are not allowed for VFREEBUSY objects (see rfc:2445), so they are not in IncidenceBase. The hierarchy is: IncidenceBase + FreeBusy + Incidence + Event + Todo + Journal So IncidenceBase contains all properties that are common to all classes, and Incidence contains all additional properties that are common to Events, Todos and Journals, but are not allowed for FreeBusy entries. */ class KCALCORE_EXPORT IncidenceBase : public CustomProperties { Q_GADGET Q_PROPERTY(QString uid READ uid WRITE setUid) Q_PROPERTY(QDateTime lastModified READ lastModified WRITE setLastModified) Q_PROPERTY(QDateTime dtStart READ dtStart WRITE setDtStart) Q_PROPERTY(bool allDay READ allDay WRITE setAllDay) Q_PROPERTY(KCalCore::Person organizer READ organizer WRITE setOrganizer) public: /** A shared pointer to an IncidenceBase. */ typedef QSharedPointer Ptr; /** The different types of incidences, per RFC2445. @see type(), typeStr() */ enum IncidenceType { TypeEvent = 0, /**< Type is an event */ TypeTodo, /**< Type is a to-do */ TypeJournal, /**< Type is a journal */ TypeFreeBusy, /**< Type is a free/busy */ TypeUnknown /**< Type unknown */ }; /** The different types of incidence date/times roles. @see dateTime() */ enum DateTimeRole { RoleAlarmStartOffset = 0,/**< Role for an incidence alarm's starting offset date/time */ RoleAlarmEndOffset, /**< Role for an incidence alarm's ending offset date/time */ RoleSort, /**< Role for an incidence's date/time used when sorting */ RoleCalendarHashing, /**< Role for looking up an incidence in a Calendar */ RoleStartTimeZone, /**< Role for determining an incidence's starting timezone */ RoleEndTimeZone, /**< Role for determining an incidence's ending timezone */ RoleEndRecurrenceBase, RoleEnd, /**< Role for determining an incidence's dtEnd, will return an invalid QDateTime if the incidence does not support dtEnd */ RoleDisplayEnd, /**< Role used for display purposes, represents the end boundary if an incidence supports dtEnd */ RoleAlarm, /**< Role for determining the date/time of the first alarm. Returns invalid time if the incidence doesn't have any alarm */ RoleRecurrenceStart, /**< Role for determining the start of the recurrence. Currently that's DTSTART for an event and DTDUE for a to-do. (NOTE: If the incidence is a to-do, recurrence should be calculated having DTSTART for a reference, not DT-DUE. This is one place KCalCore isn't compliant with RFC2445) */ RoleDisplayStart, /**< Role for display purposes, represents the start boundary of an incidence. To-dos return dtDue here, for historical reasons */ RoleDnD /**< Role for determining new start and end dates after a DnD */ }; /** The different types of incidence fields. */ enum Field { FieldDtStart, ///> Field representing the DTSTART component. FieldDtEnd, ///> Field representing the DTEND component. FieldLastModified, ///> Field representing the LAST-MODIFIED component. FieldDescription, ///> Field representing the DESCRIPTION component. FieldSummary, ///> Field representing the SUMMARY component. FieldLocation, ///> Field representing the LOCATION component. FieldCompleted, ///> Field representing the COMPLETED component. FieldPercentComplete, ///> Field representing the PERCENT-COMPLETE component. FieldDtDue, ///> Field representing the DUE component. FieldCategories, ///> Field representing the CATEGORIES component. FieldRelatedTo, ///> Field representing the RELATED-TO component. FieldRecurrence, ///> Field representing the EXDATE, EXRULE, RDATE, and RRULE components. FieldAttachment, ///> Field representing the ATTACH component. FieldSecrecy, ///> Field representing the CLASS component. FieldStatus, ///> Field representing the STATUS component. FieldTransparency, ///> Field representing the TRANSPARENCY component. FieldResources, ///> Field representing the RESOURCES component. FieldPriority, ///> Field representing the PRIORITY component. FieldGeoLatitude, ///> Field representing the latitude part of the GEO component. FieldGeoLongitude, ///> Field representing the longitude part of the GEO component. FieldRecurrenceId, ///> Field representing the RECURRENCE-ID component. FieldAlarms, ///> Field representing the VALARM component. FieldSchedulingId, ///> Field representing the X-KDE-LIBKCAL-ID component. FieldAttendees, ///> Field representing the ATTENDEE component. FieldOrganizer, ///> Field representing the ORGANIZER component. FieldCreated, ///> Field representing the CREATED component. FieldRevision, ///> Field representing the SEQUENCE component. FieldDuration, ///> Field representing the DURATION component. FieldContact, ///> Field representing the CONTACT component. FieldComment, ///> Field representing the COMMENT component. FieldUid, ///> Field representing the UID component. FieldUnknown, ///> Something changed. Always set when you use the assignment operator. FieldUrl ///> Field representing the URL component. }; /** The IncidenceObserver class. */ class KCALCORE_EXPORT IncidenceObserver { public: /** Destroys the IncidenceObserver. */ virtual ~IncidenceObserver(); /** The IncidenceObserver interface. This function is called before any changes are made. @param uid is the string containing the incidence @ref uid. @param recurrenceId is possible recurrenceid of incidence. */ virtual void incidenceUpdate(const QString &uid, const QDateTime &recurrenceId) = 0; /** The IncidenceObserver interface. This function is called after changes are completed. @param uid is the string containing the incidence @ref uid. @param recurrenceId is possible recurrenceid of incidence. */ virtual void incidenceUpdated(const QString &uid, const QDateTime &recurrenceId) = 0; }; /** Constructs an empty IncidenceBase. */ IncidenceBase(); /** Destroys the IncidenceBase. */ ~IncidenceBase() override; /** Assignment operator. All data belonging to derived classes are also copied. @see assign(). The caller guarantees that both types match. @code if ( i1.type() == i2.type() ) { i1 = i2; } else { qCDebug(KCALCORE_LOG) << "Invalid assignment!"; } @endcode Dirty field FieldUnknown will be set. @param other is the IncidenceBase to assign. */ IncidenceBase &operator=(const IncidenceBase &other); /** Compares this with IncidenceBase @p ib for equality. All data belonging to derived classes are also compared. @see equals(). @param ib is the IncidenceBase to compare against. @return true if the incidences are equal; false otherwise. */ bool operator==(const IncidenceBase &ib) const; /** Compares this with IncidenceBase @p ib for inequality. @param ib is the IncidenceBase to compare against. @return true if the incidences are /not/ equal; false otherwise. */ bool operator!=(const IncidenceBase &ib) const; /** Accept IncidenceVisitor. A class taking part in the visitor mechanism has to provide this implementation:
        bool accept(Visitor &v) { return v.visit(this); }
      
@param v is a reference to a Visitor object. @param incidence is a valid IncidenceBase object for visting. */ virtual bool accept(Visitor &v, const IncidenceBase::Ptr &incidence); /** Returns the incidence type. */ virtual IncidenceType type() const = 0; /** Prints the type of incidence as a string. */ virtual QByteArray typeStr() const = 0; /** Sets the unique id for the incidence to @p uid. @param uid is the string containing the incidence @ref uid. @see uid() */ void setUid(const QString &uid); /** Returns the unique id (@ref uid) for the incidence. @see setUid() */ Q_REQUIRED_RESULT QString uid() const; /** Returns the uri for the incidence, of form urn:x-ical:\ */ Q_REQUIRED_RESULT QUrl uri() const; /** Sets the time the incidence was last modified to @p lm. It is stored as a UTC date/time. @param lm is the QDateTime when the incidence was last modified. @see lastModified() */ virtual void setLastModified(const QDateTime &lm); /** Returns the time the incidence was last modified. @see setLastModified() */ Q_REQUIRED_RESULT QDateTime lastModified() const; /** Sets the organizer for the incidence. @param organizer is a non-null Person to use as the incidence @ref organizer. @see organizer(), setOrganizer(const QString &) */ void setOrganizer(const Person &organizer); /** Sets the incidence organizer to any string @p organizer. @param organizer is a string to use as the incidence @ref organizer. @see organizer(), setOrganizer(const Person &) */ void setOrganizer(const QString &organizer); /** Returns the Person associated with this incidence. If no Person was set through setOrganizer(), a default Person() is returned. @see setOrganizer(const QString &), setOrganizer(const Person &) */ Person organizer() const; /** Sets readonly status. @param readOnly if set, the incidence is read-only; else the incidence can be modified. @see isReadOnly(). */ virtual void setReadOnly(bool readOnly); /** Returns true the object is read-only; false otherwise. @see setReadOnly() */ Q_REQUIRED_RESULT bool isReadOnly() const; /** Sets the incidence's starting date/time with a QDateTime. The incidence's all-day status is set according to whether @p dtStart is a date/time (not all-day) or date-only (all-day). @param dtStart is the incidence start date/time. @see dtStart(). */ virtual void setDtStart(const QDateTime &dtStart); /** Returns an incidence's starting date/time as a QDateTime. @see setDtStart(). */ virtual QDateTime dtStart() const; /** Sets the incidence duration. @param duration the incidence duration @see duration() */ virtual void setDuration(const Duration &duration); /** Returns the length of the incidence duration. @see setDuration() */ Q_REQUIRED_RESULT Duration duration() const; /** Sets if the incidence has a duration. @param hasDuration true if the incidence has a duration; false otherwise. @see hasDuration() */ void setHasDuration(bool hasDuration); /** Returns true if the incidence has a duration; false otherwise. @see setHasDuration() */ Q_REQUIRED_RESULT bool hasDuration() const; /** Returns true or false depending on whether the incidence is all-day. i.e. has a date but no time attached to it. @see setAllDay() */ Q_REQUIRED_RESULT bool allDay() const; /** Sets whether the incidence is all-day, i.e. has a date but no time attached to it. @param allDay sets whether the incidence is all-day. @see allDay() */ virtual void setAllDay(bool allDay); /** Shift the times of the incidence so that they appear at the same clock time as before but in a new time zone. The shift is done from a viewing time zone rather than from the actual incidence time zone. For example, shifting an incidence whose start time is 09:00 America/New York, using an old viewing time zone (@p oldSpec) of Europe/London, to a new time zone (@p newSpec) of Europe/Paris, will result in the time being shifted from 14:00 (which is the London time of the incidence start) to 14:00 Paris time. @param oldZone the time zone which provides the clock times @param newZone the new time zone */ virtual void shiftTimes(const QTimeZone &oldZone, const QTimeZone &newZone); /** Adds a comment to the incidence. Does not add a linefeed character; simply appends the text as specified. @param comment is the QString containing the comment to add. @see removeComment(). */ void addComment(const QString &comment); /** Removes a comment from the incidence. Removes the first comment whose string is an exact match for the specified string in @p comment. @param comment is the QString containing the comment to remove. @return true if match found, false otherwise. @see addComment(). */ Q_REQUIRED_RESULT bool removeComment(const QString &comment); /** Deletes all incidence comments. */ void clearComments(); /** Returns all incidence comments as a list of strings. */ Q_REQUIRED_RESULT QStringList comments() const; /** Adds a contact to thieincidence. Does not add a linefeed character; simply appends the text as specified. @param contact is the QString containing the contact to add. @see removeContact(). */ void addContact(const QString &contact); /** Removes a contact from the incidence. Removes the first contact whose string is an exact match for the specified string in @p contact. @param contact is the QString containing the contact to remove. @return true if match found, false otherwise. @see addContact(). */ Q_REQUIRED_RESULT bool removeContact(const QString &contact); /** Deletes all incidence contacts. */ void clearContacts(); /** Returns all incidence contacts as a list of strings. */ Q_REQUIRED_RESULT QStringList contacts() const; /** Add Attendee to this incidence. IncidenceBase takes ownership of the Attendee object. @param attendee a pointer to 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); /** Removes all attendees from the incidence. */ void clearAttendees(); /** - Delete single attendee from the incidence. + Set the attendees of this incidence. + This replaces all previously set attendees, unlike addAttendee. - The given attendee will be delete()d at the end of this call. - - @param attendee The attendee to be removeComment - @param doUpdate If true the Observers are notified, if false they are not. + @param attendees A list of attendees. + @param doUpdate If true the Observers are notified, if false they are not. */ - void deleteAttendee(const Attendee::Ptr &attendee, bool doUpdate = true); + void setAttendees(const Attendee::List &attendees, bool doUpdate = true); /** Returns a list of incidence attendees. All pointers in the list are valid. */ Q_REQUIRED_RESULT Attendee::List attendees() const; /** Returns the number of incidence attendees. */ Q_REQUIRED_RESULT int attendeeCount() const; /** Returns the attendee with the specified email address. @param email is a QString containing an email address of the form "FirstName LastName ". @see attendeeByMails(), attendeesByUid(). */ Attendee::Ptr attendeeByMail(const QString &email) const; /** Returns the first incidence attendee with one of the specified email addresses. @param emails is a list of QStrings containing email addresses of the form "FirstName LastName ". @param email is a QString containing a single email address to search in addition to the list specified in @p emails. @see attendeeByMail(), attendeesByUid(). */ Attendee::Ptr 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; /** Sets the incidences url. This property can be used to point to a more dynamic rendition of the incidence. I.e. a website related to the incidence. @param url of the incience. @see url() @since 4.12 */ void setUrl(const QUrl &url); /** Returns the url. @return incidences url value @see setUrl() @since 4.12 */ Q_REQUIRED_RESULT QUrl url() const; /** Register observer. The observer is notified when the observed object changes. @param observer is a pointer to an IncidenceObserver object that will be watching this incidence. @see unRegisterObserver() */ void registerObserver(IncidenceObserver *observer); /** Unregister observer. It isn't notified anymore about changes. @param observer is a pointer to an IncidenceObserver object that will be watching this incidence. @see registerObserver(). */ void unRegisterObserver(IncidenceObserver *observer); /** Call this to notify the observers after the IncidenceBase object will be changed. */ void update(); /** Call this to notify the observers after the IncidenceBase object has changed. */ void updated(); /** Call this when a group of updates is going to be made. This suppresses change notifications until endUpdates() is called, at which point updated() will automatically be called. */ void startUpdates(); /** Call this when a group of updates is complete, to notify observers that the instance has changed. This should be called in conjunction with startUpdates(). */ void endUpdates(); /** Returns a date/time corresponding to the specified DateTimeRole. @param role is a DateTimeRole. */ virtual QDateTime dateTime(DateTimeRole role) const = 0; /** Sets the date/time corresponding to the specified DateTimeRole. @param dateTime is QDateTime value to set. @param role is a DateTimeRole. */ virtual void setDateTime(const QDateTime &dateTime, DateTimeRole role) = 0; /** Returns the Akonadi specific sub MIME type of a KCalCore::IncidenceBase item, e.g. getting "application/x-vnd.akonadi.calendar.event" for a KCalCore::Event. */ virtual QLatin1String mimeType() const = 0; /** Returns the incidence recurrenceId. @return incidences recurrenceId value @see setRecurrenceId(). */ virtual QDateTime recurrenceId() const; /** Returns a QSet with all Fields that were changed since the incidence was created or resetDirtyFields() was called. @see resetDirtyFields() */ QSet dirtyFields() const; /** Sets which fields are dirty. @see dirtyFields() @since 4.8 */ void setDirtyFields(const QSet &); /** Resets dirty fields. @see dirtyFields() */ void resetDirtyFields(); /** * Constant that identifies KCalCore data in a binary stream. * * @since 4.12 */ Q_REQUIRED_RESULT static quint32 magicSerializationIdentifier(); protected: /** Marks Field @p field as dirty. @param field is the Field type to mark as dirty. @see dirtyFields() */ void setFieldDirty(IncidenceBase::Field field); /** @copydoc CustomProperties::customPropertyUpdate() */ void customPropertyUpdate() override; /** @copydoc CustomProperties::customPropertyUpdated() */ void customPropertyUpdated() override; /** Constructs an IncidenceBase as a copy of another IncidenceBase object. @param ib is the IncidenceBase to copy. */ IncidenceBase(const IncidenceBase &ib); /** Provides polymorfic comparison for equality. Only called by IncidenceBase::operator==() which guarantees that @p incidenceBase is of the right type. @param incidenceBase is the IncidenceBase to compare against. @return true if the incidences are equal; false otherwise. */ virtual bool equals(const IncidenceBase &incidenceBase) const; /** Provides polymorfic assignment. @param other is the IncidenceBase to assign. */ virtual IncidenceBase &assign(const IncidenceBase &other); enum VirtualHook { SerializerHook, DeserializerHook }; /** Standard trick to add virtuals later. @param id is any integer unique to this class which we will use to identify the method to be called. @param data is a pointer to some glob of data, typically a struct. */ virtual void virtual_hook(VirtualHook id, void *data) = 0; /** Identifies a read-only incidence. */ bool mReadOnly; private: //@cond PRIVATE class Private; Private *const d; //@endcond friend KCALCORE_EXPORT QDataStream &operator<<(QDataStream &stream, const KCalCore::IncidenceBase::Ptr &); friend KCALCORE_EXPORT QDataStream &operator>>(QDataStream &stream, KCalCore::IncidenceBase::Ptr &); }; /** * Incidence serializer. * Uses the virtual_hook internally to avoid slicing. * * // TODO_KDE5: Provide a virtual serialize() method, as done with assign() and equals(). * * @since 4.12 */ KCALCORE_EXPORT QDataStream &operator<<(QDataStream &out, const KCalCore::IncidenceBase::Ptr &); /** * Incidence deserializer. * Uses the virtual_hook internally to avoid slicing. * * // TODO_KDE5: Provide a virtual serialize() method, as done with assign() and equals(). * * @since 4.12 */ KCALCORE_EXPORT QDataStream &operator>>(QDataStream &in, KCalCore::IncidenceBase::Ptr &); } Q_DECLARE_METATYPE(KCalCore::IncidenceBase *) Q_DECLARE_METATYPE(KCalCore::IncidenceBase::Ptr) #endif