Yingdi Yu | 0484223 | 2013-10-23 14:03:09 -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 | * |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame^] | 8 | * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| 9 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 10 | * Yingdi Yu <yingdi@cs.ucla.edu> |
Yingdi Yu | 0484223 | 2013-10-23 14:03:09 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #ifndef CHATDIALOG_H |
| 14 | #define CHATDIALOG_H |
| 15 | |
| 16 | #include <QDialog> |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame^] | 17 | #include <QTextTable> |
| 18 | #include <QStringListModel> |
| 19 | #include <QTimer> |
| 20 | |
| 21 | #include "invitelistdialog.h" |
Yingdi Yu | 0484223 | 2013-10-23 14:03:09 -0700 | [diff] [blame] | 22 | |
| 23 | #ifndef Q_MOC_RUN |
| 24 | #include <ndn.cxx/data.h> |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 25 | #include <ndn.cxx/security/keychain.h> |
| 26 | #include <ndn.cxx/wrapper/wrapper.h> |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame^] | 27 | #include "invitation-policy-manager.h" |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 28 | #include "contact-item.h" |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame^] | 29 | |
| 30 | #include <ccnx/sync-socket.h> |
| 31 | #include <sync-seq-no.h> |
| 32 | #include "chatbuf.pb.h" |
| 33 | #include "digesttreescene.h" |
Yingdi Yu | 0484223 | 2013-10-23 14:03:09 -0700 | [diff] [blame] | 34 | #endif |
| 35 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame^] | 36 | #define MAX_HISTORY_ENTRY 20 |
| 37 | |
Yingdi Yu | 0484223 | 2013-10-23 14:03:09 -0700 | [diff] [blame] | 38 | namespace Ui { |
| 39 | class ChatDialog; |
| 40 | } |
| 41 | |
| 42 | class ChatDialog : public QDialog |
| 43 | { |
| 44 | Q_OBJECT |
| 45 | |
| 46 | public: |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame^] | 47 | explicit ChatDialog(ndn::Ptr<ContactManager> contactManager, |
| 48 | const ndn::Name& chatroomPrefix, |
Yingdi Yu | 0484223 | 2013-10-23 14:03:09 -0700 | [diff] [blame] | 49 | const ndn::Name& localPrefix, |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 50 | const ndn::Name& defaultIdentity, |
Yingdi Yu | 0484223 | 2013-10-23 14:03:09 -0700 | [diff] [blame] | 51 | QWidget *parent = 0); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame^] | 52 | |
| 53 | // explicit ChatDialog(const ndn::Name& chatroomPrefix, |
| 54 | // const ndn::Name& localPrefix, |
| 55 | // const ndn::Name& defaultIdentity, |
| 56 | // const ndn::security::IdentityCertificate& identityCertificate, |
| 57 | // QWidget *parent = 0); |
| 58 | |
Yingdi Yu | 0484223 | 2013-10-23 14:03:09 -0700 | [diff] [blame] | 59 | ~ChatDialog(); |
| 60 | |
| 61 | const ndn::Name& |
| 62 | getChatroomPrefix() const |
| 63 | { return m_chatroomPrefix; } |
| 64 | |
| 65 | const ndn::Name& |
| 66 | getLocalPrefix() const |
| 67 | { return m_localPrefix; } |
| 68 | |
| 69 | void |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame^] | 70 | sendInvitation(ndn::Ptr<ContactItem> contact, bool isIntroducer); |
| 71 | |
| 72 | void |
| 73 | addTrustAnchor(const EndorseCertificate& selfEndorseCertificate); |
| 74 | |
| 75 | void |
| 76 | addChatDataRule(const ndn::Name& prefix, |
| 77 | const ndn::security::IdentityCertificate& identityCertificate, |
| 78 | bool isIntroducer); |
| 79 | |
| 80 | void |
| 81 | appendMessage(const SyncDemo::ChatMessage msg, bool isHistory = false); |
| 82 | |
| 83 | void |
| 84 | processTreeUpdateWrapper(const std::vector<Sync::MissingDataInfo>, Sync::SyncSocket *); |
| 85 | |
| 86 | void |
| 87 | processDataWrapper(ndn::Ptr<ndn::Data> data); |
| 88 | |
| 89 | void |
| 90 | processDataNoShowWrapper(ndn::Ptr<ndn::Data> data); |
| 91 | |
| 92 | void |
| 93 | processRemoveWrapper(std::string); |
Yingdi Yu | 0484223 | 2013-10-23 14:03:09 -0700 | [diff] [blame] | 94 | |
| 95 | private: |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame^] | 96 | |
| 97 | void |
| 98 | initializeSetting(); |
| 99 | |
| 100 | void |
| 101 | updateLabels(); |
| 102 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 103 | void |
| 104 | setWrapper(); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame^] | 105 | |
| 106 | void |
| 107 | initializeSync(); |
| 108 | |
| 109 | void |
| 110 | publishIntroCert(ndn::Ptr<ndn::security::IdentityCertificate> dskCertificate, bool isIntroducer); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 111 | |
| 112 | void |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame^] | 113 | onInviteReplyVerified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity, bool isIntroducer); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 114 | |
| 115 | void |
| 116 | onInviteTimeout(ndn::Ptr<ndn::Closure> closure, |
| 117 | ndn::Ptr<ndn::Interest> interest, |
| 118 | const ndn::Name& identity, |
| 119 | int retry); |
| 120 | |
| 121 | void |
| 122 | invitationRejected(const ndn::Name& identity); |
| 123 | |
| 124 | void |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame^] | 125 | invitationAccepted(const ndn::Name& identity, |
| 126 | ndn::Ptr<ndn::Data> data, |
| 127 | const std::string& inviteePrefix, |
| 128 | bool isIntroducer); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 129 | |
| 130 | void |
| 131 | onUnverified(ndn::Ptr<ndn::Data> data); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame^] | 132 | |
| 133 | |
| 134 | |
| 135 | // void |
| 136 | // fetchHistory(std::string name); |
| 137 | |
| 138 | void |
| 139 | formChatMessage(const QString &text, SyncDemo::ChatMessage &msg); |
| 140 | |
| 141 | void |
| 142 | formControlMessage(SyncDemo::ChatMessage &msg, SyncDemo::ChatMessage::ChatMessageType type); |
| 143 | |
| 144 | void |
| 145 | sendMsg(SyncDemo::ChatMessage &msg); |
| 146 | |
| 147 | void |
| 148 | resizeEvent(QResizeEvent *); |
| 149 | |
| 150 | void |
| 151 | showEvent(QShowEvent *); |
| 152 | |
| 153 | void |
| 154 | fitView(); |
| 155 | |
| 156 | QString |
| 157 | formatTime(time_t); |
| 158 | |
| 159 | void |
| 160 | printTimeInCell(QTextTable *, time_t); |
| 161 | |
| 162 | void |
| 163 | disableTreeDisplay(); |
| 164 | |
| 165 | signals: |
| 166 | void |
| 167 | dataReceived(QString name, const char *buf, size_t len, bool show, bool isHistory); |
| 168 | |
| 169 | void |
| 170 | treeUpdated(const std::vector<Sync::MissingDataInfo>); |
| 171 | |
| 172 | void |
| 173 | removeReceived(QString prefix); |
| 174 | |
| 175 | public slots: |
| 176 | void |
| 177 | processTreeUpdate(const std::vector<Sync::MissingDataInfo>); |
| 178 | |
| 179 | void |
| 180 | processData(QString name, const char *buf, size_t len, bool show, bool isHistory); |
| 181 | |
| 182 | void |
| 183 | processRemove(QString prefix); |
| 184 | |
| 185 | private slots: |
| 186 | void |
| 187 | returnPressed(); |
| 188 | |
| 189 | void |
| 190 | treeButtonPressed(); |
| 191 | |
| 192 | void |
| 193 | sendJoin(); |
| 194 | |
| 195 | void |
| 196 | sendHello(); |
| 197 | |
| 198 | void |
| 199 | sendLeave(); |
| 200 | |
| 201 | void |
| 202 | replot(); |
| 203 | |
| 204 | void |
| 205 | updateRosterList(QStringList); |
| 206 | |
| 207 | void |
| 208 | enableTreeDisplay(); |
| 209 | |
| 210 | void |
| 211 | summonReaper(); |
| 212 | |
| 213 | void |
| 214 | reap(); |
| 215 | |
| 216 | void |
| 217 | showMessage(QString, QString); |
| 218 | |
| 219 | void |
| 220 | openInviteListDialog(); |
| 221 | |
| 222 | void |
| 223 | sendInvitationWrapper(QString, bool); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 224 | |
| 225 | private: |
Yingdi Yu | 0484223 | 2013-10-23 14:03:09 -0700 | [diff] [blame] | 226 | Ui::ChatDialog *ui; |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame^] | 227 | ndn::Ptr<ContactManager> m_contactManager; |
Yingdi Yu | 0484223 | 2013-10-23 14:03:09 -0700 | [diff] [blame] | 228 | ndn::Name m_chatroomPrefix; |
| 229 | ndn::Name m_localPrefix; |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame^] | 230 | ndn::Name m_localChatPrefix; |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 231 | ndn::Name m_defaultIdentity; |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame^] | 232 | ndn::Ptr<InvitationPolicyManager> m_invitationPolicyManager; |
| 233 | ndn::Ptr<SyncPolicyManager> m_syncPolicyManager; |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 234 | ndn::Ptr<ndn::security::IdentityManager> m_identityManager; |
| 235 | ndn::Ptr<ndn::security::Keychain> m_keychain; |
| 236 | ndn::Ptr<ndn::Wrapper> m_handler; |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame^] | 237 | |
| 238 | User m_user; |
| 239 | Sync::SyncSocket *m_sock; |
| 240 | uint32_t m_session; |
| 241 | DigestTreeScene *m_scene; |
| 242 | boost::recursive_mutex m_msgMutex; |
| 243 | boost::recursive_mutex m_sceneMutex; |
| 244 | time_t m_lastMsgTime; |
| 245 | int m_randomizedInterval; |
| 246 | QTimer *m_timer; |
| 247 | QStringListModel *m_rosterModel; |
| 248 | |
| 249 | |
| 250 | // QQueue<SyncDemo::ChatMessage> m_history; |
| 251 | // bool m_historyInitialized; |
| 252 | bool m_joined; |
| 253 | |
| 254 | QList<QString> m_zombieList; |
| 255 | int m_zombieIndex; |
| 256 | |
| 257 | InviteListDialog* m_inviteListDialog; |
Yingdi Yu | 0484223 | 2013-10-23 14:03:09 -0700 | [diff] [blame] | 258 | }; |
| 259 | |
| 260 | #endif // ChatDIALOG_H |