diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,7 +120,6 @@ find_package(KF5Holidays ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5DBusAddons ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5IconThemes ${KF5_MIN_VERSION} CONFIG REQUIRED) -find_package(KF5KDELibs4Support ${KF5_MIN_VERSION} CONFIG REQUIRED) # KdepimLibs package find_package(KF5Akonadi ${AKONADI_VERSION} CONFIG REQUIRED) diff --git a/resources/kolab/pimkolab/CMakeLists.txt b/resources/kolab/pimkolab/CMakeLists.txt --- a/resources/kolab/pimkolab/CMakeLists.txt +++ b/resources/kolab/pimkolab/CMakeLists.txt @@ -33,7 +33,6 @@ kolabformat/v2helpers.cpp kolabformat/mimeobject.cpp mime/mimeutils.cpp - utils/porting.cpp conversion/kcalconversion.cpp conversion/kabcconversion.cpp conversion/commonconversion.cpp @@ -66,7 +65,6 @@ KF5::AkonadiNotes KF5::Codecs KF5::I18n - KF5::KDELibs4Support ${Libkolabxml_LIBRARIES} Qt5::Core Qt5::Xml diff --git a/resources/kolab/pimkolab/autotests/testhelpers.h b/resources/kolab/pimkolab/autotests/testhelpers.h --- a/resources/kolab/pimkolab/autotests/testhelpers.h +++ b/resources/kolab/pimkolab/autotests/testhelpers.h @@ -20,8 +20,6 @@ #include -#include - #include #include #include @@ -59,16 +57,6 @@ return qstrdup(ba.data()); } -template<> -char *toString(const KDateTime &dt) -{ - QByteArray ba = "KDateTime("; - ba += dt.toString().toAscii(); - ba += dt.timeZone().name().toAscii(); - ba += ")"; - return qstrdup(ba.data()); -} - template<> char *toString(const KCalCore::Attendee &at) { diff --git a/resources/kolab/pimkolab/conversion/commonconversion.cpp b/resources/kolab/pimkolab/conversion/commonconversion.cpp --- a/resources/kolab/pimkolab/conversion/commonconversion.cpp +++ b/resources/kolab/pimkolab/conversion/commonconversion.cpp @@ -18,10 +18,8 @@ #include "commonconversion.h" #include "pimkolab_debug.h" #include "timezoneconverter.h" -#include "utils/porting.h" #include -#include #include #include @@ -78,48 +76,6 @@ return date; } -cDateTime fromDate(const KDateTime &dt) -{ - if (!dt.isValid()) { - return cDateTime(); - } - cDateTime date; - if (dt.isDateOnly()) { //Date only - const QDate &d = dt.date(); - date.setDate(d.year(), d.month(), d.day()); - } else { - const QDate &d = dt.date(); - date.setDate(d.year(), d.month(), d.day()); - const QTime &t = dt.time(); - date.setTime(t.hour(), t.minute(), t.second()); - if (dt.timeType() == KDateTime::UTC) { //UTC - date.setUTC(true); - } else if (dt.timeType() == KDateTime::OffsetFromUTC) { - const KDateTime utcDate = dt.toUtc(); - const QDate &d = utcDate.date(); - date.setDate(d.year(), d.month(), d.day()); - const QTime &t = utcDate.time(); - date.setTime(t.hour(), t.minute(), t.second()); - date.setUTC(true); - } else if (dt.timeType() == KDateTime::TimeZone) { //Timezone - //TODO handle local timezone? - //Convert non-olson timezones if necessary - const QString timezone = TimezoneConverter::normalizeTimezone(dt.timeZone().name()); - if (!timezone.isEmpty()) { - date.setTimezone(toStdString(timezone)); - } else { - qCWarning(PIMKOLAB_LOG) << "invalid timezone: " << dt.timeZone().name() << ", assuming floating time"; - return date; - } - } else if (dt.timeType() != KDateTime::ClockTime) { - qCCritical(PIMKOLAB_LOG) << "invalid timespec, assuming floating time. Type: " << dt.timeType() << "dt: " << dt.toString(); - return date; - } - } - Q_ASSERT(date.isValid()); - return date; -} - cDateTime fromDate(const QDateTime &dt, bool isAllDay) { if (!dt.isValid()) { diff --git a/resources/kolab/pimkolab/conversion/timezoneconverter.cpp b/resources/kolab/pimkolab/conversion/timezoneconverter.cpp --- a/resources/kolab/pimkolab/conversion/timezoneconverter.cpp +++ b/resources/kolab/pimkolab/conversion/timezoneconverter.cpp @@ -16,7 +16,6 @@ */ #include "timezoneconverter.h" -#include #include #include diff --git a/resources/kolab/pimkolab/kolabformatV2/journal.cpp b/resources/kolab/pimkolab/kolabformatV2/journal.cpp --- a/resources/kolab/pimkolab/kolabformatV2/journal.cpp +++ b/resources/kolab/pimkolab/kolabformatV2/journal.cpp @@ -34,7 +34,6 @@ #include "journal.h" #include "libkolab-version.h" #include "pimkolab_debug.h" -#include "utils/porting.h" using namespace KolabV2; diff --git a/resources/kolab/pimkolab/kolabformatV2/kolabbase.h b/resources/kolab/pimkolab/kolabformatV2/kolabbase.h --- a/resources/kolab/pimkolab/kolabformatV2/kolabbase.h +++ b/resources/kolab/pimkolab/kolabformatV2/kolabbase.h @@ -36,8 +36,6 @@ #include -#include - #include #include #include @@ -102,10 +100,8 @@ // String - Date conversion methods static QString dateTimeToString(const QDateTime &time); - static QString dateTimeToString(const KDateTime &time); static QString dateToString(const QDate &date); static QDateTime stringToDateTime(const QString &time); - static KDateTime stringToKDateTime(const QString &time); static QDate stringToDate(const QString &date); // String - Sensitivity conversion methods diff --git a/resources/kolab/pimkolab/kolabformatV2/kolabbase.cpp b/resources/kolab/pimkolab/kolabformatV2/kolabbase.cpp --- a/resources/kolab/pimkolab/kolabformatV2/kolabbase.cpp +++ b/resources/kolab/pimkolab/kolabformatV2/kolabbase.cpp @@ -445,11 +445,6 @@ return time.toString(Qt::ISODate); } -QString KolabBase::dateTimeToString(const KDateTime &time) -{ - return time.toString(KDateTime::ISODate); -} - QString KolabBase::dateToString(const QDate &date) { return date.toString(Qt::ISODate); @@ -460,12 +455,6 @@ return QDateTime::fromString(time, Qt::ISODate); } -KDateTime KolabBase::stringToKDateTime(const QString &_date) -{ - const QString date(_date); - return KDateTime::fromString(date, KDateTime::ISODate); -} - QDate KolabBase::stringToDate(const QString &date) { return QDate::fromString(date, Qt::ISODate); diff --git a/resources/kolab/pimkolab/utils/porting.h b/resources/kolab/pimkolab/utils/porting.h deleted file mode 100644 --- a/resources/kolab/pimkolab/utils/porting.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - This file is part of the kcalcore library. - - Copyright (c) 2017 Daniel Vrátil - - 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 PORTING_H -#define PORTING_H - -#include -#include - -namespace Porting { -// TODO: PORTING-helper only, remove once KDateTime is gone -/** - * Helpers to retain backwards compatibility of binary serialization. - */ -void serializeQDateTimeAsKDateTime(QDataStream &out, const QDateTime &dt); -void deserializeKDateTimeAsQDateTime(QDataStream &in, QDateTime & dt); - -/** Convert a QTimeZone to a KDateTime::Spec */ -KDateTime::Spec zoneToSpec(const QTimeZone &zone); - -/** Convert a QTimeZone to a KDateTime::Spec */ -QTimeZone specToZone(const KDateTime::Spec &spec); - -/** Convert KDateTime to QDateTime, correctly preserves timespec */ -QDateTime k2q(const KDateTime &kdt); -KDateTime q2k(const QDateTime &qdt, bool isAllDay = false); -} - -#endif // PORTING_H diff --git a/resources/kolab/pimkolab/utils/porting.cpp b/resources/kolab/pimkolab/utils/porting.cpp deleted file mode 100644 --- a/resources/kolab/pimkolab/utils/porting.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/* - This file is part of the kcalcore library. - - Copyright (c) 2017 Daniel Vrátil - - 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 "porting.h" -#include "pimkolab_debug.h" - -#include -#include -#include - -KDateTime::Spec Porting::zoneToSpec(const QTimeZone &zone) -{ - if (!zone.isValid()) { - return KDateTime::Invalid; - } - if (zone == QTimeZone::utc()) { - return KDateTime::UTC; - } - if (zone == QTimeZone::systemTimeZone()) { - return KDateTime::LocalZone; - } - if (zone.id().startsWith("UTC")) { - return KDateTime::Spec(KDateTime::OffsetFromUTC, zone.offsetFromUtc(QDateTime::currentDateTimeUtc())); - } else { - return KSystemTimeZones::zone(QString::fromLatin1(zone.id())); - } -} - -namespace { -QTimeZone resolveCustomTZ(const KTimeZone &ktz) -{ - // First, let's try Microsoft - const auto msIana = QTimeZone::windowsIdToDefaultIanaId(ktz.name().toUtf8()); - if (!msIana.isEmpty()) { - return QTimeZone(msIana); - } - - int standardUtcOffset = 0; - bool matched = false; - const auto phases = ktz.phases(); - for (const auto &phase : phases) { - if (!phase.isDst()) { - standardUtcOffset = phase.utcOffset(); - matched = true; - break; - } - } - if (!matched) { - standardUtcOffset = ktz.currentOffset(Qt::UTC); - } - - const auto candidates = QTimeZone::availableTimeZoneIds(standardUtcOffset); - QMap matchedCandidates; - for (const auto &tzid : candidates) { - const QTimeZone candidate(tzid); - // This would be a fallback - if (candidate.hasTransitions() != ktz.hasTransitions()) { - matchedCandidates.insert(0, candidate); - continue; - } - - // Without transitions, we can't do any more precise matching, so just - // accept this candidate and be done with it - if (!candidate.hasTransitions() && !ktz.hasTransitions()) { - return candidate; - } - - // Calculate how many transitions this candidate shares with the ktz. - // The candidate with the most matching transitions will win. - const auto transitions = ktz.transitions(QDateTime(), QDateTime::currentDateTimeUtc()); - int matchedTransitions = 0; - for (auto it = transitions.rbegin(), end = transitions.rend(); it != end; ++it) { - const auto &transition = *it; - const QTimeZone::OffsetDataList candidateTransitions = candidate.transitions(transition.time(), transition.time()); - if (candidateTransitions.isEmpty()) { - continue; - } - const auto candidateTransition = candidateTransitions[0]; - const auto abvs = transition.phase().abbreviations(); - for (const auto &abv : abvs) { -// if (candidateTransition.abbreviation == QString::fromUtf8(abv)) { - ++matchedTransitions; - break; -// } - } - } - matchedCandidates.insert(matchedTransitions, candidate); - } - - if (!matchedCandidates.isEmpty()) { - return matchedCandidates.value(matchedCandidates.lastKey()); - } - - return {}; -} -} - -QTimeZone Porting::specToZone(const KDateTime::Spec &spec) -{ - switch (spec.type()) { - case KDateTime::Invalid: - return QTimeZone(); - case KDateTime::LocalZone: - case KDateTime::ClockTime: - return QTimeZone::systemTimeZone(); - case KDateTime::UTC: - return QTimeZone::utc(); - default: - { - auto tz = QTimeZone(spec.timeZone().name().toUtf8()); - if (!tz.isValid()) { - tz = resolveCustomTZ(spec.timeZone()); - qCDebug(PIMKOLAB_LOG) << "Resolved" << spec.timeZone().name() << "to" << tz.id(); - } - return tz; - } - } -} - -QDateTime Porting::k2q(const KDateTime &kdt) -{ - if (kdt.isValid()) { - return QDateTime(kdt.date(), kdt.time(), specToZone(kdt.timeSpec())); - } else { - return QDateTime(); - } -} - -KDateTime Porting::q2k(const QDateTime &qdt, bool allDay) -{ - if (qdt.isValid()) { - KDateTime kdt(qdt.date(), qdt.time(), zoneToSpec(qdt.timeZone())); - kdt.setDateOnly(allDay && qdt.time() == QTime(0, 0, 0)); - return kdt; - } else { - return KDateTime(); - } -}