Commit ce6d8e28 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Make it compile against qt6

parent 77d46c1b
......@@ -47,6 +47,9 @@ find_package(KF5IdentityManagement ${IDENTITYMANAGER_LIB_VERSION} CONFIG REQUIRE
find_package(KF5CalendarUtils ${CALENDARUTILS_LIB_VERSION} CONFIG REQUIRED)
ecm_set_disabled_deprecation_versions(QT 5.15.2 KF 5.91.0)
if (QT_MAJOR_VERSION STREQUAL "6")
find_package(Qt6Core5Compat)
endif()
option(USE_UNITY_CMAKE_SUPPORT "Use UNITY cmake support (speedup compile time)" OFF)
......
......@@ -19,6 +19,7 @@
#include <KLocalizedString>
#include <QLocale>
#include <QIODevice>
#include <qplugin.h>
using namespace Akonadi;
......
......@@ -59,6 +59,10 @@ PUBLIC
PRIVATE
)
if (QT_MAJOR_VERSION STREQUAL "6")
target_link_libraries(KF5AlarmCalendar PRIVATE Qt6::Core5Compat)
endif()
set_target_properties(KF5AlarmCalendar PROPERTIES
VERSION ${KALARMCAL_VERSION}
SOVERSION ${KALARMCAL_SOVERSION}
......
......@@ -16,6 +16,7 @@
#include <QStringList>
#include <QDateTime>
#include <QLocale>
#include <QRegExp>
namespace
{
......
......@@ -34,9 +34,9 @@ const QLatin1String MIME_ARCHIVED("application/x-vnd.kde.alarm.archived");
const QLatin1String MIME_TEMPLATE("application/x-vnd.kde.alarm.template");
static const QByteArray VERSION_PROPERTY("VERSION"); // X-KDE-KALARM-VERSION VCALENDAR property
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
static bool isUTC(const QString &localFile);
#endif
class Private
{
public:
......@@ -89,6 +89,7 @@ int updateVersion(const FileStorage::Ptr &fileStorage, QString &versionString)
return IncompatibleFormat; // calendar was created by another program, or an unknown version of KAlarm
}
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
// Calendar was created by an earlier version of KAlarm.
// Convert it to the current format.
const QString localFile = fileStorage->fileName();
......@@ -103,9 +104,9 @@ int updateVersion(const FileStorage::Ptr &fileStorage, QString &versionString)
} else {
qCDebug(KALARMCAL_LOG) << "KAlarm version" << version;
}
// Convert events to current KAlarm format for when/if the calendar is saved.
KAEvent::convertKCalEvents(fileStorage->calendar(), ver);
#endif
// Set the new calendar version.
setKAlarmVersion(fileStorage->calendar());
return version;
......@@ -174,7 +175,8 @@ int Private::readKAlarmVersion(const FileStorage::Ptr &fileStorage, QString &sub
}
return KAlarmCal::getVersionNumber(versionString, &subVersion);
}
// This code is for kde 3.0.0 (we will release in the future kf6
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
/******************************************************************************
* Check whether the calendar file has its times stored as UTC times,
* indicating that it was written by the KDE 3.0.0 version of KAlarm 0.5.7.
......@@ -214,7 +216,7 @@ bool isUTC(const QString &localFile)
}
return false;
}
#endif
//=============================================================================
namespace CalEvent
......
......@@ -2265,8 +2265,13 @@ KADateTime KADateTime::fromString(const QString &string, TimeFormat format, bool
//month = d.month();
} else {
// A month and day are specified
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
month = parts[3].leftRef(2).toInt(&ok);
day = parts[3].rightRef(2).toInt(&ok1);
#else
month = QStringView(parts[3]).left(2).toInt(&ok);
day = QStringView(parts[3]).right(2).toInt(&ok1);
#endif
if (!ok || !ok1) {
break;
}
......@@ -2859,10 +2864,17 @@ QDateTime fromStr(const QString &string, const QString &format, int &utcOffset,
case 's': { // milliseconds, with decimal point prefix
if (str[s] != QLatin1Char('.')) {
// If no locale, try comma, it is preferred by ISO8601 as the decimal point symbol
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const QChar dpt = QLocale().decimalPoint();
if (!str.midRef(s).startsWith(dpt)) {
return {};
}
#else
const QString dpt = QLocale().decimalPoint();
if (!QStringView(str).mid(s).startsWith(dpt)) {
return {};
}
#endif
}
++s;
if (s >= send) {
......@@ -3213,7 +3225,11 @@ bool getNumber(const QString &string, int &offset, int mindigits, int maxdigits,
return false;
}
bool ok;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
int n = string.midRef(offset, ndigits).toInt(&ok);
#else
int n = QStringView(string).mid(offset, ndigits).toInt(&ok);
#endif
if (neg) {
n = -n;
}
......
......@@ -656,7 +656,11 @@ KAEventPrivate::KAEventPrivate(const KCalendarCore::Event::Ptr &event)
flag = flags.at(++i);
}
const int len = flag.length() - 1;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
mReminderMinutes = -flag.leftRef(len).toInt(); // -> 0 if conversion fails
#else
mReminderMinutes = -QStringView(flag).left(len).toInt(); // -> 0 if conversion fails
#endif
switch (flag.at(len).toLatin1()) {
case 'M': break;
case 'H': mReminderMinutes *= 60; break;
......@@ -4015,16 +4019,28 @@ DateTime KAEventPrivate::readDateTime(const Event::Ptr &event, bool localZone, b
const QString prop = event->customProperty(KACalendar::APPNAME, KAEventPrivate::NEXT_RECUR_PROPERTY);
if (prop.length() >= SZ_DATE) {
// The next due recurrence time is specified
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const QDate d(prop.leftRef(SZ_YEAR).toInt(),
prop.midRef(SZ_YEAR, SZ_MONTH).toInt(),
prop.midRef(SZ_YEAR + SZ_MONTH, SZ_DAY).toInt());
#else
const QDate d(QStringView(prop).left(SZ_YEAR).toInt(),
QStringView(prop).mid(SZ_YEAR, SZ_MONTH).toInt(),
QStringView(prop).mid(SZ_YEAR + SZ_MONTH, SZ_DAY).toInt());
#endif
if (d.isValid()) {
if (dateOnly && prop.length() == SZ_DATE) {
next.setDate(d);
} else if (!dateOnly && prop.length() == IX_TIME + SZ_TIME && prop[SZ_DATE] == QLatin1Char('T')) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const QTime t(prop.midRef(IX_TIME, SZ_HOUR).toInt(),
prop.midRef(IX_TIME + SZ_HOUR, SZ_MIN).toInt(),
prop.midRef(IX_TIME + SZ_HOUR + SZ_MIN, SZ_SEC).toInt());
#else
const QTime t(QStringView(prop).mid(IX_TIME, SZ_HOUR).toInt(),
QStringView(prop).mid(IX_TIME + SZ_HOUR, SZ_MIN).toInt(),
QStringView(prop).mid(IX_TIME + SZ_HOUR + SZ_MIN, SZ_SEC).toInt());
#endif
if (t.isValid()) {
next.setDate(d);
next.setTime(t);
......
......@@ -58,7 +58,11 @@ int getVersionNumber(const QString &version, QString *subVersion)
if (subVersion) {
*subVersion = issue.mid(i);
}
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
v = issue.leftRef(i).toUInt(); // issue number
#else
v = QStringView(issue).left(i).toUInt(); // issue number
#endif
vernum += (v < 99 ? v : 99);
}
return vernum;
......
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