mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-12 12:54:29 +00:00
Details View: display dates as relative Short dates
CCBUG: 340982
This commit is contained in:
parent
9abe299c77
commit
f0d03c7dd7
|
@ -47,10 +47,20 @@ QString KFileItemListWidgetInformant::roleText(const QByteArray& role,
|
||||||
{
|
{
|
||||||
QString text;
|
QString text;
|
||||||
const QVariant roleValue = values.value(role);
|
const QVariant roleValue = values.value(role);
|
||||||
|
QLocale local;
|
||||||
|
KFormat formatter(local);
|
||||||
|
|
||||||
// Implementation note: In case if more roles require a custom handling
|
// Implementation note: In case if more roles require a custom handling
|
||||||
// use a hash + switch for a linear runtime.
|
// use a hash + switch for a linear runtime.
|
||||||
|
|
||||||
|
auto formatDate = [formatter, local](const QDateTime& time) {
|
||||||
|
if (DetailsModeSettings::useShortRelativeDates()) {
|
||||||
|
return formatter.formatRelativeDateTime(time, QLocale::ShortFormat);
|
||||||
|
} else {
|
||||||
|
return local.toString(time, QLocale::ShortFormat);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (role == "size") {
|
if (role == "size") {
|
||||||
if (values.value("isDir").toBool()) {
|
if (values.value("isDir").toBool()) {
|
||||||
if (!roleValue.isNull() && roleValue != -1) {
|
if (!roleValue.isNull() && roleValue != -1) {
|
||||||
|
@ -62,22 +72,25 @@ QString KFileItemListWidgetInformant::roleText(const QByteArray& role,
|
||||||
} else {
|
} else {
|
||||||
// if we have directory size available
|
// if we have directory size available
|
||||||
const KIO::filesize_t size = roleValue.value<KIO::filesize_t>();
|
const KIO::filesize_t size = roleValue.value<KIO::filesize_t>();
|
||||||
text = KFormat().formatByteSize(size);
|
text = formatter.formatByteSize(size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const KIO::filesize_t size = roleValue.value<KIO::filesize_t>();
|
const KIO::filesize_t size = roleValue.value<KIO::filesize_t>();
|
||||||
text = KFormat().formatByteSize(size);
|
text = formatter.formatByteSize(size);
|
||||||
}
|
}
|
||||||
} else if (role == "modificationtime" || role == "creationtime" || role == "accesstime") {
|
} else if (role == "modificationtime" || role == "creationtime" || role == "accesstime") {
|
||||||
bool ok;
|
bool ok;
|
||||||
const long long time = roleValue.toLongLong(&ok);
|
const long long time = roleValue.toLongLong(&ok);
|
||||||
if (ok && time != -1) {
|
if (ok && time != -1) {
|
||||||
return QLocale().toString(QDateTime::fromSecsSinceEpoch(time), QLocale::ShortFormat);
|
const QDateTime dateTime = QDateTime::fromSecsSinceEpoch(time);
|
||||||
|
text = formatDate(dateTime);
|
||||||
}
|
}
|
||||||
} else if (role == "deletiontime" || role == "imageDateTime") {
|
} else if (role == "deletiontime" || role == "imageDateTime") {
|
||||||
const QDateTime dateTime = roleValue.toDateTime();
|
const QDateTime dateTime = roleValue.toDateTime();
|
||||||
text = QLocale().toString(dateTime, QLocale::ShortFormat);
|
if (dateTime.isValid()) {
|
||||||
|
text = formatDate(dateTime);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
text = KStandardItemListWidgetInformant::roleText(role, values);
|
text = KStandardItemListWidgetInformant::roleText(role, values);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,5 +52,9 @@
|
||||||
<label>Recursive directory size limit</label>
|
<label>Recursive directory size limit</label>
|
||||||
<default>10</default>
|
<default>10</default>
|
||||||
</entry>
|
</entry>
|
||||||
|
<entry name="UseShortRelativeDates" type="Bool">
|
||||||
|
<label>if true we use short relative dates, if not short dates</label>
|
||||||
|
<default>true</default>
|
||||||
|
</entry>
|
||||||
</group>
|
</group>
|
||||||
</kcfg>
|
</kcfg>
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "views/zoomlevelinfo.h"
|
#include "views/zoomlevelinfo.h"
|
||||||
|
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
|
#include <KFormat>
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
|
@ -34,7 +35,9 @@ ViewSettingsTab::ViewSettingsTab(Mode mode, QWidget* parent) :
|
||||||
m_widthBox(nullptr),
|
m_widthBox(nullptr),
|
||||||
m_maxLinesBox(nullptr),
|
m_maxLinesBox(nullptr),
|
||||||
m_expandableFolders(nullptr),
|
m_expandableFolders(nullptr),
|
||||||
m_recursiveDirectorySizeLimit(nullptr)
|
m_recursiveDirectorySizeLimit(nullptr),
|
||||||
|
m_useRelatetiveDates(nullptr),
|
||||||
|
m_useShortDates(nullptr)
|
||||||
{
|
{
|
||||||
QFormLayout* topLayout = new QFormLayout(this);
|
QFormLayout* topLayout = new QFormLayout(this);
|
||||||
|
|
||||||
|
@ -121,6 +124,25 @@ ViewSettingsTab::ViewSettingsTab(Mode mode, QWidget* parent) :
|
||||||
topLayout->addRow(i18nc("@title:group", "Folder size displays:"), m_numberOfItems);
|
topLayout->addRow(i18nc("@title:group", "Folder size displays:"), m_numberOfItems);
|
||||||
topLayout->addRow(QString(), contentsSizeLayout);
|
topLayout->addRow(QString(), contentsSizeLayout);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
QDateTime thirtyMinutesAgo = QDateTime::currentDateTime().addSecs(-30 * 60);
|
||||||
|
QLocale local;
|
||||||
|
KFormat formatter(local);
|
||||||
|
|
||||||
|
m_useRelatetiveDates = new QRadioButton(i18nc(
|
||||||
|
"option:radio as in relative date", "Relative (e.g. '%1')", formatter.formatRelativeDateTime(thirtyMinutesAgo, QLocale::ShortFormat))
|
||||||
|
);
|
||||||
|
m_useShortDates = new QRadioButton(
|
||||||
|
i18nc("option:radio as in absolute date", "Absolute (e.g. '%1')", local.toString(thirtyMinutesAgo, QLocale::ShortFormat))
|
||||||
|
);
|
||||||
|
|
||||||
|
QButtonGroup* dateFormatGroup = new QButtonGroup(this);
|
||||||
|
dateFormatGroup->addButton(m_useRelatetiveDates);
|
||||||
|
dateFormatGroup->addButton(m_useShortDates);
|
||||||
|
|
||||||
|
topLayout->addRow(i18nc("@title:group", "Date style:"), m_useRelatetiveDates);
|
||||||
|
topLayout->addRow(QString(), m_useShortDates);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,6 +169,8 @@ ViewSettingsTab::ViewSettingsTab(Mode mode, QWidget* parent) :
|
||||||
m_recursiveDirectorySizeLimit->setEnabled(m_sizeOfContents->isChecked());
|
m_recursiveDirectorySizeLimit->setEnabled(m_sizeOfContents->isChecked());
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
|
connect(m_useRelatetiveDates, &QRadioButton::toggled, this, &ViewSettingsTab::changed);
|
||||||
|
connect(m_useShortDates, &QRadioButton::toggled, this, &ViewSettingsTab::changed);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -176,6 +200,7 @@ void ViewSettingsTab::applySettings()
|
||||||
DetailsModeSettings::setDirectorySizeCount(m_numberOfItems->isChecked());
|
DetailsModeSettings::setDirectorySizeCount(m_numberOfItems->isChecked());
|
||||||
DetailsModeSettings::setRecursiveDirectorySizeLimit(m_recursiveDirectorySizeLimit->value());
|
DetailsModeSettings::setRecursiveDirectorySizeLimit(m_recursiveDirectorySizeLimit->value());
|
||||||
#endif
|
#endif
|
||||||
|
DetailsModeSettings::setUseShortRelativeDates(m_useRelatetiveDates->isChecked());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -234,6 +259,8 @@ void ViewSettingsTab::loadSettings()
|
||||||
}
|
}
|
||||||
m_recursiveDirectorySizeLimit->setValue(DetailsModeSettings::recursiveDirectorySizeLimit());
|
m_recursiveDirectorySizeLimit->setValue(DetailsModeSettings::recursiveDirectorySizeLimit());
|
||||||
#endif
|
#endif
|
||||||
|
m_useRelatetiveDates->setChecked(DetailsModeSettings::useShortRelativeDates());
|
||||||
|
m_useShortDates->setChecked(!DetailsModeSettings::useShortRelativeDates());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -64,6 +64,8 @@ private:
|
||||||
QRadioButton* m_numberOfItems;
|
QRadioButton* m_numberOfItems;
|
||||||
QRadioButton* m_sizeOfContents;
|
QRadioButton* m_sizeOfContents;
|
||||||
QSpinBox* m_recursiveDirectorySizeLimit;
|
QSpinBox* m_recursiveDirectorySizeLimit;
|
||||||
|
QRadioButton* m_useRelatetiveDates;
|
||||||
|
QRadioButton* m_useShortDates;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue