Commit 3c3ecb1c authored by David Jarvie's avatar David Jarvie
Browse files

Remove KDE4Support

KDateTime is copied from KDE4Support into this library, renamed to
KADateTime, and updated to work properly with Qt5 QDateTime and
QTimeZone. The ClockTime time spec type is removed in favour of
LocalZone.
parent 1947b38a
......@@ -36,7 +36,8 @@ ecm_setup_version(PROJECT VARIABLE_PREFIX KALARMCAL
)
########### Find packages ###########
find_package(KF5KDELibs4Support ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5Config ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5I18n ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5Holidays ${KF5_VERSION} CONFIG REQUIRED)
......@@ -53,6 +54,10 @@ add_definitions(-DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT)
add_subdirectory(src)
add_subdirectory(serializers)
if(BUILD_TESTING)
add_subdirectory(autotests)
endif()
########### CMake Config Files ###########
set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KF5AlarmCalendar")
......
include(ECMMarkAsTest)
find_package(Qt5DBus CONFIG REQUIRED)
find_package(Qt5Test CONFIG REQUIRED)
########### next target ###############
set(kadatetimetest_SRCS kadatetimetest.cpp)
add_executable(kadatetimetest ${kadatetimetest_SRCS})
add_test(kadatetimetest kadatetimetest)
ecm_mark_as_test(kadatetimetest)
target_link_libraries(kadatetimetest KF5::AlarmCalendar Qt5::DBus Qt5::Test)
This diff is collapsed.
/*
This file is part of kalarmcal library, which provides access to KAlarm
calendar data.
Copyright (c) 2005,2011,2018 David Jarvie <djarvie@kde.org>
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 KADATETIMETEST_H
#define KADATETIMETEST_H
#include <QObject>
class KADateTimeTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void specConstructors();
void specSet();
void constructors();
void toUtc();
void toOffsetFromUtc();
void toLocalZone();
void toZone();
void toTimeSpec();
void set();
void equal();
void lessThan();
void compare();
void addSubtract();
void addMSecs();
void addSubtractDate();
void dstShifts();
void strings_iso8601();
void strings_rfc2822();
void strings_rfc3339();
void strings_qttextdate();
void strings_format();
#ifdef COMPILING_TESTS
void cache();
#endif
void stream();
void misc();
};
#endif
/*
* akonadi_serializer_kalarm.cpp - Akonadi resource serializer for KAlarm
* Copyright © 2009-2012 by David Jarvie <djarvie@kde.org>
* Copyright © 2009-2012,2018 by David Jarvie <djarvie@kde.org>
*
* 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
......@@ -30,8 +30,9 @@
#include <AkonadiCore/abstractdifferencesreporter.h>
#include <AkonadiCore/attributefactory.h>
#include <klocale.h>
#include <klocalizedstring.h>
#include <QLocale>
#include <qplugin.h>
using namespace Akonadi;
......@@ -296,10 +297,9 @@ void SerializerPluginKAlarm::compare(AbstractDifferencesReporter *reporter, cons
reportDifference(reporter, KAEventFormatter::EmailAttachments);
}
KLocale *locale = KLocale::global();
QLocale locale;
reporter->addProperty(AbstractDifferencesReporter::ConflictMode, i18nc("@label", "Item revision"),
locale->convertDigits(QString::number(left.revision()), locale->digitSet()),
locale->convertDigits(QString::number(right.revision()), locale->digitSet()));
locale.toString(left.revision()), locale.toString(right.revision()));
}
void SerializerPluginKAlarm::reportDifference(AbstractDifferencesReporter *reporter, KAEventFormatter::Parameter id)
......
/*
* kaeventformatter.cpp - converts KAlarmCal::KAEvent properties to text
* Copyright © 2010,2011 by David Jarvie <djarvie@kde.org>
* Copyright © 2010,2011,2018 by David Jarvie <djarvie@kde.org>
*
* 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
......@@ -26,15 +26,14 @@
#include <kcalutils/incidenceformatter.h>
#include <kglobal.h>
#include <kdatetime.h>
#include <KLocale>
#include <klocalizedstring.h>
#include <QLocale>
static QString trueFalse(bool value);
static QString number(unsigned long n);
static QString minutes(int n);
static QString minutesHoursDays(int minutes);
static QString dateTime(const KDateTime &);
static QString dateTime(const KAlarmCal::KADateTime &);
KAEventFormatter::KAEventFormatter(const KAEvent &e, bool falseForUnspecified)
: mEvent(e)
......@@ -287,7 +286,7 @@ QString KAEventFormatter::value(Parameter param) const
case StartTime:
return dateTime(mEvent.startDateTime().kDateTime());
case TemplateAfterTime:
return (mEvent.templateAfterTime() >= 0) ? number(mEvent.templateAfterTime()) : trueFalse(false);
return (mEvent.templateAfterTime() >= 0) ? QLocale().toString(mEvent.templateAfterTime()) : trueFalse(false);
case Recurs:
return trueFalse(mEvent.recurs());
case Recurrence:
......@@ -306,9 +305,9 @@ QString KAEventFormatter::value(Parameter param) const
case RepeatInterval:
return mEvent.repetitionText(true);
case RepeatCount:
return mEvent.repetition() ? number(mEvent.repetition().count()) : QString();
return mEvent.repetition() ? QLocale().toString(mEvent.repetition().count()) : QString();
case NextRepetition:
return mEvent.repetition() ? number(mEvent.nextRepetition()) : QString();
return mEvent.repetition() ? QLocale().toString(mEvent.nextRepetition()) : QString();
case WorkTimeOnly:
return trueFalse(mEvent.workTimeOnly());
case HolidaysExcluded:
......@@ -326,7 +325,7 @@ QString KAEventFormatter::value(Parameter param) const
case Archive:
return trueFalse(mEvent.toBeArchived());
case Revision:
return number(mEvent.revision());
return QLocale().toString(mEvent.revision());
case CustomProperties:
{
if (mEvent.customProperties().isEmpty()) {
......@@ -373,7 +372,7 @@ QString KAEventFormatter::value(Parameter param) const
case ConfirmAck:
return trueFalse(mEvent.confirmAck());
case KMailSerial:
return mEvent.kmailSerialNumber() ? number(mEvent.kmailSerialNumber()) : trueFalse(false);
return mEvent.kmailSerialNumber() ? QLocale().toString(qulonglong(mEvent.kmailSerialNumber())) : trueFalse(false);
case Sound:
return !mEvent.audioFile().isEmpty() ? mEvent.audioFile()
: mEvent.speak() ? i18nc("@info", "Speak")
......@@ -403,7 +402,7 @@ QString KAEventFormatter::value(Parameter param) const
case EmailSubject:
return mEvent.emailSubject();
case EmailFromId:
return (mEvent.actionSubType() == KAEvent::EMAIL) ? number(mEvent.emailFromId()) : QString();
return (mEvent.actionSubType() == KAEvent::EMAIL) ? QLocale().toString(mEvent.emailFromId()) : QString();
case EmailTo:
return mEvent.emailAddresses(QStringLiteral(", "));
case EmailBcc:
......@@ -422,20 +421,12 @@ QString trueFalse(bool value)
: i18nc("@info General purpose status indication: yes or no", "No");
}
// Convert an integer to digits for the locale.
// Do not use for date/time or monetary numbers (which have their own digit sets).
QString number(unsigned long n)
{
KLocale *locale = KLocale::global();
return locale->convertDigits(QString::number(n), locale->digitSet());
}
QString minutes(int n)
{
return i18ncp("@info", "1 Minute", "%1 Minutes", n);
}
QString dateTime(const KDateTime &dt)
QString dateTime(const KAlarmCal::KADateTime &dt)
{
if (dt.isDateOnly()) {
return dt.toString(QStringLiteral("%Y-%m-%d %:Z"));
......
......@@ -9,13 +9,13 @@ set(kalarmcal_LIB_SRCS
alarmtext.cpp
identities.cpp
kaevent.cpp
kadatetime.cpp
datetime.cpp
repetition.cpp
version.cpp
collectionattribute.cpp
compatibilityattribute.cpp
eventattribute.cpp
utils.cpp
)
ecm_qt_declare_logging_category(kalarmcal_LIB_SRCS HEADER kalarmcal_debug.h IDENTIFIER KALARMCAL_LOG CATEGORY_NAME org.kde.pim.kalarmcal)
......@@ -28,12 +28,13 @@ add_library(KF5::AlarmCalendar ALIAS KF5AlarmCalendar)
target_link_libraries(KF5AlarmCalendar
PUBLIC
KF5::ConfigCore
KF5::I18n
KF5::Holidays
KF5::IdentityManagement
KF5::CoreAddons
KF5::CalendarCore
KF5::AkonadiCore
KF5::KDELibs4Support
PRIVATE
)
......@@ -57,11 +58,11 @@ ecm_generate_headers(KAlarmCal_CamelCase_HEADERS
CollectionAttribute
CompatibilityAttribute
DateTime
KADateTime
EventAttribute
KAEvent
KARecurrence
Repetition
Utils
PREFIX KAlarmCal
REQUIRED_HEADERS KAlarmCal_HEADERS
)
......
......@@ -589,3 +589,5 @@ QString AlarmText::Private::todoTitle(const QString &text)
}
} // namespace KAlarmCal
// vim: et sw=4:
......@@ -20,8 +20,8 @@
* MA 02110-1301, USA.
*/
#ifndef ALARMTEXT_H
#define ALARMTEXT_H
#ifndef KALARM_ALARMTEXT_H
#define KALARM_ALARMTEXT_H
#include "kalarmcal_export.h"
......@@ -207,5 +207,6 @@ private:
} // namespace KAlarmCal
#endif // ALARMTEXT_H
#endif // KALARM_ALARMTEXT_H
// vim: et sw=4:
......@@ -257,3 +257,5 @@ void CollectionAttribute::deserialize(const QByteArray &data)
}
} // namespace KAlarmCal
// vim: et sw=4:
......@@ -156,3 +156,4 @@ private:
#endif // KALARM_COLLECTION_ATTRIBUTE_H
// vim: et sw=4:
......@@ -142,3 +142,5 @@ void CompatibilityAttribute::deserialize(const QByteArray &data)
}
} // namespace KAlarmCal
// vim: et sw=4:
......@@ -97,3 +97,4 @@ private:
#endif // KALARM_COMPATIBILITY_ATTRIBUTE_H
// vim: et sw=4:
......@@ -2,7 +2,7 @@
* datetime.cpp - date/time with start-of-day time for date-only values
* This file is part of kalarmcal library, which provides access to KAlarm
* calendar data.
* Copyright © 2003,2005-2007,2009-2011,2016 by David Jarvie <djarvie@kde.org>
* Copyright © 2003,2005-2007,2009-2011,2016,2018 by David Jarvie <djarvie@kde.org>
*
* 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
......@@ -21,10 +21,7 @@
*/
#include "datetime.h"
#include <klocalizedstring.h>
#include <ktimezone.h>
#include <QDateTime>
#include <QTimeZone>
#include <QLocale>
namespace KAlarmCal
......@@ -34,13 +31,14 @@ class Q_DECL_HIDDEN DateTime::Private
{
public:
Private() {}
Private(const QDate &d, const KDateTime::Spec &spec) : mDateTime(d, spec) {}
Private(const QDate &d, const QTime &t, const KDateTime::Spec &spec) : mDateTime(d, t, spec) {}
Private(const QDateTime &dt, const KDateTime::Spec &spec) : mDateTime(dt, spec) {}
Private(const KDateTime &dt) : mDateTime(dt) {}
Private(const QDate &d, const KADateTime::Spec &spec) : mDateTime(d, spec) {}
Private(const QDate &d, const QTime &t, const KADateTime::Spec &spec) : mDateTime(d, t, spec) {}
Private(const QDateTime &dt, const KADateTime::Spec &spec) : mDateTime(dt, spec) {}
Private(const QDateTime &dt) : mDateTime(dt) {}
Private(const KADateTime &dt) : mDateTime(dt) {}
static QTime mStartOfDay;
KDateTime mDateTime;
KADateTime mDateTime;
};
QTime DateTime::Private::mStartOfDay;
......@@ -50,22 +48,27 @@ DateTime::DateTime()
{
}
DateTime::DateTime(const QDate &d, const KDateTime::Spec &spec)
DateTime::DateTime(const QDate &d, const KADateTime::Spec &spec)
: d(new Private(d, spec))
{
}
DateTime::DateTime(const QDate &d, const QTime &t, const KDateTime::Spec &spec)
DateTime::DateTime(const QDate &d, const QTime &t, const KADateTime::Spec &spec)
: d(new Private(d, t, spec))
{
}
DateTime::DateTime(const QDateTime &dt, const KDateTime::Spec &spec)
DateTime::DateTime(const QDateTime &dt, const KADateTime::Spec &spec)
: d(new Private(dt, spec))
{
}
DateTime::DateTime(const KDateTime &dt)
DateTime::DateTime(const QDateTime &dt)
: d(new Private(dt))
{
}
DateTime::DateTime(const KADateTime &dt)
: d(new Private(dt))
{
}
......@@ -88,7 +91,7 @@ DateTime &DateTime::operator=(const DateTime &dt)
return *this;
}
DateTime &DateTime::operator=(const KDateTime &dt)
DateTime &DateTime::operator=(const KADateTime &dt)
{
d->mDateTime = dt;
return *this;
......@@ -124,12 +127,12 @@ void DateTime::setDate(const QDate &date)
d->mDateTime.setDate(date);
}
QDateTime DateTime::rawDateTime() const
QDateTime DateTime::qDateTime() const
{
return d->mDateTime.dateTime();
return d->mDateTime.qDateTime();
}
KDateTime DateTime::kDateTime() const
KADateTime DateTime::kDateTime() const
{
return d->mDateTime;
}
......@@ -147,54 +150,59 @@ void DateTime::setTime(const QTime &t)
QDateTime DateTime::effectiveDateTime() const
{
if (d->mDateTime.isDateOnly()) {
QDateTime dt = d->mDateTime.dateTime(); // preserve Qt::UTC or Qt::LocalTime
QDateTime dt = d->mDateTime.qDateTime(); // preserve Qt::UTC or Qt::LocalTime
dt.setTime(d->mStartOfDay);
return dt;
}
return d->mDateTime.dateTime();
return d->mDateTime.qDateTime();
}
void DateTime::setDateTime(const QDateTime &dt)
KADateTime DateTime::effectiveKDateTime() const
{
d->mDateTime.setDateTime(dt);
if (d->mDateTime.isDateOnly()) {
KADateTime dt = d->mDateTime;
dt.setTime(d->mStartOfDay);
return dt;
}
return d->mDateTime;
}
KDateTime DateTime::effectiveKDateTime() const
QDateTime DateTime::calendarDateTime() const
{
if (d->mDateTime.isDateOnly()) {
KDateTime dt = d->mDateTime;
dt.setTime(d->mStartOfDay);
QDateTime dt = d->mDateTime.qDateTime();
dt.setTime(QTime(0, 0));
return dt;
}
return d->mDateTime;
return d->mDateTime.qDateTime();
}
KDateTime DateTime::calendarKDateTime() const
KADateTime DateTime::calendarKDateTime() const
{
if (d->mDateTime.isDateOnly()) {
KDateTime dt = d->mDateTime;
KADateTime dt = d->mDateTime;
dt.setTime(QTime(0, 0));
return dt;
}
return d->mDateTime;
}
KTimeZone DateTime::timeZone() const
QTimeZone DateTime::timeZone() const
{
return d->mDateTime.timeZone();
}
KDateTime::Spec DateTime::timeSpec() const
KADateTime::Spec DateTime::timeSpec() const
{
return d->mDateTime.timeSpec();
}
void DateTime::setTimeSpec(const KDateTime::Spec &spec)
void DateTime::setTimeSpec(const KADateTime::Spec &spec)
{
d->mDateTime.setTimeSpec(spec);
}
KDateTime::SpecType DateTime::timeType() const
KADateTime::SpecType DateTime::timeType() const
{
return d->mDateTime.timeType();
}
......@@ -204,11 +212,6 @@ bool DateTime::isLocalZone() const
return d->mDateTime.isLocalZone();
}
bool DateTime::isClockTime() const
{
return d->mDateTime.isClockTime();
}
bool DateTime::isUtc() const
{
return d->mDateTime.isUtc();
......@@ -254,17 +257,12 @@ DateTime DateTime::toLocalZone() const
return DateTime(d->mDateTime.toLocalZone());
}
DateTime DateTime::toClockTime() const
{
return DateTime(d->mDateTime.toClockTime());
}
DateTime DateTime::toZone(const KTimeZone &zone) const
DateTime DateTime::toZone(const QTimeZone &zone) const
{
return DateTime(d->mDateTime.toZone(zone));
}
DateTime DateTime::toTimeSpec(const KDateTime::Spec &spec) const
DateTime DateTime::toTimeSpec(const KADateTime::Spec &spec) const
{
return DateTime(d->mDateTime.toTimeSpec(spec));
}
......@@ -324,29 +322,21 @@ qint64 DateTime::secsTo_long(const DateTime &dt) const
return d->mDateTime.secsTo(dt.d->mDateTime);
}
QString DateTime::toString(Qt::DateFormat f) const
QString DateTime::toString(KADateTime::TimeFormat f) const
{
if (d->mDateTime.isDateOnly()) {
return d->mDateTime.date().toString(f);
} else {
return d->mDateTime.dateTime().toString(f);
}
return d->mDateTime.toString(f);
}
QString DateTime::toString(const QString &format) const
{
if (d->mDateTime.isDateOnly()) {
return d->mDateTime.date().toString(format);
} else {
return d->mDateTime.dateTime().toString(format);
}
return d->mDateTime.toString(format);
}
QString DateTime::formatLocale(bool shortFormat) const
{
QLocale::FormatType format = shortFormat ? QLocale::ShortFormat : QLocale::LongFormat;
return d->mDateTime.isDateOnly() ? QLocale().toString(d->mDateTime.date(), format)
: QLocale().toString(d->mDateTime.dateTime(), format);
: QLocale().toString(d->mDateTime.qDateTime(), format);
}
void DateTime::setStartOfDay(const QTime &sod)
......@@ -354,7 +344,7 @@ void DateTime::setStartOfDay(const QTime &sod)
Private::mStartOfDay = sod;
}
KDateTime::Comparison DateTime::compare(const DateTime &other) const
KADateTime::Comparison DateTime::compare(const DateTime &other) const
{
return d->mDateTime.compare(other.d->mDateTime);
}
......@@ -369,7 +359,7 @@ bool operator==(const DateTime &dt1, const DateTime &dt2)
return dt1.d->mDateTime == dt2.d->mDateTime;
}
bool operator==(const KDateTime &dt1, const DateTime &dt2)
bool operator==(const KADateTime &dt1, const DateTime &dt2)
{
return dt1 == dt2.d->mDateTime;
}
......@@ -377,12 +367,12 @@ bool operator==(const KDateTime &dt1, const DateTime &dt2)
bool operator<(const DateTime &dt1, const DateTime &dt2)
{
if (dt1.d->mDateTime.isDateOnly() && !dt2.d->mDateTime.isDateOnly()) {
KDateTime dt = dt1.d->mDateTime.addDays(1);
KADateTime dt = dt1.d->mDateTime.addDays(1);
dt.setTime(DateTime::Private::mStartOfDay);
return dt <= dt2.d->mDateTime;
}
if (!dt1.d->mDateTime.isDateOnly() && dt2.d->mDateTime.isDateOnly()) {
KDateTime dt = dt2.d->mDateTime;
KADateTime dt = dt2.d->mDateTime;
dt.setTime(DateTime::Private::mStartOfDay);
return dt1.d->mDateTime < dt;
}
......@@ -390,3 +380,5 @@ bool operator<(const DateTime &dt1, const DateTime &dt2)
}
} // namespace KAlarmCal
// vim: et sw=4:
......@@ -2,7 +2,7 @@
* datetime.h - date/time with start-of-day time for date-only values
* This file is part of kalarmcal library, which provides access to KAlarm
* calendar data.
* Copyright © 2003,2005-2007,2009,2011 by David Jarvie <djarvie@kde.org>
* Copyright © 2003,2005-2007,2009,2011,2018 by David Jarvie <djarvie@kde.org>
*
* 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
......@@ -24,17 +24,17 @@
#include "kalarmcal_export.h"
#include <kdatetime.h>
#include "kadatetime.h"
namespace KAlarmCal
{
/**
* @short As KDateTime, but with a configurable start-of-day time for date-only values.
* @short As KADateTime, but with a configurable start-of-day time for date-only values.
*
* The DateTime class holds a date, with or without a time.
*
* DateTime is very similar to the KDateTime class. The time assumed for date-only values
* DateTime is very similar to the KADateTime class. The time assumed for date-only values
* is the start-of-day time set by setStartOfDay().
*
* @author David Jarvie <djarvie@kde.org>
......@@ -48,16 +48,19 @@ public:
DateTime();
/** Constructor for a date-only value. */
DateTime(const QDate &d, const KDateTime::Spec &spec);
DateTime(const QDate &d, const KADateTime::Spec &spec);