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