diff --git a/CMakeLists.txt b/CMakeLists.txt index 447c413..49235ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,7 @@ add_executable(cutefish-filemanager desktop/desktopview.cpp desktop/desktopsettings.cpp + helper/datehelper.cpp helper/thumbnailer.cpp helper/pathhistory.cpp diff --git a/helper/datehelper.cpp b/helper/datehelper.cpp new file mode 100644 index 0000000..396fd01 --- /dev/null +++ b/helper/datehelper.cpp @@ -0,0 +1,34 @@ +#include "datehelper.h" +#include + +DateHelper::DateHelper(QObject *parent) : QObject(parent) +{ + +} + +QString DateHelper::friendlyTime(const QDateTime &time) +{ + QDateTime now = QDateTime::currentDateTime(); + qint64 minutes = qRound64(time.secsTo(now) / 60.0f); + + if (minutes < 1) + return tr("Now"); + else if (minutes == 1) + return tr("1 minute ago"); + else if (minutes < 60) + return tr("%1 minutes ago").arg(minutes); + + qint64 hours = qRound64(minutes / 60.0f); + if (hours == 1) + return tr("1 hour ago"); + else if (hours < 24) + return tr("%1 hours ago").arg(hours); + + qint64 days = qRound64(hours / 24.0f); + if (days == 1) + return tr("1 day ago"); + else if (days <= 10) + return tr("%1 days ago").arg(days); + + return time.toString(Qt::DefaultLocaleShortDate); +} diff --git a/helper/datehelper.h b/helper/datehelper.h new file mode 100644 index 0000000..adf5db2 --- /dev/null +++ b/helper/datehelper.h @@ -0,0 +1,16 @@ +#ifndef DATEHELPER_H +#define DATEHELPER_H + +#include + +class DateHelper : public QObject +{ + Q_OBJECT + +public: + explicit DateHelper(QObject *parent = nullptr); + + Q_INVOKABLE static QString friendlyTime(const QDateTime &time); +}; + +#endif // DATEHELPER_H diff --git a/main.cpp b/main.cpp index 5730a56..c9a8d76 100644 --- a/main.cpp +++ b/main.cpp @@ -34,6 +34,7 @@ #include "desktop/desktopsettings.h" #include "desktop/desktopview.h" #include "helper/thumbnailer.h" +#include "helper/datehelper.h" int main(int argc, char *argv[]) { diff --git a/model/foldermodel.cpp b/model/foldermodel.cpp index 5a30284..9fca36c 100644 --- a/model/foldermodel.cpp +++ b/model/foldermodel.cpp @@ -28,6 +28,8 @@ #include "../dialogs/propertiesdialog.h" #include "../dialogs/createfolderdialog.h" +#include "../helper/datehelper.h" + // Qt #include #include @@ -184,7 +186,7 @@ QVariant FolderModel::data(const QModelIndex &index, int role) const return QVariant(); } case ModifiedRole: { - return item.timeString(KFileItem::ModificationTime); + return DateHelper::friendlyTime(item.time(KFileItem::ModificationTime)); } default: break; diff --git a/qml/FolderGridView.qml b/qml/FolderGridView.qml index 4ccc368..fd1b015 100644 --- a/qml/FolderGridView.qml +++ b/qml/FolderGridView.qml @@ -585,9 +585,9 @@ GridView { visible: false wrapMode: TextEdit.Wrap horizontalAlignment: TextEdit.AlignHCenter - z: 999 topPadding: FishUI.Units.smallSpacing bottomPadding: FishUI.Units.smallSpacing + z: 999 property Item targetItem: null @@ -597,6 +597,7 @@ GridView { width = targetItem.width - FishUI.Units.smallSpacing height = targetItem.labelArea.paintedHeight + FishUI.Units.largeSpacing * 2 x = targetItem.x + Math.abs(Math.min(control.contentX, control.originX)) + x = targetItem.x + (targetItem.width - _editor.width) y = pos.y - FishUI.Units.largeSpacing text = targetItem.labelArea.text targetItem.labelArea.visible = false diff --git a/qml/FolderListItem.qml b/qml/FolderListItem.qml index a5de58f..abd6e7d 100644 --- a/qml/FolderListItem.qml +++ b/qml/FolderListItem.qml @@ -3,6 +3,7 @@ import QtQuick.Controls 2.12 import QtQuick.Layouts 1.12 import QtGraphicalEffects 1.0 import FishUI 1.0 as FishUI +import Cutefish.FileManager 1.0 Item { id: _listItem