Several status view fixes

Change-Id: I4118c40eeca6b4660bd1ca8f456c650ffb04a637
diff --git a/src/forwarder-status.cpp b/src/forwarder-status.cpp
index df203e5..80d6f63 100644
--- a/src/forwarder-status.cpp
+++ b/src/forwarder-status.cpp
@@ -83,20 +83,20 @@
 {
   beginResetModel();
   m_items.clear();
-  addItem(ForwarderStatusItem("Version",       QString::fromStdString(status.getNfdVersion())));
-  addItem(ForwarderStatusItem("Start Time",     QString::fromStdString(time::toIsoString(status.getStartTimestamp()))));
-  addItem(ForwarderStatusItem("Current Time",   QString::fromStdString(time::toIsoString(status.getCurrentTimestamp()))));
-  addItem(ForwarderStatusItem("Name Tree Entries", QString::number(status.getNNameTreeEntries())));
-  addItem(ForwarderStatusItem("Fib Entries",   QString::number(status.getNFibEntries())));
-  addItem(ForwarderStatusItem("PitEntries",   QString::number(status.getNPitEntries())));
-  addItem(ForwarderStatusItem("Measurements Entries", QString::number(status.getNMeasurementsEntries())));
-  addItem(ForwarderStatusItem("Content Store Entries",    QString::number(status.getNCsEntries())));
-  addItem(ForwarderStatusItem("Incoming Interests",  QString::number(status.getNInInterests())));
-  addItem(ForwarderStatusItem("Outgoing Interests", QString::number(status.getNOutInterests())));
-  addItem(ForwarderStatusItem("Incoming Data",      QString::number(status.getNInDatas())));
-  addItem(ForwarderStatusItem("Outgoing Data",      QString::number(status.getNOutDatas())));
-  addItem(ForwarderStatusItem("Incoming Nacks",      QString::number(status.getNInDatas())));
-  addItem(ForwarderStatusItem("Outgoing Nacks",     QString::number(status.getNOutDatas())));
+  addItem({"Version",               status.getNfdVersion()});
+  addItem({"Start Time",            status.getStartTimestamp()});
+  addItem({"Current Time",          status.getCurrentTimestamp()});
+  addItem({"Name Tree Entries",     status.getNNameTreeEntries()});
+  addItem({"Fib Entries",           status.getNFibEntries()});
+  addItem({"PitEntries",            status.getNPitEntries()});
+  addItem({"Measurements Entries",  status.getNMeasurementsEntries()});
+  addItem({"Content Store Entries", status.getNCsEntries()});
+  addItem({"Incoming Interests",    status.getNInInterests()});
+  addItem({"Outgoing Interests",    status.getNOutInterests()});
+  addItem({"Incoming Data",         status.getNInDatas()});
+  addItem({"Outgoing Data",         status.getNOutDatas()});
+  addItem({"Incoming Nacks",        status.getNInDatas()});
+  addItem({"Outgoing Nacks",        status.getNOutDatas()});
   endResetModel();
 }
 
diff --git a/src/forwarder-status.hpp b/src/forwarder-status.hpp
index 0d4282e..742b5da 100644
--- a/src/forwarder-status.hpp
+++ b/src/forwarder-status.hpp
@@ -20,8 +20,9 @@
 #ifndef NCC_FORWARDER_STATUS_HPP
 #define NCC_FORWARDER_STATUS_HPP
 
-#include <QtCore/QAbstractListModel>
-#include <QtCore/QStringList>
+#include <QAbstractListModel>
+#include <QStringList>
+#include <QDateTime>
 
 #include <ndn-cxx/interest.hpp>
 #include <ndn-cxx/mgmt/nfd/forwarder-status.hpp>
@@ -37,6 +38,23 @@
   {
   }
 
+  ForwarderStatusItem(const QString& type, const std::string& value)
+    : m_type(type)
+    , m_value(QString::fromStdString(value))
+  {
+  }
+
+  ForwarderStatusItem(const QString& type, uint64_t value)
+    : m_type(type)
+    , m_value(QString::number(value))
+  {
+  }
+
+  ForwarderStatusItem(const QString& type, const time::system_clock::TimePoint& value)
+    : ForwarderStatusItem(type, time::toString(value))
+  {
+  }
+
   const QString&
   type() const
   {
diff --git a/src/status-viewer.cpp b/src/status-viewer.cpp
index f4f81f4..ea97b1b 100644
--- a/src/status-viewer.cpp
+++ b/src/status-viewer.cpp
@@ -23,83 +23,93 @@
 namespace ndn {
 
 StatusViewer::StatusViewer(Face& face, KeyChain& keyChain)
-  : s_face(face)
-  , s_keyChain(keyChain)
-  , s_controller(new nfd::Controller(s_face, s_keyChain))
-  , s_scheduler(s_face.getIoService())
+  : m_face(face)
+  , m_keyChain(keyChain)
+  , m_controller(new nfd::Controller(m_face, m_keyChain))
+  , m_scheduler(m_face.getIoService())
+  , m_nextStatusRetrieval(m_scheduler)
 {
-  QQmlContext* s_context = s_engine.rootContext();
+  QQmlContext* m_context = m_engine.rootContext();
 
-  s_context->setContextProperty("forwarderModel", &s_forwarderStatusModel);
-  s_context->setContextProperty("channelModel", &s_channelModel);
-  s_context->setContextProperty("faceModel", &s_faceModel);
-  s_context->setContextProperty("fibModel", &s_fibModel);
-  s_context->setContextProperty("ribModel", &s_ribModel);
-  s_context->setContextProperty("strategyModel", &s_strategyModel);
-  s_context->setContextProperty("statusViewer", this);
+  m_context->setContextProperty("forwarderModel", &m_forwarderStatusModel);
+  m_context->setContextProperty("channelModel", &m_channelModel);
+  m_context->setContextProperty("faceModel", &m_faceModel);
+  m_context->setContextProperty("fibModel", &m_fibModel);
+  m_context->setContextProperty("ribModel", &m_ribModel);
+  m_context->setContextProperty("strategyModel", &m_strategyModel);
+  m_context->setContextProperty("statusViewer", this);
 
-  s_engine.load((QUrl("qrc:/status.qml")));
+  m_engine.load((QUrl("qrc:/status.qml")));
 }
 
 void
 StatusViewer::onStatusRetrieved(const nfd::ForwarderStatus& status)
 {
-  emit s_forwarderStatusModel.onDataReceived(status);
+  emit m_forwarderStatusModel.onDataReceived(status);
 }
 
 void
 StatusViewer::onChannelStatusRetrieved(const std::vector<nfd::ChannelStatus>& status)
 {
-  emit s_channelModel.onDataReceived(status);
+  emit m_channelModel.onDataReceived(status);
 }
 
 void
 StatusViewer::onFaceStatusRetrieved(const std::vector<nfd::FaceStatus>& status)
 {
-  emit s_faceModel.onDataReceived(status);
+  emit m_faceModel.onDataReceived(status);
 }
 
 void
 StatusViewer::onFibStatusRetrieved(const std::vector<nfd::FibEntry>& status)
 {
-  emit s_fibModel.onDataReceived(status);
+  emit m_fibModel.onDataReceived(status);
 }
 
 void
 StatusViewer::onRibStatusRetrieved(const std::vector<nfd::RibEntry>& status)
 {
-  emit s_ribModel.onDataReceived(status);
+  emit m_ribModel.onDataReceived(status);
 }
 
 void
 StatusViewer::onStrategyChoiceStatusRetrieved(const std::vector<nfd::StrategyChoice>& status)
 {
-  emit s_strategyModel.onDataReceived(status);
+  emit m_strategyModel.onDataReceived(status);
 }
 
 void
 StatusViewer::onStatusTimeout()
 {
   std::cerr << "Should not really happen, most likely a serious problem" << std::endl;
-  s_scheduler.scheduleEvent(time::seconds(15), bind(&StatusViewer::requestNfdStatus, this));
+  m_scheduler.scheduleEvent(time::seconds(15), bind(&StatusViewer::requestNfdStatus, this));
+}
+
+void
+StatusViewer::cancelEvents()
+{
+  m_nextStatusRetrieval.cancel();
+  std::cerr << "Future events canceled" << std::endl;
 }
 
 void
 StatusViewer::requestNfdStatus()
 {
-  s_controller->fetch<ndn::nfd::ForwarderGeneralStatusDataset>(bind(&StatusViewer::onStatusRetrieved, this, _1),
+  std::cerr << "requestNfdStatus" << std::endl;
+
+  m_controller->fetch<ndn::nfd::ForwarderGeneralStatusDataset>(bind(&StatusViewer::onStatusRetrieved, this, _1),
                                                                bind(&StatusViewer::onStatusTimeout, this));
-  s_controller->fetch<ndn::nfd::ChannelDataset>(bind(&StatusViewer::onChannelStatusRetrieved, this, _1),
+  m_controller->fetch<ndn::nfd::ChannelDataset>(bind(&StatusViewer::onChannelStatusRetrieved, this, _1),
                                                 bind(&StatusViewer::onStatusTimeout, this));
-  s_controller->fetch<ndn::nfd::FaceDataset>(bind(&StatusViewer::onFaceStatusRetrieved, this, _1),
+  m_controller->fetch<ndn::nfd::FaceDataset>(bind(&StatusViewer::onFaceStatusRetrieved, this, _1),
                                              bind(&StatusViewer::onStatusTimeout, this));
-  s_controller->fetch<ndn::nfd::FibDataset>(bind(&StatusViewer::onFibStatusRetrieved, this, _1),
+  m_controller->fetch<ndn::nfd::FibDataset>(bind(&StatusViewer::onFibStatusRetrieved, this, _1),
                                             bind(&StatusViewer::onStatusTimeout, this));
-  s_controller->fetch<ndn::nfd::RibDataset>(bind(&StatusViewer::onRibStatusRetrieved, this, _1),
+  m_controller->fetch<ndn::nfd::RibDataset>(bind(&StatusViewer::onRibStatusRetrieved, this, _1),
                                             bind(&StatusViewer::onStatusTimeout, this));
-  s_controller->fetch<ndn::nfd::StrategyChoiceDataset>(bind(&StatusViewer::onStrategyChoiceStatusRetrieved, this, _1),
+  m_controller->fetch<ndn::nfd::StrategyChoiceDataset>(bind(&StatusViewer::onStrategyChoiceStatusRetrieved, this, _1),
                                                        bind(&StatusViewer::onStatusTimeout, this));
-  s_scheduler.scheduleEvent(time::seconds(15), bind(&StatusViewer::requestNfdStatus, this));
+  m_nextStatusRetrieval = m_scheduler.scheduleEvent(time::seconds(15), bind(&StatusViewer::requestNfdStatus, this));
 }
 
 void
diff --git a/src/status-viewer.hpp b/src/status-viewer.hpp
index ac815b8..8d8fe23 100644
--- a/src/status-viewer.hpp
+++ b/src/status-viewer.hpp
@@ -84,20 +84,24 @@
   void
   present();
 
+  void
+  cancelEvents();
+
 private:
-  Face& s_face;
-  KeyChain& s_keyChain;
-  nfd::Controller* s_controller;
-  Scheduler s_scheduler;
+  QQmlApplicationEngine m_engine;
 
-  QQmlApplicationEngine s_engine;
+  Face& m_face;
+  KeyChain& m_keyChain;
+  nfd::Controller* m_controller;
+  Scheduler m_scheduler;
+  util::scheduler::ScopedEventId m_nextStatusRetrieval;
 
-  ForwarderStatusModel s_forwarderStatusModel;
-  ChannelStatusModel s_channelModel;
-  FaceStatusModel s_faceModel;
-  FibStatusModel s_fibModel;
-  RibStatusModel s_ribModel;
-  StrategyStatusModel s_strategyModel;
+  ForwarderStatusModel m_forwarderStatusModel;
+  ChannelStatusModel m_channelModel;
+  FaceStatusModel m_faceModel;
+  FibStatusModel m_fibModel;
+  RibStatusModel m_ribModel;
+  StrategyStatusModel m_strategyModel;
 };
 
 } // namespace ndn
diff --git a/src/status.qml b/src/status.qml
index 27f89bf..a22d34c 100644
--- a/src/status.qml
+++ b/src/status.qml
@@ -10,6 +10,10 @@
     minimumWidth: 700
     minimumHeight: 400
 
+    onClosing: {
+      statusViewer.cancelEvents();
+    }
+
     TabView {
         anchors.fill: parent
         anchors.topMargin: 20
@@ -18,7 +22,7 @@
         anchors.rightMargin: 20
 
         Tab {
-            title: "Forwarder"
+            title: "General"
             TableView {
                 anchors.fill: parent
                 anchors.topMargin: 20
@@ -39,7 +43,7 @@
             }
         }
         Tab {
-            title: "Channel"
+            title: "Channels"
             TableView {
                 anchors.fill: parent
                 anchors.topMargin: 20
@@ -55,7 +59,7 @@
             }
         }
         Tab {
-            title: "Face"
+            title: "Faces"
             TableView {
                 anchors.fill: parent
                 anchors.topMargin: 20
@@ -208,7 +212,7 @@
             }
         }
         Tab {
-            title: "Strategy"
+            title: "Strategies"
             TableView {
                 anchors.fill: parent
                 anchors.topMargin: 20
diff --git a/src/tray-menu.cpp b/src/tray-menu.cpp
index 104878a..d8028df 100644
--- a/src/tray-menu.cpp
+++ b/src/tray-menu.cpp
@@ -96,10 +96,12 @@
 
   m_context->setContextProperty("nccVersion", nccVersion);
 
-  m_menu->addAction(m_entryPref);
   m_menu->addAction(m_entryStatus);
   m_menu->addAction(m_entrySec);
 
+  m_menu->addSeparator();
+  m_menu->addAction(m_entryPref);
+
 #ifdef OSX_BUILD
   connect(m_entryEnableCli, SIGNAL(triggered()), this, SLOT(enableCli()));
   m_menu->addAction(m_entryEnableCli);
@@ -108,6 +110,7 @@
   m_menu->addAction(m_checkForUpdates);
 #endif
 
+  m_menu->addSeparator();
   m_menu->addAction(m_entryQuit);
   m_tray = new QSystemTrayIcon(this);
   m_tray->setContextMenu(m_menu);