bug+codestyle: Fix compile bugs and adjust code style

Change-Id: I008bb538441c099fa25b8b967fbf23ffce13a220
diff --git a/src/digest-tree-scene.hpp b/src/digest-tree-scene.hpp
new file mode 100644
index 0000000..434ee07
--- /dev/null
+++ b/src/digest-tree-scene.hpp
@@ -0,0 +1,291 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013, Regents of the University of California
+ *                     Yingdi Yu
+ *
+ * BSD license, See the LICENSE file for more information
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef CHRONOS_DIGEST_TREE_SCENE_HPP
+#define CHRONOS_DIGEST_TREE_SCENE_HPP
+
+#include <QtGui/QGraphicsScene>
+#include <QColor>
+#include <QMap>
+
+#ifndef Q_MOC_RUN
+#include "tree-layout.hpp"
+#include <sync-seq-no.h>
+#include <sync-logic.h>
+#include <ctime>
+#include <vector>
+#include <boost/shared_ptr.hpp>
+#endif
+
+const int FRESHNESS = 60;
+
+class QGraphicsTextItem;
+
+namespace chronos {
+
+class User;
+class DisplayUser;
+typedef boost::shared_ptr<DisplayUser> DisplayUserPtr;
+static DisplayUserPtr DisplayUserNullPtr;
+
+class DigestTreeScene : public QGraphicsScene
+{
+  Q_OBJECT
+
+typedef QMap<QString, DisplayUserPtr> Roster;
+typedef QMap<QString, DisplayUserPtr>::iterator Roster_iterator;
+typedef QMapIterator<QString, DisplayUserPtr> RosterIterator;
+
+public:
+  DigestTreeScene(QWidget *parent = 0);
+
+  void
+  processUpdate(const std::vector<Sync::MissingDataInfo>& v, QString digest);
+
+  void
+  msgReceived(QString prefix, QString nick);
+
+  void
+  clearAll();
+
+  bool
+  removeNode(const QString prefix);
+
+  void
+  plot(QString digest);
+
+  QStringList
+  getRosterList();
+
+  void
+  setCurrentPrefix(QString prefix)
+  {
+    m_currentPrefix = prefix;
+  }
+
+  QMap<QString, DisplayUserPtr> getRosterFull()
+  {
+    return m_roster;
+  }
+
+signals:
+  void
+  replot();
+
+  void
+  rosterChanged(QStringList);
+
+private slots:
+  void
+  emitReplot();
+
+private:
+  void
+  plotEdge(const std::vector<chronos::TreeLayout::Coordinate>& v, int nodeSize);
+
+  void
+  plotNode(const std::vector<chronos::TreeLayout::Coordinate>& v, QString digest, int nodeSize);
+
+  void
+  reDrawNode(DisplayUserPtr p, QColor rimColor);
+
+  QString
+  trimRoutablePrefix(QString prefix);
+
+private:
+  Roster m_roster;
+  QGraphicsTextItem* m_rootDigest;
+  DisplayUserPtr previouslyUpdatedUser;
+  QString m_currentPrefix;
+};
+
+class User
+{
+public:
+  User()
+    :m_received(::time(NULL))
+  {
+  }
+
+  User(QString n, QString p, QString c)
+    : m_nick(n)
+    , m_prefix(p)
+    , m_chatroom(c)
+    , m_received(::time(NULL))
+  {
+  }
+
+  void
+  setNick(QString nick)
+  {
+    m_nick = nick;
+  }
+
+  void
+  setPrefix(QString prefix)
+  {
+    m_prefix = prefix;
+  }
+
+  void
+  setChatroom(QString chatroom)
+  {
+    m_chatroom = chatroom;
+  }
+
+  void
+  setSeq(Sync::SeqNo seq)
+  {
+    m_seq = seq;
+  }
+
+  void
+  setReceived(time_t t)
+  {
+    m_received = t;
+  }
+
+  void
+  setOriginPrefix(QString originPrefix)
+  {
+    m_originPrefix = originPrefix;
+  }
+
+  QString
+  getNick()
+  {
+    return m_nick;
+  }
+
+  QString getPrefix()
+  {
+    return m_prefix;
+  }
+
+  QString getChatroom()
+  {
+    return m_chatroom;
+  }
+
+  QString getOriginPrefix()
+  {
+    return m_originPrefix;
+  }
+
+  Sync::SeqNo
+  getSeqNo()
+  {
+    return m_seq;
+  }
+
+  time_t getReceived()
+  {
+    return m_received;
+  }
+
+private:
+  QString m_nick;
+  QString m_prefix;
+  QString m_chatroom;
+  QString m_originPrefix;
+  Sync::SeqNo m_seq;
+  time_t m_received;
+};
+
+class DisplayUser : public User
+{
+public:
+  DisplayUser()
+    : m_seqTextItem(NULL)
+    , m_nickTextItem(NULL)
+    , m_rimRectItem(NULL)
+  {
+  }
+
+  DisplayUser(QString n, QString p , QString c)
+    : User(n, p, c)
+    , m_seqTextItem(NULL)
+    , m_nickTextItem(NULL)
+    , m_rimRectItem(NULL)
+  {
+  }
+
+  QGraphicsTextItem*
+  getSeqTextItem()
+  {
+    return m_seqTextItem;
+  }
+
+  QGraphicsTextItem*
+  getNickTextItem()
+  {
+    return m_nickTextItem;
+  }
+
+  QGraphicsRectItem*
+  getRimRectItem()
+  {
+    return m_rimRectItem;
+  }
+
+  QGraphicsRectItem*
+  getInnerRectItem()
+  {
+    return m_innerRectItem;
+  }
+
+  QGraphicsRectItem*
+  getNickRectItem()
+  {
+    return m_nickRectItem;
+  }
+
+  void
+  setSeqTextItem(QGraphicsTextItem* item)
+  {
+    m_seqTextItem = item;
+  }
+
+  void
+  setNickTextItem(QGraphicsTextItem* item)
+  {
+    m_nickTextItem = item;
+  }
+
+  void
+  setRimRectItem(QGraphicsRectItem* item)
+  {
+    m_rimRectItem = item;
+  }
+
+  void
+  setInnerRectItem(QGraphicsRectItem* item)
+  {
+    m_innerRectItem = item;
+  }
+
+  void
+  setNickRectItem(QGraphicsRectItem* item)
+  {
+    m_nickRectItem = item;
+  }
+
+private:
+  QGraphicsTextItem* m_seqTextItem;
+  QGraphicsTextItem* m_nickTextItem;
+  QGraphicsRectItem* m_rimRectItem;
+  QGraphicsRectItem* m_innerRectItem;
+  QGraphicsRectItem* m_nickRectItem;
+};
+
+} // namespace chronos
+
+#endif // CHRONOS_DIGEST_TREE_SCENE_HPP