New Qt5-based implementation

Change-Id: I1a165aacd8c8254a250a14a2024fecf50c986abe
diff --git a/qt5/app.icns b/qt5/app.icns
new file mode 100644
index 0000000..ececc16
--- /dev/null
+++ b/qt5/app.icns
Binary files differ
diff --git a/qt5/fib-status.cpp b/qt5/fib-status.cpp
new file mode 100644
index 0000000..eaae8af
--- /dev/null
+++ b/qt5/fib-status.cpp
@@ -0,0 +1,170 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2014, Regents of the University of California,
+ *
+ * This file is part of NFD Control Center.  See AUTHORS.md for complete list of NFD
+ * authors and contributors.
+ *
+ * NFD Control Center is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD Control Center is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with NFD
+ * Control Center, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "fib-status.hpp"
+
+#ifdef WAF
+#include "fib-status.moc"
+// #include "fib-status.cpp.moc"
+#endif
+
+#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/name.hpp>
+#include <ndn-cxx/interest.hpp>
+#include <ndn-cxx/encoding/buffer-stream.hpp>
+#include <ndn-cxx/management/nfd-fib-entry.hpp>
+#include <ndn-cxx/management/nfd-face-status.hpp>
+#include <ndn-cxx/management/nfd-forwarder-status.hpp>
+
+namespace ndn {
+
+FibStatusModel::FibStatusModel(Face& face, QObject *parent/* = 0*/)
+  : QAbstractListModel(parent)
+  , m_face(face)
+{
+}
+
+int
+FibStatusModel::rowCount(const QModelIndex &parent/* = QModelIndex()*/) const
+{
+  return m_items.count();
+}
+
+void
+FibStatusModel::addItem(const FibStatusItem &item)
+{
+  beginInsertRows(QModelIndex(), rowCount(), rowCount());
+  m_items << item;
+  endInsertRows();
+}
+
+QVariant
+FibStatusModel::data(const QModelIndex & index, int role) const
+{
+  if (index.row() < 0 || index.row() >= m_items.count()) {
+    return QVariant();
+  }
+
+  const FibStatusItem &item = m_items.at(index.row());
+  if (role == PrefixRole) {
+    return item.prefix();
+  } else if (role == FaceIdRole) {
+    return item.faceId();
+  } else if (role == CostRole) {
+    return item.cost();
+  }
+
+  return QVariant();
+}
+
+QHash<int, QByteArray>
+FibStatusModel::roleNames() const
+{
+  QHash<int, QByteArray> roles;
+  roles[PrefixRole] = "prefix";
+  roles[FaceIdRole] = "faceId";
+  roles[CostRole] = "cost";
+  return roles;
+}
+
+void
+FibStatusModel::clear()
+{
+  beginResetModel();
+  m_items.clear();
+  endResetModel();
+}
+
+Q_INVOKABLE void
+FibStatusModel::fetchFibInformation()
+{
+  // m_buffer = make_shared<OBufferStream>();
+
+  // Interest interest("/localhost/nfd/fib/list");
+  // interest.setChildSelector(1);
+  // interest.setMustBeFresh(true);
+  // m_face.expressInterest(interest,
+  //                        bind(&FibStatusModel::fetchSegments, this, _2,
+  //                             &FibStatusModel::afterFetchedFibEnumerationInformation),
+  //                        bind(&FibStatusModel::onTimeout, this));
+  // try {
+  //   m_face.processEvents();
+  // } catch (Tlv::Error e) {
+  //   std::cerr << e.what() << std::endl;
+  //   clear();
+  // }
+}
+
+void
+FibStatusModel::afterFetchedFibEnumerationInformation()
+{
+//   beginResetModel();
+//   m_items.clear();
+//   ConstBufferPtr buf = m_buffer->buf();
+
+//   Block block;
+//   size_t offset = 0;
+//   while (offset < buf->size()) {
+//     bool ok = Block::fromBuffer(buf, offset, block);
+//     if (!ok) {
+//       std::cerr << "ERROR: cannot decode FibEntry TLV" << std::endl;
+//       break;
+//     }
+//     offset += block.size();
+
+//     nfd::FibEntry fibEntry(block);
+
+//     for (std::list<nfd::NextHopRecord>::const_iterator
+//            nextHop = fibEntry.getNextHopRecords().begin();
+//          nextHop != fibEntry.getNextHopRecords().end();
+//          ++nextHop) {
+//       addItem(FibStatusItem(QString::fromStdString(fibEntry.getPrefix().toUri()),
+//                             nextHop->getFaceId(), nextHop->getCost()));
+//     }
+//   }
+//   endResetModel();
+}
+
+
+void
+FibStatusModel::fetchSegments(const Data& data, void (FibStatusModel::*onDone)())
+{
+  // m_buffer->write(reinterpret_cast<const char*>(data.getContent().value()),
+  //                 data.getContent().value_size());
+
+  // uint64_t currentSegment = data.getName().get(-1).toSegment();
+
+  // const name::Component& finalBlockId = data.getMetaInfo().getFinalBlockId();
+  // if (finalBlockId.empty() ||
+  //     finalBlockId.toSegment() > currentSegment) {
+  //   m_face.expressInterest(data.getName().getPrefix(-1).appendSegment(currentSegment+1),
+  //                          bind(&FibStatusModel::fetchSegments, this, _2, onDone),
+  //                          bind(&FibStatusModel::onTimeout, this));
+  // } else {
+  //   return (this->*onDone)();
+  // }
+}
+
+void
+FibStatusModel::onTimeout()
+{
+  std::cerr << "Request timed out" << std::endl;
+}
+
+} // namespace ndn
diff --git a/qt5/fib-status.hpp b/qt5/fib-status.hpp
new file mode 100644
index 0000000..0ebd80e
--- /dev/null
+++ b/qt5/fib-status.hpp
@@ -0,0 +1,113 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2014, Regents of the University of California,
+ *
+ * This file is part of NFD Control Center.  See AUTHORS.md for complete list of NFD
+ * authors and contributors.
+ *
+ * NFD Control Center is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD Control Center is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with NFD
+ * Control Center, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NCC_FIB_STATUS_HPP
+#define NCC_FIB_STATUS_HPP
+
+#include <QtCore/QAbstractListModel>
+#include <QtCore/QStringList>
+
+namespace ndn {
+class Face;
+class Data;
+
+class FibStatusItem
+{
+public:
+  FibStatusItem(const QString &prefix, uint64_t faceId, uint64_t cost)
+    : m_prefix(prefix)
+    , m_faceId(faceId)
+    , m_cost(cost)
+  {
+  }
+
+  const QString&
+  prefix() const
+  {
+    return m_prefix;
+  }
+
+  uint64_t
+  faceId() const
+  {
+    return m_faceId;
+  }
+
+  uint64_t
+  cost() const
+  {
+    return m_cost;
+  }
+
+private:
+  QString m_prefix;
+  uint64_t m_faceId;
+  uint64_t m_cost;
+};
+
+class FibStatusModel : public QAbstractListModel
+{
+  Q_OBJECT
+
+public:
+  enum FibStatusRoles {
+    PrefixRole = Qt::UserRole + 1,
+    FaceIdRole,
+    CostRole
+  };
+
+  explicit
+  FibStatusModel(Face& face, QObject *parent = 0);
+
+  int
+  rowCount(const QModelIndex &parent = QModelIndex()) const;
+
+  void
+  addItem(const FibStatusItem &item);
+
+  QVariant
+  data(const QModelIndex & index, int role) const;
+
+  QHash<int, QByteArray>
+  roleNames() const;
+
+  void
+  clear();
+
+  Q_INVOKABLE void
+  fetchFibInformation();
+
+  void
+  afterFetchedFibEnumerationInformation();
+
+  void
+  fetchSegments(const Data& data, void (FibStatusModel::*onDone)());
+
+  void
+  onTimeout();
+
+private:
+  Face& m_face;
+  QList<FibStatusItem> m_items;
+  // shared_ptr<OBufferStream> m_buffer;
+};
+
+} // namespace ndn
+
+#endif // NCC_FIB_STATUS_HPP
diff --git a/qt5/forwarder-status.cpp b/qt5/forwarder-status.cpp
new file mode 100644
index 0000000..300c29e
--- /dev/null
+++ b/qt5/forwarder-status.cpp
@@ -0,0 +1,135 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2014, Regents of the University of California,
+ *
+ * This file is part of NFD Control Center.  See AUTHORS.md for complete list of NFD
+ * authors and contributors.
+ *
+ * NFD Control Center is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD Control Center is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with NFD
+ * Control Center, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "forwarder-status.hpp"
+
+#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/name.hpp>
+#include <ndn-cxx/interest.hpp>
+#include <ndn-cxx/management/nfd-fib-entry.hpp>
+#include <ndn-cxx/management/nfd-face-status.hpp>
+#include <ndn-cxx/management/nfd-forwarder-status.hpp>
+
+#ifdef WAF
+#include "forwarder-status.moc"
+// #include "forwarder-status.cpp.moc"
+#endif
+
+namespace ndn {
+
+ForwarderStatusModel::ForwarderStatusModel(Face& face, QObject* parent/* = 0*/)
+  : QAbstractListModel(parent)
+  , m_face(face)
+{
+  connect(this, SIGNAL(onDataReceived(ndn::shared_ptr<const ndn::Data>)), this,
+          SLOT(updateStatus(ndn::shared_ptr<const ndn::Data>)));
+}
+
+int
+ForwarderStatusModel::rowCount(const QModelIndex& parent/* = QModelIndex()*/) const
+{
+  return m_items.count();
+}
+
+void
+ForwarderStatusModel::addItem(const ForwarderStatusItem& item)
+{
+  beginInsertRows(QModelIndex(), rowCount(), rowCount());
+  m_items << item;
+  endInsertRows();
+}
+
+QVariant
+ForwarderStatusModel::data(const QModelIndex& index, int role) const
+{
+  if (index.row() < 0 || index.row() >= m_items.count()) {
+    return QVariant();
+  }
+
+  const ForwarderStatusItem& item = m_items.at(index.row());
+  if (role == TypeRole) {
+    return item.type();
+  }
+  else if (role == ValueRole) {
+    return item.value();
+  }
+  return QVariant();
+}
+
+QHash<int, QByteArray>
+ForwarderStatusModel::roleNames() const
+{
+  QHash<int, QByteArray> roles;
+  roles[TypeRole] = "type";
+  roles[ValueRole] = "value";
+  return roles;
+}
+
+Q_INVOKABLE void
+ForwarderStatusModel::fetchVersionInformation()
+{
+  Interest interest("/localhost/nfd/status");
+  interest.setMustBeFresh(true);
+  m_face.expressInterest(interest,
+                         bind(&ForwarderStatusModel::afterFetchedVersionInformation, this, _2),
+                         bind(&ForwarderStatusModel::onTimeout, this, _1));
+}
+
+void
+ForwarderStatusModel::clear()
+{
+  beginResetModel();
+  m_items.clear();
+  endResetModel ();
+}
+
+void
+ForwarderStatusModel::afterFetchedVersionInformation(const Data& data)
+{
+  emit onDataReceived(data.shared_from_this());
+}
+
+void
+ForwarderStatusModel::updateStatus(shared_ptr<const Data> data)
+{
+  beginResetModel();
+  m_items.clear();
+  nfd::ForwarderStatus status(data->getContent());
+  addItem(ForwarderStatusItem("version",       QString::number(status.getNfdVersion())));
+  addItem(ForwarderStatusItem("startTime",     QString::fromStdString(time::toIsoString(status.getStartTimestamp()))));
+  addItem(ForwarderStatusItem("currentTime",   QString::fromStdString(time::toIsoString(status.getCurrentTimestamp()))));
+  addItem(ForwarderStatusItem("nNameTreeEntries", QString::number(status.getNNameTreeEntries())));
+  addItem(ForwarderStatusItem("nFibEntries",   QString::number(status.getNFibEntries())));
+  addItem(ForwarderStatusItem("nPitEntries",   QString::number(status.getNPitEntries())));
+  addItem(ForwarderStatusItem("nMeasurementsEntries", QString::number(status.getNMeasurementsEntries())));
+  addItem(ForwarderStatusItem("nCsEntries",    QString::number(status.getNCsEntries())));
+  addItem(ForwarderStatusItem("nInInterests",  QString::number(status.getNInInterests())));
+  addItem(ForwarderStatusItem("nOutInterests", QString::number(status.getNOutInterests())));
+  addItem(ForwarderStatusItem("nInDatas",      QString::number(status.getNInDatas())));
+  addItem(ForwarderStatusItem("nOutDatas",     QString::number(status.getNOutDatas())));
+  endResetModel();
+}
+
+void
+ForwarderStatusModel::onTimeout(const Interest& interest)
+{
+  std::cerr << "Request timed out (should not really happen)" << std::endl;
+}
+
+} // namespace ndn
diff --git a/qt5/forwarder-status.hpp b/qt5/forwarder-status.hpp
new file mode 100644
index 0000000..2c3f3b6
--- /dev/null
+++ b/qt5/forwarder-status.hpp
@@ -0,0 +1,111 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2014, Regents of the University of California,
+ *
+ * This file is part of NFD Control Center.  See AUTHORS.md for complete list of NFD
+ * authors and contributors.
+ *
+ * NFD Control Center is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD Control Center is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with NFD
+ * Control Center, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NCC_FORWARDER_STATUS_HPP
+#define NCC_FORWARDER_STATUS_HPP
+
+#include <QtCore/QAbstractListModel>
+#include <QtCore/QStringList>
+
+#include <ndn-cxx/face.hpp>
+
+namespace ndn {
+
+class ForwarderStatusItem
+{
+public:
+  ForwarderStatusItem(const QString& type, const QString& value)
+    : m_type(type)
+    , m_value(value)
+  {
+  }
+
+  const QString&
+  type() const
+  {
+    return m_type;
+  }
+
+  const QString&
+  value() const
+  {
+    return m_value;
+  }
+
+private:
+  QString m_type;
+  QString m_value;
+};
+
+
+class ForwarderStatusModel : public QAbstractListModel
+{
+  Q_OBJECT
+
+signals:
+  void
+  onDataReceived(ndn::shared_ptr<const ndn::Data>);
+
+public:
+
+  enum ForwarderStatusRoles {
+    TypeRole = Qt::UserRole + 1,
+    ValueRole
+  };
+
+  explicit
+  ForwarderStatusModel(Face& face, QObject* parent = 0);
+
+  int
+  rowCount(const QModelIndex& parent = QModelIndex()) const;
+
+  void
+  addItem(const ForwarderStatusItem& item);
+
+  QVariant
+  data(const QModelIndex& index, int role) const;
+
+  QHash<int, QByteArray>
+  roleNames() const;
+
+  Q_INVOKABLE void
+  fetchVersionInformation();
+
+  void
+  clear();
+
+  void
+  afterFetchedVersionInformation(const Data& data);
+
+  void
+  onTimeout(const Interest& interest);
+
+private slots:
+
+  void
+  updateStatus(ndn::shared_ptr<const ndn::Data> data);
+
+private:
+  Face& m_face;
+  QList<ForwarderStatusItem> m_items;
+};
+
+} // namespace ndn
+
+#endif // NCC_FORWARDER_STATUS_HPP
diff --git a/qt5/main.cpp b/qt5/main.cpp
new file mode 100644
index 0000000..81a7ba6
--- /dev/null
+++ b/qt5/main.cpp
@@ -0,0 +1,144 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2014, Regents of the University of California,
+ *
+ * This file is part of NFD Control Center.  See AUTHORS.md for complete list of NFD
+ * authors and contributors.
+ *
+ * NFD Control Center is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD Control Center is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with NFD
+ * Control Center, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <QtQml/QQmlApplicationEngine>
+#include <QtWidgets/QApplication>
+#include <QtQml/QQmlContext>
+
+#include "forwarder-status.hpp"
+#include "fib-status.hpp"
+#include "tray-menu.hpp"
+
+#include <ndn-cxx/face.hpp>
+#include <boost/thread.hpp>
+
+namespace ndn {
+
+class Ncc
+{
+public:
+  Ncc()
+    : m_isActive(true)
+    , m_forwarderModel(m_face)
+    , m_fibModel(m_face)
+  {
+    QQmlContext* context = m_engine.rootContext();
+
+    context->setContextProperty("forwarderModel", &m_forwarderModel);
+    context->setContextProperty("fibModel", &m_fibModel);
+    context->setContextProperty("trayModel", &m_tray);
+
+    m_engine.load((QUrl("qrc:/main.qml")));
+
+    m_nfdThread = boost::thread(&Ncc::nfdConnectionLoop, this);
+  }
+
+  void
+  nfdConnectionLoop()
+  {
+    try {
+#ifdef BOOST_THREAD_USES_CHRONO
+      time::seconds retryTimeout = time::seconds(5);
+#else
+      boost::posix_time::time_duration retryTimeout = boost::posix_time::seconds(1);
+#endif
+
+      while (m_isActive) {
+        try {
+          while (m_isActive) {
+            m_face.expressInterest(Interest("/localhost/nfd/status"),
+                                   bind(&Ncc::onStatusRetrieved, this),
+                                   bind(&Ncc::onStatusTimeout, this));
+            m_face.processEvents(time::milliseconds::zero(), true);
+          }
+        }
+        catch (const std::exception&) {
+          emit m_tray.nfdActivityUpdate(false);
+#ifdef BOOST_THREAD_USES_CHRONO
+          boost::this_thread::sleep_for(retryTimeout);
+#else
+          boost::this_thread::sleep(retryTimeout);
+#endif
+        }
+      }
+    }
+    catch (const boost::thread_interrupted&) {
+      // done
+    }
+  }
+
+  void
+  onStatusRetrieved()
+  {
+    emit m_tray.nfdActivityUpdate(true);
+  }
+
+  void
+  onStatusTimeout()
+  {
+    emit m_tray.nfdActivityUpdate(false);
+
+    std::cerr << "Should not really happen, most likely a serious problem" << std::endl;
+    m_face.expressInterest(Interest("/localhost/nfd/status"),
+                           bind(&Ncc::onStatusRetrieved, this),
+                           bind(&Ncc::onStatusTimeout, this));
+  }
+
+  void
+  stop()
+  {
+    m_isActive = false;
+    m_face.shutdown();
+    m_nfdThread.interrupt();
+    m_nfdThread.join();
+  }
+
+private:
+  volatile bool m_isActive;
+  boost::thread m_nfdThread;
+
+  Face m_face;
+
+  QQmlApplicationEngine m_engine;
+
+  ForwarderStatusModel m_forwarderModel;
+  FibStatusModel m_fibModel;
+  TrayMenu m_tray;
+};
+
+} // namespace ndn
+
+Q_DECLARE_METATYPE(ndn::shared_ptr<const ndn::Data>)
+
+int
+main(int argc, char *argv[])
+{
+  qRegisterMetaType<ndn::shared_ptr<const ndn::Data> >();
+
+  QApplication app(argc, argv);
+
+  ndn::Ncc controlCenterGui;
+
+  QApplication::setQuitOnLastWindowClosed(false);
+  int retval = app.exec();
+
+  controlCenterGui.stop();
+
+  return retval;
+}
diff --git a/qt5/main.qml b/qt5/main.qml
new file mode 100644
index 0000000..c7a151f
--- /dev/null
+++ b/qt5/main.qml
@@ -0,0 +1,175 @@
+import QtQuick 2.2
+import QtQuick.Window 2.1
+import QtQuick.Controls 1.1
+import QtQuick.Layouts 1.0
+
+ApplicationWindow {
+    visible: false
+    id: window
+    title: "NFD Control Center"
+    minimumWidth: 600
+    minimumHeight: 400
+
+    TabView {
+        anchors.fill: parent
+        anchors.topMargin: 20
+        anchors.bottomMargin: 20
+        anchors.leftMargin: 20
+        anchors.rightMargin: 20
+
+        Tab {
+            title: "General"
+            ColumnLayout {
+                anchors.fill: parent
+                GroupBox {
+                    title: "Basic"
+                    id: checkboxControl
+                    anchors.top: parent.top
+                    anchors.left: parent.left
+                    anchors.right: parent.right
+                    anchors.topMargin: 20
+                    anchors.leftMargin: 20
+                    anchors.rightMargin: 20
+                    anchors.bottomMargin: 20
+                    Column {
+                        spacing: 5
+                        anchors.fill: parent
+                        anchors.topMargin: 10
+                        anchors.bottomMargin: 10
+                        anchors.leftMargin: 10
+                        anchors.rightMargin: 10
+                        CheckBox {
+                            id: startOnLogin
+                            enabled: false
+                            text: "Automatically start NFD Control Center on login"
+                        }
+                        CheckBox {
+                            id: discoverHub
+                            text: "Discover nearest NDN hub"
+                            onCheckedChanged: {
+                                if (this.checked) {
+                                    trayModel.autoConfig()
+                                }
+                            }
+                        }
+                        CheckBox {
+                            id: checkUpdate
+                            enabled: false
+                            text: "Check for software updates"
+                        }
+                    }
+                }
+                GroupBox {
+                    title: "Status"
+                    id: status
+                    anchors.top: checkboxControl.bottom
+                    anchors.left: parent.left
+                    anchors.right: parent.right
+                    anchors.topMargin: 20
+                    anchors.leftMargin: 20
+                    anchors.rightMargin: 20
+                    anchors.bottomMargin: 20
+                    Row {
+                        spacing: 20
+                        anchors.topMargin: 10
+                        anchors.leftMargin: 10
+                        anchors.rightMargin: 10
+                        anchors.bottomMargin: 10
+                        anchors.fill: parent
+                        Button {
+                            text: "Traffic map"
+                            onClicked: Qt.openUrlExternally('http://ndnmap.arl.wustl.edu')
+                        }
+                        Button {
+                            text: "Routing status"
+                            onClicked: Qt.openUrlExternally('http://netlab.cs.memphis.edu/script/htm/status.htm')
+                        }
+                    }
+                }
+            }
+        }
+        Tab {
+            title: "FIB status"
+            TableView {
+                anchors.fill: parent
+                anchors.topMargin: 20
+                anchors.bottomMargin: 20
+                anchors.leftMargin: 20
+                anchors.rightMargin: 20
+                TableViewColumn{
+                    role: "prefix"
+                    title: "NDN prefix"
+                    width: 300
+                }
+                TableViewColumn{
+                    role: "faceId"
+                    title: "Face ID"
+                    width: 50
+                }
+                TableViewColumn{
+                    role: "cost"
+                    title: "Cost"
+                    width: 50
+                }
+                model: fibModel
+            }
+        }
+        Tab {
+            title: "Forwarder status"
+            TableView {
+                anchors.fill: parent
+                anchors.topMargin: 20
+                anchors.bottomMargin: 20
+                anchors.leftMargin: 20
+                anchors.rightMargin: 20
+                model: forwarderModel
+                TableViewColumn{
+                    role: "type"
+                    title: "Type"
+                    width: 200
+                }
+                TableViewColumn{
+                    role: "value"
+                    title: "Value"
+                    width: 200
+                }
+            }
+        }
+        Tab {
+            title: "Security"
+            Column {
+                spacing: 2
+                anchors.fill: parent
+                anchors.topMargin: 20
+                anchors.bottomMargin: 20
+                anchors.leftMargin: 20
+                anchors.rightMargin: 20
+                Button {
+                    text: "Obtain NDN Certificate"
+                    onClicked: Qt.openUrlExternally('http://ndncert.named-data.net')
+                }
+            }
+        }
+    }
+    Connections {
+        target: trayModel;
+        onShowApp: {
+            window.show()
+            window.raise()
+        }
+    }
+    Timer {
+        interval: 1000; running: true; repeat: true
+        onTriggered: {
+            trayModel.checkNfdRunning()
+            fibModel.fetchFibInformation()
+        }
+    }
+
+    Timer {
+        interval: 5500; running: true; repeat: true
+        onTriggered: {
+            forwarderModel.fetchVersionInformation()
+        }
+    }
+}
diff --git a/qt5/nfd-control-center.desktop.in b/qt5/nfd-control-center.desktop.in
new file mode 100644
index 0000000..742ae47
--- /dev/null
+++ b/qt5/nfd-control-center.desktop.in
@@ -0,0 +1,12 @@
+[Desktop Entry]
+Version=1.0
+Name=NDNx Control Center
+Keywords=Internet;NDN;NDNx
+Exec=@BINDIR@/@BINARY@
+Terminal=false
+X-MultipleArgs=false
+Type=Application
+Icon=@DATAROOTDIR@/ndnx-control-center/ndnx-main.png
+Categories=GNOME;GTK;Network;
+StartupNotify=true
+Actions=NewWindow;NewPrivateWindow;
diff --git a/qt5/qml.qrc b/qt5/qml.qrc
new file mode 100644
index 0000000..19a180f
--- /dev/null
+++ b/qt5/qml.qrc
@@ -0,0 +1,13 @@
+<RCC>
+    <qresource prefix="/">
+        <file>main.qml</file>
+        <file>resources/icon-connected-white.png</file>
+        <file>resources/icon-disconnected-white.png</file>
+        <file>resources/GenericNetworkIcon_22_128x128x32.png</file>
+        <file>resources/Keychain_22_128x128x32.png</file>
+        <file>resources/System Preferences_22_128x128x32.png</file>
+        <file>resources/ToolbarAdvanced_22_128x128x32.png</file>
+        <file>resources/icon-connected-black.png</file>
+        <file>resources/icon-disconnected-black.png</file>
+    </qresource>
+</RCC>
diff --git a/qt5/resources/GenericNetworkIcon_22_128x128x32.png b/qt5/resources/GenericNetworkIcon_22_128x128x32.png
new file mode 100644
index 0000000..35bc465
--- /dev/null
+++ b/qt5/resources/GenericNetworkIcon_22_128x128x32.png
Binary files differ
diff --git a/qt5/resources/Keychain_22_128x128x32.png b/qt5/resources/Keychain_22_128x128x32.png
new file mode 100644
index 0000000..fbb89eb
--- /dev/null
+++ b/qt5/resources/Keychain_22_128x128x32.png
Binary files differ
diff --git a/qt5/resources/System Preferences_22_128x128x32.png b/qt5/resources/System Preferences_22_128x128x32.png
new file mode 100644
index 0000000..54bec62
--- /dev/null
+++ b/qt5/resources/System Preferences_22_128x128x32.png
Binary files differ
diff --git a/qt5/resources/ToolbarAdvanced_22_128x128x32.png b/qt5/resources/ToolbarAdvanced_22_128x128x32.png
new file mode 100644
index 0000000..1ea369f
--- /dev/null
+++ b/qt5/resources/ToolbarAdvanced_22_128x128x32.png
Binary files differ
diff --git a/qt5/resources/icon-connected-black.png b/qt5/resources/icon-connected-black.png
new file mode 100644
index 0000000..3ce424f
--- /dev/null
+++ b/qt5/resources/icon-connected-black.png
Binary files differ
diff --git a/qt5/resources/icon-connected-white.png b/qt5/resources/icon-connected-white.png
new file mode 100644
index 0000000..55f0dc4
--- /dev/null
+++ b/qt5/resources/icon-connected-white.png
Binary files differ
diff --git a/qt5/resources/icon-disconnected-black.png b/qt5/resources/icon-disconnected-black.png
new file mode 100644
index 0000000..0670f42
--- /dev/null
+++ b/qt5/resources/icon-disconnected-black.png
Binary files differ
diff --git a/qt5/resources/icon-disconnected-white.png b/qt5/resources/icon-disconnected-white.png
new file mode 100644
index 0000000..39997cd
--- /dev/null
+++ b/qt5/resources/icon-disconnected-white.png
Binary files differ
diff --git a/qt5/tray-menu.cpp b/qt5/tray-menu.cpp
new file mode 100644
index 0000000..43c5727
--- /dev/null
+++ b/qt5/tray-menu.cpp
@@ -0,0 +1,153 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2014, Regents of the University of California,
+ *
+ * This file is part of NFD Control Center.  See AUTHORS.md for complete list of NFD
+ * authors and contributors.
+ *
+ * NFD Control Center is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD Control Center is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with NFD
+ * Control Center, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.hpp"
+#include "tray-menu.hpp"
+
+#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/interest.hpp>
+
+
+#ifdef OSX_BUILD
+#define CONNECT_ICON ":/resources/icon-connected-black.png"
+#define DISCONNECT_ICON ":/resources/icon-disconnected-black.png"
+#else
+#define CONNECT_ICON ":/resources/icon-connected-white.png"
+#define DISCONNECT_ICON ":/resources/icon-disconnected-white.png"
+#endif
+
+#ifdef WAF
+#include "tray-menu.moc"
+// #include "tray-menu.cpp.moc"
+#endif
+
+namespace ndn {
+
+TrayMenu::TrayMenu()
+{
+  menu = new QMenu(this);
+  pref = new QAction("Preferences...", menu);
+  quit = new QAction("Quit", menu);
+
+  // connect(start, SIGNAL(triggered()), this, SLOT(startNfd()));
+  // connect(stop, SIGNAL(triggered()), this, SLOT(stopNfd()));
+  connect(pref, SIGNAL(triggered()), this, SIGNAL(showApp()));
+  connect(quit, SIGNAL(triggered()), this, SLOT(quitApp()));
+
+  connect(this, SIGNAL(nfdActivityUpdate(bool)), this, SLOT(updateNfdActivityIcon(bool)));
+
+  // menu->addAction(start);
+  // menu->addAction(stop);
+  menu->addAction(pref);
+  menu->addAction(quit);
+  tray = new QSystemTrayIcon(this);
+  tray->setContextMenu(menu);
+  connect(tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
+          this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
+  tray->setIcon(QIcon(DISCONNECT_ICON));
+  tray->show();
+}
+
+TrayMenu::~TrayMenu()
+{
+}
+
+Q_INVOKABLE void
+TrayMenu::checkNfdRunning()
+{
+  // Face face;
+  // Interest interest("/localhost/nfd/status");
+  // face.expressInterest(interest, 0, 0);
+  // try {
+  //   face.processEvents();
+  //   tray->setIcon(QIcon(CONNECT_ICON));
+  // } catch (Tlv::Error) {
+  //   tray->setIcon(QIcon(DISCONNECT_ICON));
+  // }
+}
+
+Q_INVOKABLE void
+TrayMenu::autoConfig()
+{
+  std::cout << "auto config" <<std::endl;
+  QProcess* proc = new QProcess();
+  connect(proc,SIGNAL(finished(int)), proc, SLOT(deleteLater()));
+  proc->start(NFD_AUTOCONFIG_COMMAND);
+}
+
+void
+TrayMenu::quitApp()
+{
+  QCoreApplication::exit(0);
+}
+
+void
+TrayMenu::iconActivated(QSystemTrayIcon::ActivationReason reason)
+{
+  switch (reason) {
+  // case QSystemTrayIcon::Trigger:
+  //   emit showApp();
+  //   break;
+  case QSystemTrayIcon::Context:
+    break;
+  default:
+    break;
+  }
+}
+
+void
+TrayMenu::startNfd()
+{
+  QProcess * proc = new QProcess();
+  connect(proc,SIGNAL(finished(int)), proc, SLOT(deleteLater()));
+#ifdef __linux__
+  proc->start("gksudo", QStringList() << NFD_START_COMMAND);
+#else
+  proc->start("osascript", QStringList()
+              << "-e"
+              << "do shell script \"" NFD_START_COMMAND "\" with administrator privileges");
+#endif
+}
+
+void
+TrayMenu::stopNfd()
+{
+  QProcess * proc = new QProcess();
+  connect(proc,SIGNAL(finished(int)), proc, SLOT(deleteLater()));
+#ifdef __linux__
+  proc->start("gksudo", QStringList() << NFD_STOP_COMMAND);
+#else
+  proc->start("osascript", QStringList()
+              << "-e"
+              << "do shell script \"" NFD_STOP_COMMAND "\" with administrator privileges");
+#endif
+}
+
+void
+TrayMenu::updateNfdActivityIcon(bool isActive)
+{
+  if (isActive) {
+    tray->setIcon(QIcon(CONNECT_ICON));
+  }
+  else {
+    tray->setIcon(QIcon(DISCONNECT_ICON));
+  }
+}
+
+} // namespace ndn
diff --git a/qt5/tray-menu.hpp b/qt5/tray-menu.hpp
new file mode 100644
index 0000000..b4c2c33
--- /dev/null
+++ b/qt5/tray-menu.hpp
@@ -0,0 +1,83 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2014, Regents of the University of California,
+ *
+ * This file is part of NFD Control Center.  See AUTHORS.md for complete list of NFD
+ * authors and contributors.
+ *
+ * NFD Control Center is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD Control Center is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with NFD
+ * Control Center, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NCC_TRAY_MENU_HPP
+#define NCC_TRAY_MENU_HPP
+
+#include <QtCore/QObject>
+#include <QtCore/QProcess>
+#include <QtCore/QCoreApplication>
+
+#include <QtWidgets/QSystemTrayIcon>
+#include <QtWidgets/QAction>
+#include <QtWidgets/QMenu>
+
+namespace ndn {
+
+class TrayMenu : public QWidget
+{
+  Q_OBJECT
+
+signals:
+  void
+  showApp();
+
+  void
+  nfdActivityUpdate(bool isActive);
+
+public:
+  TrayMenu();
+
+  ~TrayMenu();
+
+  Q_INVOKABLE void
+  checkNfdRunning();
+
+  Q_INVOKABLE void
+  autoConfig();
+
+private slots:
+
+  void
+  quitApp();
+
+  void
+  iconActivated(QSystemTrayIcon::ActivationReason reason);
+
+  void
+  startNfd();
+
+  void
+  stopNfd();
+
+  void
+  updateNfdActivityIcon(bool isActive);
+
+private:
+  QSystemTrayIcon *tray;
+  QMenu* menu;
+  QAction* pref;
+  QAction* quit;
+  // QAction* start;
+  // QAction* stop;
+};
+
+} // namespace ndn
+
+#endif // NCC_TRAY_MENU_HPP
diff --git a/qt5/wscript b/qt5/wscript
new file mode 100644
index 0000000..2447fa8
--- /dev/null
+++ b/qt5/wscript
@@ -0,0 +1,46 @@
+# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+from waflib import Logs, Utils, Task, TaskGen
+
+top = '..'
+
+def configure(conf):
+    conf.load(['gnu_dirs', 'qt5'])
+
+    conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
+                   uselib_store='NDN_CXX', mandatory=True)
+
+    conf.define('RESOURCES_DIR', Utils.subst_vars("${DATAROOTDIR}/nfd-control-center", conf.env))
+
+    if Utils.unversioned_sys_platform() == "darwin":
+        conf.define('OSX_BUILD', 1)
+
+def build(bld):
+    app = bld(
+        features=['qt5', 'cxxprogram', 'cxx'],
+        includes = ".. .",
+
+        use = "NDN_CXX BOOST QT5CORE QT5DBUS QT5QML QT5WIDGETS",
+
+        defines = "WAF",
+        source = bld.path.ant_glob(['*.cpp', '**/*.qrc', '**/*.ui', '**/*.qrc']),
+        )
+
+    if Utils.unversioned_sys_platform() != "darwin":
+        app.target = "../nfd-control-center",
+
+        bld(features = "subst",
+             source = 'nfd-control-center.desktop.in',
+             target = 'nfd-control-center.desktop',
+             BINARY = "nfd-control-center",
+             install_path = "${DATAROOTDIR}/nfd-control-center"
+            )
+
+        bld.install_files("${DATAROOTDIR}/nfd-control-center",
+                      bld.path.ant_glob(['Resources/*']))
+    else:
+        app.target = "../NFD Control Center"
+        app.mac_app = True
+        app.mac_plist = '../osx/Info.plist'
+        app.mac_resources = [i.path_from(bld.path)
+                               for i in bld.path.parent.ant_glob('osx/Resources/*')]