blob: a4792bce3217a6fa7efdee230bb3ae0664fcfbf3 [file] [log] [blame]
Yingdi Yu04842232013-10-23 14:03:09 -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 *
Yingdi Yu42f66462013-10-31 17:38:22 -07008 * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
9 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
10 * Yingdi Yu <yingdi@cs.ucla.edu>
Yingdi Yu04842232013-10-23 14:03:09 -070011 */
12
13#ifndef CHATDIALOG_H
14#define CHATDIALOG_H
15
16#include <QDialog>
Yingdi Yu42f66462013-10-31 17:38:22 -070017#include <QTextTable>
18#include <QStringListModel>
19#include <QTimer>
20
21#include "invitelistdialog.h"
Yingdi Yu04842232013-10-23 14:03:09 -070022
23#ifndef Q_MOC_RUN
24#include <ndn.cxx/data.h>
Yingdi Yuc4d08d22013-10-23 23:07:29 -070025#include <ndn.cxx/security/keychain.h>
26#include <ndn.cxx/wrapper/wrapper.h>
Yingdi Yu42f66462013-10-31 17:38:22 -070027#include "invitation-policy-manager.h"
Yingdi Yuc4d08d22013-10-23 23:07:29 -070028#include "contact-item.h"
Yingdi Yu42f66462013-10-31 17:38:22 -070029
30#include <ccnx/sync-socket.h>
31#include <sync-seq-no.h>
32#include "chatbuf.pb.h"
33#include "digesttreescene.h"
Yingdi Yu04842232013-10-23 14:03:09 -070034#endif
35
Yingdi Yu42f66462013-10-31 17:38:22 -070036#define MAX_HISTORY_ENTRY 20
37
Yingdi Yu04842232013-10-23 14:03:09 -070038namespace Ui {
39class ChatDialog;
40}
41
42class ChatDialog : public QDialog
43{
44 Q_OBJECT
45
46public:
Yingdi Yu42f66462013-10-31 17:38:22 -070047 explicit ChatDialog(ndn::Ptr<ContactManager> contactManager,
48 const ndn::Name& chatroomPrefix,
Yingdi Yu04842232013-10-23 14:03:09 -070049 const ndn::Name& localPrefix,
Yingdi Yuc4d08d22013-10-23 23:07:29 -070050 const ndn::Name& defaultIdentity,
Yingdi Yu04842232013-10-23 14:03:09 -070051 QWidget *parent = 0);
Yingdi Yu42f66462013-10-31 17:38:22 -070052
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 Yu04842232013-10-23 14:03:09 -070059 ~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 Yu42f66462013-10-31 17:38:22 -070070 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 Yu04842232013-10-23 14:03:09 -070094
95private:
Yingdi Yu42f66462013-10-31 17:38:22 -070096
97 void
98 initializeSetting();
99
100 void
101 updateLabels();
102
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700103 void
104 setWrapper();
Yingdi Yu42f66462013-10-31 17:38:22 -0700105
106 void
107 initializeSync();
108
109 void
110 publishIntroCert(ndn::Ptr<ndn::security::IdentityCertificate> dskCertificate, bool isIntroducer);
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700111
112 void
Yingdi Yu42f66462013-10-31 17:38:22 -0700113 onInviteReplyVerified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity, bool isIntroducer);
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700114
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 Yu42f66462013-10-31 17:38:22 -0700125 invitationAccepted(const ndn::Name& identity,
126 ndn::Ptr<ndn::Data> data,
127 const std::string& inviteePrefix,
128 bool isIntroducer);
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700129
130 void
131 onUnverified(ndn::Ptr<ndn::Data> data);
Yingdi Yu42f66462013-10-31 17:38:22 -0700132
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
165signals:
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
175public 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
185private 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 Yuc4d08d22013-10-23 23:07:29 -0700224
225private:
Yingdi Yu04842232013-10-23 14:03:09 -0700226 Ui::ChatDialog *ui;
Yingdi Yu42f66462013-10-31 17:38:22 -0700227 ndn::Ptr<ContactManager> m_contactManager;
Yingdi Yu04842232013-10-23 14:03:09 -0700228 ndn::Name m_chatroomPrefix;
229 ndn::Name m_localPrefix;
Yingdi Yu42f66462013-10-31 17:38:22 -0700230 ndn::Name m_localChatPrefix;
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700231 ndn::Name m_defaultIdentity;
Yingdi Yu42f66462013-10-31 17:38:22 -0700232 ndn::Ptr<InvitationPolicyManager> m_invitationPolicyManager;
233 ndn::Ptr<SyncPolicyManager> m_syncPolicyManager;
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700234 ndn::Ptr<ndn::security::IdentityManager> m_identityManager;
235 ndn::Ptr<ndn::security::Keychain> m_keychain;
236 ndn::Ptr<ndn::Wrapper> m_handler;
Yingdi Yu42f66462013-10-31 17:38:22 -0700237
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 Yu04842232013-10-23 14:03:09 -0700258};
259
260#endif // ChatDIALOG_H