blob: 9e0c3b3c5864e390b6a0311ec4776e0c0611921c [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 Yua1a688f2014-02-06 18:09:22 -080033#include "invitation.h"
34
35#ifdef WITH_SECURITY
36#include "validator-panel.h"
37#include "validator-invitation.h"
38#else
39#include <ndn-cpp-dev/security/validator-null.hpp>
40#endif
41
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070042#endif
Yingdi Yudef90612013-10-09 22:34:42 -070043
Yingdi Yu53eb8a72013-10-23 11:50:51 -070044
Yingdi Yudef90612013-10-09 22:34:42 -070045namespace Ui {
46class ContactPanel;
47}
48
49class ContactPanel : public QDialog
50{
Yingdi Yuc4d08d22013-10-23 23:07:29 -070051 Q_OBJECT
Yingdi Yudef90612013-10-09 22:34:42 -070052
53public:
Yingdi Yua1a688f2014-02-06 18:09:22 -080054 explicit ContactPanel(ndn::shared_ptr<ndn::Face> face,
55 QWidget *parent = 0);
Yingdi Yu53eb8a72013-10-23 11:50:51 -070056
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070057 ~ContactPanel();
Yingdi Yudef90612013-10-09 22:34:42 -070058
Yingdi Yua1a688f2014-02-06 18:09:22 -080059private:
Yingdi Yu53eb8a72013-10-23 11:50:51 -070060 void
Yingdi Yu42372442013-11-06 18:43:31 -080061 createAction();
62
63 void
Yingdi Yu53eb8a72013-10-23 11:50:51 -070064 openDB();
65
66 void
Yingdi Yu64206112013-12-24 11:16:32 +080067 loadTrustAnchor();
Yingdi Yu53eb8a72013-10-23 11:50:51 -070068
69 void
Yingdi Yu2ab22e72013-11-10 01:38:21 -080070 setLocalPrefix(int retry = 10);
Yingdi Yu53eb8a72013-10-23 11:50:51 -070071
72 void
Yingdi Yua1a688f2014-02-06 18:09:22 -080073 onLocalPrefix(const ndn::Interest& interest, ndn::Data& data);
Yingdi Yu53eb8a72013-10-23 11:50:51 -070074
75 void
Yingdi Yua1a688f2014-02-06 18:09:22 -080076 onLocalPrefixTimeout(const ndn::Interest& interest, int retry);
Yingdi Yu53eb8a72013-10-23 11:50:51 -070077
78 void
Yingdi Yu53eb8a72013-10-23 11:50:51 -070079 setInvitationListener();
80
81 void
Yingdi Yua1a688f2014-02-06 18:09:22 -080082 onInvitation(const ndn::Name& prefix, const ndn::Interest& interest);
Yingdi Yu53eb8a72013-10-23 11:50:51 -070083
84 void
Yingdi Yua1a688f2014-02-06 18:09:22 -080085 onInvitationRegisterFailed(const ndn::Name& prefix, const std::string& msg);
86
87 inline void
88 onInvitationValidated(const ndn::shared_ptr<const ndn::Interest>& interest);
89
90 inline void
91 onInvitationValidationFailed(const ndn::shared_ptr<const ndn::Interest>& interest);
92
93 void
94 popChatInvitation(const ndn::Name& interestName);
Yingdi Yu64206112013-12-24 11:16:32 +080095
Yingdi Yu42372442013-11-06 18:43:31 -080096 void
Yingdi Yu64206112013-12-24 11:16:32 +080097 sendInterest(const ndn::Interest& interest,
Yingdi Yua1a688f2014-02-06 18:09:22 -080098 const ndn::OnDataValidated& onValidated,
99 const ndn::OnDataValidationFailed& onValidationFailed,
100 const chronos::TimeoutNotify& timeoutNotify,
Yingdi Yu7630f642014-01-16 19:13:03 -0800101 int retry = 1);
Yingdi Yu64206112013-12-24 11:16:32 +0800102
103 void
Yingdi Yua1a688f2014-02-06 18:09:22 -0800104 onTargetData(const ndn::Interest& interest,
105 ndn::Data& data,
106 const ndn::OnDataValidated& onValidated,
107 const ndn::OnDataValidationFailed& onValidationFailed);
Yingdi Yu64206112013-12-24 11:16:32 +0800108
109 void
Yingdi Yua1a688f2014-02-06 18:09:22 -0800110 onTargetTimeout(const ndn::Interest& interest,
Yingdi Yu64206112013-12-24 11:16:32 +0800111 int retry,
Yingdi Yua1a688f2014-02-06 18:09:22 -0800112 const ndn::OnDataValidated& onValidated,
113 const ndn::OnDataValidationFailed& onValidationFailed,
114 const chronos::TimeoutNotify& timeoutNotify);
Yingdi Yu42372442013-11-06 18:43:31 -0800115
116 void
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800117 collectEndorsement();
118
119 void
Yingdi Yua1a688f2014-02-06 18:09:22 -0800120 onDnsEndorseeValidated(const ndn::shared_ptr<const ndn::Data>& data, int count);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800121
122 void
Yingdi Yua1a688f2014-02-06 18:09:22 -0800123 onDnsEndorseeValidationFailed(const ndn::shared_ptr<const ndn::Data>& data, int count);
Yingdi Yu64206112013-12-24 11:16:32 +0800124
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800125 void
Yingdi Yu64206112013-12-24 11:16:32 +0800126 onDnsEndorseeTimeoutNotify(int count);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800127
128 void
129 updateCollectStatus(int count);
130
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700131 std::string
132 getRandomString();
133
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700134signals:
135 void
Yingdi Yu908f8412013-11-09 00:03:26 -0800136 refreshCertDirectory();
137
Yingdi Yu01a942b2013-10-10 15:00:58 -0700138private slots:
139 void
Yingdi Yub29f78c2013-11-09 20:12:31 -0800140 showError(const QString& msg);
141
142 void
Yingdi Yueb98f7d2013-11-10 01:34:57 -0800143 showWarning(const QString& msg);
144
145 void
Yingdi Yu01a942b2013-10-10 15:00:58 -0700146 updateSelection(const QItemSelection &selected,
147 const QItemSelection &deselected);
148
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700149 void
Yingdi Yu42372442013-11-06 18:43:31 -0800150 updateDefaultIdentity(const QString& identity,
151 const QString& nickName);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700152
153 void
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700154 openProfileEditor();
155
Yingdi Yud59b5932013-10-16 13:16:49 -0700156 void
157 openAddContactPanel();
Yingdi Yu908f8412013-11-09 00:03:26 -0800158
159 void
160 openBrowseContactDialog();
Yingdi Yud59b5932013-10-16 13:16:49 -0700161
Yingdi Yu79c25a22013-10-21 13:38:38 -0700162 void
163 openSetAliasDialog();
Yingdi Yu908f8412013-11-09 00:03:26 -0800164
165 void
166 removeContactButton();
Yingdi Yu100267f2013-10-21 15:01:40 -0700167
168 void
169 openStartChatDialog();
Yingdi Yu79c25a22013-10-21 13:38:38 -0700170
171 void
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700172 openSettingDialog();
173
174 void
Yingdi Yu79c25a22013-10-21 13:38:38 -0700175 refreshContactList();
176
177 void
178 showContextMenu(const QPoint& pos);
179
Yingdi Yu100267f2013-10-21 15:01:40 -0700180 void
Yingdi Yua1a688f2014-02-06 18:09:22 -0800181 startChatroom(const QString& chatroom);
Yingdi Yu100267f2013-10-21 15:01:40 -0700182
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700183 void
Yingdi Yua1a688f2014-02-06 18:09:22 -0800184 startChatroom2(const ndn::Name& invitationInterest);
185
186 inline void
187 acceptInvitation(const ndn::Name& invitationInterest);
188
189 inline void
190 rejectInvitation(const ndn::Name& invitationInterest);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700191
192 void
Yingdi Yua1a688f2014-02-06 18:09:22 -0800193 prepareInvitationReply(const ndn::Name& invitationInterest, const std::string& content);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700194
Yingdi Yua50c3252013-11-03 15:05:26 -0800195 void
196 isIntroducerChanged(int state);
197
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800198 void
199 addScopeClicked();
200
201 void
202 deleteScopeClicked();
203
204 void
205 saveScopeClicked();
206
207 void
208 endorseButtonClicked();
Yingdi Yu42372442013-11-06 18:43:31 -0800209
210 void
211 removeChatDialog(const ndn::Name& chatroomName);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800212
Yingdi Yu6ea54e42013-11-12 17:50:21 -0800213 void
Yingdi Yua1a688f2014-02-06 18:09:22 -0800214 addContactIntoValidator(const ndn::Name& nameSpace);
Yingdi Yu6ea54e42013-11-12 17:50:21 -0800215
216 void
Yingdi Yua1a688f2014-02-06 18:09:22 -0800217 removeContactFromValidator(const ndn::Name& keyName);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800218
219
Yingdi Yudef90612013-10-09 22:34:42 -0700220private:
Yingdi Yueaa84e22014-01-16 10:30:26 -0800221
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700222 Ui::ContactPanel *ui;
Yingdi Yub29f78c2013-11-09 20:12:31 -0800223 WarningDialog* m_warningDialog;
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700224 QStringListModel* m_contactListModel;
225 ProfileEditor* m_profileEditor;
Yingdi Yud59b5932013-10-16 13:16:49 -0700226 AddContactPanel* m_addContactPanel;
Yingdi Yu908f8412013-11-09 00:03:26 -0800227 BrowseContactDialog* m_browseContactDialog;
Yingdi Yu79c25a22013-10-21 13:38:38 -0700228 SetAliasDialog* m_setAliasDialog;
Yingdi Yu100267f2013-10-21 15:01:40 -0700229 StartChatDialog* m_startChatDialog;
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700230 InvitationDialog* m_invitationDialog;
231 SettingDialog* m_settingDialog;
Yingdi Yu6df61252014-01-21 11:05:11 -0800232 std::map<ndn::Name, ChatDialog*> m_chatDialogs;
Yingdi Yu79c25a22013-10-21 13:38:38 -0700233 QAction* m_menuAlias;
Yingdi Yu79c25a22013-10-21 13:38:38 -0700234
Yingdi Yua1a688f2014-02-06 18:09:22 -0800235#ifdef WITH_SECURITY
236 ndn::shared_ptr<chronos::ValidatorPanel> m_panelValidator;
237 ndn::shared_ptr<chronos::ValidatorInvitation> m_invitationValidator;
238#else
239 ndn::shared_ptr<ndn::Validator> m_panelValidator;
240 ndn::shared_ptr<ndn::Validator> m_invitationValidator;
241#endif
Yingdi Yuaccbda92013-12-27 08:44:12 +0800242
Yingdi Yua1a688f2014-02-06 18:09:22 -0800243 ndn::shared_ptr<ndn::KeyChain> m_keyChain;
244 ndn::shared_ptr<ndn::Face> m_face;
245 ndn::shared_ptr<boost::asio::io_service> m_ioService;
Yingdi Yuaccbda92013-12-27 08:44:12 +0800246
Yingdi Yua1a688f2014-02-06 18:09:22 -0800247 ndn::shared_ptr<chronos::ContactManager> m_contactManager;
248
249 std::vector<ndn::shared_ptr<chronos::ContactItem> > m_contactList;
250 ndn::shared_ptr<std::vector<bool> > m_collectStatus;
251
252 const ndn::RegisteredPrefixId* m_invitationListenerId;
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700253
254 ndn::Name m_defaultIdentity;
Yingdi Yu42372442013-11-06 18:43:31 -0800255 std::string m_nickName;
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700256 ndn::Name m_localPrefix;
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700257 ndn::Name m_inviteListenPrefix;
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700258
Yingdi Yua1a688f2014-02-06 18:09:22 -0800259 ndn::shared_ptr<chronos::ContactItem> m_currentSelectedContact;
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800260 QSqlTableModel* m_trustScopeModel;
261 QSqlTableModel* m_endorseDataModel;
262 EndorseComboBoxDelegate* m_endorseComboBoxDelegate;
Yingdi Yudef90612013-10-09 22:34:42 -0700263};
264
Yingdi Yua1a688f2014-02-06 18:09:22 -0800265void
266ContactPanel::onInvitationValidated(const ndn::shared_ptr<const ndn::Interest>& interest)
267{ popChatInvitation(interest->getName()); }
268
269void
270ContactPanel::onInvitationValidationFailed(const ndn::shared_ptr<const ndn::Interest>& interest)
271{}
272
273void
274ContactPanel::acceptInvitation(const ndn::Name& invitationInterest)
275{
276 prepareInvitationReply(invitationInterest, m_localPrefix.toUri());
277 startChatroom2(invitationInterest);
278}
279
280void
281ContactPanel::rejectInvitation(const ndn::Name& invitationInterest)
282{ prepareInvitationReply(invitationInterest, "nack"); }
283
284
Yingdi Yudef90612013-10-09 22:34:42 -0700285#endif // CONTACTPANEL_H