[Pkg-owncloud-commits] [owncloud-client] 334/484: AcitivityWidget: Moved timespan-in-words method to utility.
Sandro Knauß
hefee-guest at moszumanska.debian.org
Wed Dec 16 00:38:01 UTC 2015
This is an automated email from the git hooks/post-receive script.
hefee-guest pushed a commit to branch master
in repository owncloud-client.
commit e38bc6eab8bc76acb4f1470a12ee2d4a377b0c2a
Author: Klaas Freitag <freitag at owncloud.com>
Date: Mon Nov 16 18:08:25 2015 +0100
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.
---
src/gui/activitywidget.cpp | 22 +---------------------
src/gui/activitywidget.h | 1 -
src/libsync/utility.cpp | 31 +++++++++++++++++++++++++++++++
src/libsync/utility.h | 10 ++++++++++
4 files changed, 42 insertions(+), 22 deletions(-)
diff --git a/src/gui/activitywidget.cpp b/src/gui/activitywidget.cpp
index 731c026..4601613 100644
--- a/src/gui/activitywidget.cpp
+++ b/src/gui/activitywidget.cpp
@@ -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();
diff --git a/src/gui/activitywidget.h b/src/gui/activitywidget.h
index 7949a74..df5e73c 100644
--- a/src/gui/activitywidget.h
+++ b/src/gui/activitywidget.h
@@ -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;
diff --git a/src/libsync/utility.cpp b/src/libsync/utility.cpp
index dbe25ae..914e9f8 100644
--- a/src/libsync/utility.cpp
+++ b/src/libsync/utility.cpp
@@ -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()
diff --git a/src/libsync/utility.h b/src/libsync/utility.h
index 2691e2a..7aa31e3 100644
--- a/src/libsync/utility.h
+++ b/src/libsync/utility.h
@@ -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;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git
More information about the Pkg-owncloud-commits
mailing list