From 93d17c8deb662dc0c2e969c281b8eee9c69835d4 Mon Sep 17 00:00:00 2001
From: Emmanuel Lepage Vallee <elv1313@gmail.com>
Date: Mon, 6 Jun 2016 02:01:39 -0400
Subject: [PATCH] account: Trask last event time_t

This is useful to display the "uptime" next to the account name in
the statusbar.

I track the uptime in a client function to avoid adding to much
logic in account.cpp.

Change-Id: Ie4c5f47b99f7be97c6d1abce91d6e02856e8741c
---
 src/account.cpp            |  2 ++
 src/account.h              |  1 +
 src/accountmodel.cpp       |  1 +
 src/accountstatusmodel.cpp | 14 +++++++++++++-
 src/accountstatusmodel.h   |  1 +
 5 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/account.cpp b/src/account.cpp
index 245c5f04..6645313d 100644
--- a/src/account.cpp
+++ b/src/account.cpp
@@ -1259,6 +1259,8 @@ QVariant Account::roleData(int role) const
             return extension<SecurityEvaluationExtension>()->securityLevelIcon(this);
          }
          break;
+      case CAST(Account::Role::LastStatusChangeTimeStamp):
+         return QVariant::fromValue(statusModel()->lastTimeStamp());
       default:
          return QVariant();
    }
diff --git a/src/account.h b/src/account.h
index 41b6c64b..a61c2ce1 100644
--- a/src/account.h
+++ b/src/account.h
@@ -307,6 +307,7 @@ class LIB_EXPORT Account : public ItemBase {
          HasActiveCallLimit          ,
          SecurityLevel               ,
          SecurityLevelIcon           ,
+         LastStatusChangeTimeStamp   ,
       };
 
       ///@enum RoleState Whether a role can be used in a certain context
diff --git a/src/accountmodel.cpp b/src/accountmodel.cpp
index 984b31c2..2ad0697f 100644
--- a/src/accountmodel.cpp
+++ b/src/accountmodel.cpp
@@ -198,6 +198,7 @@ QHash<int,QByteArray> AccountModel::roleNames() const
       roles.insert(CAST(Account::Role::TurnServerRealm             ) ,QByteArray("turnServerRealm"               ));
       roles.insert(CAST(Account::Role::TurnServerEnabled           ) ,QByteArray("turnEnabled"                   ));
       roles.insert(CAST(Account::Role::TlsPrivateKey               ) ,QByteArray("tlsPrivateKey"                 ));
+      roles.insert(CAST(Account::Role::LastStatusChangeTimeStamp   ) ,QByteArray("lastStatusChangeTimeStamp"     ));
 
    }
    return roles;
diff --git a/src/accountstatusmodel.cpp b/src/accountstatusmodel.cpp
index 98bf1c53..6cdc2f7e 100644
--- a/src/accountstatusmodel.cpp
+++ b/src/accountstatusmodel.cpp
@@ -56,6 +56,7 @@ struct AccountStatusRow {
    QString                  description;
    int                      code       ;
    QDateTime                time       ;
+   time_t                   timestamp  ;
    uint                     counter    ;
    AccountStatusModel::Type type       ;
 };
@@ -68,6 +69,7 @@ public:
    //Attributes
    Account* m_pAccount;
    QVector<AccountStatusRow*> m_lRows;
+   time_t m_FallbackTime_t;
 };
 
 
@@ -76,9 +78,11 @@ code(_code),counter(0),
 time(QDateTime::currentDateTime()),type(_type)
 {
     description = _description;
+    timestamp   = time.toTime_t();
 }
 
-AccountStatusModelPrivate::AccountStatusModelPrivate(Account* parent) : m_pAccount(parent)
+AccountStatusModelPrivate::AccountStatusModelPrivate(Account* parent) : m_pAccount(parent),
+m_FallbackTime_t(QDateTime::currentDateTime().toTime_t())
 {
 }
 
@@ -221,3 +225,11 @@ int AccountStatusModel::lastErrorCode() const
 
    return d_ptr->m_lRows.last()->code;
 }
+
+time_t AccountStatusModel::lastTimeStamp() const
+{
+   if (d_ptr->m_lRows.isEmpty())
+      return d_ptr->m_FallbackTime_t;
+
+   return d_ptr->m_lRows.last()->timestamp;
+}
diff --git a/src/accountstatusmodel.h b/src/accountstatusmodel.h
index 6f5540b3..c76c328f 100644
--- a/src/accountstatusmodel.h
+++ b/src/accountstatusmodel.h
@@ -65,6 +65,7 @@ public:
    //Getter
    QString lastErrorMessage() const;
    int     lastErrorCode   () const;
+   time_t  lastTimeStamp   () const;
 
 private:
    //Private mutators
-- 
GitLab