Use friendly date format
This commit is contained in:
parent
c7d09c918f
commit
8879e12625
7 changed files with 58 additions and 2 deletions
|
@ -34,6 +34,7 @@ add_executable(cutefish-filemanager
|
||||||
desktop/desktopview.cpp
|
desktop/desktopview.cpp
|
||||||
desktop/desktopsettings.cpp
|
desktop/desktopsettings.cpp
|
||||||
|
|
||||||
|
helper/datehelper.cpp
|
||||||
helper/thumbnailer.cpp
|
helper/thumbnailer.cpp
|
||||||
helper/pathhistory.cpp
|
helper/pathhistory.cpp
|
||||||
|
|
||||||
|
|
34
helper/datehelper.cpp
Normal file
34
helper/datehelper.cpp
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#include "datehelper.h"
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
16
helper/datehelper.h
Normal file
16
helper/datehelper.h
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#ifndef DATEHELPER_H
|
||||||
|
#define DATEHELPER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class DateHelper : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit DateHelper(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
Q_INVOKABLE static QString friendlyTime(const QDateTime &time);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DATEHELPER_H
|
1
main.cpp
1
main.cpp
|
@ -34,6 +34,7 @@
|
||||||
#include "desktop/desktopsettings.h"
|
#include "desktop/desktopsettings.h"
|
||||||
#include "desktop/desktopview.h"
|
#include "desktop/desktopview.h"
|
||||||
#include "helper/thumbnailer.h"
|
#include "helper/thumbnailer.h"
|
||||||
|
#include "helper/datehelper.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
#include "../dialogs/propertiesdialog.h"
|
#include "../dialogs/propertiesdialog.h"
|
||||||
#include "../dialogs/createfolderdialog.h"
|
#include "../dialogs/createfolderdialog.h"
|
||||||
|
|
||||||
|
#include "../helper/datehelper.h"
|
||||||
|
|
||||||
// Qt
|
// Qt
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
@ -184,7 +186,7 @@ QVariant FolderModel::data(const QModelIndex &index, int role) const
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
case ModifiedRole: {
|
case ModifiedRole: {
|
||||||
return item.timeString(KFileItem::ModificationTime);
|
return DateHelper::friendlyTime(item.time(KFileItem::ModificationTime));
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -585,9 +585,9 @@ GridView {
|
||||||
visible: false
|
visible: false
|
||||||
wrapMode: TextEdit.Wrap
|
wrapMode: TextEdit.Wrap
|
||||||
horizontalAlignment: TextEdit.AlignHCenter
|
horizontalAlignment: TextEdit.AlignHCenter
|
||||||
z: 999
|
|
||||||
topPadding: FishUI.Units.smallSpacing
|
topPadding: FishUI.Units.smallSpacing
|
||||||
bottomPadding: FishUI.Units.smallSpacing
|
bottomPadding: FishUI.Units.smallSpacing
|
||||||
|
z: 999
|
||||||
|
|
||||||
property Item targetItem: null
|
property Item targetItem: null
|
||||||
|
|
||||||
|
@ -597,6 +597,7 @@ GridView {
|
||||||
width = targetItem.width - FishUI.Units.smallSpacing
|
width = targetItem.width - FishUI.Units.smallSpacing
|
||||||
height = targetItem.labelArea.paintedHeight + FishUI.Units.largeSpacing * 2
|
height = targetItem.labelArea.paintedHeight + FishUI.Units.largeSpacing * 2
|
||||||
x = targetItem.x + Math.abs(Math.min(control.contentX, control.originX))
|
x = targetItem.x + Math.abs(Math.min(control.contentX, control.originX))
|
||||||
|
x = targetItem.x + (targetItem.width - _editor.width)
|
||||||
y = pos.y - FishUI.Units.largeSpacing
|
y = pos.y - FishUI.Units.largeSpacing
|
||||||
text = targetItem.labelArea.text
|
text = targetItem.labelArea.text
|
||||||
targetItem.labelArea.visible = false
|
targetItem.labelArea.visible = false
|
||||||
|
|
|
@ -3,6 +3,7 @@ import QtQuick.Controls 2.12
|
||||||
import QtQuick.Layouts 1.12
|
import QtQuick.Layouts 1.12
|
||||||
import QtGraphicalEffects 1.0
|
import QtGraphicalEffects 1.0
|
||||||
import FishUI 1.0 as FishUI
|
import FishUI 1.0 as FishUI
|
||||||
|
import Cutefish.FileManager 1.0
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: _listItem
|
id: _listItem
|
||||||
|
|
Loading…
Reference in a new issue