mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-26 15:06:08 +03:00
AcitivityWidget: Moved timespan-in-words method to utility.
Also added a second parameter, fixed plural translation and added a less-than-a-minute-ago term.
This commit is contained in:
parent
c781155b60
commit
e38bc6eab8
4 changed files with 42 additions and 22 deletions
|
@ -96,7 +96,7 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const
|
|||
return a._accName;
|
||||
break;
|
||||
case ActivityItemDelegate::PointInTimeRole:
|
||||
return timeSpanFromNow(a._dateTime);
|
||||
return Utility::timeAgoInWords(a._dateTime);
|
||||
break;
|
||||
case ActivityItemDelegate::AccountConnectedRole:
|
||||
return (ast && ast->isConnected());
|
||||
|
@ -109,26 +109,6 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const
|
|||
|
||||
}
|
||||
|
||||
QString ActivityListModel::timeSpanFromNow(const QDateTime& dt) const
|
||||
{
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
|
||||
if( dt.daysTo(now)>0 ) {
|
||||
return tr("%1 day(s) ago").arg(dt.daysTo(now));
|
||||
} else {
|
||||
qint64 secs = dt.secsTo(now);
|
||||
|
||||
if( floor(secs / 3600.0) > 0 ) {
|
||||
int hours = floor(secs/3600.0);
|
||||
return( tr("%1 hour(s) ago").arg(hours));
|
||||
} else {
|
||||
int minutes = qRound(secs/60.0);
|
||||
return( tr("%1 minute(s) ago").arg(minutes));
|
||||
}
|
||||
}
|
||||
return tr("Some time ago");
|
||||
}
|
||||
|
||||
int ActivityListModel::rowCount(const QModelIndex&) const
|
||||
{
|
||||
return _finalList.count();
|
||||
|
|
|
@ -116,7 +116,6 @@ private slots:
|
|||
private:
|
||||
void startFetchJob(AccountState* s);
|
||||
void combineActivityLists();
|
||||
QString timeSpanFromNow(const QDateTime& dt) const;
|
||||
|
||||
QMap<AccountState*, ActivityList> _activityLists;
|
||||
ActivityList _finalList;
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <QUrl>
|
||||
#include <QDebug>
|
||||
#include <QProcess>
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
#include <QDateTime>
|
||||
#include <QSysInfo>
|
||||
|
@ -430,6 +431,36 @@ QByteArray Utility::versionOfInstalledBinary( const QString& command )
|
|||
return re;
|
||||
}
|
||||
|
||||
QString Utility::timeAgoInWords(const QDateTime& dt, const QDateTime& from)
|
||||
{
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
|
||||
if( from.isValid() ) {
|
||||
now = from;
|
||||
}
|
||||
|
||||
if( dt.daysTo(now)>0 ) {
|
||||
int dtn = dt.daysTo(now);
|
||||
return QObject::tr("%1 day(s) ago", "", dtn).arg(dtn);
|
||||
} else {
|
||||
qint64 secs = dt.secsTo(now);
|
||||
|
||||
if( floor(secs / 3600.0) > 0 ) {
|
||||
int hours = floor(secs/3600.0);
|
||||
return( QObject::tr("%1 hour(s) ago", "", hours).arg(hours));
|
||||
} else {
|
||||
int minutes = qRound(secs/60.0);
|
||||
if( minutes == 0 ) {
|
||||
return QObject::tr("Less than a minute ago");
|
||||
}
|
||||
return( QObject::tr("%1 minute(s) ago", "", minutes).arg(minutes));
|
||||
}
|
||||
}
|
||||
return QObject::tr("Some time ago");
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------- */
|
||||
|
||||
static const char STOPWATCH_END_TAG[] = "_STOPWATCH_END";
|
||||
|
||||
void Utility::StopWatch::start()
|
||||
|
|
|
@ -107,6 +107,16 @@ namespace Utility
|
|||
|
||||
OWNCLOUDSYNC_EXPORT QString fileNameForGuiUse(const QString& fName);
|
||||
|
||||
/**
|
||||
* @brief timeAgoInWords - human readable time span
|
||||
*
|
||||
* Use this to get a string that describes the timespan between the first and
|
||||
* the second timestamp in a human readable and understandable form.
|
||||
*
|
||||
* If the second parameter is ommitted, the current time is used.
|
||||
*/
|
||||
OWNCLOUDSYNC_EXPORT QString timeAgoInWords(const QDateTime& dt, const QDateTime& from = QDateTime() );
|
||||
|
||||
class OWNCLOUDSYNC_EXPORT StopWatch {
|
||||
private:
|
||||
QHash<QString, quint64> _lapTimes;
|
||||
|
|
Loading…
Reference in a new issue