mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-14 02:14:21 +01:00
Format the last played column more nicely
This commit is contained in:
parent
ac90d74a28
commit
f55ffe15d6
@ -17,6 +17,7 @@
|
||||
#include "utilities.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDateTime>
|
||||
#include <QDir>
|
||||
#include <QIODevice>
|
||||
#include <QStringList>
|
||||
@ -67,6 +68,22 @@ QString WordyTime(quint64 seconds) {
|
||||
return parts.join(" ");
|
||||
}
|
||||
|
||||
QString Ago(int seconds_since_epoch, const QLocale& locale) {
|
||||
const QDateTime now = QDateTime::currentDateTime();
|
||||
const QDateTime then = QDateTime::fromTime_t(seconds_since_epoch);
|
||||
const int days_ago = then.date().daysTo(now.date());
|
||||
const QString time = then.time().toString(locale.timeFormat(QLocale::ShortFormat));
|
||||
|
||||
if (days_ago == 0)
|
||||
return tr("Today") + " " + time;
|
||||
if (days_ago == 1)
|
||||
return tr("Yesterday") + " " + time;
|
||||
if (days_ago <= 7)
|
||||
return tr("%1 days ago").arg(days_ago);
|
||||
|
||||
return then.date().toString(locale.dateTimeFormat());
|
||||
}
|
||||
|
||||
QString PrettySize(quint64 bytes) {
|
||||
QString ret;
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
#ifndef UTILITIES_H
|
||||
#define UTILITIES_H
|
||||
|
||||
#include <QLocale>
|
||||
#include <QString>
|
||||
|
||||
#include <boost/scoped_array.hpp>
|
||||
@ -27,6 +28,7 @@ namespace Utilities {
|
||||
QString PrettyTime(int seconds);
|
||||
QString PrettySize(quint64 bytes);
|
||||
QString WordyTime(quint64 seconds);
|
||||
QString Ago(int seconds_since_epoch, const QLocale& locale);
|
||||
|
||||
quint64 FileSystemCapacity(const QString& path);
|
||||
quint64 FileSystemFreeSpace(const QString& path);
|
||||
|
@ -263,6 +263,16 @@ QString DateItemDelegate::displayText(const QVariant &value, const QLocale &loca
|
||||
QLocale::system().dateTimeFormat(QLocale::ShortFormat));
|
||||
}
|
||||
|
||||
QString LastPlayedItemDelegate::displayText(const QVariant& value, const QLocale& locale) const {
|
||||
bool ok = false;
|
||||
const int time = value.toInt(&ok);
|
||||
|
||||
if (!ok || time == -1)
|
||||
return tr("Never");
|
||||
|
||||
return Utilities::Ago(time, locale);
|
||||
}
|
||||
|
||||
QString FileTypeItemDelegate::displayText(const QVariant &value, const QLocale &locale) const {
|
||||
bool ok = false;
|
||||
Song::FileType type = Song::FileType(value.toInt(&ok));
|
||||
@ -336,6 +346,9 @@ QSize RatingItemDelegate::sizeHint(
|
||||
|
||||
QString RatingItemDelegate::displayText(
|
||||
const QVariant& value, const QLocale&) const {
|
||||
if (value.isNull() || value.toDouble() <= 0)
|
||||
return QString();
|
||||
|
||||
// Round to the nearest .5
|
||||
const float rating = float(int(value.toDouble() * kStarCount * 2 + 0.5)) / 2;
|
||||
return QString::number(rating, 'f', 1);
|
||||
|
@ -85,6 +85,12 @@ class DateItemDelegate : public PlaylistDelegateBase {
|
||||
QString displayText(const QVariant& value, const QLocale& locale) const;
|
||||
};
|
||||
|
||||
class LastPlayedItemDelegate : public PlaylistDelegateBase {
|
||||
public:
|
||||
LastPlayedItemDelegate(QObject* parent) : PlaylistDelegateBase(parent) {}
|
||||
QString displayText(const QVariant& value, const QLocale& locale) const;
|
||||
};
|
||||
|
||||
class FileTypeItemDelegate : public PlaylistDelegateBase {
|
||||
public:
|
||||
FileTypeItemDelegate(QObject* parent) : PlaylistDelegateBase(parent) {}
|
||||
|
@ -125,7 +125,7 @@ void PlaylistView::SetItemDelegates(LibraryBackend* backend) {
|
||||
setItemDelegateForColumn(Playlist::Column_Bitrate, new PlaylistDelegateBase(this, tr("kbps")));
|
||||
setItemDelegateForColumn(Playlist::Column_Filename, new NativeSeparatorsDelegate(this));
|
||||
setItemDelegateForColumn(Playlist::Column_Rating, new RatingItemDelegate(this));
|
||||
setItemDelegateForColumn(Playlist::Column_LastPlayed, new DateItemDelegate(this));
|
||||
setItemDelegateForColumn(Playlist::Column_LastPlayed, new LastPlayedItemDelegate(this));
|
||||
}
|
||||
|
||||
void PlaylistView::SetPlaylist(Playlist *playlist) {
|
||||
|
Loading…
Reference in New Issue
Block a user