blob: ce7f7b7e8a3ee3312c3f9de1e724486d462e7fdb [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 Yu9b34b1f2013-11-01 17:37:51 -070034#include "panel-policy-manager.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,
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 Yu46948282013-11-06 18:43:31 -0800142
143 void
Yingdi Yu76dd8002013-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 Yu978b3ae2013-10-23 11:50:51 -0700146
Yingdi Yub2e747d2013-11-05 23:06:43 -0800147 void
Yingdi Yu76dd8002013-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 Yu46948282013-11-06 18:43:31 -0800155 const ndn::Name& inviterNameSpace,
Yingdi Yu76dd8002013-12-24 11:16:32 +0800156 ndn::ptr_lib::shared_ptr<ndn::IdentityCertificate> certificate);
Yingdi Yu46948282013-11-06 18:43:31 -0800157
158 void
Yingdi Yub2e747d2013-11-05 23:06:43 -0800159 collectEndorsement();
160
161 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800162 onDnsEndorseeVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, int count);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800163
164 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800165 onDnsEndorseeVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, int count);
166
Yingdi Yub2e747d2013-11-05 23:06:43 -0800167 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800168 onDnsEndorseeTimeoutNotify(int count);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800169
170 void
171 updateCollectStatus(int count);
172
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700173 std::string
174 getRandomString();
175
Yingdi Yueda39aa2013-10-23 23:07:29 -0700176signals:
177 void
178 newInvitationReady();
179
Yingdi Yuae8217c2013-11-09 00:03:26 -0800180 void
181 refreshCertDirectory();
182
Yingdi Yu40eca752013-10-10 15:00:58 -0700183private slots:
184 void
Yingdi Yu8e135832013-11-09 20:12:31 -0800185 showError(const QString& msg);
186
187 void
Yingdi Yue433a502013-11-10 01:34:57 -0800188 showWarning(const QString& msg);
189
190 void
Yingdi Yu40eca752013-10-10 15:00:58 -0700191 updateSelection(const QItemSelection &selected,
192 const QItemSelection &deselected);
193
Yingdi Yu3b318c12013-10-15 17:54:00 -0700194 void
Yingdi Yu46948282013-11-06 18:43:31 -0800195 updateDefaultIdentity(const QString& identity,
196 const QString& nickName);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700197
198 void
Yingdi Yu3b318c12013-10-15 17:54:00 -0700199 openProfileEditor();
200
Yingdi Yu0269c872013-10-16 13:16:49 -0700201 void
202 openAddContactPanel();
Yingdi Yuae8217c2013-11-09 00:03:26 -0800203
204 void
205 openBrowseContactDialog();
Yingdi Yu0269c872013-10-16 13:16:49 -0700206
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700207 void
208 openSetAliasDialog();
Yingdi Yuae8217c2013-11-09 00:03:26 -0800209
210 void
211 removeContactButton();
Yingdi Yu595aadc2013-10-21 15:01:40 -0700212
213 void
214 openStartChatDialog();
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700215
216 void
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700217 openSettingDialog();
218
219 void
Yingdi Yueda39aa2013-10-23 23:07:29 -0700220 openInvitationDialog();
221
222 void
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700223 refreshContactList();
224
225 void
226 showContextMenu(const QPoint& pos);
227
Yingdi Yu595aadc2013-10-21 15:01:40 -0700228 void
Yingdi Yu46948282013-11-06 18:43:31 -0800229 startChatroom(const QString& chatroom,
230 const QString& invitee,
231 bool isIntroducer);
Yingdi Yu595aadc2013-10-21 15:01:40 -0700232
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700233 void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700234 startChatroom2(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 acceptInvitation(const ChronosInvitation& invitation,
Yingdi Yu76dd8002013-12-24 11:16:32 +0800239 const ndn::IdentityCertificate& identityCertificate);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700240
241 void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700242 rejectInvitation(const ChronosInvitation& invitation);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700243
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800244 void
245 isIntroducerChanged(int state);
246
Yingdi Yub2e747d2013-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 Yu46948282013-11-06 18:43:31 -0800258
259 void
260 removeChatDialog(const ndn::Name& chatroomName);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800261
Yingdi Yu72232692013-11-12 17:50:21 -0800262 void
263 addContactIntoPanelPolicy(const ndn::Name& nameSpace);
264
265 void
266 removeContactFromPanelPolicy(const ndn::Name& keyName);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800267
268
Yingdi Yu847aa862013-10-09 16:35:53 -0700269private:
Yingdi Yu3b318c12013-10-15 17:54:00 -0700270 Ui::ContactPanel *ui;
Yingdi Yu8e135832013-11-09 20:12:31 -0800271 WarningDialog* m_warningDialog;
Yingdi Yu76dd8002013-12-24 11:16:32 +0800272 ndn::ptr_lib::shared_ptr<ContactManager> m_contactManager;
Yingdi Yu3b318c12013-10-15 17:54:00 -0700273 QStringListModel* m_contactListModel;
274 ProfileEditor* m_profileEditor;
Yingdi Yu0269c872013-10-16 13:16:49 -0700275 AddContactPanel* m_addContactPanel;
Yingdi Yuae8217c2013-11-09 00:03:26 -0800276 BrowseContactDialog* m_browseContactDialog;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700277 SetAliasDialog* m_setAliasDialog;
Yingdi Yu595aadc2013-10-21 15:01:40 -0700278 StartChatDialog* m_startChatDialog;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700279 InvitationDialog* m_invitationDialog;
280 SettingDialog* m_settingDialog;
Yingdi Yu76dd8002013-12-24 11:16:32 +0800281 std::map<ndn::Name, ChatDialog*, ndn::Name::BreadthFirstLess> m_chatDialogs;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700282 QAction* m_menuInvite;
283 QAction* m_menuAlias;
Yingdi Yu76dd8002013-12-24 11:16:32 +0800284 std::vector<ndn::ptr_lib::shared_ptr<ContactItem> > m_contactList;
285 ndn::ptr_lib::shared_ptr<std::vector<bool> > m_collectStatus;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700286
Yingdi Yu76dd8002013-12-24 11:16:32 +0800287 ndn::ptr_lib::shared_ptr<PanelPolicyManager> m_policyManager;
Yingdi Yuf8f572d2014-01-13 11:19:47 -0800288 ndn::ptr_lib::shared_ptr<ndn::KeyChain> m_keyChain;
Yingdi Yu76dd8002013-12-24 11:16:32 +0800289 ndn::ptr_lib::shared_ptr<ndn::Face> m_face;
Yingdi Yu6eabbd72013-12-27 08:44:12 +0800290
291 boost::recursive_mutex m_mutex;
292 boost::thread m_thread;
293 bool m_running;
294
Yingdi Yu76dd8002013-12-24 11:16:32 +0800295 uint64_t m_invitationListenerId;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700296
297 ndn::Name m_defaultIdentity;
Yingdi Yu46948282013-11-06 18:43:31 -0800298 std::string m_nickName;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700299 ndn::Name m_localPrefix;
Yingdi Yueda39aa2013-10-23 23:07:29 -0700300 ndn::Name m_inviteListenPrefix;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700301
Yingdi Yu76dd8002013-12-24 11:16:32 +0800302 ndn::ptr_lib::shared_ptr<ContactItem> m_currentSelectedContact;
Yingdi Yub2e747d2013-11-05 23:06:43 -0800303 QSqlTableModel* m_trustScopeModel;
304 QSqlTableModel* m_endorseDataModel;
305 EndorseComboBoxDelegate* m_endorseComboBoxDelegate;
Yingdi Yu847aa862013-10-09 16:35:53 -0700306};
307
308#endif // CONTACTPANEL_H