blob: 4d871a19b489964f7159ea1d0ee43e6ff2b4bba7 [file] [log] [blame]
Yingdi Yu9e0dc292013-10-10 11:39:45 -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: Yingdi Yu <yingdi@cs.ucla.edu>
9 */
10
Yingdi Yudef90612013-10-09 22:34:42 -070011#ifndef CONTACTPANEL_H
12#define CONTACTPANEL_H
13
14#include <QDialog>
Yingdi Yu01a942b2013-10-10 15:00:58 -070015#include <QStringListModel>
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070016#include <QtSql/QSqlDatabase>
Yingdi Yu79c25a22013-10-21 13:38:38 -070017#include <QMenu>
Yingdi Yub29f78c2013-11-09 20:12:31 -080018#include <QMessageBox>
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070019
20#include "profileeditor.h"
Yingdi Yud59b5932013-10-16 13:16:49 -070021#include "addcontactpanel.h"
Yingdi Yu79c25a22013-10-21 13:38:38 -070022#include "setaliasdialog.h"
Yingdi Yu100267f2013-10-21 15:01:40 -070023#include "startchatdialog.h"
Yingdi Yu53eb8a72013-10-23 11:50:51 -070024#include "invitationdialog.h"
25#include "settingdialog.h"
Yingdi Yuc4d08d22013-10-23 23:07:29 -070026#include "chatdialog.h"
Yingdi Yu8dacdf22013-11-05 23:06:43 -080027#include "endorse-combobox-delegate.h"
Yingdi Yu908f8412013-11-09 00:03:26 -080028#include "browsecontactdialog.h"
Yingdi Yu10436892013-11-10 16:26:52 -080029#include "warningdialog.h"
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070030
31#ifndef Q_MOC_RUN
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070032#include "contact-manager.h"
Yingdi Yu42f66462013-10-31 17:38:22 -070033#include "chronos-invitation.h"
Yingdi Yueaa84e22014-01-16 10:30:26 -080034#include "sec-policy-chrono-chat-panel.h"
Yingdi Yuaccbda92013-12-27 08:44:12 +080035#include <boost/thread/locks.hpp>
36#include <boost/thread/recursive_mutex.hpp>
37#include <boost/thread/thread.hpp>
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070038#endif
Yingdi Yudef90612013-10-09 22:34:42 -070039
Yingdi Yu53eb8a72013-10-23 11:50:51 -070040
Yingdi Yudef90612013-10-09 22:34:42 -070041namespace Ui {
42class ContactPanel;
43}
44
45class ContactPanel : public QDialog
46{
Yingdi Yuc4d08d22013-10-23 23:07:29 -070047 Q_OBJECT
Yingdi Yudef90612013-10-09 22:34:42 -070048
49public:
Yingdi Yub29f78c2013-11-09 20:12:31 -080050 explicit ContactPanel(QWidget *parent = 0);
Yingdi Yu53eb8a72013-10-23 11:50:51 -070051
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070052 ~ContactPanel();
Yingdi Yudef90612013-10-09 22:34:42 -070053
Yingdi Yu53eb8a72013-10-23 11:50:51 -070054private:
Yingdi Yuaccbda92013-12-27 08:44:12 +080055
56 void
57 startFace();
58
59 void
60 shutdownFace();
61
62 void
63 eventLoop();
64
Yingdi Yu64206112013-12-24 11:16:32 +080065 void
66 connectToDaemon();
67
68 void
69 onConnectionData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
70 const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
71
72 void
73 onConnectionDataTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest);
74
Yingdi Yu53eb8a72013-10-23 11:50:51 -070075 void
Yingdi Yu42372442013-11-06 18:43:31 -080076 createAction();
77
78 void
Yingdi Yu53eb8a72013-10-23 11:50:51 -070079 openDB();
80
81 void
Yingdi Yu64206112013-12-24 11:16:32 +080082 loadTrustAnchor();
Yingdi Yu53eb8a72013-10-23 11:50:51 -070083
84 void
Yingdi Yu2ab22e72013-11-10 01:38:21 -080085 setLocalPrefix(int retry = 10);
Yingdi Yu53eb8a72013-10-23 11:50:51 -070086
87 void
Yingdi Yu64206112013-12-24 11:16:32 +080088 onLocalPrefix(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
89 const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
Yingdi Yu53eb8a72013-10-23 11:50:51 -070090
91 void
Yingdi Yu64206112013-12-24 11:16:32 +080092 onLocalPrefixTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
Yingdi Yu2ab22e72013-11-10 01:38:21 -080093 int retry);
Yingdi Yu53eb8a72013-10-23 11:50:51 -070094
95 void
Yingdi Yu53eb8a72013-10-23 11:50:51 -070096 setInvitationListener();
97
98 void
Yingdi Yu64206112013-12-24 11:16:32 +080099 onInvitation(const ndn::ptr_lib::shared_ptr<const ndn::Name>& prefix,
100 const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
101 ndn::Transport& transport,
102 uint64_t registeredPrefixI);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700103
104 void
Yingdi Yu64206112013-12-24 11:16:32 +0800105 onInvitationRegisterFailed(const ndn::ptr_lib::shared_ptr<const ndn::Name>& prefix);
106
Yingdi Yu42372442013-11-06 18:43:31 -0800107 void
Yingdi Yu64206112013-12-24 11:16:32 +0800108 sendInterest(const ndn::Interest& interest,
109 const ndn::OnVerified& onVerified,
110 const ndn::OnVerifyFailed& onVerifyFailed,
111 const TimeoutNotify& timeoutNotify,
112 int retry = 1,
113 int stepCount = 0);
114
115 void
116 onTargetData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
117 const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
118 int stepCount,
119 const ndn::OnVerified& onVerified,
120 const ndn::OnVerifyFailed& onVerifyFailed,
121 const TimeoutNotify& timeoutNotify);
122
123 void
124 onTargetTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
125 int retry,
126 int stepCount,
127 const ndn::OnVerified& onVerified,
128 const ndn::OnVerifyFailed& onVerifyFailed,
129 const TimeoutNotify& timeoutNotify);
130
131
132 void
133 onCertData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
134 const ndn::ptr_lib::shared_ptr<ndn::Data>& cert,
135 ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> previousStep);
136
137 void
138 onCertTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
139 const ndn::OnVerifyFailed& onVerifyFailed,
140 const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
141 ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> nextStep);
Yingdi Yu42372442013-11-06 18:43:31 -0800142
143 void
Yingdi Yu64206112013-12-24 11:16:32 +0800144 onInvitationCertVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
145 ndn::ptr_lib::shared_ptr<ChronosInvitation> invitation);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700146
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800147 void
Yingdi Yu64206112013-12-24 11:16:32 +0800148 onInvitationCertVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
149
150 void
151 onInvitationCertTimeoutNotify();
152
153 void
154 popChatInvitation(ndn::ptr_lib::shared_ptr<ChronosInvitation> invitation,
Yingdi Yu42372442013-11-06 18:43:31 -0800155 const ndn::Name& inviterNameSpace,
Yingdi Yu64206112013-12-24 11:16:32 +0800156 ndn::ptr_lib::shared_ptr<ndn::IdentityCertificate> certificate);
Yingdi Yu42372442013-11-06 18:43:31 -0800157
158 void
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800159 collectEndorsement();
160
161 void
Yingdi Yu64206112013-12-24 11:16:32 +0800162 onDnsEndorseeVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, int count);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800163
164 void
Yingdi Yu64206112013-12-24 11:16:32 +0800165 onDnsEndorseeVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, int count);
166
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800167 void
Yingdi Yu64206112013-12-24 11:16:32 +0800168 onDnsEndorseeTimeoutNotify(int count);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800169
170 void
171 updateCollectStatus(int count);
172
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700173 std::string
174 getRandomString();
175
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700176signals:
177 void
178 newInvitationReady();
179
Yingdi Yu908f8412013-11-09 00:03:26 -0800180 void
181 refreshCertDirectory();
182
Yingdi Yu01a942b2013-10-10 15:00:58 -0700183private slots:
184 void
Yingdi Yub29f78c2013-11-09 20:12:31 -0800185 showError(const QString& msg);
186
187 void
Yingdi Yueb98f7d2013-11-10 01:34:57 -0800188 showWarning(const QString& msg);
189
190 void
Yingdi Yu01a942b2013-10-10 15:00:58 -0700191 updateSelection(const QItemSelection &selected,
192 const QItemSelection &deselected);
193
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700194 void
Yingdi Yu42372442013-11-06 18:43:31 -0800195 updateDefaultIdentity(const QString& identity,
196 const QString& nickName);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700197
198 void
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700199 openProfileEditor();
200
Yingdi Yud59b5932013-10-16 13:16:49 -0700201 void
202 openAddContactPanel();
Yingdi Yu908f8412013-11-09 00:03:26 -0800203
204 void
205 openBrowseContactDialog();
Yingdi Yud59b5932013-10-16 13:16:49 -0700206
Yingdi Yu79c25a22013-10-21 13:38:38 -0700207 void
208 openSetAliasDialog();
Yingdi Yu908f8412013-11-09 00:03:26 -0800209
210 void
211 removeContactButton();
Yingdi Yu100267f2013-10-21 15:01:40 -0700212
213 void
214 openStartChatDialog();
Yingdi Yu79c25a22013-10-21 13:38:38 -0700215
216 void
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700217 openSettingDialog();
218
219 void
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700220 openInvitationDialog();
221
222 void
Yingdi Yu79c25a22013-10-21 13:38:38 -0700223 refreshContactList();
224
225 void
226 showContextMenu(const QPoint& pos);
227
Yingdi Yu100267f2013-10-21 15:01:40 -0700228 void
Yingdi Yu42372442013-11-06 18:43:31 -0800229 startChatroom(const QString& chatroom,
230 const QString& invitee,
231 bool isIntroducer);
Yingdi Yu100267f2013-10-21 15:01:40 -0700232
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700233 void
Yingdi Yu42f66462013-10-31 17:38:22 -0700234 startChatroom2(const ChronosInvitation& invitation,
Yingdi Yu64206112013-12-24 11:16:32 +0800235 const ndn::IdentityCertificate& identityCertificate);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700236
237 void
Yingdi Yu42f66462013-10-31 17:38:22 -0700238 acceptInvitation(const ChronosInvitation& invitation,
Yingdi Yu64206112013-12-24 11:16:32 +0800239 const ndn::IdentityCertificate& identityCertificate);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700240
241 void
Yingdi Yu42f66462013-10-31 17:38:22 -0700242 rejectInvitation(const ChronosInvitation& invitation);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700243
Yingdi Yua50c3252013-11-03 15:05:26 -0800244 void
245 isIntroducerChanged(int state);
246
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800247 void
248 addScopeClicked();
249
250 void
251 deleteScopeClicked();
252
253 void
254 saveScopeClicked();
255
256 void
257 endorseButtonClicked();
Yingdi Yu42372442013-11-06 18:43:31 -0800258
259 void
260 removeChatDialog(const ndn::Name& chatroomName);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800261
Yingdi Yu6ea54e42013-11-12 17:50:21 -0800262 void
263 addContactIntoPanelPolicy(const ndn::Name& nameSpace);
264
265 void
266 removeContactFromPanelPolicy(const ndn::Name& keyName);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800267
268
Yingdi Yudef90612013-10-09 22:34:42 -0700269private:
Yingdi Yueaa84e22014-01-16 10:30:26 -0800270
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700271 Ui::ContactPanel *ui;
Yingdi Yub29f78c2013-11-09 20:12:31 -0800272 WarningDialog* m_warningDialog;
Yingdi Yu64206112013-12-24 11:16:32 +0800273 ndn::ptr_lib::shared_ptr<ContactManager> m_contactManager;
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700274 QStringListModel* m_contactListModel;
275 ProfileEditor* m_profileEditor;
Yingdi Yud59b5932013-10-16 13:16:49 -0700276 AddContactPanel* m_addContactPanel;
Yingdi Yu908f8412013-11-09 00:03:26 -0800277 BrowseContactDialog* m_browseContactDialog;
Yingdi Yu79c25a22013-10-21 13:38:38 -0700278 SetAliasDialog* m_setAliasDialog;
Yingdi Yu100267f2013-10-21 15:01:40 -0700279 StartChatDialog* m_startChatDialog;
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700280 InvitationDialog* m_invitationDialog;
281 SettingDialog* m_settingDialog;
Yingdi Yu64206112013-12-24 11:16:32 +0800282 std::map<ndn::Name, ChatDialog*, ndn::Name::BreadthFirstLess> m_chatDialogs;
Yingdi Yu79c25a22013-10-21 13:38:38 -0700283 QAction* m_menuInvite;
284 QAction* m_menuAlias;
Yingdi Yu64206112013-12-24 11:16:32 +0800285 std::vector<ndn::ptr_lib::shared_ptr<ContactItem> > m_contactList;
286 ndn::ptr_lib::shared_ptr<std::vector<bool> > m_collectStatus;
Yingdi Yu79c25a22013-10-21 13:38:38 -0700287
Yingdi Yueaa84e22014-01-16 10:30:26 -0800288 ndn::ptr_lib::shared_ptr<SecPolicyChronoChatPanel> m_policy;
Yingdi Yuc9ffa9f2014-01-13 11:19:47 -0800289 ndn::ptr_lib::shared_ptr<ndn::KeyChain> m_keyChain;
Yingdi Yu64206112013-12-24 11:16:32 +0800290 ndn::ptr_lib::shared_ptr<ndn::Face> m_face;
Yingdi Yuaccbda92013-12-27 08:44:12 +0800291
292 boost::recursive_mutex m_mutex;
293 boost::thread m_thread;
294 bool m_running;
295
Yingdi Yu64206112013-12-24 11:16:32 +0800296 uint64_t m_invitationListenerId;
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700297
298 ndn::Name m_defaultIdentity;
Yingdi Yu42372442013-11-06 18:43:31 -0800299 std::string m_nickName;
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700300 ndn::Name m_localPrefix;
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700301 ndn::Name m_inviteListenPrefix;
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700302
Yingdi Yu64206112013-12-24 11:16:32 +0800303 ndn::ptr_lib::shared_ptr<ContactItem> m_currentSelectedContact;
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800304 QSqlTableModel* m_trustScopeModel;
305 QSqlTableModel* m_endorseDataModel;
306 EndorseComboBoxDelegate* m_endorseComboBoxDelegate;
Yingdi Yudef90612013-10-09 22:34:42 -0700307};
308
309#endif // CONTACTPANEL_H