blob: 4d9eb8df98d7d1b822c278092ba638189fb6c8df [file] [log] [blame]
Yingdi Yu847aa862013-10-09 16:35:53 -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
11#ifndef CONTACTPANEL_H
12#define CONTACTPANEL_H
13
14#include <QDialog>
Yingdi Yu40eca752013-10-10 15:00:58 -070015#include <QStringListModel>
Yingdi Yu3b318c12013-10-15 17:54:00 -070016#include <QtSql/QSqlDatabase>
Yingdi Yu2ac40fb2013-10-21 13:38:38 -070017#include <QMenu>
Yingdi Yu8e135832013-11-09 20:12:31 -080018#include <QMessageBox>
Yingdi Yu3b318c12013-10-15 17:54:00 -070019
20#include "profileeditor.h"
Yingdi Yu0269c872013-10-16 13:16:49 -070021#include "addcontactpanel.h"
Yingdi Yu2ac40fb2013-10-21 13:38:38 -070022#include "setaliasdialog.h"
Yingdi Yu595aadc2013-10-21 15:01:40 -070023#include "startchatdialog.h"
Yingdi Yu978b3ae2013-10-23 11:50:51 -070024#include "invitationdialog.h"
25#include "settingdialog.h"
Yingdi Yueda39aa2013-10-23 23:07:29 -070026#include "chatdialog.h"
Yingdi Yub2e747d2013-11-05 23:06:43 -080027#include "endorse-combobox-delegate.h"
Yingdi Yuae8217c2013-11-09 00:03:26 -080028#include "browsecontactdialog.h"
Yingdi Yub5a0fd32013-11-10 16:26:52 -080029#include "warningdialog.h"
Yingdi Yu3b318c12013-10-15 17:54:00 -070030
31#ifndef Q_MOC_RUN
Yingdi Yu9236c432013-10-18 11:29:25 -070032#include "contact-manager.h"
Yingdi Yu7989eb22013-10-31 17:38:22 -070033#include "chronos-invitation.h"
Yingdi Yu93adb1a2014-01-16 10:30:26 -080034#include "sec-policy-chrono-chat-panel.h"
Yingdi Yu6eabbd72013-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 Yu3b318c12013-10-15 17:54:00 -070038#endif
Yingdi Yu847aa862013-10-09 16:35:53 -070039
Yingdi Yu978b3ae2013-10-23 11:50:51 -070040
Yingdi Yu847aa862013-10-09 16:35:53 -070041namespace Ui {
42class ContactPanel;
43}
44
45class ContactPanel : public QDialog
46{
Yingdi Yueda39aa2013-10-23 23:07:29 -070047 Q_OBJECT
Yingdi Yu847aa862013-10-09 16:35:53 -070048
49public:
Yingdi Yu8e135832013-11-09 20:12:31 -080050 explicit ContactPanel(QWidget *parent = 0);
Yingdi Yu978b3ae2013-10-23 11:50:51 -070051
Yingdi Yu3b318c12013-10-15 17:54:00 -070052 ~ContactPanel();
Yingdi Yu847aa862013-10-09 16:35:53 -070053
Yingdi Yu978b3ae2013-10-23 11:50:51 -070054private:
Yingdi Yu6eabbd72013-12-27 08:44:12 +080055
56 void
57 startFace();
58
59 void
60 shutdownFace();
61
62 void
63 eventLoop();
64
Yingdi Yu76dd8002013-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 Yu978b3ae2013-10-23 11:50:51 -070075 void
Yingdi Yu46948282013-11-06 18:43:31 -080076 createAction();
77
78 void
Yingdi Yu978b3ae2013-10-23 11:50:51 -070079 openDB();
80
81 void
Yingdi Yu76dd8002013-12-24 11:16:32 +080082 loadTrustAnchor();
Yingdi Yu978b3ae2013-10-23 11:50:51 -070083
84 void
Yingdi Yufdb8ab82013-11-10 01:38:21 -080085 setLocalPrefix(int retry = 10);
Yingdi Yu978b3ae2013-10-23 11:50:51 -070086
87 void
Yingdi Yu76dd8002013-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 Yu978b3ae2013-10-23 11:50:51 -070090
91 void
Yingdi Yu76dd8002013-12-24 11:16:32 +080092 onLocalPrefixTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
Yingdi Yufdb8ab82013-11-10 01:38:21 -080093 int retry);
Yingdi Yu978b3ae2013-10-23 11:50:51 -070094
95 void
Yingdi Yu978b3ae2013-10-23 11:50:51 -070096 setInvitationListener();
97
98 void
Yingdi Yu76dd8002013-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 Yu978b3ae2013-10-23 11:50:51 -0700103
104 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800105 onInvitationRegisterFailed(const ndn::ptr_lib::shared_ptr<const ndn::Name>& prefix);
106
Yingdi Yu46948282013-11-06 18:43:31 -0800107 void
Yingdi Yu76dd8002013-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,
Yingdi Yu68de61d2014-01-16 19:13:03 -0800112 int retry = 1);
Yingdi Yu76dd8002013-12-24 11:16:32 +0800113
114 void
115 onTargetData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
116 const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
Yingdi Yu76dd8002013-12-24 11:16:32 +0800117 const ndn::OnVerified& onVerified,
Yingdi Yu68de61d2014-01-16 19:13:03 -0800118 const ndn::OnVerifyFailed& onVerifyFailed);
Yingdi Yu76dd8002013-12-24 11:16:32 +0800119
120 void
121 onTargetTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
122 int retry,
Yingdi Yu76dd8002013-12-24 11:16:32 +0800123 const ndn::OnVerified& onVerified,
124 const ndn::OnVerifyFailed& onVerifyFailed,
125 const TimeoutNotify& timeoutNotify);
126
127
128 void
129 onCertData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
130 const ndn::ptr_lib::shared_ptr<ndn::Data>& cert,
131 ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> previousStep);
132
133 void
134 onCertTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
135 const ndn::OnVerifyFailed& onVerifyFailed,
136 const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
137 ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> nextStep);
Yingdi Yu46948282013-11-06 18:43:31 -0800138
139 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800140 onInvitationCertVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
141 ndn::ptr_lib::shared_ptr<ChronosInvitation> invitation);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700142
Yingdi Yub2e747d2013-11-05 23:06:43 -0800143 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800144 onInvitationCertVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
145
146 void
147 onInvitationCertTimeoutNotify();
148
149 void
150 popChatInvitation(ndn::ptr_lib::shared_ptr<ChronosInvitation> invitation,
Yingdi Yu46948282013-11-06 18:43:31 -0800151 const ndn::Name& inviterNameSpace,
Yingdi Yu76dd8002013-12-24 11:16:32 +0800152 ndn::ptr_lib::shared_ptr<ndn::IdentityCertificate> certificate);
Yingdi Yu46948282013-11-06 18:43:31 -0800153
154 void
Yingdi Yub2e747d2013-11-05 23:06:43 -0800155 collectEndorsement();
156
157 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800158 onDnsEndorseeVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, int count);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800159
160 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800161 onDnsEndorseeVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, int count);
162
Yingdi Yub2e747d2013-11-05 23:06:43 -0800163 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800164 onDnsEndorseeTimeoutNotify(int count);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800165
166 void
167 updateCollectStatus(int count);
168
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700169 std::string
170 getRandomString();
171
Yingdi Yueda39aa2013-10-23 23:07:29 -0700172signals:
173 void
174 newInvitationReady();
175
Yingdi Yuae8217c2013-11-09 00:03:26 -0800176 void
177 refreshCertDirectory();
178
Yingdi Yu40eca752013-10-10 15:00:58 -0700179private slots:
180 void
Yingdi Yu8e135832013-11-09 20:12:31 -0800181 showError(const QString& msg);
182
183 void
Yingdi Yue433a502013-11-10 01:34:57 -0800184 showWarning(const QString& msg);
185
186 void
Yingdi Yu40eca752013-10-10 15:00:58 -0700187 updateSelection(const QItemSelection &selected,
188 const QItemSelection &deselected);
189
Yingdi Yu3b318c12013-10-15 17:54:00 -0700190 void
Yingdi Yu46948282013-11-06 18:43:31 -0800191 updateDefaultIdentity(const QString& identity,
192 const QString& nickName);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700193
194 void
Yingdi Yu3b318c12013-10-15 17:54:00 -0700195 openProfileEditor();
196
Yingdi Yu0269c872013-10-16 13:16:49 -0700197 void
198 openAddContactPanel();
Yingdi Yuae8217c2013-11-09 00:03:26 -0800199
200 void
201 openBrowseContactDialog();
Yingdi Yu0269c872013-10-16 13:16:49 -0700202
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700203 void
204 openSetAliasDialog();
Yingdi Yuae8217c2013-11-09 00:03:26 -0800205
206 void
207 removeContactButton();
Yingdi Yu595aadc2013-10-21 15:01:40 -0700208
209 void
210 openStartChatDialog();
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700211
212 void
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700213 openSettingDialog();
214
215 void
Yingdi Yueda39aa2013-10-23 23:07:29 -0700216 openInvitationDialog();
217
218 void
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700219 refreshContactList();
220
221 void
222 showContextMenu(const QPoint& pos);
223
Yingdi Yu595aadc2013-10-21 15:01:40 -0700224 void
Yingdi Yu46948282013-11-06 18:43:31 -0800225 startChatroom(const QString& chatroom,
226 const QString& invitee,
227 bool isIntroducer);
Yingdi Yu595aadc2013-10-21 15:01:40 -0700228
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700229 void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700230 startChatroom2(const ChronosInvitation& invitation,
Yingdi Yu76dd8002013-12-24 11:16:32 +0800231 const ndn::IdentityCertificate& identityCertificate);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700232
233 void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700234 acceptInvitation(const ChronosInvitation& invitation,
Yingdi Yu76dd8002013-12-24 11:16:32 +0800235 const ndn::IdentityCertificate& identityCertificate);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700236
237 void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700238 rejectInvitation(const ChronosInvitation& invitation);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700239
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800240 void
241 isIntroducerChanged(int state);
242
Yingdi Yub2e747d2013-11-05 23:06:43 -0800243 void
244 addScopeClicked();
245
246 void
247 deleteScopeClicked();
248
249 void
250 saveScopeClicked();
251
252 void
253 endorseButtonClicked();
Yingdi Yu46948282013-11-06 18:43:31 -0800254
255 void
256 removeChatDialog(const ndn::Name& chatroomName);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800257
Yingdi Yu72232692013-11-12 17:50:21 -0800258 void
259 addContactIntoPanelPolicy(const ndn::Name& nameSpace);
260
261 void
262 removeContactFromPanelPolicy(const ndn::Name& keyName);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800263
264
Yingdi Yu847aa862013-10-09 16:35:53 -0700265private:
Yingdi Yu93adb1a2014-01-16 10:30:26 -0800266
Yingdi Yu3b318c12013-10-15 17:54:00 -0700267 Ui::ContactPanel *ui;
Yingdi Yu8e135832013-11-09 20:12:31 -0800268 WarningDialog* m_warningDialog;
Yingdi Yu76dd8002013-12-24 11:16:32 +0800269 ndn::ptr_lib::shared_ptr<ContactManager> m_contactManager;
Yingdi Yu3b318c12013-10-15 17:54:00 -0700270 QStringListModel* m_contactListModel;
271 ProfileEditor* m_profileEditor;
Yingdi Yu0269c872013-10-16 13:16:49 -0700272 AddContactPanel* m_addContactPanel;
Yingdi Yuae8217c2013-11-09 00:03:26 -0800273 BrowseContactDialog* m_browseContactDialog;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700274 SetAliasDialog* m_setAliasDialog;
Yingdi Yu595aadc2013-10-21 15:01:40 -0700275 StartChatDialog* m_startChatDialog;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700276 InvitationDialog* m_invitationDialog;
277 SettingDialog* m_settingDialog;
Yingdi Yub6fb0302014-01-21 11:05:11 -0800278 std::map<ndn::Name, ChatDialog*> m_chatDialogs;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700279 QAction* m_menuInvite;
280 QAction* m_menuAlias;
Yingdi Yu76dd8002013-12-24 11:16:32 +0800281 std::vector<ndn::ptr_lib::shared_ptr<ContactItem> > m_contactList;
282 ndn::ptr_lib::shared_ptr<std::vector<bool> > m_collectStatus;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700283
Yingdi Yu93adb1a2014-01-16 10:30:26 -0800284 ndn::ptr_lib::shared_ptr<SecPolicyChronoChatPanel> m_policy;
Yingdi Yu68de61d2014-01-16 19:13:03 -0800285 ndn::ptr_lib::shared_ptr<ndn::Verifier> m_verifier;
Yingdi Yuf8f572d2014-01-13 11:19:47 -0800286 ndn::ptr_lib::shared_ptr<ndn::KeyChain> m_keyChain;
Yingdi Yu76dd8002013-12-24 11:16:32 +0800287 ndn::ptr_lib::shared_ptr<ndn::Face> m_face;
Yingdi Yu6eabbd72013-12-27 08:44:12 +0800288
289 boost::recursive_mutex m_mutex;
290 boost::thread m_thread;
291 bool m_running;
292
Yingdi Yu76dd8002013-12-24 11:16:32 +0800293 uint64_t m_invitationListenerId;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700294
295 ndn::Name m_defaultIdentity;
Yingdi Yu46948282013-11-06 18:43:31 -0800296 std::string m_nickName;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700297 ndn::Name m_localPrefix;
Yingdi Yueda39aa2013-10-23 23:07:29 -0700298 ndn::Name m_inviteListenPrefix;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700299
Yingdi Yu76dd8002013-12-24 11:16:32 +0800300 ndn::ptr_lib::shared_ptr<ContactItem> m_currentSelectedContact;
Yingdi Yub2e747d2013-11-05 23:06:43 -0800301 QSqlTableModel* m_trustScopeModel;
302 QSqlTableModel* m_endorseDataModel;
303 EndorseComboBoxDelegate* m_endorseComboBoxDelegate;
Yingdi Yu847aa862013-10-09 16:35:53 -0700304};
305
306#endif // CONTACTPANEL_H