From 625373ffa85f5a60009688ce5e10c46b66d07bc4 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Mon, 14 Aug 2023 22:35:05 +0300 Subject: [PATCH] kdecore: drop KDateTime with the rewrite (see f452e2e50bf76bf83488bf281df1b8851eb650f9), KDateTime is just glue-code for compatibility now. the exception is KDateTime::isNightTime() (written by me) which is used only in one place (kde-workspace/plasma/dataengines/weather/ions/wetter.com/ion_wettercom.cpp) and can be moved there Signed-off-by: Ivailo Monev --- includes/CMakeLists.txt | 1 - includes/KDateTime | 1 - kdecore/CMakeLists.txt | 2 - kdecore/date/kdatetime.cpp | 111 ----------------------------- kdecore/date/kdatetime.h | 76 -------------------- kdecore/io/kdebug.cpp | 8 +-- kdecore/io/kdebug.h | 2 - kfile/kdirsortfilterproxymodel.cpp | 16 ++--- kio/kfile/kpropertiesdialog.cpp | 2 +- kio/kio/fileundomanager.cpp | 7 +- kio/kio/fileundomanager.h | 9 ++- kio/kio/kdirmodel.cpp | 4 +- kio/kio/kfileitem.cpp | 14 ++-- kio/kio/kfileitem.h | 4 +- kio/tests/fileundomanagertest.cpp | 13 ++-- 15 files changed, 31 insertions(+), 239 deletions(-) delete mode 100644 includes/KDateTime delete mode 100644 kdecore/date/kdatetime.cpp delete mode 100644 kdecore/date/kdatetime.h diff --git a/includes/CMakeLists.txt b/includes/CMakeLists.txt index cae30b7a..9266ba3a 100644 --- a/includes/CMakeLists.txt +++ b/includes/CMakeLists.txt @@ -79,7 +79,6 @@ install( KDEDModule KDEPrintDialog KCalendarWidget - KDateTime KDBusMenuExporter KDBusMenuImporter KDesktopFile diff --git a/includes/KDateTime b/includes/KDateTime deleted file mode 100644 index 5959eed3..00000000 --- a/includes/KDateTime +++ /dev/null @@ -1 +0,0 @@ -#include "../kdatetime.h" diff --git a/kdecore/CMakeLists.txt b/kdecore/CMakeLists.txt index 8d374e2f..79b8a5b5 100644 --- a/kdecore/CMakeLists.txt +++ b/kdecore/CMakeLists.txt @@ -49,7 +49,6 @@ set(kdecore_LIB_SRCS config/ksharedconfig.cpp config/kcoreconfigskeleton.cpp config/ksettings.cpp - date/kdatetime.cpp date/ktimezone.cpp date/ksystemtimezone.cpp io/kdebug.cpp @@ -196,7 +195,6 @@ install( config/ksharedconfig.h config/kcoreconfigskeleton.h config/ksettings.h - date/kdatetime.h date/ksystemtimezone.h date/ktimezone.h io/kdebug.h diff --git a/kdecore/date/kdatetime.cpp b/kdecore/date/kdatetime.cpp deleted file mode 100644 index 2e13f9d5..00000000 --- a/kdecore/date/kdatetime.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* - This file is part of the KDE libraries - Copyright (C) 2023 Ivailo Monev - - 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 "kdatetime.h" -#include "ksystemtimezone.h" - -KDateTime::KDateTime() - : QDateTime() -{ -} - -KDateTime::KDateTime(const QDate &date) - : QDateTime(date) -{ -} - -KDateTime::KDateTime(const QDate &date, const QTime &time, Qt::TimeSpec spec) - : QDateTime(date, time, spec) -{ -} - -KDateTime::KDateTime(const QDateTime &other) - : QDateTime(other) -{ -} - -KDateTime::KDateTime(const KDateTime &other) - : QDateTime(other) -{ -} - -KTimeZone KDateTime::timeZone() const -{ - switch (timeSpec()) { - case Qt::LocalTime: { - return KSystemTimeZones::local(); - } - case Qt::UTC: { - return KTimeZone::utc(); - } - case Qt::OffsetFromUTC: { - return KTimeZone(); - } - } - return KTimeZone(); -} - -bool KDateTime::isNightTime() const -{ - const int month = date().month(); - const int hour = time().hour(); - if (month <= 3 || month >= 9) { - return (hour >= 19 || hour <= 6); - } - return (hour >= 20 || hour <= 5); -} - -QDate KDateTime::currentLocalDate() -{ - return QDateTime::currentDateTime().date(); -} - -KDateTime KDateTime::currentLocalDateTime() -{ - return QDateTime::currentDateTime(); -} - -KDateTime KDateTime::currentUtcDateTime() -{ - return QDateTime::currentDateTimeUtc(); -} - -KDateTime KDateTime::currentDateTime(const KTimeZone &zone) -{ - return zone.toZoneTime(QDateTime::currentDateTimeUtc()); -} - -QT_BEGIN_NAMESPACE -QDataStream& operator<<(QDataStream &s, const KDateTime &kdt) -{ - s << kdt.date() << kdt.time() << int(kdt.timeSpec()); - return s; -} - -QDataStream& operator>>(QDataStream &s, KDateTime &kdt) -{ - QDate date; - QTime time; - int spec = int(Qt::UTC); - s >> date >> time >> spec; - kdt = KDateTime(date, time, static_cast(spec)); - return s; -} -QT_END_NAMESPACE diff --git a/kdecore/date/kdatetime.h b/kdecore/date/kdatetime.h deleted file mode 100644 index 3eefd4e1..00000000 --- a/kdecore/date/kdatetime.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - This file is part of the KDE libraries - Copyright (C) 2023 Ivailo Monev - - 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 KDATETIME_H -#define KDATETIME_H - -#include - -#include -#include - -/** - * @short A class representing a date and time with an associated time zone - * - * @see KTimeZone, KSystemTimeZones, QDateTime, QDate, QTime - * @see W3C: Working with Time Zones - * @author Ivailo Monev \. - * @warning KDateTime and KLocale do not output interchangable formats - */ -class KDECORE_EXPORT KDateTime : public QDateTime -{ -public: - KDateTime(); - KDateTime(const QDate &date); - KDateTime(const QDate &date, const QTime &time, Qt::TimeSpec spec = Qt::LocalTime); - KDateTime(const QDateTime &other); - KDateTime(const KDateTime &other); - - /** - * Returns the time zone for the date and time according to the time - * specification type as follows: - * - @c Qt::LocalTime : the local time zone is returned. - * - @c Qt::UTC : the UTC time zone is returned. - * - * @return time zone as defined above, or invalid in all other cases - */ - KTimeZone timeZone() const; - /** - * @return @c true if date represents night time of the day, @c false otherwise - * @since 4.20 - */ - bool isNightTime() const; - - static QDate currentLocalDate(); - static KDateTime currentLocalDateTime(); - static KDateTime currentUtcDateTime(); - static KDateTime currentDateTime(const KTimeZone &zone); -}; - -Q_DECLARE_METATYPE(KDateTime) - -QT_BEGIN_NAMESPACE -/** Write @p kdt to the datastream @p out, in binary format. */ -QDataStream KDECORE_EXPORT& operator<<(QDataStream &out, const KDateTime &kdt); -/** Read a KDateTime object into @p kdt from @p in, in binary format. */ -QDataStream KDECORE_EXPORT& operator>>(QDataStream &in, KDateTime &kdt); -QT_END_NAMESPACE - -#endif // KDATETIME_H diff --git a/kdecore/io/kdebug.cpp b/kdecore/io/kdebug.cpp index ea82e283..0846eec8 100644 --- a/kdecore/io/kdebug.cpp +++ b/kdecore/io/kdebug.cpp @@ -24,12 +24,12 @@ #include "kmessage.h" #include "kstandarddirs.h" #include "kcomponentdata.h" -#include "kdatetime.h" #include "kurl.h" #include #include #include +#include #include #include @@ -634,12 +634,6 @@ QDebug KDebug(const QtMsgType type, const char* const funcinfo, const int area) return QDebug(globalKDebugConfig->areaDevice(type, funcinfo, area)); } -QDebug operator<<(QDebug s, const KDateTime &time) -{ - s.nospace() << "KDateTime(" << time.toString() << ")"; - return s.space(); -} - QDebug operator<<(QDebug s, const KUrl &url) { s.nospace() << "KUrl(" << url.prettyUrl() << ")"; diff --git a/kdecore/io/kdebug.h b/kdecore/io/kdebug.h index 3dc708ab..1814c363 100644 --- a/kdecore/io/kdebug.h +++ b/kdecore/io/kdebug.h @@ -92,9 +92,7 @@ KDECORE_EXPORT QDebug KDebug(const QtMsgType type, const char* const funcinfo, c // operators for KDE types class KUrl; -class KDateTime; KDECORE_EXPORT QDebug operator<<(QDebug s, const KUrl &url); -KDECORE_EXPORT QDebug operator<<(QDebug s, const KDateTime &time); #define kDebug(...) KDebug(QtDebugMsg, Q_FUNC_INFO, ##__VA_ARGS__) #define kWarning(...) KDebug(QtWarningMsg, Q_FUNC_INFO, ##__VA_ARGS__) diff --git a/kfile/kdirsortfilterproxymodel.cpp b/kfile/kdirsortfilterproxymodel.cpp index f4e173e8..c83f72c0 100644 --- a/kfile/kdirsortfilterproxymodel.cpp +++ b/kfile/kdirsortfilterproxymodel.cpp @@ -21,13 +21,11 @@ */ #include "kdirsortfilterproxymodel.h" - -#include -#include -#include -#include -#include -#include +#include "kdirmodel.h" +#include "kfileitem.h" +#include "kglobalsettings.h" +#include "klocale.h" +#include "kstringhandler.h" class KDirSortFilterProxyModel::KDirSortFilterProxyModelPrivate @@ -231,8 +229,8 @@ bool KDirSortFilterProxyModel::subSortLessThan(const QModelIndex& left, } case KDirModel::ModifiedTime: { - KDateTime leftModifiedTime = leftFileItem.time(KFileItem::ModificationTime).toLocalTime(); - KDateTime rightModifiedTime = rightFileItem.time(KFileItem::ModificationTime).toLocalTime(); + QDateTime leftModifiedTime = leftFileItem.time(KFileItem::ModificationTime).toLocalTime(); + QDateTime rightModifiedTime = rightFileItem.time(KFileItem::ModificationTime).toLocalTime(); if (leftModifiedTime == rightModifiedTime) { return d->compare(leftFileItem.text(), rightFileItem.text(), sortCaseSensitivity()) < 0; diff --git a/kio/kfile/kpropertiesdialog.cpp b/kio/kfile/kpropertiesdialog.cpp index 4217b33a..d66c75ef 100644 --- a/kio/kfile/kpropertiesdialog.cpp +++ b/kio/kfile/kpropertiesdialog.cpp @@ -1000,7 +1000,7 @@ KFilePropsPlugin::KFilePropsPlugin(KPropertiesDialog *props) if (!d->bMultiple) { // Dates for multiple don't make much sense... - KDateTime dt = item.time(KFileItem::CreationTime); + QDateTime dt = item.time(KFileItem::CreationTime); if (!dt.isNull()) { l = new QLabel(i18n("Created:"), d->m_frame); grid->addWidget(l, curRow, 0, Qt::AlignRight); diff --git a/kio/kio/fileundomanager.cpp b/kio/kio/fileundomanager.cpp index 51767a37..e262cfd6 100644 --- a/kio/kio/fileundomanager.cpp +++ b/kio/kio/fileundomanager.cpp @@ -23,7 +23,6 @@ #include "clipboardupdater_p.h" #include "fileundomanager_adaptor.h" -#include #include #include #include @@ -441,8 +440,8 @@ void FileUndoManagerPrivate::slotResult(KJob *job) time_t mtime = statJob->statResult().numberValue(KIO::UDSEntry::UDS_MODIFICATION_TIME, -1); if (mtime != op.m_mtime) { kDebug() << op.m_dst << " was modified after being copied!"; - KDateTime srcTime; srcTime.setTime_t(op.m_mtime); srcTime = srcTime.toLocalTime(); - KDateTime destTime; destTime.setTime_t(mtime); destTime = destTime.toLocalTime(); + QDateTime srcTime; srcTime.setTime_t(op.m_mtime); srcTime = srcTime.toLocalTime(); + QDateTime destTime; destTime.setTime_t(mtime); destTime = destTime.toLocalTime(); if (!m_uiInterface->copiedFileWasModified(op.m_src, op.m_dst, srcTime, destTime)) { stopUndo(false); } @@ -768,7 +767,7 @@ void FileUndoManager::UiInterface::jobError(KIO::Job* job) job->ui()->showErrorMessage(); } -bool FileUndoManager::UiInterface::copiedFileWasModified(const KUrl& src, const KUrl& dest, const KDateTime& srcTime, const KDateTime& destTime) +bool FileUndoManager::UiInterface::copiedFileWasModified(const KUrl& src, const KUrl& dest, const QDateTime& srcTime, const QDateTime& destTime) { Q_UNUSED(srcTime); // not sure it should appear in the msgbox // Possible improvement: only show the time if date is today diff --git a/kio/kio/fileundomanager.h b/kio/kio/fileundomanager.h index 09358876..85f8ee8d 100644 --- a/kio/kio/fileundomanager.h +++ b/kio/kio/fileundomanager.h @@ -20,12 +20,11 @@ #ifndef KIO_FILEUNDOMANAGER_H #define KIO_FILEUNDOMANAGER_H -#include -#include - #include -class KDateTime; +#include +#include +#include namespace KIO { @@ -101,7 +100,7 @@ public: * Note that this is called after confirmDeletion. * Return true if we should proceed with deleting dest. */ - virtual bool copiedFileWasModified(const KUrl& src, const KUrl& dest, const KDateTime& srcTime, const KDateTime& destTime); + virtual bool copiedFileWasModified(const KUrl& src, const KUrl& dest, const QDateTime& srcTime, const QDateTime& destTime); private: class UiInterfacePrivate; diff --git a/kio/kio/kdirmodel.cpp b/kio/kio/kdirmodel.cpp index 47cf4183..26f14dfc 100644 --- a/kio/kio/kdirmodel.cpp +++ b/kio/kio/kdirmodel.cpp @@ -20,7 +20,6 @@ #include "kdirmodel.h" #include "kdirlister.h" #include "kfileitem.h" -#include #include #include #include @@ -652,8 +651,7 @@ QVariant KDirModel::data( const QModelIndex & index, int role ) const // Default to "file size in bytes" like in kde3's filedialog return KGlobal::locale()->formatNumber(item.size(), 0); case ModifiedTime: { - KDateTime dt = item.time(KFileItem::ModificationTime); - return KGlobal::locale()->formatDateTime(dt); + return KGlobal::locale()->formatDateTime(item.time(KFileItem::ModificationTime)); } case Permissions: return item.permissionsString(); diff --git a/kio/kio/kfileitem.cpp b/kio/kio/kfileitem.cpp index f986f63b..4049e03f 100644 --- a/kio/kio/kfileitem.cpp +++ b/kio/kio/kfileitem.cpp @@ -141,7 +141,7 @@ public: void init(); QString localPath() const; - KDateTime time(KFileItem::FileTimes which) const; + QDateTime time(KFileItem::FileTimes which) const; void setTime(KFileItem::FileTimes which, long long time_t_val) const; QString user() const; QString group() const; @@ -216,7 +216,7 @@ public: // For special case like link to dirs over FTP QString m_guessedMimeType; - mutable KDateTime m_time[3]; + mutable QDateTime m_time[3]; }; void KFileItemPrivate::init() @@ -269,7 +269,7 @@ void KFileItemPrivate::setTime(KFileItem::FileTimes mappedWhich, long long time_ m_time[mappedWhich] = m_time[mappedWhich].toLocalTime(); // #160979 } -KDateTime KFileItemPrivate::time(KFileItem::FileTimes mappedWhich) const +QDateTime KFileItemPrivate::time(KFileItem::FileTimes mappedWhich) const { if (!m_time[mappedWhich].isNull()) { return m_time[mappedWhich]; @@ -302,11 +302,11 @@ KDateTime KFileItemPrivate::time(KFileItem::FileTimes mappedWhich) const if (KDE::stat(m_url.toLocalFile(KUrl::RemoveTrailingSlash), &buf) == 0) { setTime(KFileItem::ModificationTime, buf.st_mtime); setTime(KFileItem::AccessTime, buf.st_atime); - m_time[KFileItem::CreationTime] = KDateTime(); + m_time[KFileItem::CreationTime] = QDateTime(); return m_time[mappedWhich]; } } - return KDateTime(); + return QDateTime(); } /////// @@ -501,10 +501,10 @@ KACL KFileItem::defaultACL() const return KACL(); } -KDateTime KFileItem::time(FileTimes which) const +QDateTime KFileItem::time(FileTimes which) const { if (!d) { - return KDateTime(); + return QDateTime(); } return d->time(which); } diff --git a/kio/kio/kfileitem.h b/kio/kio/kfileitem.h index b5b37b58..637c9cf8 100644 --- a/kio/kio/kfileitem.h +++ b/kio/kio/kfileitem.h @@ -22,12 +22,12 @@ #include +#include #include #include #include #include #include -#include class KFileItemPrivate; @@ -293,7 +293,7 @@ public: * @return the time asked for, (time_t)0 if not available * @see timeString() */ - KDateTime time(FileTimes which) const; + QDateTime time(FileTimes which) const; /** * Requests the modification, access or creation time as a string, depending diff --git a/kio/tests/fileundomanagertest.cpp b/kio/tests/fileundomanagertest.cpp index 41e19659..fc2374aa 100644 --- a/kio/tests/fileundomanagertest.cpp +++ b/kio/tests/fileundomanagertest.cpp @@ -20,16 +20,17 @@ #include #include "fileundomanagertest.h" -#include +#include +#include +#include +#include #include #include #include #include #include #include -#include - #include #include #include @@ -40,10 +41,6 @@ #include #include -#include -#include -#include - #include "moc_fileundomanagertest.cpp" QTEST_KDEMAIN( FileUndoManagerTest, GUI ) @@ -129,7 +126,7 @@ public: virtual void jobError( KIO::Job* job ) { kFatal() << job->errorString() ; } - virtual bool copiedFileWasModified( const KUrl& src, const KUrl& dest, const KDateTime& srcTime, const KDateTime& destTime ) { + virtual bool copiedFileWasModified( const KUrl& src, const KUrl& dest, const QDateTime& srcTime, const QDateTime& destTime ) { Q_UNUSED( src ); m_dest = dest; Q_UNUSED( srcTime );