diff --git a/autotests/testperson.cpp b/autotests/testperson.cpp index 071bf09c6..171a512d2 100644 --- a/autotests/testperson.cpp +++ b/autotests/testperson.cpp @@ -1,113 +1,111 @@ /* This file is part of the kcalcore library. Copyright (C) 2006-2009 Allen Winter Copyright (C) 2010 Casey Link Copyright (C) 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company 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. */ #include "testperson.h" #include "person.h" #include #include QTEST_MAIN(PersonTest) using namespace KCalCore; void PersonTest::testValidity() { Person person(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com")); QVERIFY(person.name() == QLatin1String("fred")); } void PersonTest::testCompare() { Person person1(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com")); Person person2(QStringLiteral("wilma"), QStringLiteral("wilma@flintstone.com")); Person::Ptr person3 = Person::fromFullName(QStringLiteral("fred ")); Person person1copy(person1); // test copy constructor Person person1assign = person1; // test operator= QVERIFY(!(person1 == person2)); QVERIFY(person1 == *person3.data()); QVERIFY(person1 == person1copy); QVERIFY(person1 == person1assign); QVERIFY(person1.name() == QLatin1String("fred")); QVERIFY(person2.email() == QLatin1String("wilma@flintstone.com")); QVERIFY(person3->name() == QLatin1String("fred")); QVERIFY(person3->email() == QLatin1String("fred@flintstone.com")); } void PersonTest::testStringify() { Person person1(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com")); Person person2(QStringLiteral("wilma"), QStringLiteral("wilma@flintstone.com")); QVERIFY(person1.fullName() == QLatin1String("fred ")); QVERIFY(person2.fullName() == QLatin1String("wilma ")); person1.setName(QLatin1String("")); QVERIFY(person1.fullName() == QLatin1String("fred@flintstone.com")); person1.setEmail(QString()); QVERIFY(person1.fullName().isEmpty()); } void PersonTest::testDataStreamIn() { Person::Ptr person1(new Person(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com"))); - int initial_count = person1->count(); QByteArray byteArray; QDataStream out_stream(&byteArray, QIODevice::WriteOnly); out_stream << person1; QDataStream in_stream(&byteArray, QIODevice::ReadOnly); QString name, email; int count; in_stream >> name; QVERIFY(name == QLatin1String("fred")); in_stream >> email; QVERIFY(email == QLatin1String("fred@flintstone.com")); in_stream >> count; - QVERIFY(count == initial_count); + QCOMPARE(count, 0); } void PersonTest::testDataStreamOut() { Person::Ptr person1(new Person(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com"))); QByteArray byteArray; QDataStream out_stream(&byteArray, QIODevice::WriteOnly); out_stream << person1; QDataStream in_stream(&byteArray, QIODevice::ReadOnly); Person::Ptr person2; in_stream >> person2; QVERIFY(person2->name() == person1->name()); QVERIFY(person2->email() == person1->email()); - QVERIFY(person2->count() == person1->count()); } diff --git a/src/person.cpp b/src/person.cpp index 936fa9f45..f2131c152 100644 --- a/src/person.cpp +++ b/src/person.cpp @@ -1,397 +1,385 @@ /* This file is part of the kcalcore library. Copyright (c) 2001 Cornelius Schumacher Copyright (C) 2003-2004 Reinhold Kainhofer Copyright (C) 2010 Casey Link Copyright (C) 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company 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 Person class. @brief Represents a person, by name and email address. @author Cornelius Schumacher \ @author Reinhold Kainhofer \ */ #include "person.h" #include #include using namespace KCalCore; /** Private class that helps to provide binary compatibility between releases. @internal */ //@cond PRIVATE class Q_DECL_HIDDEN KCalCore::Person::Private { public: Private() {} QString mName; // person name QString mEmail; // person email address - int mCount = 0; // person reference count }; //@endcond Person::Person() : d(new KCalCore::Person::Private) { } Person::Person(const QString &name, const QString &email) : d(new KCalCore::Person::Private) { d->mName = name; d->mEmail = email; } Person::Person(const Person &person) : d(new KCalCore::Person::Private(*person.d)) { } Person::~Person() { delete d; } bool KCalCore::Person::operator==(const Person &person) const { return d->mName == person.d->mName && d->mEmail == person.d->mEmail; } bool KCalCore::Person::operator!=(const Person &person) const { return !(*this == person); } Person &KCalCore::Person::operator=(const Person &person) { // check for self assignment if (&person == this) { return *this; } *d = *person.d; return *this; } QString Person::fullName() const { 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('>'); } } } QString Person::name() const { return d->mName; } QString Person::email() const { return d->mEmail; } bool Person::isEmpty() const { return d->mEmail.isEmpty() && d->mName.isEmpty(); } void Person::setName(const QString &name) { d->mName = name; } void Person::setEmail(const QString &email) { if (email.startsWith(QLatin1String("mailto:"), Qt::CaseInsensitive)) { d->mEmail = email.mid(7); } else { d->mEmail = email; } } bool Person::isValidEmail(const QString &email) { const int pos = email.lastIndexOf(QLatin1Char('@')); return (pos > 0) && (email.lastIndexOf(QLatin1Char('.')) > pos) && ((email.length() - pos) > 4); } -void Person::setCount(int count) -{ - d->mCount = count; -} - -int Person::count() const -{ - return d->mCount; -} - uint KCalCore::qHash(const KCalCore::Person &key) { return qHash(key.fullName()); } QDataStream &KCalCore::operator<<(QDataStream &stream, const KCalCore::Person::Ptr &person) { return stream << person->d->mName << person->d->mEmail - << person->d->mCount; + << (int)(0); } QDataStream &KCalCore::operator>>(QDataStream &stream, Person::Ptr &person) { QString name, email; int count; stream >> name >> email >> count; Person::Ptr person_tmp(new Person(name, email)); - person_tmp->setCount(count); person.swap(person_tmp); return stream; } // The following function was lifted directly from KPIMUtils // in order to eliminate the dependency on that library. // Any changes made here should be ported there, and vice versa. static bool extractEmailAddressAndName(const QString &aStr, QString &mail, QString &name) { name.clear(); mail.clear(); const int len = aStr.length(); const char cQuotes = '"'; bool bInComment = false; bool bInQuotesOutsideOfEmail = false; int i = 0, iAd = 0, iMailStart = 0, iMailEnd = 0; QChar c; unsigned int commentstack = 0; // Find the '@' of the email address // skipping all '@' inside "(...)" comments: while (i < len) { c = aStr[i]; if (QLatin1Char('(') == c) { commentstack++; } if (QLatin1Char(')') == c) { commentstack--; } bInComment = commentstack != 0; if (QLatin1Char('"') == c && !bInComment) { bInQuotesOutsideOfEmail = !bInQuotesOutsideOfEmail; } if (!bInComment && !bInQuotesOutsideOfEmail) { if (QLatin1Char('@') == c) { iAd = i; break; // found it } } ++i; } if (!iAd) { // We suppose the user is typing the string manually and just // has not finished typing the mail address part. // So we take everything that's left of the '<' as name and the rest as mail for (i = 0; len > i; ++i) { c = aStr[i]; if (QLatin1Char('<') != c) { name.append(c); } else { break; } } mail = aStr.mid(i + 1); if (mail.endsWith(QLatin1Char('>'))) { mail.truncate(mail.length() - 1); } } else { // Loop backwards until we find the start of the string // or a ',' that is outside of a comment // and outside of quoted text before the leading '<'. bInComment = false; bInQuotesOutsideOfEmail = false; for (i = iAd - 1; 0 <= i; --i) { c = aStr[i]; if (bInComment) { if (QLatin1Char('(') == c) { if (!name.isEmpty()) { name.prepend(QLatin1Char(' ')); } bInComment = false; } else { name.prepend(c); // all comment stuff is part of the name } } else if (bInQuotesOutsideOfEmail) { if (QLatin1Char(cQuotes) == c) { bInQuotesOutsideOfEmail = false; } else if (c != QLatin1Char('\\')) { name.prepend(c); } } else { // found the start of this addressee ? if (QLatin1Char(',') == c) { break; } // stuff is before the leading '<' ? if (iMailStart) { if (QLatin1Char(cQuotes) == c) { bInQuotesOutsideOfEmail = true; // end of quoted text found } else { name.prepend(c); } } else { switch (c.toLatin1()) { case '<': iMailStart = i; break; case ')': if (!name.isEmpty()) { name.prepend(QLatin1Char(' ')); } bInComment = true; break; default: if (QLatin1Char(' ') != c) { mail.prepend(c); } } } } } name = name.simplified(); mail = mail.simplified(); if (mail.isEmpty()) { return false; } mail.append(QLatin1Char('@')); // Loop forward until we find the end of the string // or a ',' that is outside of a comment // and outside of quoted text behind the trailing '>'. bInComment = false; bInQuotesOutsideOfEmail = false; int parenthesesNesting = 0; for (i = iAd + 1; len > i; ++i) { c = aStr[i]; if (bInComment) { if (QLatin1Char(')') == c) { if (--parenthesesNesting == 0) { bInComment = false; if (!name.isEmpty()) { name.append(QLatin1Char(' ')); } } else { // nested ")", add it name.append(QLatin1Char(')')); // name can't be empty here } } else { if (QLatin1Char('(') == c) { // nested "(" ++parenthesesNesting; } name.append(c); // all comment stuff is part of the name } } else if (bInQuotesOutsideOfEmail) { if (QLatin1Char(cQuotes) == c) { bInQuotesOutsideOfEmail = false; } else if (c != QLatin1Char('\\')) { name.append(c); } } else { // found the end of this addressee ? if (QLatin1Char(',') == c) { break; } // stuff is behind the trailing '>' ? if (iMailEnd) { if (QLatin1Char(cQuotes) == c) { bInQuotesOutsideOfEmail = true; // start of quoted text found } else { name.append(c); } } else { switch (c.toLatin1()) { case '>': iMailEnd = i; break; case '(': if (!name.isEmpty()) { name.append(QLatin1Char(' ')); } if (++parenthesesNesting > 0) { bInComment = true; } break; default: if (QLatin1Char(' ') != c) { mail.append(c); } } } } } } name = name.simplified(); mail = mail.simplified(); return !(name.isEmpty() || mail.isEmpty()); } Person::Ptr Person::fromFullName(const QString &fullName) { QString email, name; extractEmailAddressAndName(fullName, email, name); return Person::Ptr(new Person(name, email)); } diff --git a/src/person.h b/src/person.h index a8697cd32..553f837ab 100644 --- a/src/person.h +++ b/src/person.h @@ -1,230 +1,211 @@ /* This file is part of the kcalcore library. Copyright (c) 2001-2003 Cornelius Schumacher Copyright (C) 2003-2004 Reinhold Kainhofer 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 Person class. @author Cornelius Schumacher \ @author Reinhold Kainhofer \ */ #ifndef KCALCORE_PERSON_H #define KCALCORE_PERSON_H #include "kcalcore_export.h" #include #include #include #include namespace KCalCore { /** @brief Represents a person, by name and email address. This class represents a person, with a name and an email address. It supports the "FirstName LastName\ " format. */ class KCALCORE_EXPORT Person { public: /** A shared pointer to a Person object. */ typedef QSharedPointer Ptr; /** List of persons. */ typedef QVector List; /** Constructs a blank person. */ Person(); /** Constructs a person with name and email address taken from @p fullName. @param fullName is the name and email of the person in the form "FirstName LastName \". @return A Person object pointer. */ static Person::Ptr fromFullName(const QString &fullName); /** Constructs a person with the name @p name and email address @p email. @param name is the name of this person. @param email is the email address of this person. */ Person(const QString &name, const QString &email); /** Constructs a person as a copy of another person object. @param person is the person to copy. */ Person(const Person &person); /** Destroys a person. */ virtual ~Person(); /** Returns true if the person name and email address are empty. */ Q_REQUIRED_RESULT bool isEmpty() const; /** Returns the full name of this person. @return A QString containing the person's full name in the form "FirstName LastName \". */ Q_REQUIRED_RESULT QString fullName() const; /** Sets the name of the person to @p name. @param name is the name of this person. @see name() */ void setName(const QString &name); /** Returns the person name string. @see setName() */ Q_REQUIRED_RESULT QString name() const; /** Sets the email address for this person to @p email. @param email is the email address for this person. @see email() */ void setEmail(const QString &email); /** Returns the email address for this person. @return A QString containing the person's email address. @see setEmail() */ Q_REQUIRED_RESULT QString email() const; /** Returns true if person's email address is valid. Simple email validity check, test that there: * is at least one @ * is at least one character in the local part * is at least one dot in the domain part * is at least four characters in the domain (assuming that no-one has an address at the tld, that the tld is at least 2 chars) @param email is the email address to validate */ Q_REQUIRED_RESULT static bool isValidEmail(const QString &email); - /** - Sets the number of references for this person. - - This can be initialized in a loading function (see ExtendedStorage), - where the number of contact appearances etc. are counted. - - @param count number of references - - @see count() - */ - void setCount(int count); - - /** - Returns the number of references or zero if it is not initialized. - - @see setCount() - */ - Q_REQUIRED_RESULT int count() const; - /** Compares this with @p person for equality. @param person is the person to compare. */ bool operator==(const Person &person) const; /** Compares this with @p person for non-equality. @param person is the person to compare. */ bool operator!=(const Person &person) const; /** Sets this person equal to @p person. @param person is the person to copy. */ Person &operator=(const Person &person); private: //@cond PRIVATE class Private; 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, KCalCore::Person::Ptr &person); }; /** Serializes the @p person object into the @p stream. */ KCALCORE_EXPORT QDataStream &operator<<(QDataStream &stream, const KCalCore::Person::Ptr &person); /** Initializes the @p person object from the @p stream. */ KCALCORE_EXPORT QDataStream &operator>>(QDataStream &stream, KCalCore::Person::Ptr &person); /** Return a hash value for a Person argument. @param key is a Person. */ KCALCORE_EXPORT uint qHash(const KCalCore::Person &key); } //@cond PRIVATE Q_DECLARE_TYPEINFO(KCalCore::Person::Ptr, Q_MOVABLE_TYPE); Q_DECLARE_METATYPE(KCalCore::Person::Ptr) //@endcond #endif diff --git a/src/sorting.cpp b/src/sorting.cpp index e04faabc9..ea3e5b180 100644 --- a/src/sorting.cpp +++ b/src/sorting.cpp @@ -1,439 +1,435 @@ /* This file is part of the kcalcore library. 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. */ #include "sorting.h" #include "event.h" #include "journal.h" #include "todo.h" #include "utils.h" // PENDING(kdab) Review // The QString::compare() need to be replace by a DUI string comparisons. // See http://qt.gitorious.org/maemo-6-ui-framework/libdui // If not compiled in "meego-mode" should we be using locale compares? using namespace KCalCore; /** * How one QDateTime compares with another. * * If any all-day events are involved, comparison of QDateTime values * requires them to be considered as representing time periods. An all-day * instance represents a time period from 00:00:00 to 23:59:59.999 on a given * date, while a date/time instance can be considered to represent a time * period whose start and end times are the same. They may therefore be * earlier or later, or may overlap or be contained one within the other. * * Values may be OR'ed with each other in any combination of 'consecutive' * intervals to represent different types of relationship. * * In the descriptions of the values below, * - s1 = start time of first instance * - e1 = end time of first instance * - s2 = start time of second instance * - e2 = end time of second instance. */ enum DateTimeComparison { Before = 0x01, /**< The first QDateTime is strictly earlier than the second, * i.e. e1 < s2. */ AtStart = 0x02, /**< The first QDateTime starts at the same time as the second, * and ends before the end of the second, * i.e. s1 = s2, e1 < e2. */ Inside = 0x04, /**< The first QDateTime starts after the start of the second, * and ends before the end of the second, * i.e. s1 > s2, e1 < e2. */ AtEnd = 0x08, /**< The first QDateTime starts after the start of the second, * and ends at the same time as the second, * i.e. s1 > s2, e1 = e2. */ After = 0x10, /**< The first QDateTime is strictly later than the second, * i.e. s1 > e2. */ Equal = AtStart | Inside | AtEnd, /**< Simultaneous, i.e. s1 = s2 && e1 = e2. */ Outside = Before | AtStart | Inside | AtEnd | After, /**< The first QDateTime starts before the start of the other, * and ends after the end of the other, * i.e. s1 < s2, e1 > e2. */ StartsAt = AtStart | Inside | AtEnd | After, /**< The first QDateTime starts at the same time as the other, * and ends after the end of the other, * i.e. s1 = s2, e1 > e2. */ EndsAt = Before | AtStart | Inside | AtEnd /**< The first QDateTime starts before the start of the other, * and ends at the same time as the other, * i.e. s1 < s2, e1 = e2. */ }; /** * Compare two QDateTime instances to determine whether they are * simultaneous, earlier or later. * The comparison takes time zones into account: if the two instances have * different time zones, they are first converted to UTC before comparing. * * If both instances are not all-day values, the first instance is considered to * be either simultaneous, earlier or later, and does not overlap. * * If one instance is all-day and the other is a not all-day, the first instance * is either strictly earlier, strictly later, or overlaps. * * If both instance are all-day, they are considered simultaneous if both * their start of day and end of day times are simultaneous with each * other. (Both start and end of day times need to be considered in case a * daylight savings change occurs during that day.) Otherwise, the first instance * can be strictly earlier, earlier but overlapping, later but overlapping, * or strictly later. * * Note that if either instance is a local time (Qt::TimeSpec of Qt::LocalTime), * the result cannot be guaranteed to be correct, since by definition they * contain no information about time zones or daylight savings changes. * * @return DateTimeComparison indicating teh relationship of dt1 to dt2 * @see operator==(), operator!=(), operator<(), operator<=(), operator>=(), operator>() */ DateTimeComparison compare(const QDateTime &dt1, bool isAllDay1, const QDateTime &dt2, bool isAllDay2) { QDateTime start1, start2; //FIXME When secondOccurrence is available in QDateTime //const bool conv = (!d->equalSpec(*other.d) || d->secondOccurrence() != other.d->secondOccurrence()); const bool conv = dt1.timeSpec() != dt2.timeSpec() || (dt1.timeSpec() == Qt::OffsetFromUTC && dt1.offsetFromUtc() != dt2.offsetFromUtc()) || (dt1.timeSpec() == Qt::TimeZone && dt1.timeZone() != dt2.timeZone()); if (conv) { // Different time specs or one is a time which occurs twice, // so convert to UTC before comparing start1 = dt1.toUTC(); start2 = dt2.toUTC(); } else { // Same time specs, so no need to convert to UTC start1 = dt1; start2 = dt2; } if (isAllDay1 || isAllDay2) { // At least one of the instances is date-only, so we need to compare // time periods rather than just times. QDateTime end1, end2; if (conv) { if (isAllDay1) { QDateTime dt(dt1); dt.setTime(QTime(23, 59, 59, 999)); end1 = dt.toUTC(); } else { end1 = start1; } if (isAllDay2) { QDateTime dt(dt2); dt.setTime(QTime(23, 59, 59, 999)); end2 = dt.toUTC(); } else { end2 = start2; } } else { if (isAllDay1) { end1 = QDateTime(dt1.date(), QTime(23, 59, 59, 999), Qt::LocalTime); } else { end1 = dt1; } if (isAllDay2) { end2 = QDateTime(dt2.date(), QTime(23, 59, 59, 999), Qt::LocalTime); } else { end2 = dt2; } } if (start1 == start2) { return !isAllDay1 ? AtStart : (end1 == end2) ? Equal : (end1 < end2) ? static_cast(AtStart | Inside) : static_cast(AtStart | Inside | AtEnd | After); } if (start1 < start2) { return (end1 < start2) ? Before : (end1 == end2) ? static_cast(Before | AtStart | Inside | AtEnd) : (end1 == start2) ? static_cast(Before | AtStart) : (end1 < end2) ? static_cast(Before | AtStart | Inside) : Outside; } else { return (start1 > end2) ? After : (start1 == end2) ? (end1 == end2 ? AtEnd : static_cast(AtEnd | After)) : (end1 == end2) ? static_cast(Inside | AtEnd) : (end1 < end2) ? Inside : static_cast(Inside | AtEnd | After); } } return (start1 == start2) ? Equal : (start1 < start2) ? Before : After; } bool KCalCore::Events::startDateLessThan(const Event::Ptr &e1, const Event::Ptr &e2) { DateTimeComparison res = compare(e1->dtStart(), e1->allDay(), e2->dtStart(), e2->allDay()); if (res == Equal) { return Events::summaryLessThan(e1, e2); } else { return (res & Before || res & AtStart); } } bool KCalCore::Events::startDateMoreThan(const Event::Ptr &e1, const Event::Ptr &e2) { DateTimeComparison res = compare(e1->dtStart(), e1->allDay(), e2->dtStart(), e2->allDay()); if (res == Equal) { return Events::summaryMoreThan(e1, e2); } else { return (res & After || res & AtEnd); } } bool KCalCore::Events::summaryLessThan(const Event::Ptr &e1, const Event::Ptr &e2) { return QString::compare(e1->summary(), e2->summary(), Qt::CaseInsensitive) < 0; } bool KCalCore::Events::summaryMoreThan(const Event::Ptr &e1, const Event::Ptr &e2) { return QString::compare(e1->summary(), e2->summary(), Qt::CaseInsensitive) > 0; } bool KCalCore::Events::endDateLessThan(const Event::Ptr &e1, const Event::Ptr &e2) { DateTimeComparison res = compare(e1->dtEnd(), e1->allDay(), e2->dtEnd(), e2->allDay()); if (res == Equal) { return Events::summaryLessThan(e1, e2); } else { return (res & Before || res & AtStart); } } bool KCalCore::Events::endDateMoreThan(const Event::Ptr &e1, const Event::Ptr &e2) { DateTimeComparison res = compare(e1->dtEnd(), e1->allDay(), e2->dtEnd(), e2->allDay()); if (res == Equal) { return Events::summaryMoreThan(e1, e2); } else { return (res & After || res & AtEnd); } } bool KCalCore::Journals::dateLessThan(const Journal::Ptr &j1, const Journal::Ptr &j2) { DateTimeComparison res = compare(j1->dtStart(), j1->allDay(), j2->dtStart(), j2->allDay()); return (res & Before || res & AtStart); } bool KCalCore::Journals::dateMoreThan(const Journal::Ptr &j1, const Journal::Ptr &j2) { DateTimeComparison res = compare(j1->dtStart(), j1->allDay(), j2->dtStart(), j2->allDay()); return (res & After || res & AtEnd); } bool KCalCore::Journals::summaryLessThan(const Journal::Ptr &j1, const Journal::Ptr &j2) { return QString::compare(j1->summary(), j2->summary(), Qt::CaseInsensitive) < 0; } bool KCalCore::Journals::summaryMoreThan(const Journal::Ptr &j1, const Journal::Ptr &j2) { return QString::compare(j1->summary(), j2->summary(), Qt::CaseInsensitive) > 0; } bool KCalCore::Todos::startDateLessThan(const Todo::Ptr &t1, const Todo::Ptr &t2) { DateTimeComparison res = compare(t1->dtStart(), t1->allDay(), t2->dtStart(), t2->allDay()); if (res == Equal) { return Todos::summaryLessThan(t1, t2); } else { return (res & Before || res & AtStart); } } bool KCalCore::Todos::startDateMoreThan(const Todo::Ptr &t1, const Todo::Ptr &t2) { DateTimeComparison res = compare(t1->dtStart(), t1->allDay(), t2->dtStart(), t2->allDay()); if (res == Equal) { return Todos::summaryMoreThan(t1, t2); } else { return (res & After || res & AtEnd); } } bool KCalCore::Todos::dueDateLessThan(const Todo::Ptr &t1, const Todo::Ptr &t2) { DateTimeComparison res = compare(t1->dtDue(), t1->allDay(), t2->dtDue(), t2->allDay()); if (res == Equal) { return Todos::summaryLessThan(t1, t2); } else { return (res & Before || res & AtStart); } } bool KCalCore::Todos::dueDateMoreThan(const Todo::Ptr &t1, const Todo::Ptr &t2) { DateTimeComparison res = compare(t1->dtDue(), t1->allDay(), t2->dtDue(), t2->allDay()); if (res == Equal) { return Todos::summaryMoreThan(t1, t2); } else { return (res & After || res & AtEnd); } } bool KCalCore::Todos::priorityLessThan(const Todo::Ptr &t1, const Todo::Ptr &t2) { if (t1->priority() < t2->priority()) { return true; } else if (t1->priority() == t2->priority()) { return Todos::summaryLessThan(t1, t2); } else { return false; } } bool KCalCore::Todos::priorityMoreThan(const Todo::Ptr &t1, const Todo::Ptr &t2) { if (t1->priority() > t2->priority()) { return true; } else if (t1->priority() == t2->priority()) { return Todos::summaryMoreThan(t1, t2); } else { return false; } } bool KCalCore::Todos::percentLessThan(const Todo::Ptr &t1, const Todo::Ptr &t2) { if (t1->percentComplete() < t2->percentComplete()) { return true; } else if (t1->percentComplete() == t2->percentComplete()) { return Todos::summaryLessThan(t1, t2); } else { return false; } } bool KCalCore::Todos::percentMoreThan(const Todo::Ptr &t1, const Todo::Ptr &t2) { if (t1->percentComplete() > t2->percentComplete()) { return true; } else if (t1->percentComplete() == t2->percentComplete()) { return Todos::summaryMoreThan(t1, t2); } else { return false; } } bool KCalCore::Todos::summaryLessThan(const Todo::Ptr &t1, const Todo::Ptr &t2) { return QString::compare(t1->summary(), t2->summary(), Qt::CaseInsensitive) < 0; } bool KCalCore::Todos::summaryMoreThan(const Todo::Ptr &t1, const Todo::Ptr &t2) { return QString::compare(t1->summary(), t2->summary(), Qt::CaseInsensitive) > 0; } bool KCalCore::Todos::createdLessThan(const Todo::Ptr &t1, const Todo::Ptr &t2) { DateTimeComparison res = compare(t1->created(), t1->allDay(), t2->created(), t2->allDay()); if (res == Equal) { return Todos::summaryLessThan(t1, t2); } else { return (res & Before || res & AtStart); } } bool KCalCore::Todos::createdMoreThan(const Todo::Ptr &t1, const Todo::Ptr &t2) { DateTimeComparison res = compare(t1->created(), t1->allDay(), t2->created(), t2->allDay()); if (res == Equal) { return Todos::summaryMoreThan(t1, t2); } else { return (res & After || res & AtEnd); } } bool KCalCore::Incidences::dateLessThan(const Incidence::Ptr &i1, const Incidence::Ptr &i2) { DateTimeComparison res = compare(i1->dateTime(Incidence::RoleSort), i1->allDay(), i2->dateTime(Incidence::RoleSort), i2->allDay()); if (res == Equal) { return Incidences::summaryLessThan(i1, i2); } else { return (res & Before || res & AtStart); } } bool KCalCore::Incidences::dateMoreThan(const Incidence::Ptr &i1, const Incidence::Ptr &i2) { DateTimeComparison res = compare(i1->dateTime(Incidence::RoleSort), i1->allDay(), i2->dateTime(Incidence::RoleSort), i2->allDay()); if (res == Equal) { return Incidences::summaryMoreThan(i1, i2); } else { return (res & After || res & AtEnd); } } bool KCalCore::Incidences::createdLessThan(const Incidence::Ptr &i1, const Incidence::Ptr &i2) { DateTimeComparison res = compare(i1->created(), i1->allDay(), i2->created(), i2->allDay()); if (res == Equal) { return Incidences::summaryLessThan(i1, i2); } else { return (res & Before || res & AtStart); } } bool KCalCore::Incidences::createdMoreThan(const Incidence::Ptr &i1, const Incidence::Ptr &i2) { DateTimeComparison res = compare(i1->created(), i1->allDay(), i2->created(), i2->allDay()); if (res == Equal) { return Incidences::summaryMoreThan(i1, i2); } else { return (res & After || res & AtEnd); } } bool KCalCore::Incidences::summaryLessThan(const Incidence::Ptr &i1, const Incidence::Ptr &i2) { return QString::compare(i1->summary(), i2->summary(), Qt::CaseInsensitive) < 0; } bool KCalCore::Incidences::summaryMoreThan(const Incidence::Ptr &i1, const Incidence::Ptr &i2) { return QString::compare(i1->summary(), i2->summary(), Qt::CaseInsensitive) > 0; } -bool KCalCore::Persons::countMoreThan(const Person::Ptr &p1, const Person::Ptr &p2) -{ - return p1->count() > p2->count(); -} diff --git a/src/sorting.h b/src/sorting.h index e5e9a0190..44f4fd635 100644 --- a/src/sorting.h +++ b/src/sorting.h @@ -1,103 +1,100 @@ /* This file is part of the kcalcore library. 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. */ #ifndef KCALCORE_SORTING_H #define KCALCORE_SORTING_H #include "event.h" #include "journal.h" #include "todo.h" #include "freebusy.h" #include "person.h" #include "kcalcore_export.h" namespace KCalCore { namespace Events { KCALCORE_EXPORT bool startDateLessThan(const Event::Ptr &e1, const Event::Ptr &e2); KCALCORE_EXPORT bool summaryLessThan(const Event::Ptr &e1, const Event::Ptr &e2); KCALCORE_EXPORT bool summaryMoreThan(const Event::Ptr &e1, const Event::Ptr &e2); KCALCORE_EXPORT bool startDateMoreThan(const Event::Ptr &e1, const Event::Ptr &e2); KCALCORE_EXPORT bool endDateLessThan(const Event::Ptr &e1, const Event::Ptr &e2); KCALCORE_EXPORT bool endDateMoreThan(const Event::Ptr &e1, const Event::Ptr &e2); } namespace Todos { KCALCORE_EXPORT bool startDateLessThan(const Todo::Ptr &t1, const Todo::Ptr &t2); KCALCORE_EXPORT bool startDateMoreThan(const Todo::Ptr &t1, const Todo::Ptr &t2); KCALCORE_EXPORT bool dueDateLessThan(const Todo::Ptr &t1, const Todo::Ptr &t2); KCALCORE_EXPORT bool dueDateMoreThan(const Todo::Ptr &t1, const Todo::Ptr &t2); KCALCORE_EXPORT bool priorityLessThan(const Todo::Ptr &t1, const Todo::Ptr &t2); KCALCORE_EXPORT bool priorityMoreThan(const Todo::Ptr &t1, const Todo::Ptr &t2); KCALCORE_EXPORT bool percentLessThan(const Todo::Ptr &t1, const Todo::Ptr &t2); KCALCORE_EXPORT bool percentMoreThan(const Todo::Ptr &t1, const Todo::Ptr &t2); KCALCORE_EXPORT bool summaryLessThan(const Todo::Ptr &t1, const Todo::Ptr &t2); KCALCORE_EXPORT bool summaryMoreThan(const Todo::Ptr &t1, const Todo::Ptr &t2); KCALCORE_EXPORT bool createdLessThan(const Todo::Ptr &t1, const Todo::Ptr &t2); KCALCORE_EXPORT bool createdMoreThan(const Todo::Ptr &t1, const Todo::Ptr &t2); } namespace Journals { KCALCORE_EXPORT bool dateLessThan(const Journal::Ptr &j1, const Journal::Ptr &j2); KCALCORE_EXPORT bool dateMoreThan(const Journal::Ptr &j1, const Journal::Ptr &j2); KCALCORE_EXPORT bool summaryLessThan(const Journal::Ptr &j1, const Journal::Ptr &j2); KCALCORE_EXPORT bool summaryMoreThan(const Journal::Ptr &j1, const Journal::Ptr &j2); } namespace Incidences { KCALCORE_EXPORT bool dateLessThan(const Incidence::Ptr &i1, const Incidence::Ptr &i2); KCALCORE_EXPORT bool dateMoreThan(const Incidence::Ptr &i1, const Incidence::Ptr &i2); KCALCORE_EXPORT bool createdLessThan(const Incidence::Ptr &i1, const Incidence::Ptr &i2); KCALCORE_EXPORT bool createdMoreThan(const Incidence::Ptr &i1, const Incidence::Ptr &i2); KCALCORE_EXPORT bool summaryLessThan(const Incidence::Ptr &i1, const Incidence::Ptr &i2); KCALCORE_EXPORT bool summaryMoreThan(const Incidence::Ptr &i1, const Incidence::Ptr &i2); } -namespace Persons { -KCALCORE_EXPORT bool countMoreThan(const Person::Ptr &p1, const Person::Ptr &p2); -} } #endif