blob: c239a4928ad22277bdef87a757883619366387d9 [file] [log] [blame]
Yingdi Yu7989eb22013-10-31 17:38:22 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 * Yingdi Yu
5 *
6 * BSD license, See the LICENSE file for more information
7 *
8 * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
9 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
10 */
11
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070012#ifndef DIGESTTREESCENE_H
13#define DIGESTTREESCENE_H
14
Alexander Afanasyevf829f4d2013-05-07 15:59:36 -070015#include "treelayout.h"
16
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070017#include <QtGui/QGraphicsScene>
Alexander Afanasyevf829f4d2013-05-07 15:59:36 -070018#include <QColor>
19#include <QMap>
20
21#ifndef Q_MOC_RUN
Yingdi Yu3a014852014-02-11 22:54:11 -080022#include <ndn-cpp-dev/util/scheduler.hpp>
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070023#include <sync-seq-no.h>
24#include <sync-logic.h>
25#include <ctime>
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070026#include <vector>
Alexander Afanasyev4a979312013-11-07 15:30:05 -080027#include <boost/shared_ptr.hpp>
Alexander Afanasyevf829f4d2013-05-07 15:59:36 -070028#endif
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070029
Zhenkai Zhuc61dbc22012-10-08 11:36:37 -070030const int FRESHNESS = 60;
Zhenkai Zhu86df7412012-09-27 16:30:20 -070031
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070032class QGraphicsTextItem;
33
34class User;
35class DisplayUser;
Alexander Afanasyev4a979312013-11-07 15:30:05 -080036typedef boost::shared_ptr<DisplayUser> DisplayUserPtr;
Zhenkai Zhu7f52e1b2012-10-09 11:45:36 -070037static DisplayUserPtr DisplayUserNullPtr;
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070038
39class DigestTreeScene : public QGraphicsScene
40{
41 Q_OBJECT
42
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070043typedef QMap<QString, DisplayUserPtr> Roster;
44typedef QMap<QString, DisplayUserPtr>::iterator Roster_iterator;
45typedef QMapIterator<QString, DisplayUserPtr> RosterIterator;
46
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070047public:
Yingdi Yu3a014852014-02-11 22:54:11 -080048 DigestTreeScene(ndn::shared_ptr<boost::asio::io_service> ioService,
49 QWidget *parent = 0);
Zhenkai Zhu82a62752012-06-04 17:11:04 -070050 void processUpdate(const std::vector<Sync::MissingDataInfo> &v, QString digest);
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070051 void msgReceived(QString prefix, QString nick);
Zhenkai Zhu82a62752012-06-04 17:11:04 -070052 void clearAll();
Zhenkai Zhu591e8c32012-09-26 11:57:50 -070053 bool removeNode(const QString prefix);
Zhenkai Zhu86df7412012-09-27 16:30:20 -070054 void plot(QString digest);
Zhenkai Zhu6082ede2012-09-27 17:28:46 -070055 QStringList getRosterList();
Zhenkai Zhu716fe852012-10-08 18:27:55 -070056 void setCurrentPrefix(QString prefix) {m_currentPrefix = prefix;}
Zhenkai Zhu7f52e1b2012-10-09 11:45:36 -070057 QMap<QString, DisplayUserPtr> getRosterFull() { return m_roster;}
Zhenkai Zhu86df7412012-09-27 16:30:20 -070058
59signals:
60 void replot();
Zhenkai Zhu25e33e52012-09-28 13:00:07 -070061 void rosterChanged(QStringList);
Zhenkai Zhu86df7412012-09-27 16:30:20 -070062
63private slots:
64 void emitReplot();
65
Zhenkai Zhu82a62752012-06-04 17:11:04 -070066private:
Zhenkai Zhu21d75f92012-06-04 21:23:34 -070067 void plotEdge(const std::vector<TreeLayout::Coordinate> &v, int nodeSize);
68 void plotNode(const std::vector<TreeLayout::Coordinate> &v, QString digest, int nodeSize);
Zhenkai Zhud13acd02012-06-04 15:25:20 -070069 void reDrawNode(DisplayUserPtr p, QColor rimColor);
Yingdi Yu3a014852014-02-11 22:54:11 -080070
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070071private:
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070072 Roster m_roster;
73 QGraphicsTextItem *m_rootDigest;
Zhenkai Zhud13acd02012-06-04 15:25:20 -070074 DisplayUserPtr previouslyUpdatedUser;
Zhenkai Zhu716fe852012-10-08 18:27:55 -070075 QString m_currentPrefix;
Yingdi Yu3a014852014-02-11 22:54:11 -080076 ndn::Scheduler m_scheduler;
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070077};
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070078
79class User
80{
81public:
82 User():m_received(time(NULL)) {}
83 User(QString n, QString p, QString c): m_nick(n), m_prefix(p), m_chatroom(c), m_received(time(NULL)) {}
84 void setNick(QString nick) {m_nick = nick;}
85 void setPrefix(QString prefix) {m_prefix = prefix;}
86 void setChatroom(QString chatroom) {m_chatroom = chatroom;}
87 void setSeq(Sync::SeqNo seq) {m_seq = seq;}
Zhenkai Zhu86df7412012-09-27 16:30:20 -070088 void setReceived(time_t t) {m_received = t;}
Zhenkai Zhue95c64a2012-09-27 21:46:44 -070089 void setOriginPrefix(QString originPrefix) { m_originPrefix = originPrefix;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070090 QString getNick() { return m_nick;}
91 QString getPrefix() { return m_prefix;}
92 QString getChatroom() { return m_chatroom;}
Zhenkai Zhue95c64a2012-09-27 21:46:44 -070093 QString getOriginPrefix() { return m_originPrefix;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070094 Sync::SeqNo getSeqNo() { return m_seq;}
95 time_t getReceived() { return m_received;}
96private:
97 QString m_nick;
98 QString m_prefix;
99 QString m_chatroom;
Zhenkai Zhue95c64a2012-09-27 21:46:44 -0700100 QString m_originPrefix;
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -0700101 Sync::SeqNo m_seq;
102 time_t m_received;
103};
104
105class DisplayUser : public User
106{
107public:
108 DisplayUser():m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {}
109 DisplayUser(QString n, QString p , QString c): User(n, p, c), m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {}
110 QGraphicsTextItem *getSeqTextItem() {return m_seqTextItem;}
111 QGraphicsTextItem *getNickTextItem() {return m_nickTextItem;}
112 QGraphicsRectItem *getRimRectItem() {return m_rimRectItem;}
Zhenkai Zhud13acd02012-06-04 15:25:20 -0700113 QGraphicsRectItem *getInnerRectItem() {return m_innerRectItem;}
114 QGraphicsRectItem *getNickRectItem() {return m_nickRectItem;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -0700115 void setSeqTextItem(QGraphicsTextItem *item) { m_seqTextItem = item;}
116 void setNickTextItem(QGraphicsTextItem *item) { m_nickTextItem = item;}
117 void setRimRectItem(QGraphicsRectItem *item) {m_rimRectItem = item;}
Zhenkai Zhud13acd02012-06-04 15:25:20 -0700118 void setInnerRectItem(QGraphicsRectItem *item) {m_innerRectItem = item;}
119 void setNickRectItem(QGraphicsRectItem *item) {m_nickRectItem = item;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -0700120private:
121 QGraphicsTextItem *m_seqTextItem;
122 QGraphicsTextItem *m_nickTextItem;
123 QGraphicsRectItem *m_rimRectItem;
Zhenkai Zhud13acd02012-06-04 15:25:20 -0700124 QGraphicsRectItem *m_innerRectItem;
125 QGraphicsRectItem *m_nickRectItem;
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -0700126};
127
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -0700128#endif