Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 4d7beb7b authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

Adapt to KCalCore API changes

parent 7c12c8b2
......@@ -37,6 +37,7 @@ ecm_setup_version(PROJECT
set(REQUIRED_QT_VERSION "5.8.0")
find_package(Qt5 ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS
Core
Network
Widgets
WebEngineWidgets
Xml
......@@ -53,6 +54,9 @@ find_package(KF5Contacts ${KCONTACTS_LIB_VERSION} CONFIG REQUIRED)
add_definitions( -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT )
add_definitions("-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII")
add_definitions(-DQT_NO_URL_CAST_FROM_STRING)
# TODO FIX!
add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x000000)
############## Targets ##############
add_subdirectory(src)
add_subdirectory(examples)
......
......@@ -50,6 +50,8 @@ target_link_libraries(KPimGAPICalendar
PUBLIC
KPim::GAPICore
KF5::CalendarCore
PRIVATE
Qt5::Network
)
set_target_properties(KPimGAPICalendar PROPERTIES
......
......@@ -34,13 +34,10 @@
#include <KCalCore/Recurrence>
#include <KCalCore/RecurrenceRule>
#include <KCalCore/ICalFormat>
#include <KCalCore/Utils>
#include <QJsonDocument>
#include <KDateTime>
#include <KSystemTimeZones>
#include <QTimeZone>
#include <QVariant>
namespace KGAPI2
......@@ -328,26 +325,26 @@ ObjectPtr Private::JSONToEvent(const QVariantMap& data, const QString &timezone)
/* Start date */
QVariantMap startData = data.value(QStringLiteral("start")).toMap();
KDateTime dtStart;
QDateTime dtStart;
if (startData.contains(QStringLiteral("date"))) {
dtStart = KDateTime::fromString(startData.value(QStringLiteral("date")).toString(), KDateTime::ISODate);
dtStart = QDateTime::fromString(startData.value(QStringLiteral("date")).toString(), Qt::ISODate);
event->setAllDay(true);
} else if (startData.contains(QStringLiteral("dateTime"))) {
dtStart = KDateTime::fromString(startData.value(QStringLiteral("dateTime")).toString(), KDateTime::RFC3339Date);
dtStart = Utils::rfc3339DateFromString(startData.value(QStringLiteral("dateTime")).toString());
// If there's a timezone specified in the "start" entity, then use it
if (startData.contains(QStringLiteral("timeZone"))) {
const KTimeZone tz = KSystemTimeZones::zone(startData.value(QStringLiteral("timeZone")).toString());
const QTimeZone tz = QTimeZone(startData.value(QStringLiteral("timeZone")).toString().toUtf8());
if (tz.isValid()) {
dtStart = dtStart.toTimeSpec(KDateTime::Spec(tz));
dtStart = dtStart.toTimeZone(tz);
} else {
qCWarning(KGAPIDebug) << "Invalid timezone" << startData.value(QStringLiteral("timeZone")).toString();
}
// Otherwise try to fallback to calendar-wide timezone
} else if (!timezone.isEmpty()) {
const KTimeZone tz = KSystemTimeZones::zone(timezone);
const QTimeZone tz(timezone.toUtf8());
if (tz.isValid()) {
dtStart = dtStart.toTimeSpec(KDateTime::Spec(tz));
dtStart.setTimeZone(tz);;
} else {
qCWarning(KGAPIDebug) << "Invalid timezone" << timezone;
}
......@@ -357,26 +354,27 @@ ObjectPtr Private::JSONToEvent(const QVariantMap& data, const QString &timezone)
/* End date */
QVariantMap endData = data.value(QStringLiteral("end")).toMap();
KDateTime dtEnd;
QDateTime dtEnd;
if (endData.contains(QStringLiteral("date"))) {
dtEnd = KDateTime::fromString(endData.value(QStringLiteral("date")).toString(), KDateTime::ISODate);
dtEnd = QDateTime::fromString(endData.value(QStringLiteral("date")).toString(), Qt::ISODate);
/* For Google, all-day events starts on Monday and ends on Tuesday,
* while in KDE, it both starts and ends on Monday. */
dtEnd = dtEnd.addDays(-1);
event->setAllDay(true);
} else if (endData.contains(QStringLiteral("dateTime"))) {
dtEnd = KDateTime::fromString(endData.value(QStringLiteral("dateTime")).toString(), KDateTime::RFC3339Date);
dtEnd = Utils::rfc3339DateFromString(endData.value(QStringLiteral("dateTime")).toString());
if (endData.contains(QStringLiteral("timeZone"))) {
const KTimeZone tz = KSystemTimeZones::zone(endData.value(QStringLiteral("timeZone")).toString());
const QTimeZone tz(endData.value(QStringLiteral("timeZone")).toString().toUtf8());
if (tz.isValid()) {
dtEnd = dtEnd.toTimeSpec(KDateTime::Spec(tz));
dtEnd = dtEnd.toTimeZone(tz);
} else {
qCWarning(KGAPIDebug) << "Invalid timezone" << endData.value(QStringLiteral("timeZone")).toString();
}
} else if (!timezone.isEmpty()) {
const KTimeZone tz = KSystemTimeZones::zone(timezone);
const QTimeZone tz(timezone.toUtf8());
if (tz.isValid()) {
dtEnd = dtEnd.toTimeSpec(KDateTime::Spec(tz));
dtEnd = dtEnd.toTimeZone(tz);
} else {
qCWarning(KGAPIDebug) << "Invalid timezone" << timezone;
}
......@@ -460,7 +458,7 @@ ObjectPtr Private::JSONToEvent(const QVariantMap& data, const QString &timezone)
for (const QVariant & r : overrides) {
QVariantMap override = r.toMap();
KCalCore::Alarm::Ptr alarm(new KCalCore::Alarm(static_cast<KCalCore::Incidence*>(event.data())));
alarm->setTime(KCalCore::k2q(event->dtStart()));
alarm->setTime(event->dtStart());
if (override.value(QStringLiteral("method")).toString() == QLatin1String("popup")) {
alarm->setType(KCalCore::Alarm::Display);
......@@ -577,11 +575,11 @@ QByteArray eventToJSON(const EventPtr& event)
if (event->allDay()) {
start.insert(QStringLiteral("date"), event->dtStart().toString(QStringLiteral("%Y-%m-%d")));
} else {
start.insert(QStringLiteral("dateTime"), event->dtStart().toString(KDateTime::RFC3339Date));
start.insert(QStringLiteral("dateTime"), Utils::rfc3339DateToString(event->dtStart()));
}
QString tzStart = event->dtStart().timeZone().name();
QString tzStart = QString::fromUtf8(event->dtStart().timeZone().id());
if (!recurrence.isEmpty() && tzStart.isEmpty()) {
tzStart = KTimeZone::utc().name();
tzStart = QString::fromUtf8(QTimeZone::utc().id());
}
if (!tzStart.isEmpty()) {
start.insert(QStringLiteral("timeZone"), Private::checkAndConverCDOTZID(tzStart, event));
......@@ -593,14 +591,14 @@ QByteArray eventToJSON(const EventPtr& event)
if (event->allDay()) {
/* For Google, all-day events starts on Monday and ends on Tuesday,
* while in KDE, it both starts and ends on Monday. */
KDateTime dtEnd = event->dtEnd().addDays(1);
QDateTime dtEnd = event->dtEnd().addDays(1);
end.insert(QStringLiteral("date"), dtEnd.toString(QStringLiteral("%Y-%m-%d")));
} else {
end.insert(QStringLiteral("dateTime"), event->dtEnd().toString(KDateTime::RFC3339Date));
end.insert(QStringLiteral("dateTime"), Utils::rfc3339DateToString(event->dtEnd()));
}
QString tzEnd = event->dtEnd().timeZone().name();
QString tzEnd = QString::fromUtf8(event->dtEnd().timeZone().id());
if (!recurrence.isEmpty() && tzEnd.isEmpty()) {
tzEnd = KTimeZone::utc().name();
tzEnd = QString::fromUtf8(QTimeZone::utc().id());
}
if (!tzEnd.isEmpty()) {
end.insert(QStringLiteral("timeZone"), Private::checkAndConverCDOTZID(tzEnd, event));
......@@ -735,7 +733,7 @@ KCalCore::DateList Private::parseRDate(const QString& rule)
{
KCalCore::DateList list;
QString value;
KTimeZone tz;
QTimeZone tz;
QString left = rule.left(rule.indexOf(QLatin1Char(':')));
const QStringList params = left.split(QLatin1Char(';'));
......@@ -744,7 +742,7 @@ KCalCore::DateList Private::parseRDate(const QString& rule)
value = param.mid(param.indexOf(QLatin1Char('=')) + 1);
} else if (param.startsWith(QLatin1String("TZID"))) {
QString _name = param.mid(param.indexOf(QLatin1Char('=')) + 1);
tz = KSystemTimeZones::zone(_name);
tz = QTimeZone(_name.toUtf8());
}
}
......@@ -757,16 +755,16 @@ KCalCore::DateList Private::parseRDate(const QString& rule)
dt = QDate::fromString(date, QStringLiteral("yyyyMMdd"));
} else if (value == QLatin1String("PERIOD")) {
QString start = date.left(date.indexOf(QLatin1Char('/')));
KDateTime kdt = KDateTime::fromString(start, KDateTime::RFC3339Date);
QDateTime kdt = Utils::rfc3339DateFromString(start);
if (tz.isValid()) {
kdt.setTimeSpec(tz);
kdt.setTimeZone(tz);
}
dt = kdt.date();
} else {
KDateTime kdt = KDateTime::fromString(date, KDateTime::RFC3339Date);
QDateTime kdt = Utils::rfc3339DateFromString(date);
if (tz.isValid()) {
kdt.setTimeSpec(tz);
kdt.setTimeZone(tz);
}
dt = kdt.date();
......@@ -989,14 +987,10 @@ static const QMap<QString, QString> MSSTTZTable = initMSStandardTimeTZTable();
QString Private::checkAndConverCDOTZID(const QString& tzid, const EventPtr& event)
{
/* Try to match the @tzid to any valid timezone we know. */
KTimeZones timeZones;
const KTimeZones::ZoneMap zones = timeZones.zones();
KTimeZones::ZoneMap::const_iterator iter;
for (iter = zones.constBegin(); iter != zones.constEnd(); ++iter) {
if (iter.key() == tzid) {
/* Yay, @tzid is a valid TZID in Olson format */
return tzid;
}
QTimeZone tz(tzid.toUtf8());
if (tz.isValid()) {
/* Yay, @tzid is a valid TZID in Olson format */
return tzid;
}
/* Damn, no match. Parse the iCal and try to find X-MICROSOFT-CDO-TZID
......
......@@ -23,7 +23,6 @@
#include "utils.h"
#include "account.h"
#include <KDateTime>
#include <QVariantMap>
#include <QNetworkRequest>
#include <QNetworkAccessManager>
......@@ -83,8 +82,8 @@ QDateTime FreeBusyQueryJob::timeMax() const
void FreeBusyQueryJob::start()
{
QVariantMap requestData({
{ QStringLiteral("timeMin"), KDateTime(d->timeMin).toString(KDateTime::RFC3339Date) },
{ QStringLiteral("timeMax"), KDateTime(d->timeMax).toString(KDateTime::RFC3339Date) },
{ QStringLiteral("timeMin"), Utils::rfc3339DateToString(d->timeMin) },
{ QStringLiteral("timeMax"), Utils::rfc3339DateToString(d->timeMax) },
{ QStringLiteral("items"),
QVariantList({
QVariantMap({ { QStringLiteral("id"), d->id } })
......@@ -129,8 +128,8 @@ void FreeBusyQueryJob::handleReply(const QNetworkReply *reply, const QByteArray
for (const QVariant &busyV : busyList) {
const QVariantMap busy = busyV.toMap();
d->busy << BusyRange{
KDateTime::fromString(busy[QStringLiteral("start")].toString(), KDateTime::RFC3339Date).dateTime(),
KDateTime::fromString(busy[QStringLiteral("end")].toString(), KDateTime::RFC3339Date).dateTime()
Utils::rfc3339DateFromString(busy[QStringLiteral("start")].toString()),
Utils::rfc3339DateFromString(busy[QStringLiteral("end")].toString())
};
}
}
......
......@@ -47,6 +47,8 @@ target_link_libraries(KPimGAPITasks
PUBLIC
KPim::GAPICore
KF5::CalendarCore
PRIVATE
Qt5::Network
)
set_target_properties(KPimGAPITasks PROPERTIES
......
......@@ -203,10 +203,10 @@ ObjectPtr Private::JSONToTask(const QVariantMap &jsonData)
task->setStatus(KCalCore::Incidence::StatusNone);
}
task->setDtDue(KDateTime::fromString(jsonData.value(QStringLiteral("due")).toString(), KDateTime::RFC3339Date));
task->setDtDue(Utils::rfc3339DateFromString(jsonData.value(QStringLiteral("due")).toString()));
if (task->status() == KCalCore::Incidence::StatusCompleted) {
task->setCompleted(KDateTime::fromString(jsonData.value(QStringLiteral("completed")).toString(), KDateTime::RFC3339Date));
task->setCompleted(Utils::rfc3339DateFromString(jsonData.value(QStringLiteral("completed")).toString()));
}
task->setDeleted(jsonData.value(QStringLiteral("deleted")).toBool());
......@@ -263,12 +263,12 @@ QByteArray taskToJSON(const TaskPtr &task)
if (task->dtDue().isValid()) {
/* Google accepts only UTC time strictly in this format :( */
output.insert(QStringLiteral("due"), task->dtDue().toUtc().toString(QStringLiteral("%Y-%m-%dT%H:%M:%S.%:sZ")));
output.insert(QStringLiteral("due"), task->dtDue().toUTC().toString(QStringLiteral("yyyy-MM-ddThh:mm:ss.zzzZ")));
}
if ((task->status() == KCalCore::Incidence::StatusCompleted) && task->completed().isValid()) {
/* Google accepts only UTC time strictly in this format :( */
output.insert(QStringLiteral("completed"), task->completed().toUtc().toString(QStringLiteral("%Y-%m-%dT%H:%M:%S.%:sZ")));
output.insert(QStringLiteral("completed"), task->completed().toUTC().toString(QStringLiteral("yyyy-MM-ddThh:mm:ss.zzzZ")));
output.insert(QStringLiteral("status"), QStringLiteral("completed"));
} else {
output.insert(QStringLiteral("status"), QStringLiteral("needsAction"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment