kdecore: drop KDateTime

with the rewrite (see f452e2e50b),
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 <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-08-14 22:35:05 +03:00
parent 3fc6433561
commit 625373ffa8
15 changed files with 31 additions and 239 deletions

View file

@ -79,7 +79,6 @@ install(
KDEDModule
KDEPrintDialog
KCalendarWidget
KDateTime
KDBusMenuExporter
KDBusMenuImporter
KDesktopFile

View file

@ -1 +0,0 @@
#include "../kdatetime.h"

View file

@ -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

View file

@ -1,111 +0,0 @@
/*
This file is part of the KDE libraries
Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
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<Qt::TimeSpec>(spec));
return s;
}
QT_END_NAMESPACE

View file

@ -1,76 +0,0 @@
/*
This file is part of the KDE libraries
Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
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 <ktimezone.h>
#include <QMetaType>
#include <QDataStream>
/**
* @short A class representing a date and time with an associated time zone
*
* @see KTimeZone, KSystemTimeZones, QDateTime, QDate, QTime
* @see <a href="http://www.w3.org/TR/timezone/">W3C: Working with Time Zones</a>
* @author Ivailo Monev \<xakepa10@gmail.com\>.
* @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

View file

@ -24,12 +24,12 @@
#include "kmessage.h"
#include "kstandarddirs.h"
#include "kcomponentdata.h"
#include "kdatetime.h"
#include "kurl.h"
#include <QCoreApplication>
#include <QFile>
#include <QMutex>
#include <QDateTime>
#include <unistd.h>
#include <stdio.h>
@ -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() << ")";

View file

@ -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__)

View file

@ -21,13 +21,11 @@
*/
#include "kdirsortfilterproxymodel.h"
#include <kdatetime.h>
#include <kdirmodel.h>
#include <kfileitem.h>
#include <kglobalsettings.h>
#include <klocale.h>
#include <kstringhandler.h>
#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;

View file

@ -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);

View file

@ -23,7 +23,6 @@
#include "clipboardupdater_p.h"
#include "fileundomanager_adaptor.h"
#include <kdatetime.h>
#include <kdebug.h>
#include <kdirnotify.h>
#include <kglobal.h>
@ -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

View file

@ -20,12 +20,11 @@
#ifndef KIO_FILEUNDOMANAGER_H
#define KIO_FILEUNDOMANAGER_H
#include <QtCore/QObject>
#include <kurl.h>
#include <kio/kio_export.h>
class KDateTime;
#include <QObject>
#include <QDateTime>
#include <kurl.h>
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;

View file

@ -20,7 +20,6 @@
#include "kdirmodel.h"
#include "kdirlister.h"
#include "kfileitem.h"
#include <kdatetime.h>
#include <kicon.h>
#include <klocale.h>
#include <kglobal.h>
@ -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();

View file

@ -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);
}

View file

@ -22,12 +22,12 @@
#include <sys/stat.h>
#include <QDateTime>
#include <kio/global.h>
#include <kio/udsentry.h>
#include <kurl.h>
#include <kacl.h>
#include <kmimetype.h>
#include <kdatetime.h>
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

View file

@ -20,16 +20,17 @@
#include <qtest_kde.h>
#include "fileundomanagertest.h"
#include <kio/fileundomanager.h>
#include <QClipboard>
#include <QApplication>
#include <QMimeData>
#include <kio/fileundomanager.h>
#include <kio/copyjob.h>
#include <kio/job.h>
#include <kio/deletejob.h>
#include <kio/netaccess.h>
#include <kio/paste.h>
#include <kprotocolinfo.h>
#include <kdatetime.h>
#include <kde_file.h>
#include <kdebug.h>
#include <kconfig.h>
@ -40,10 +41,6 @@
#include <time.h>
#include <sys/time.h>
#include <QClipboard>
#include <QApplication>
#include <QMimeData>
#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 );