Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 1 | /* -*- 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 Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 12 | #ifndef DIGESTTREESCENE_H |
| 13 | #define DIGESTTREESCENE_H |
| 14 | |
Alexander Afanasyev | f829f4d | 2013-05-07 15:59:36 -0700 | [diff] [blame] | 15 | #include "treelayout.h" |
| 16 | |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 17 | #include <QtGui/QGraphicsScene> |
Alexander Afanasyev | f829f4d | 2013-05-07 15:59:36 -0700 | [diff] [blame] | 18 | #include <QColor> |
| 19 | #include <QMap> |
| 20 | |
| 21 | #ifndef Q_MOC_RUN |
Yingdi Yu | 3a01485 | 2014-02-11 22:54:11 -0800 | [diff] [blame^] | 22 | #include <ndn-cpp-dev/util/scheduler.hpp> |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 23 | #include <sync-seq-no.h> |
| 24 | #include <sync-logic.h> |
| 25 | #include <ctime> |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 26 | #include <vector> |
Alexander Afanasyev | 4a97931 | 2013-11-07 15:30:05 -0800 | [diff] [blame] | 27 | #include <boost/shared_ptr.hpp> |
Alexander Afanasyev | f829f4d | 2013-05-07 15:59:36 -0700 | [diff] [blame] | 28 | #endif |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 29 | |
Zhenkai Zhu | c61dbc2 | 2012-10-08 11:36:37 -0700 | [diff] [blame] | 30 | const int FRESHNESS = 60; |
Zhenkai Zhu | 86df741 | 2012-09-27 16:30:20 -0700 | [diff] [blame] | 31 | |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 32 | class QGraphicsTextItem; |
| 33 | |
| 34 | class User; |
| 35 | class DisplayUser; |
Alexander Afanasyev | 4a97931 | 2013-11-07 15:30:05 -0800 | [diff] [blame] | 36 | typedef boost::shared_ptr<DisplayUser> DisplayUserPtr; |
Zhenkai Zhu | 7f52e1b | 2012-10-09 11:45:36 -0700 | [diff] [blame] | 37 | static DisplayUserPtr DisplayUserNullPtr; |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 38 | |
| 39 | class DigestTreeScene : public QGraphicsScene |
| 40 | { |
| 41 | Q_OBJECT |
| 42 | |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 43 | typedef QMap<QString, DisplayUserPtr> Roster; |
| 44 | typedef QMap<QString, DisplayUserPtr>::iterator Roster_iterator; |
| 45 | typedef QMapIterator<QString, DisplayUserPtr> RosterIterator; |
| 46 | |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 47 | public: |
Yingdi Yu | 3a01485 | 2014-02-11 22:54:11 -0800 | [diff] [blame^] | 48 | DigestTreeScene(ndn::shared_ptr<boost::asio::io_service> ioService, |
| 49 | QWidget *parent = 0); |
Zhenkai Zhu | 82a6275 | 2012-06-04 17:11:04 -0700 | [diff] [blame] | 50 | void processUpdate(const std::vector<Sync::MissingDataInfo> &v, QString digest); |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 51 | void msgReceived(QString prefix, QString nick); |
Zhenkai Zhu | 82a6275 | 2012-06-04 17:11:04 -0700 | [diff] [blame] | 52 | void clearAll(); |
Zhenkai Zhu | 591e8c3 | 2012-09-26 11:57:50 -0700 | [diff] [blame] | 53 | bool removeNode(const QString prefix); |
Zhenkai Zhu | 86df741 | 2012-09-27 16:30:20 -0700 | [diff] [blame] | 54 | void plot(QString digest); |
Zhenkai Zhu | 6082ede | 2012-09-27 17:28:46 -0700 | [diff] [blame] | 55 | QStringList getRosterList(); |
Zhenkai Zhu | 716fe85 | 2012-10-08 18:27:55 -0700 | [diff] [blame] | 56 | void setCurrentPrefix(QString prefix) {m_currentPrefix = prefix;} |
Zhenkai Zhu | 7f52e1b | 2012-10-09 11:45:36 -0700 | [diff] [blame] | 57 | QMap<QString, DisplayUserPtr> getRosterFull() { return m_roster;} |
Zhenkai Zhu | 86df741 | 2012-09-27 16:30:20 -0700 | [diff] [blame] | 58 | |
| 59 | signals: |
| 60 | void replot(); |
Zhenkai Zhu | 25e33e5 | 2012-09-28 13:00:07 -0700 | [diff] [blame] | 61 | void rosterChanged(QStringList); |
Zhenkai Zhu | 86df741 | 2012-09-27 16:30:20 -0700 | [diff] [blame] | 62 | |
| 63 | private slots: |
| 64 | void emitReplot(); |
| 65 | |
Zhenkai Zhu | 82a6275 | 2012-06-04 17:11:04 -0700 | [diff] [blame] | 66 | private: |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 67 | void plotEdge(const std::vector<TreeLayout::Coordinate> &v, int nodeSize); |
| 68 | void plotNode(const std::vector<TreeLayout::Coordinate> &v, QString digest, int nodeSize); |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 69 | void reDrawNode(DisplayUserPtr p, QColor rimColor); |
Yingdi Yu | 3a01485 | 2014-02-11 22:54:11 -0800 | [diff] [blame^] | 70 | |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 71 | private: |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 72 | Roster m_roster; |
| 73 | QGraphicsTextItem *m_rootDigest; |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 74 | DisplayUserPtr previouslyUpdatedUser; |
Zhenkai Zhu | 716fe85 | 2012-10-08 18:27:55 -0700 | [diff] [blame] | 75 | QString m_currentPrefix; |
Yingdi Yu | 3a01485 | 2014-02-11 22:54:11 -0800 | [diff] [blame^] | 76 | ndn::Scheduler m_scheduler; |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 77 | }; |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 78 | |
| 79 | class User |
| 80 | { |
| 81 | public: |
| 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 Zhu | 86df741 | 2012-09-27 16:30:20 -0700 | [diff] [blame] | 88 | void setReceived(time_t t) {m_received = t;} |
Zhenkai Zhu | e95c64a | 2012-09-27 21:46:44 -0700 | [diff] [blame] | 89 | void setOriginPrefix(QString originPrefix) { m_originPrefix = originPrefix;} |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 90 | QString getNick() { return m_nick;} |
| 91 | QString getPrefix() { return m_prefix;} |
| 92 | QString getChatroom() { return m_chatroom;} |
Zhenkai Zhu | e95c64a | 2012-09-27 21:46:44 -0700 | [diff] [blame] | 93 | QString getOriginPrefix() { return m_originPrefix;} |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 94 | Sync::SeqNo getSeqNo() { return m_seq;} |
| 95 | time_t getReceived() { return m_received;} |
| 96 | private: |
| 97 | QString m_nick; |
| 98 | QString m_prefix; |
| 99 | QString m_chatroom; |
Zhenkai Zhu | e95c64a | 2012-09-27 21:46:44 -0700 | [diff] [blame] | 100 | QString m_originPrefix; |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 101 | Sync::SeqNo m_seq; |
| 102 | time_t m_received; |
| 103 | }; |
| 104 | |
| 105 | class DisplayUser : public User |
| 106 | { |
| 107 | public: |
| 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 Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 113 | QGraphicsRectItem *getInnerRectItem() {return m_innerRectItem;} |
| 114 | QGraphicsRectItem *getNickRectItem() {return m_nickRectItem;} |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 115 | void setSeqTextItem(QGraphicsTextItem *item) { m_seqTextItem = item;} |
| 116 | void setNickTextItem(QGraphicsTextItem *item) { m_nickTextItem = item;} |
| 117 | void setRimRectItem(QGraphicsRectItem *item) {m_rimRectItem = item;} |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 118 | void setInnerRectItem(QGraphicsRectItem *item) {m_innerRectItem = item;} |
| 119 | void setNickRectItem(QGraphicsRectItem *item) {m_nickRectItem = item;} |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 120 | private: |
| 121 | QGraphicsTextItem *m_seqTextItem; |
| 122 | QGraphicsTextItem *m_nickTextItem; |
| 123 | QGraphicsRectItem *m_rimRectItem; |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 124 | QGraphicsRectItem *m_innerRectItem; |
| 125 | QGraphicsRectItem *m_nickRectItem; |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 126 | }; |
| 127 | |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 128 | #endif |