bug+codestyle: Fix compile bugs and adjust code style

Change-Id: I008bb538441c099fa25b8b967fbf23ffce13a220
diff --git a/src/chat-dialog.hpp b/src/chat-dialog.hpp
new file mode 100644
index 0000000..12051f1
--- /dev/null
+++ b/src/chat-dialog.hpp
@@ -0,0 +1,352 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013, Regents of the University of California
+ *
+ * BSD license, See the LICENSE file for more information
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ *         Yingdi Yu <yingdi@cs.ucla.edu>
+ */
+
+#ifndef CHRONOS_CHAT_DIALOG_HPP
+#define CHRONOS_CHAT_DIALOG_HPP
+
+#include <QDialog>
+#include <QTextTable>
+#include <QStringListModel>
+#include <QSystemTrayIcon>
+#include <QMenu>
+#include <QTimer>
+
+#ifndef Q_MOC_RUN
+#include "common.hpp"
+#include "contact-manager.hpp"
+#include "invitation.hpp"
+#include "contact.hpp"
+#include "chatbuf.pb.h"
+#include "intro-cert-list.pb.h"
+#include "digest-tree-scene.hpp"
+#include "trust-tree-scene.hpp"
+#include "trust-tree-node.hpp"
+#include "validator-invitation.hpp"
+#include <sync-socket.h>
+#include <sync-seq-no.h>
+#include <ndn-cxx/security/key-chain.hpp>
+#include <boost/thread/locks.hpp>
+#include <boost/thread/recursive_mutex.hpp>
+#include <boost/thread/thread.hpp>
+#endif
+
+#include "invite-list-dialog.hpp"
+
+
+#define MAX_HISTORY_ENTRY   20
+
+namespace Ui {
+class ChatDialog;
+}
+
+namespace chronos {
+
+class ChatDialog : public QDialog
+{
+  Q_OBJECT
+
+public:
+  explicit
+  ChatDialog(ContactManager* contactManager,
+             shared_ptr<ndn::Face> face,
+             const ndn::IdentityCertificate& myCertificate,
+             const Name& chatroomPrefix,
+             const Name& localPrefix,
+             const std::string& nick,
+             bool witSecurity,
+             QWidget* parent = 0);
+
+  ~ChatDialog();
+
+  void
+  addSyncAnchor(const Invitation& invitation);
+
+  void
+  processTreeUpdateWrapper(const std::vector<Sync::MissingDataInfo>&, Sync::SyncSocket *);
+
+  void
+  processDataWrapper(const shared_ptr<const Data>& data);
+
+  void
+  processDataNoShowWrapper(const shared_ptr<const Data>& data);
+
+  void
+  processRemoveWrapper(const std::string& prefix);
+
+protected:
+  void
+  closeEvent(QCloseEvent* e);
+
+  void
+  changeEvent(QEvent* e);
+
+  void
+  resizeEvent(QResizeEvent* e);
+
+  void
+  showEvent(QShowEvent* e);
+
+private:
+  void
+  updatePrefix();
+
+  void
+  updateLabels();
+
+  void
+  initializeSync();
+
+  void
+  sendInvitation(shared_ptr<Contact> contact, bool isIntroducer);
+
+  void
+  replyWrapper(const Interest& interest, Data& data,
+               size_t routablePrefixOffset, bool isIntroducer);
+
+  void
+  replyTimeoutWrapper(const Interest& interest,
+                      size_t routablePrefixOffset);
+
+  void
+  onReplyValidated(const shared_ptr<const Data>& data,
+                   size_t inviteeRoutablePrefixOffset,
+                   bool isIntroduce);
+
+  void
+  onReplyValidationFailed(const shared_ptr<const Data>& data,
+                          const std::string& failureInfo);
+
+  void
+  invitationRejected(const Name& identity);
+
+  void
+  invitationAccepted(const ndn::IdentityCertificate& inviteeCert,
+                     const Name& inviteePrefix, bool isIntroducer);
+
+  void
+  fetchIntroCert(const Name& identity, const Name& prefix);
+
+  void
+  onIntroCertList(const Interest& interest, const Data& data);
+
+  void
+  onIntroCertListTimeout(const Interest& interest, int retry, const std::string& msg);
+
+  void
+  introCertWrapper(const Interest& interest, Data& data);
+
+  void
+  introCertTimeoutWrapper(const Interest& interest, int retry, const QString& msg);
+
+  void
+  onCertListInterest(const Name& prefix, const Interest& interest);
+
+  void
+  onCertListRegisterFailed(const Name& prefix, const std::string& msg);
+
+  void
+  onCertSingleInterest(const Name& prefix, const Interest& interest);
+
+  void
+  onCertSingleRegisterFailed(const Name& prefix, const std::string& msg);
+
+
+  void
+  sendMsg(SyncDemo::ChatMessage& msg);
+
+  void
+  disableSyncTreeDisplay();
+
+  void
+  appendMessage(const SyncDemo::ChatMessage msg, bool isHistory = false);
+
+  void
+  processRemove(QString prefix);
+
+  ndn::Name
+  getInviteeRoutablePrefix(const Name& invitee);
+
+  void
+  formChatMessage(const QString& text, SyncDemo::ChatMessage& msg);
+
+  void
+  formControlMessage(SyncDemo::ChatMessage &msg, SyncDemo::ChatMessage::ChatMessageType type);
+
+  QString
+  formatTime(time_t timestamp);
+
+  void
+  printTimeInCell(QTextTable* table, time_t timestamp);
+
+  std::string
+  getRandomString();
+
+  void
+  showMessage(const QString&, const QString&);
+
+  void
+  fitView();
+
+  void
+  summonReaper();
+
+  void
+  getTree(TrustTreeNodeList& nodeList);
+
+  void
+  plotTrustTree();
+
+signals:
+  void
+  processData(const shared_ptr<const Data>& data, bool show, bool isHistory);
+
+  void
+  processTreeUpdate(const std::vector<Sync::MissingDataInfo>);
+
+  void
+  closeChatDialog(const QString& chatroomName);
+
+  void
+  inivationRejection(const QString& msg);
+
+  void
+  showChatMessage(const QString& chatroomName, const QString& from, const QString& data);
+
+  void
+  resetIcon();
+
+  void
+  reply(const Interest& interest, const shared_ptr<const Data>& data,
+        size_t routablePrefixOffset, bool isIntroducer);
+
+  void
+  replyTimeout(const Interest& interest, size_t routablePrefixOffset);
+
+  void
+  introCert(const Interest& interest, const shared_ptr<const Data>& data);
+
+  void
+  introCertTimeout(const Interest& interest, int retry, const QString& msg);
+
+  void
+  waitForContactList();
+
+public slots:
+  void
+  onLocalPrefixUpdated(const QString& localPrefix);
+
+  void
+  onClose();
+
+private slots:
+  void
+  onReturnPressed();
+
+  void
+  onSyncTreeButtonPressed();
+
+  void
+  onTrustTreeButtonPressed();
+
+  void
+  onProcessData(const shared_ptr<const Data>& data, bool show, bool isHistory);
+
+  void
+  onProcessTreeUpdate(const std::vector<Sync::MissingDataInfo>&);
+
+  void
+  onReplot();
+
+  void
+  onRosterChanged(QStringList staleUserList);
+
+  void
+  onInviteListDialogRequested();
+
+  void
+  sendJoin();
+
+  void
+  sendHello();
+
+  void
+  sendLeave();
+
+  void
+  enableSyncTreeDisplay();
+
+  void
+  reap();
+
+  void
+  onSendInvitation(QString invitee);
+
+  void
+  onReply(const Interest& interest, const shared_ptr<const Data>& data,
+          size_t routablePrefixOffset, bool isIntroducer);
+
+  void
+  onReplyTimeout(const Interest& interest, size_t routablePrefixOffset);
+
+  void
+  onIntroCert(const Interest& interest, const shared_ptr<const Data>& data);
+
+  void
+  onIntroCertTimeout(const Interest& interest, int retry, const QString& msg);
+
+private:
+  Ui::ChatDialog *ui;
+  ndn::KeyChain m_keyChain;
+
+  ContactManager* m_contactManager;
+  shared_ptr<ndn::Face> m_face;
+
+  ndn::IdentityCertificate m_myCertificate;
+  Name m_identity;
+
+  Name m_certListPrefix;
+  const ndn::RegisteredPrefixId* m_certListPrefixId;
+  Name m_certSinglePrefix;
+  const ndn::RegisteredPrefixId* m_certSinglePrefixId;
+
+  std::string m_chatroomName;
+  Name m_chatroomPrefix;
+  Name m_localPrefix;
+  bool m_useRoutablePrefix;
+  Name m_chatPrefix;
+  Name m_localChatPrefix;
+  std::string m_nick;
+  DigestTreeScene *m_scene;
+  TrustTreeScene *m_trustScene;
+  QStringListModel *m_rosterModel;
+  QTimer* m_timer;
+
+
+  int64_t m_lastMsgTime;
+  int m_randomizedInterval;
+  bool m_joined;
+
+  Sync::SyncSocket *m_sock;
+  uint64_t m_session;
+  shared_ptr<ndn::SecRuleRelative> m_dataRule;
+
+  InviteListDialog* m_inviteListDialog;
+  shared_ptr<ValidatorInvitation> m_invitationValidator;
+
+  boost::recursive_mutex m_msgMutex;
+  boost::recursive_mutex m_sceneMutex;
+  QList<QString> m_zombieList;
+  int m_zombieIndex;
+};
+
+} // namespace chronos
+
+#endif // CHRONOS_CHAT_DIALOG_HPP