diff --git a/3rdparty/kdepim/libkdepim/CMakeLists.txt b/3rdparty/kdepim/libkdepim/CMakeLists.txt --- a/3rdparty/kdepim/libkdepim/CMakeLists.txt +++ b/3rdparty/kdepim/libkdepim/CMakeLists.txt @@ -54,7 +54,6 @@ KF5::I18n KF5::ItemViews KF5::JobWidgets - KF5::KDELibs4Support KF5::KIOCore KF5::Ldap KF5::Wallet diff --git a/3rdparty/kdepim/libkdepim/kdateedit.cpp b/3rdparty/kdepim/libkdepim/kdateedit.cpp --- a/3rdparty/kdepim/libkdepim/kdateedit.cpp +++ b/3rdparty/kdepim/libkdepim/kdateedit.cpp @@ -26,22 +26,49 @@ #include "kdateedit.h" -#include -#include -#include -#include - #include #include #include +#include #include #include #include +#include #include #include +#include + using namespace KPIM; +class DateFormat +{ +public: + DateFormat() + { + // Check if we can use the QLocale::ShortFormat + if (!QLocale().toString(QDate(2015, 1, 1), QLocale::ShortFormat).contains(QStringLiteral("2015"))) { + mFallbackFormat = QStringLiteral("dd/MM/yyyy"); + } + } + + QDate toDate( const QString &string ) + { + return mFallbackFormat.isEmpty() ? QLocale().toDate( string, QLocale::ShortFormat ) + : QLocale().toDate( string, mFallbackFormat ); + } + + QString toString( const QDate &date ) + { + return mFallbackFormat.isEmpty() ? QLocale().toString( date, QLocale::ShortFormat ) + : QLocale().toString( date, mFallbackFormat ); + } + +private: + QString mFallbackFormat; +}; +Q_GLOBAL_STATIC(DateFormat, sDateFormat); + class DateValidator : public QValidator { public: @@ -62,9 +89,8 @@ return Acceptable; } - bool ok = false; - KGlobal::locale()->readDate( str, &ok ); - if ( ok ) { + QDate result = sDateFormat->toDate( str ); + if ( result.isValid() ) { return Acceptable; } else { return Intermediate; @@ -83,7 +109,7 @@ setEditable( true ); mDate = QDate::currentDate(); - QString today = KGlobal::locale()->formatDate( mDate, KLocale::ShortDate ); + QString today = sDateFormat->toString( mDate ); addItem( today ); setCurrentIndex( 0 ); @@ -142,7 +168,7 @@ return; } - QRect desk = KGlobalSettings::desktopGeometry( this ); + QRect desk = QApplication::desktop()->screenGeometry( this ); QPoint popupPoint = mapToGlobal( QPoint( 0, 0 ) ); @@ -262,7 +288,7 @@ (*replaced) = true; } } else { - result = KGlobal::locale()->readDate( text ); + result = sDateFormat->toDate( text ); } return result; @@ -424,7 +450,7 @@ QString dayName; for ( int i = 1; i <= 7; ++i ) { - dayName = KGlobal::locale()->calendar()->weekDayName( i ).toLower(); + dayName = QDate::longDayName( i ).toLower(); mKeywordMap.insert( dayName, i + 100 ); } @@ -445,7 +471,7 @@ { QString dateString; if ( mDate.isValid() ) { - dateString = KGlobal::locale()->formatDate( mDate, KLocale::ShortDate ); + dateString = sDateFormat->toString( mDate ); } // We do not want to generate a signal here, diff --git a/tests/units/widgets/editorviewtest.cpp b/tests/units/widgets/editorviewtest.cpp --- a/tests/units/widgets/editorviewtest.cpp +++ b/tests/units/widgets/editorviewtest.cpp @@ -34,8 +34,6 @@ #include "addressline/addresseelineedit.h" #include "kdateedit.h" -#include -#include class EditorModelStub : public QObject { @@ -544,7 +542,7 @@ auto today = QDate::currentDate(); // WHEN - startDateEdit->setEditText(today.toString(Qt::ISODate)); // ### ISO? really? this only works because KLocale::readDate is clever, but it's not what the user would type + startDateEdit->setEditText(today.toString("dd/MM/yyyy")); QTest::keyClick(startDateEdit, Qt::Key_Enter); // THEN @@ -585,7 +583,7 @@ // WHEN QVERIFY(dueDateEdit->isEnabled()); - dueDateEdit->setEditText(today.toString(Qt::ISODate)); + dueDateEdit->setEditText(today.toString("dd/MM/yyyy")); QTest::keyClick(dueDateEdit, Qt::Key_Enter); // THEN @@ -610,7 +608,7 @@ startTodayButton->click(); // THEN - QCOMPARE(startDateEdit->currentText(), KLocale::global()->formatDate(today, KLocale::ShortDate)); + QCOMPARE(startDateEdit->currentText(), today.toString("dd/MM/yyyy")); QCOMPARE(model.property("startDate").toDateTime().date(), today); }