blob: 1c2c9fc2b5b67b4a1cd4c25d093a506a5a6f9b38 [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 Yu3b318c12013-10-15 17:54:00 -070035#endif
Yingdi Yu847aa862013-10-09 16:35:53 -070036
Yingdi Yu978b3ae2013-10-23 11:50:51 -070037
Yingdi Yu847aa862013-10-09 16:35:53 -070038namespace Ui {
39class ContactPanel;
40}
41
42class ContactPanel : public QDialog
43{
Yingdi Yueda39aa2013-10-23 23:07:29 -070044 Q_OBJECT
Yingdi Yu847aa862013-10-09 16:35:53 -070045
46public:
Yingdi Yu8e135832013-11-09 20:12:31 -080047 explicit ContactPanel(QWidget *parent = 0);
Yingdi Yu978b3ae2013-10-23 11:50:51 -070048
Yingdi Yu3b318c12013-10-15 17:54:00 -070049 ~ContactPanel();
Yingdi Yu847aa862013-10-09 16:35:53 -070050
Yingdi Yu978b3ae2013-10-23 11:50:51 -070051private:
Yingdi Yu76dd8002013-12-24 11:16:32 +080052 void
53 connectToDaemon();
54
55 void
56 onConnectionData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
57 const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
58
59 void
60 onConnectionDataTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest);
61
Yingdi Yu978b3ae2013-10-23 11:50:51 -070062 void
Yingdi Yu46948282013-11-06 18:43:31 -080063 createAction();
64
65 void
Yingdi Yu978b3ae2013-10-23 11:50:51 -070066 openDB();
67
68 void
Yingdi Yu76dd8002013-12-24 11:16:32 +080069 loadTrustAnchor();
Yingdi Yu978b3ae2013-10-23 11:50:51 -070070
71 void
Yingdi Yufdb8ab82013-11-10 01:38:21 -080072 setLocalPrefix(int retry = 10);
Yingdi Yu978b3ae2013-10-23 11:50:51 -070073
74 void
Yingdi Yu76dd8002013-12-24 11:16:32 +080075 onLocalPrefix(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
76 const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
Yingdi Yu978b3ae2013-10-23 11:50:51 -070077
78 void
Yingdi Yu76dd8002013-12-24 11:16:32 +080079 onLocalPrefixTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
Yingdi Yufdb8ab82013-11-10 01:38:21 -080080 int retry);
Yingdi Yu978b3ae2013-10-23 11:50:51 -070081
82 void
Yingdi Yu978b3ae2013-10-23 11:50:51 -070083 setInvitationListener();
84
85 void
Yingdi Yu76dd8002013-12-24 11:16:32 +080086 onInvitation(const ndn::ptr_lib::shared_ptr<const ndn::Name>& prefix,
87 const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
88 ndn::Transport& transport,
89 uint64_t registeredPrefixI);
Yingdi Yu978b3ae2013-10-23 11:50:51 -070090
91 void
Yingdi Yu76dd8002013-12-24 11:16:32 +080092 onInvitationRegisterFailed(const ndn::ptr_lib::shared_ptr<const ndn::Name>& prefix);
93
Yingdi Yu46948282013-11-06 18:43:31 -080094 void
Yingdi Yu76dd8002013-12-24 11:16:32 +080095 sendInterest(const ndn::Interest& interest,
96 const ndn::OnVerified& onVerified,
97 const ndn::OnVerifyFailed& onVerifyFailed,
98 const TimeoutNotify& timeoutNotify,
99 int retry = 1,
100 int stepCount = 0);
101
102 void
103 onTargetData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
104 const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
105 int stepCount,
106 const ndn::OnVerified& onVerified,
107 const ndn::OnVerifyFailed& onVerifyFailed,
108 const TimeoutNotify& timeoutNotify);
109
110 void
111 onTargetTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
112 int retry,
113 int stepCount,
114 const ndn::OnVerified& onVerified,
115 const ndn::OnVerifyFailed& onVerifyFailed,
116 const TimeoutNotify& timeoutNotify);
117
118
119 void
120 onCertData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
121 const ndn::ptr_lib::shared_ptr<ndn::Data>& cert,
122 ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> previousStep);
123
124 void
125 onCertTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
126 const ndn::OnVerifyFailed& onVerifyFailed,
127 const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
128 ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> nextStep);
Yingdi Yu46948282013-11-06 18:43:31 -0800129
130 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800131 onInvitationCertVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
132 ndn::ptr_lib::shared_ptr<ChronosInvitation> invitation);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700133
Yingdi Yub2e747d2013-11-05 23:06:43 -0800134 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800135 onInvitationCertVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
136
137 void
138 onInvitationCertTimeoutNotify();
139
140 void
141 popChatInvitation(ndn::ptr_lib::shared_ptr<ChronosInvitation> invitation,
Yingdi Yu46948282013-11-06 18:43:31 -0800142 const ndn::Name& inviterNameSpace,
Yingdi Yu76dd8002013-12-24 11:16:32 +0800143 ndn::ptr_lib::shared_ptr<ndn::IdentityCertificate> certificate);
Yingdi Yu46948282013-11-06 18:43:31 -0800144
145 void
Yingdi Yub2e747d2013-11-05 23:06:43 -0800146 collectEndorsement();
147
148 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800149 onDnsEndorseeVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, int count);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800150
151 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800152 onDnsEndorseeVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, int count);
153
Yingdi Yub2e747d2013-11-05 23:06:43 -0800154 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800155 onDnsEndorseeTimeoutNotify(int count);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800156
157 void
158 updateCollectStatus(int count);
159
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700160 std::string
161 getRandomString();
162
Yingdi Yueda39aa2013-10-23 23:07:29 -0700163signals:
164 void
165 newInvitationReady();
166
Yingdi Yuae8217c2013-11-09 00:03:26 -0800167 void
168 refreshCertDirectory();
169
Yingdi Yu40eca752013-10-10 15:00:58 -0700170private slots:
171 void
Yingdi Yu8e135832013-11-09 20:12:31 -0800172 showError(const QString& msg);
173
174 void
Yingdi Yue433a502013-11-10 01:34:57 -0800175 showWarning(const QString& msg);
176
177 void
Yingdi Yu40eca752013-10-10 15:00:58 -0700178 updateSelection(const QItemSelection &selected,
179 const QItemSelection &deselected);
180
Yingdi Yu3b318c12013-10-15 17:54:00 -0700181 void
Yingdi Yu46948282013-11-06 18:43:31 -0800182 updateDefaultIdentity(const QString& identity,
183 const QString& nickName);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700184
185 void
Yingdi Yu3b318c12013-10-15 17:54:00 -0700186 openProfileEditor();
187
Yingdi Yu0269c872013-10-16 13:16:49 -0700188 void
189 openAddContactPanel();
Yingdi Yuae8217c2013-11-09 00:03:26 -0800190
191 void
192 openBrowseContactDialog();
Yingdi Yu0269c872013-10-16 13:16:49 -0700193
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700194 void
195 openSetAliasDialog();
Yingdi Yuae8217c2013-11-09 00:03:26 -0800196
197 void
198 removeContactButton();
Yingdi Yu595aadc2013-10-21 15:01:40 -0700199
200 void
201 openStartChatDialog();
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700202
203 void
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700204 openSettingDialog();
205
206 void
Yingdi Yueda39aa2013-10-23 23:07:29 -0700207 openInvitationDialog();
208
209 void
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700210 refreshContactList();
211
212 void
213 showContextMenu(const QPoint& pos);
214
Yingdi Yu595aadc2013-10-21 15:01:40 -0700215 void
Yingdi Yu46948282013-11-06 18:43:31 -0800216 startChatroom(const QString& chatroom,
217 const QString& invitee,
218 bool isIntroducer);
Yingdi Yu595aadc2013-10-21 15:01:40 -0700219
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700220 void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700221 startChatroom2(const ChronosInvitation& invitation,
Yingdi Yu76dd8002013-12-24 11:16:32 +0800222 const ndn::IdentityCertificate& identityCertificate);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700223
224 void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700225 acceptInvitation(const ChronosInvitation& invitation,
Yingdi Yu76dd8002013-12-24 11:16:32 +0800226 const ndn::IdentityCertificate& identityCertificate);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700227
228 void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700229 rejectInvitation(const ChronosInvitation& invitation);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700230
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800231 void
232 isIntroducerChanged(int state);
233
Yingdi Yub2e747d2013-11-05 23:06:43 -0800234 void
235 addScopeClicked();
236
237 void
238 deleteScopeClicked();
239
240 void
241 saveScopeClicked();
242
243 void
244 endorseButtonClicked();
Yingdi Yu46948282013-11-06 18:43:31 -0800245
246 void
247 removeChatDialog(const ndn::Name& chatroomName);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800248
Yingdi Yu72232692013-11-12 17:50:21 -0800249 void
250 addContactIntoPanelPolicy(const ndn::Name& nameSpace);
251
252 void
253 removeContactFromPanelPolicy(const ndn::Name& keyName);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800254
255
Yingdi Yu847aa862013-10-09 16:35:53 -0700256private:
Yingdi Yu3b318c12013-10-15 17:54:00 -0700257 Ui::ContactPanel *ui;
Yingdi Yu8e135832013-11-09 20:12:31 -0800258 WarningDialog* m_warningDialog;
Yingdi Yu76dd8002013-12-24 11:16:32 +0800259 ndn::ptr_lib::shared_ptr<ContactManager> m_contactManager;
Yingdi Yu3b318c12013-10-15 17:54:00 -0700260 QStringListModel* m_contactListModel;
261 ProfileEditor* m_profileEditor;
Yingdi Yu0269c872013-10-16 13:16:49 -0700262 AddContactPanel* m_addContactPanel;
Yingdi Yuae8217c2013-11-09 00:03:26 -0800263 BrowseContactDialog* m_browseContactDialog;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700264 SetAliasDialog* m_setAliasDialog;
Yingdi Yu595aadc2013-10-21 15:01:40 -0700265 StartChatDialog* m_startChatDialog;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700266 InvitationDialog* m_invitationDialog;
267 SettingDialog* m_settingDialog;
Yingdi Yu76dd8002013-12-24 11:16:32 +0800268 std::map<ndn::Name, ChatDialog*, ndn::Name::BreadthFirstLess> m_chatDialogs;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700269 QAction* m_menuInvite;
270 QAction* m_menuAlias;
Yingdi Yu76dd8002013-12-24 11:16:32 +0800271 std::vector<ndn::ptr_lib::shared_ptr<ContactItem> > m_contactList;
272 ndn::ptr_lib::shared_ptr<std::vector<bool> > m_collectStatus;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700273
Yingdi Yu76dd8002013-12-24 11:16:32 +0800274 ndn::ptr_lib::shared_ptr<PanelPolicyManager> m_policyManager;
275 ndn::ptr_lib::shared_ptr<ndn::IdentityManager> m_identityManager;
276 ndn::ptr_lib::shared_ptr<ndn::Transport> m_transport;
277 ndn::ptr_lib::shared_ptr<ndn::Face> m_face;
278 uint64_t m_invitationListenerId;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700279
280 ndn::Name m_defaultIdentity;
Yingdi Yu46948282013-11-06 18:43:31 -0800281 std::string m_nickName;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700282 ndn::Name m_localPrefix;
Yingdi Yueda39aa2013-10-23 23:07:29 -0700283 ndn::Name m_inviteListenPrefix;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700284
Yingdi Yu76dd8002013-12-24 11:16:32 +0800285 ndn::ptr_lib::shared_ptr<ContactItem> m_currentSelectedContact;
Yingdi Yub2e747d2013-11-05 23:06:43 -0800286 QSqlTableModel* m_trustScopeModel;
287 QSqlTableModel* m_endorseDataModel;
288 EndorseComboBoxDelegate* m_endorseComboBoxDelegate;
Yingdi Yu847aa862013-10-09 16:35:53 -0700289};
290
291#endif // CONTACTPANEL_H