remove demo from this repo
diff --git a/demo/chatbuf.proto b/demo/chatbuf.proto
deleted file mode 100644
index 2b7d2ac..0000000
--- a/demo/chatbuf.proto
+++ /dev/null
@@ -1,14 +0,0 @@
-package SyncDemo;
-
-message ChatMessage {
- required string to = 1;
- required string from = 2;
- enum ChatMessageType {
- CHAT = 0;
- HELLO = 1;
- OTHER = 2;
- }
- required ChatMessageType type = 3 [default = CHAT];
- optional string data = 4;
- optional int32 timestamp = 5;
-}
diff --git a/demo/chatdialog.cpp b/demo/chatdialog.cpp
deleted file mode 100644
index 0f6e806..0000000
--- a/demo/chatdialog.cpp
+++ /dev/null
@@ -1,397 +0,0 @@
-#include <QtGui>
-#include "chatdialog.h"
-#include "settingdialog.h"
-#include <ctime>
-#include <iostream>
-#include <QTimer>
-#include <QMetaType>
-
-#define BROADCAST_PREFIX_FOR_SYNC_DEMO "/ndn/broadcast/sync-demo"
-
-void
-ChatDialog::testDraw()
-{
- std::string prefix[5] = {"/ndn/1", "/ndn/2", "/ndn/3", "/ndn/4", "/ndn/5"};
- std::string nick[5] = {"tom", "jerry", "jason", "michael", "hurry"};
- std::vector<Sync::MissingDataInfo> v;
- for (int i = 0; i < 5; i++)
- {
- Sync::MissingDataInfo mdi = {prefix[i], Sync::SeqNo(0), Sync::SeqNo(i * (2 << i) )};
- v.push_back(mdi);
- }
-
- m_scene->processUpdate(v, "12341234@!#%!@");
-
- for (int i = 0; i < 5; i++)
- {
- m_scene-> msgReceived(prefix[i].c_str(), nick[i].c_str());
- }
-
- fitView();
-}
-
-ChatDialog::ChatDialog(QWidget *parent)
- : QDialog(parent), m_sock(NULL)
-{
- // have to register this, otherwise
- // the signal-slot system won't recognize this type
- qRegisterMetaType<std::vector<Sync::MissingDataInfo> >("std::vector<Sync::MissingDataInfo>");
- qRegisterMetaType<size_t>("size_t");
- setupUi(this);
- m_session = time(NULL);
-
- readSettings();
-
- updateLabels();
-
- lineEdit->setFocusPolicy(Qt::StrongFocus);
- m_scene = new DigestTreeScene(this);
-
- treeViewer->setScene(m_scene);
- m_scene->plot("Empty");
- QRectF rect = m_scene->itemsBoundingRect();
- m_scene->setSceneRect(rect);
-
- // create sync socket
- if(!m_user.getChatroom().isEmpty()) {
- std::string syncPrefix = BROADCAST_PREFIX_FOR_SYNC_DEMO;
- syncPrefix += "/";
- syncPrefix += m_user.getChatroom().toStdString();
- try
- {
- m_sock = new Sync::SyncAppSocket(syncPrefix, bind(&ChatDialog::processTreeUpdateWrapper, this, _1, _2), bind(&ChatDialog::processRemove, this, _1));
- }
- catch (Sync::CcnxOperationException ex)
- {
- QMessageBox::critical(this, tr("Sync-Demo"), tr("Canno connect to ccnd.\n Have you started your ccnd?"), QMessageBox::Ok);
- std::exit(1);
- }
- }
-
- connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
- connect(setButton, SIGNAL(pressed()), this, SLOT(buttonPressed()));
- connect(this, SIGNAL(dataReceived(QString, const char *, size_t)), this, SLOT(processData(QString, const char *, size_t)));
- connect(this, SIGNAL(treeUpdated(const std::vector<Sync::MissingDataInfo>)), this, SLOT(processTreeUpdate(const std::vector<Sync::MissingDataInfo>)));
- //testDraw();
-}
-
-ChatDialog::~ChatDialog()
-{
- if (m_sock != NULL)
- {
- delete m_sock;
- m_sock = NULL;
- }
-}
-
-void
-ChatDialog::appendMessage(const SyncDemo::ChatMessage msg)
-{
- boost::mutex::scoped_lock lock(m_msgMutex);
-
- if (msg.type() != SyncDemo::ChatMessage::CHAT) {
- return;
- }
-
- if (!msg.has_data()) {
- return;
- }
-
- if (msg.from().empty() || msg.data().empty()) {
- return;
- }
-
- QTextCursor cursor(textEdit->textCursor());
- cursor.movePosition(QTextCursor::End);
- QTextTableFormat tableFormat;
- tableFormat.setBorder(0);
- QTextTable *table = cursor.insertTable(1, 2, tableFormat);
- QString from = QString("<%1>: ").arg(msg.from().c_str());
- table->cellAt(0, 0).firstCursorPosition().insertText(from);
- table->cellAt(0, 1).firstCursorPosition().insertText(msg.data().c_str());
- QScrollBar *bar = textEdit->verticalScrollBar();
- bar->setValue(bar->maximum());
-}
-
-void
-ChatDialog::processTreeUpdateWrapper(const std::vector<Sync::MissingDataInfo> v, Sync::SyncAppSocket *sock)
-{
- emit treeUpdated(v);
-#ifdef __DEBUG
- std::cout << "<<< Tree update signal emitted" << std::endl;
-#endif
-}
-
-void
-ChatDialog::processTreeUpdate(const std::vector<Sync::MissingDataInfo> v)
-{
-#ifdef __DEBUG
- std::cout << "<<< processing Tree Update" << std::endl;
-#endif
- if (v.empty())
- {
- return;
- }
-
- // reflect the changes on digest tree
- {
- boost::mutex::scoped_lock lock(m_sceneMutex);
- m_scene->processUpdate(v, m_sock->getRootDigest().c_str());
- }
-
- int n = v.size();
- int totalMissingPackets = 0;
- for (int i = 0; i < n; i++)
- {
- totalMissingPackets += v[i].high.getSeq() - v[i].low.getSeq() + 1;
- }
-
- if (totalMissingPackets < 10) {
- for (int i = 0; i < n; i++)
- {
- for (Sync::SeqNo seq = v[i].low; seq <= v[i].high; ++seq)
- {
- m_sock->fetchRaw(v[i].prefix, seq, bind(&ChatDialog::processDataWrapper, this, _1, _2, _3), 2);
-#ifdef __DEBUG
- std::cout << "<<< Fetching " << v[i].prefix << "/" <<seq.getSession() <<"/" << seq.getSeq() << std::endl;
-#endif
- }
- }
- }
- else
- {
- // too bad; too many missing packets
- // we may just join a new chatroom
- // or some network patition just healed
- // we don't try to fetch any data in this case (for now)
- }
-
- // adjust the view
- fitView();
-
-}
-
-void
-ChatDialog::processDataWrapper(std::string name, const char *buf, size_t len)
-{
- emit dataReceived(name.c_str(), buf, len);
-#ifdef __DEBUG
- std::cout <<"<<< " << name << " fetched" << std::endl;
-#endif
-}
-
-void
-ChatDialog::processData(QString name, const char *buf, size_t len)
-{
- SyncDemo::ChatMessage msg;
- if (!msg.ParseFromArray(buf, len))
- {
- std::cerr << "Errrrr.. Can not parse msg at "<<__FILE__ <<":"<<__LINE__<<". what is happening?" << std::endl;
- abort();
- }
-
- // display msg received from network
- // we have to do so; this function is called by ccnd thread
- // so if we call appendMsg directly
- // Qt crash as "QObject: Cannot create children for a parent that is in a different thread"
- // the "cannonical" way to is use signal-slot
- appendMessage(msg);
-
- // update the tree view
- std::string stdStrName = name.toStdString();
- std::string stdStrNameWithoutSeq = stdStrName.substr(0, stdStrName.find_last_of('/'));
- std::string prefix = stdStrNameWithoutSeq.substr(0, stdStrNameWithoutSeq.find_last_of('/'));
-#ifdef __DEBUG
- std::cout <<"<<< updating scene for" << prefix << ": " << msg.from() << std::endl;
-#endif
- {
- boost::mutex::scoped_lock lock(m_sceneMutex);
- m_scene->msgReceived(prefix.c_str(), msg.from().c_str());
- }
- fitView();
-}
-
-void
-ChatDialog::processRemove(std::string prefix)
-{
-}
-
-void
-ChatDialog::formChatMessage(const QString &text, SyncDemo::ChatMessage &msg) {
- msg.set_from(m_user.getNick().toStdString());
- msg.set_to(m_user.getChatroom().toStdString());
- msg.set_data(text.toStdString());
- time_t seconds = time(NULL);
- msg.set_timestamp(seconds);
- msg.set_type(SyncDemo::ChatMessage::CHAT);
-}
-
-bool
-ChatDialog::readSettings()
-{
-#ifndef __DEBUG
- QSettings s(ORGANIZATION, APPLICATION);
- QString nick = s.value("nick", "").toString();
- QString chatroom = s.value("chatroom", "").toString();
- QString prefix = s.value("prefix", "").toString();
- if (nick == "" || chatroom == "" || prefix == "") {
- QTimer::singleShot(500, this, SLOT(buttonPressed()));
- return false;
- }
- else {
- m_user.setNick(nick);
- m_user.setChatroom(chatroom);
- m_user.setPrefix(prefix);
- return true;
- }
-#else
- QTimer::singleShot(500, this, SLOT(buttonPressed()));
- return false;
-#endif
-}
-
-void
-ChatDialog::writeSettings()
-{
-#ifndef __DEBUG
- QSettings s(ORGANIZATION, APPLICATION);
- s.setValue("nick", m_user.getNick());
- s.setValue("chatroom", m_user.getChatroom());
- s.setValue("prefix", m_user.getPrefix());
-#endif
-}
-
-void
-ChatDialog::updateLabels()
-{
- QString settingDisp = QString("<User: %1>, <Chatroom: %2>").arg(m_user.getNick()).arg(m_user.getChatroom());
- infoLabel->setText(settingDisp);
- QString prefixDisp = QString("<Prefix: %1>").arg(m_user.getPrefix());
- prefixLabel->setText(prefixDisp);
-}
-
-void
-ChatDialog::returnPressed()
-{
- QString text = lineEdit->text();
- if (text.isEmpty())
- return;
-
- lineEdit->clear();
-
- SyncDemo::ChatMessage msg;
- formChatMessage(text, msg);
-
- appendMessage(msg);
-
- // send msg
- size_t size = msg.ByteSize();
- char *buf = new char[size];
- msg.SerializeToArray(buf, size);
- if (!msg.IsInitialized())
- {
- std::cerr << "Errrrr.. msg was not probally initialized "<<__FILE__ <<":"<<__LINE__<<". what is happening?" << std::endl;
- abort();
- }
- m_sock->publishRaw(m_user.getPrefix().toStdString(), m_session, buf, size, 60);
-
- int nextSequence = m_sock->getNextSeq(m_user.getPrefix().toStdString(), m_session);
- Sync::MissingDataInfo mdi = {m_user.getPrefix().toStdString(), Sync::SeqNo(0), Sync::SeqNo(nextSequence - 1)};
- std::vector<Sync::MissingDataInfo> v;
- v.push_back(mdi);
- {
- boost::mutex::scoped_lock lock(m_sceneMutex);
- m_scene->processUpdate(v, m_sock->getRootDigest().c_str());
- m_scene->msgReceived(m_user.getPrefix(), m_user.getNick());
- }
- fitView();
-}
-
-void
-ChatDialog::buttonPressed()
-{
- SettingDialog dialog(this, m_user.getNick(), m_user.getChatroom(), m_user.getPrefix());
- connect(&dialog, SIGNAL(updated(QString, QString, QString)), this, SLOT(settingUpdated(QString, QString, QString)));
- dialog.exec();
- QTimer::singleShot(100, this, SLOT(checkSetting()));
-}
-
-void
-ChatDialog::checkSetting()
-{
- if (m_user.getPrefix().isEmpty() || m_user.getNick().isEmpty() || m_user.getChatroom().isEmpty())
- {
- buttonPressed();
- }
-}
-
-void
-ChatDialog::settingUpdated(QString nick, QString chatroom, QString prefix)
-{
- bool needWrite = false;
- if (!nick.isEmpty() && nick != m_user.getNick()) {
- m_user.setNick(nick);
- needWrite = true;
- }
- if (!prefix.isEmpty() && prefix != m_user.getPrefix()) {
- m_user.setPrefix(prefix);
- needWrite = true;
- // TODO: set the previous prefix as left?
- }
- if (!chatroom.isEmpty() && chatroom != m_user.getChatroom()) {
- m_user.setChatroom(chatroom);
- needWrite = true;
-
- {
- boost::mutex::scoped_lock lock(m_sceneMutex);
- m_scene->clearAll();
- m_scene->plot("Empty");
- }
- // TODO: perhaps need to do a lot. e.g. use a new SyncAppSokcet
- if (m_sock != NULL)
- {
- delete m_sock;
- m_sock = NULL;
- }
- std::string syncPrefix = BROADCAST_PREFIX_FOR_SYNC_DEMO;
- syncPrefix += "/";
- syncPrefix += m_user.getChatroom().toStdString();
- try
- {
- m_sock = new Sync::SyncAppSocket(syncPrefix, bind(&ChatDialog::processTreeUpdateWrapper, this, _1, _2), bind(&ChatDialog::processRemove, this, _1));
- }
- catch (Sync::CcnxOperationException ex)
- {
- QMessageBox::critical(this, tr("Sync-Demo"), tr("Canno connect to ccnd.\n Have you started your ccnd?"), QMessageBox::Ok);
- std::exit(1);
- }
-
- fitView();
-
- }
- if (needWrite) {
- writeSettings();
- updateLabels();
- }
-}
-
-void
-ChatDialog::resizeEvent(QResizeEvent *e)
-{
- fitView();
-}
-
-void
-ChatDialog::showEvent(QShowEvent *e)
-{
- fitView();
-}
-
-void
-ChatDialog::fitView()
-{
- boost::mutex::scoped_lock lock(m_sceneMutex);
- QRectF rect = m_scene->itemsBoundingRect();
- m_scene->setSceneRect(rect);
- treeViewer->fitInView(m_scene->itemsBoundingRect(), Qt::KeepAspectRatio);
-}
diff --git a/demo/chatdialog.h b/demo/chatdialog.h
deleted file mode 100644
index e5e0c34..0000000
--- a/demo/chatdialog.h
+++ /dev/null
@@ -1,60 +0,0 @@
-#ifndef CHATDIALOG_H
-#define CHATDIALOG_H
-#include <boost/function.hpp>
-#include <boost/thread/mutex.hpp>
-#include <vector>
-#include "digesttreescene.h"
-#include "ui_chatdialog.h"
-#include "chatbuf.pb.h"
-#include <sync-app-socket.h>
-#include <sync-logic.h>
-#include <sync-seq-no.h>
-
-#define ORGANIZATION "IRL@UCLA"
-#define APPLICATION "SYNC-DEMO"
-
-class ChatDialog : public QDialog, private Ui::ChatDialog
-{
- Q_OBJECT
-
-public:
- ChatDialog(QWidget *parent = 0);
- ~ChatDialog();
- void processRemove(const std::string);
- void appendMessage(const SyncDemo::ChatMessage msg);
- void processTreeUpdateWrapper(const std::vector<Sync::MissingDataInfo>, Sync::SyncAppSocket *);
- void processDataWrapper(std::string, const char *buf, size_t len);
-
-public slots:
- void processTreeUpdate(const std::vector<Sync::MissingDataInfo>);
- void processData(QString name, const char *buf, size_t len);
-
-private:
- void formChatMessage(const QString &text, SyncDemo::ChatMessage &msg);
- bool readSettings();
- void writeSettings();
- void updateLabels();
- void resizeEvent(QResizeEvent *);
- void showEvent(QShowEvent *);
- void fitView();
- void testDraw();
-
-private slots:
- void returnPressed();
- void buttonPressed();
- void checkSetting();
- void settingUpdated(QString, QString, QString);
-
-signals:
- void dataReceived(QString name, const char *buf, size_t len);
- void treeUpdated(const std::vector<Sync::MissingDataInfo>);
-
-private:
- User m_user;
- Sync::SyncAppSocket *m_sock;
- uint32_t m_session;
- DigestTreeScene *m_scene;
- boost::mutex m_msgMutex;
- boost::mutex m_sceneMutex;
-};
-#endif
diff --git a/demo/chatdialog.ui b/demo/chatdialog.ui
deleted file mode 100644
index 9e659ab..0000000
--- a/demo/chatdialog.ui
+++ /dev/null
@@ -1,121 +0,0 @@
-<ui version="4.0">
- <class>ChatDialog</class>
- <widget class="QDialog" name="ChatDialog">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>600</width>
- <height>600</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Sync Demo</string>
- </property>
- <layout class="QVBoxLayout">
- <property name="spacing">
- <number>6</number>
- </property>
- <item>
- <layout class="QVBoxLayout">
- <property name="margin">
- <number>0</number>
- </property>
- <property name="spacing">
- <number>6</number>
- </property>
- <item >
- <layout class="QHBoxLayout">
- <property name="margin">
- <number>0</number>
- </property>
- <property name="spacing">
- <number>6</number>
- </property>
- <item>
- <layout class = "QVBoxLayout" >
- <property name="margin">
- <number>0</number>
- </property>
- <property name="spacing">
- <number>6</number>
- </property>
- <item>
- <widget class="QLabel" name="infoLabel">
- <property name="focusPolicy">
- <enum>Qt::NoFocus</enum>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLabel" name="prefixLabel">
- <property name="focusPolicy">
- <enum>Qt::NoFocus</enum>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <widget class="QPushButton" name="setButton">
- <property name="focusPolicy">
- <enum>Qt::NoFocus</enum>
- </property>
- <property name="text">
- <string>Settings</string>
- </property>
- <property name="minimumWidth">
- <number>150</number>
- </property>
- <property name="maximumWidth">
- <number>150</number>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <widget class="QGraphicsView" name="treeViewer">
- <property name="focusPolicy">
- <enum>Qt::NoFocus</enum>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QTextEdit" name="textEdit">
- <property name="focusPolicy">
- <enum>Qt::NoFocus</enum>
- </property>
- <property name="readOnly">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <layout class="QHBoxLayout">
- <property name="margin">
- <number>0</number>
- </property>
- <property name="spacing">
- <number>6</number>
- </property>
- <item>
- <widget class="QLabel" name="label">
- <property name="text">
- <string>Message:</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLineEdit" name="lineEdit" />
- </item>
- </layout>
- </item>
- </layout>
- </widget>
- <resources/>
- <connections/>
-</ui>
-
diff --git a/demo/digesttreescene.cpp b/demo/digesttreescene.cpp
deleted file mode 100644
index 30c087e..0000000
--- a/demo/digesttreescene.cpp
+++ /dev/null
@@ -1,243 +0,0 @@
-#include <QtGui>
-#include <vector>
-#include <iostream>
-#include <assert.h>
-#include <boost/lexical_cast.hpp>
-#include <memory>
-#include "digesttreescene.h"
-
-static const double Pi = 3.14159265358979323846264338327950288419717;
-
-
-DigestTreeScene::DisplayUserPtr DigestTreeScene::DisplayUserNullPtr;
-
-DigestTreeScene::DigestTreeScene(QWidget *parent)
- : QGraphicsScene(parent)
-{
- previouslyUpdatedUser = DisplayUserNullPtr;
-}
-
-void
-DigestTreeScene::processUpdate(const std::vector<Sync::MissingDataInfo> &v, QString digest)
-{
- int n = v.size();
- bool rePlot = false;
- for (int i = 0; i < n; i++)
- {
- Roster_iterator it = m_roster.find(v[i].prefix.c_str());
- if (it == m_roster.end())
- {
- rePlot = true;
- DisplayUserPtr p(new DisplayUser());
- p->setPrefix(v[i].prefix.c_str());
- p->setSeq(v[i].high);
- m_roster.insert(p->getPrefix(), p);
- }
- else
- {
- it.value()->setSeq(v[i].high);
- }
- }
-
- if (rePlot)
- {
- plot(digest);
- }
- else
- {
- for (int i = 0; i < n; i++)
- {
- Roster_iterator it = m_roster.find(v[i].prefix.c_str());
- if (it != m_roster.end()) {
- DisplayUserPtr p = it.value();
- QGraphicsTextItem *item = p->getSeqTextItem();
- QGraphicsRectItem *rectItem = p->getInnerRectItem();
- std::string s = boost::lexical_cast<std::string>(p->getSeqNo().getSeq());
- item->setPlainText(s.c_str());
- QRectF textBR = item->boundingRect();
- QRectF rectBR = rectItem->boundingRect();
- item->setPos(rectBR.x() + (rectBR.width() - textBR.width())/2, rectBR.y() + (rectBR.height() - textBR.height())/2);
- }
- }
- m_rootDigest->setPlainText(digest);
- }
-}
-
-void
-DigestTreeScene::msgReceived(QString prefix, QString nick)
-{
-#ifdef __DEBUG
- std::cout << "Finding " << prefix.toStdString() << std::endl;
-#endif
- Roster_iterator it = m_roster.find(prefix);
- if (it != m_roster.end())
- {
- DisplayUserPtr p = it.value();
- if (nick != p->getNick()) {
- p->setNick(nick);
- QGraphicsTextItem *nickItem = p->getNickTextItem();
- QGraphicsRectItem *nickRectItem = p->getNickRectItem();
- nickItem->setPlainText(p->getNick());
- QRectF rectBR = nickRectItem->boundingRect();
- QRectF nickBR = nickItem->boundingRect();
- nickItem->setPos(rectBR.x() + (rectBR.width() - nickBR.width())/2, rectBR.y() + 5);
- }
-
- reDrawNode(p, Qt::red);
-
- if (previouslyUpdatedUser != DisplayUserNullPtr && previouslyUpdatedUser != p)
- {
- reDrawNode(previouslyUpdatedUser, Qt::darkBlue);
- }
-
- previouslyUpdatedUser = p;
- }
-#ifdef __DEBUG
- else
- {
- std::cout << "Couldn't find prefix, let's check"<< std::endl;
- Roster_iterator ii = m_roster.begin();
- while (ii != m_roster.end())
- {
- std::cout <<"Prefix: " << ii.key().toStdString() << std::endl;
- ++ii;
- }
- }
-#endif
-}
-
-void
-DigestTreeScene::clearAll()
-{
- clear();
- m_roster.clear();
-}
-
-void
-DigestTreeScene::plot(QString digest)
-{
- clear();
-
- int nodeSize = 40;
-
- int siblingDistance = 100, levelDistance = 100;
- std::auto_ptr<TreeLayout> layout(new OneLevelTreeLayout());
- layout->setSiblingDistance(siblingDistance);
- layout->setLevelDistance(levelDistance);
-
- int n = m_roster.size();
- std::vector<TreeLayout::Coordinate> childNodesCo(n);
-
- layout->setOneLevelLayout(childNodesCo);
-
- plotEdge(childNodesCo, nodeSize);
- plotNode(childNodesCo, digest, nodeSize);
-
- previouslyUpdatedUser = DisplayUserNullPtr;
-
-}
-
-void
-DigestTreeScene::plotEdge(const std::vector<TreeLayout::Coordinate> &childNodesCo, int nodeSize)
-{
- int n = childNodesCo.size();
- for (int i = 0; i < n; i++) {
- double x1 = 0.0, y1 = 0.0;
- double x2 = childNodesCo[i].x, y2 = childNodesCo[i].y;
- QPointF src(x1 + nodeSize/2, y1 + nodeSize/2);
- QPointF dest(x2 + nodeSize/2, y2 + nodeSize/2);
- QLineF line(src, dest);
- double angle = ::acos(line.dx() / line.length());
-
- double arrowSize = 10;
- QPointF sourceArrowP0 = src + QPointF((nodeSize/2 + 10) * line.dx() / line.length(), (nodeSize/2 +10) * line.dy() / line.length());
- QPointF sourceArrowP1 = sourceArrowP0 + QPointF(cos(angle + Pi / 3 - Pi/2) * arrowSize,
- sin(angle + Pi / 3 - Pi/2) * arrowSize);
- QPointF sourceArrowP2 = sourceArrowP0 + QPointF(cos(angle + Pi - Pi / 3 - Pi/2) * arrowSize,
- sin(angle + Pi - Pi / 3 - Pi/2) * arrowSize);
-
- addLine(QLineF(sourceArrowP0, dest), QPen(Qt::black));
- addPolygon(QPolygonF() << sourceArrowP0<< sourceArrowP1 << sourceArrowP2, QPen(Qt::black), QBrush(Qt::black));
- }
-}
-
-void
-DigestTreeScene::plotNode(const std::vector<TreeLayout::Coordinate> &childNodesCo, QString digest, int nodeSize)
-{
- RosterIterator it(m_roster);
- int n = childNodesCo.size();
- int rim = 3;
-
- // plot root node
- QRectF rootBoundingRect(0, 0, nodeSize, nodeSize);
- QRectF rootInnerBoundingRect(rim, rim, nodeSize - rim * 2, nodeSize - rim * 2);
- addRect(rootBoundingRect, QPen(Qt::black), QBrush(Qt::darkRed));
- addRect(rootInnerBoundingRect, QPen(Qt::black), QBrush(Qt::lightGray));
- QRectF digestRect(- 5.5 * nodeSize , - nodeSize, 12 * nodeSize, 30);
- addRect(digestRect, QPen(Qt::darkCyan), QBrush(Qt::darkCyan));
-
- QGraphicsTextItem *digestItem = addText(digest);
- QRectF digestBoundingRect = digestItem->boundingRect();
- digestItem->setDefaultTextColor(Qt::black);
- digestItem->setFont(QFont("Cursive", 12, QFont::Bold));
- digestItem->setPos(- 4.5 * nodeSize + (12 * nodeSize - digestBoundingRect.width()) / 2, - nodeSize + 5);
- m_rootDigest = digestItem;
-
- // plot child nodes
- for (int i = 0; i < n; i++)
- {
- if (it.hasNext())
- {
- it.next();
- }
- else
- {
- abort();
- }
-
- double x = childNodesCo[i].x;
- double y = childNodesCo[i].y;
- QRectF boundingRect(x, y, nodeSize, nodeSize);
- QRectF innerBoundingRect(x + rim, y + rim, nodeSize - rim * 2, nodeSize - rim * 2);
- DisplayUserPtr p = it.value();
- QGraphicsRectItem *rectItem = addRect(boundingRect, QPen(Qt::black), QBrush(Qt::darkBlue));
- p->setRimRectItem(rectItem);
-
- QGraphicsRectItem *innerRectItem = addRect(innerBoundingRect, QPen(Qt::black), QBrush(Qt::lightGray));
- p->setInnerRectItem(innerRectItem);
-
- std::string s = boost::lexical_cast<std::string>(p->getSeqNo().getSeq());
- QGraphicsTextItem *seqItem = addText(s.c_str());
- seqItem->setFont(QFont("Cursive", 12, QFont::Bold));
- QRectF seqBoundingRect = seqItem->boundingRect();
- seqItem->setPos(x + nodeSize / 2 - seqBoundingRect.width() / 2, y + nodeSize / 2 - seqBoundingRect.height() / 2);
- p->setSeqTextItem(seqItem);
-
- QRectF textRect(x - nodeSize / 2, y + nodeSize, 2 * nodeSize, 30);
- QGraphicsRectItem *nickRectItem = addRect(textRect, QPen(Qt::darkCyan), QBrush(Qt::darkCyan));
- p->setNickRectItem(nickRectItem);
- QGraphicsTextItem *nickItem = addText(p->getNick());
- QRectF textBoundingRect = nickItem->boundingRect();
- nickItem->setDefaultTextColor(Qt::white);
- nickItem->setFont(QFont("Cursive", 12, QFont::Bold));
- nickItem->setPos(x + nodeSize / 2 - textBoundingRect.width() / 2, y + nodeSize + 5);
- p->setNickTextItem(nickItem);
- }
-
-}
-
-void
-DigestTreeScene::reDrawNode(DisplayUserPtr p, QColor rimColor)
-{
- QGraphicsRectItem *rimItem = p->getRimRectItem();
- rimItem->setBrush(QBrush(rimColor));
- QGraphicsRectItem *innerItem = p->getInnerRectItem();
- innerItem->setBrush(QBrush(Qt::lightGray));
- QGraphicsTextItem *seqTextItem = p->getSeqTextItem();
- std::string s = boost::lexical_cast<std::string>(p->getSeqNo().getSeq());
- seqTextItem->setPlainText(s.c_str());
- QRectF textBR = seqTextItem->boundingRect();
- QRectF innerBR = innerItem->boundingRect();
- seqTextItem->setPos(innerBR.x() + (innerBR.width() - textBR.width())/2, innerBR.y() + (innerBR.height() - textBR.height())/2);
-}
-
diff --git a/demo/digesttreescene.h b/demo/digesttreescene.h
deleted file mode 100644
index f041b11..0000000
--- a/demo/digesttreescene.h
+++ /dev/null
@@ -1,92 +0,0 @@
-#ifndef DIGESTTREESCENE_H
-#define DIGESTTREESCENE_H
-
-#include <QtGui/QGraphicsScene>
-#include <sync-seq-no.h>
-#include <sync-logic.h>
-#include <ctime>
-#include <QMap>
-#include <vector>
-#include <tr1/memory>
-#include <QColor>
-#include "treelayout.h"
-
-class QGraphicsTextItem;
-
-class User;
-class DisplayUser;
-
-class DigestTreeScene : public QGraphicsScene
-{
- Q_OBJECT
-
-typedef std::tr1::shared_ptr<DisplayUser> DisplayUserPtr;
-typedef QMap<QString, DisplayUserPtr> Roster;
-typedef QMap<QString, DisplayUserPtr>::iterator Roster_iterator;
-typedef QMapIterator<QString, DisplayUserPtr> RosterIterator;
-static DisplayUserPtr DisplayUserNullPtr;
-
-public:
- DigestTreeScene(QWidget *parent = 0);
- void processUpdate(const std::vector<Sync::MissingDataInfo> &v, QString digest);
- void msgReceived(QString prefix, QString nick);
- void clearAll();
- void plot(QString digest);
-private:
- void plotEdge(const std::vector<TreeLayout::Coordinate> &v, int nodeSize);
- void plotNode(const std::vector<TreeLayout::Coordinate> &v, QString digest, int nodeSize);
- void reDrawNode(DisplayUserPtr p, QColor rimColor);
-private:
- Roster m_roster;
- QGraphicsTextItem *m_rootDigest;
- DisplayUserPtr previouslyUpdatedUser;
-
-};
-
-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() {m_received = time(NULL);}
- QString getNick() { return m_nick;}
- QString getPrefix() { return m_prefix;}
- QString getChatroom() { return m_chatroom;}
- Sync::SeqNo getSeqNo() { return m_seq;}
- time_t getReceived() { return m_received;}
-private:
- QString m_nick;
- QString m_prefix;
- QString m_chatroom;
- 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;
-};
-
-#endif
diff --git a/demo/main.cpp b/demo/main.cpp
deleted file mode 100644
index 6b73923..0000000
--- a/demo/main.cpp
+++ /dev/null
@@ -1,12 +0,0 @@
-#include<QApplication>
-#include "chatdialog.h"
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
-
- ChatDialog dialog;
- dialog.show();
- dialog.activateWindow();
- return app.exec();
-}
diff --git a/demo/settingdialog.cpp b/demo/settingdialog.cpp
deleted file mode 100644
index 8f0bbca..0000000
--- a/demo/settingdialog.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-#include "settingdialog.h"
-#include <QRegExp>
-#include <QValidator>
-
-SettingDialog::SettingDialog(QWidget *parent, QString nick, QString chatroom, QString prefix)
- : QDialog(parent)
-{
- setupUi(this);
-
- QRegExp noWhiteSpace("^\\S+.*$");
- QValidator *nwsValidator = new QRegExpValidator(noWhiteSpace, this);
- nickEdit->setPlaceholderText(nick);
- nickEdit->setValidator(nwsValidator);
- roomEdit->setPlaceholderText(chatroom);
- roomEdit->setValidator(nwsValidator);
- prefixEdit->setPlaceholderText(prefix);
-
- // simple validator for ccnx prefix
- QRegExp rx("(^(/[^/]+)+$)|(^/$)");
- QValidator *validator = new QRegExpValidator(rx, this);
- prefixEdit->setValidator(validator);
-
- okButton->setDefault(true);
-
- connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
- connect(okButton, SIGNAL(clicked()), this, SLOT(update()));
-}
-
-void
-SettingDialog::update()
-{
- emit updated(nickEdit->text(), roomEdit->text(), prefixEdit->text());
- accept();
-}
-
-void
-SettingDialog::keyPressEvent(QKeyEvent *e)
-{
- switch(e->key()) {
- case Qt::Key_Enter:
- update();
- break;
- default:
- QDialog::keyPressEvent(e);
- }
-}
diff --git a/demo/settingdialog.h b/demo/settingdialog.h
deleted file mode 100644
index f9fc31c..0000000
--- a/demo/settingdialog.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef SETTINGDIALOG_H
-#define SETTINGDIALOG_H
-#include "ui_settingdialog.h"
-#include <QKeyEvent>
-
-class SettingDialog : public QDialog, private Ui::SettingDialog
-{
- Q_OBJECT
-
-public:
- SettingDialog(QWidget *parent = 0, QString nick = QString("NULL"), QString chatroom = QString("NULL"), QString prefix = QString("NULL"));
- virtual void keyPressEvent(QKeyEvent *e);
-
-private slots:
- void update();
-
-signals:
- void updated(QString, QString, QString);
-
-};
-
-#endif
diff --git a/demo/settingdialog.ui b/demo/settingdialog.ui
deleted file mode 100644
index b848aa9..0000000
--- a/demo/settingdialog.ui
+++ /dev/null
@@ -1,112 +0,0 @@
-<ui version="4.0">
- <class>SettingDialog</class>
- <widget class="QDialog" name="SettingDialog">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>300</width>
- <height>200</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Chat Settings</string>
- </property>
- <layout class="QVBoxLayout">
- <property name="spacing">
- <number>6</number>
- </property>
- <item>
- <layout class="QHBoxLayout">
- <property name="spacing">
- <number>6</number>
- </property>
- <!-- first group -->
- <item>
- <layout class="QVBoxLayout">
- <property name="spacing">
- <number>6</number>
- </property>
- <item>
- <widget class="QLabel">
- <property name="text">
- <string>Nickname</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLabel">
- <property name="text">
- <string>Chatroom</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLabel">
- <property name="text">
- <string>Prefix</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <!-- first group -->
-
- <!-- second group -->
- <item>
- <layout class="QVBoxLayout">
- <property name="spacing">
- <number>6</number>
- </property>
- <item>
- <widget class="QLineEdit" name="nickEdit">
- <property name="maxLength">
- <number>200</number>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLineEdit" name="roomEdit">
- <property name="maxLength">
- <number>200</number>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLineEdit" name="prefixEdit">
- <property name="maxLength">
- <number>200</number>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <!-- second group -->
- </layout>
- </item>
- <item>
- <layout class="QHBoxLayout">
- <property name="spacing">
- <number>6</number>
- </property>
- <item>
- <widget class="QPushButton" name="cancelButton">
- <property name="text">
- <string>Cancel</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="okButton">
- <property name="text">
- <string>OK</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
- </widget>
- <resources/>
- <connections/>
-</ui>
diff --git a/demo/sync-demo.pri b/demo/sync-demo.pri
deleted file mode 100644
index 3ff4309..0000000
--- a/demo/sync-demo.pri
+++ /dev/null
@@ -1,18 +0,0 @@
-PROTOPATH += .
-PROTOPATHS =
-for(p, PROTOPATH):PROTOPATHS += --proto_path=$${p}
-
-protobuf_decl.name = protobuf header
-protobuf_decl.input = PROTOS
-protobuf_decl.output = ${QMAKE_FILE_BASE}.pb.h
-protobuf_decl.commands = protoc --cpp_out="." $${PROTOPATHS} ${QMAKE_FILE_NAME}
-protobuf_decl.variable_out = GENERATED_FILES
-QMAKE_EXTRA_COMPILERS += protobuf_decl
-
-protobuf_impl.name = protobuf implementation
-protobuf_impl.input = PROTOS
-protobuf_impl.output = ${QMAKE_FILE_BASE}.pb.cc
-protobuf_impl.depends = ${QMAKE_FILE_BASE}.pb.h
-protobuf_impl.commands = $$escape_expand(\\n)
-protobuf_impl.variable_out = GENERATED_SOURCES
-QMAKE_EXTRA_COMPILERS += protobuf_impl
diff --git a/demo/sync-demo.pro b/demo/sync-demo.pro
deleted file mode 100644
index 24fcdd1..0000000
--- a/demo/sync-demo.pro
+++ /dev/null
@@ -1,27 +0,0 @@
-TEMPLATE = app
-TARGET = sync-demo
-DEFINES += __DEBUG
-HEADERS = chatdialog.h \
- digesttreescene.h \
- settingdialog.h \
- treelayout.h
-
-SOURCES = main.cpp \
- chatdialog.cpp \
- digesttreescene.cpp \
- settingdialog.cpp \
- treelayout.cpp
-
-FORMS = chatdialog.ui \
- settingdialog.ui
-
-QMAKE_CXXFLAGS *= -g
-QMAKE_CFLAGS *= -g
-
-QMAKE_LIBDIR *= /opt/local/lib /usr/local/lib /usr/lib ../build
-INCLUDEPATH *= /opt/local/include /usr/local/include ../include
-LIBS *= -lccn -lssl -lcrypto -lpthread -lprotobuf -lsync
-CONFIG += console
-
-PROTOS = chatbuf.proto
-include (sync-demo.pri)
diff --git a/demo/treelayout.cpp b/demo/treelayout.cpp
deleted file mode 100644
index 0a40484..0000000
--- a/demo/treelayout.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-#include "treelayout.h"
-
-void
-OneLevelTreeLayout::setOneLevelLayout(std::vector<Coordinate> &childNodesCo)
-{
- if (childNodesCo.empty())
- {
- return;
- }
- double y = getLevelDistance();
- double sd = getSiblingDistance();
- int n = childNodesCo.size();
- double x = - (n - 1) * sd / 2;
- for (int i = 0; i < n; i++)
- {
- childNodesCo[i].x = x;
- childNodesCo[i].y = y;
- x += sd;
- }
-}
diff --git a/demo/treelayout.h b/demo/treelayout.h
deleted file mode 100644
index 498210c..0000000
--- a/demo/treelayout.h
+++ /dev/null
@@ -1,32 +0,0 @@
-#ifndef TREELAYOUT_H
-#define TREELAYOUT_H
-#include <vector>
-
-class TreeLayout
-{
-public:
- struct Coordinate
- {
- double x;
- double y;
- };
- TreeLayout(){}
- virtual void setOneLevelLayout(std::vector<Coordinate> &childNodesCo){};
- void setSiblingDistance(int d) {m_siblingDistance = d;}
- void setLevelDistance(int d) {m_levelDistance = d;}
- int getSiblingDistance() {return m_siblingDistance;}
- int getLevelDistance() {return m_levelDistance;}
- virtual ~TreeLayout(){}
-private:
- int m_siblingDistance;
- int m_levelDistance;
-};
-
-class OneLevelTreeLayout: public TreeLayout
-{
-public:
- OneLevelTreeLayout(){}
- virtual void setOneLevelLayout(std::vector<Coordinate> &childNodesCo);
- virtual ~OneLevelTreeLayout(){}
-};
-#endif