Yingdi Yu | 9e0dc29 | 2013-10-10 11:39:45 -0700 | [diff] [blame] | 1 | /* -*- 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 Yu | def9061 | 2013-10-09 22:34:42 -0700 | [diff] [blame] | 11 | #ifndef CONTACTPANEL_H |
| 12 | #define CONTACTPANEL_H |
| 13 | |
| 14 | #include <QDialog> |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 15 | #include <QStringListModel> |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 16 | #include <QtSql/QSqlDatabase> |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 17 | #include <QMenu> |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 18 | #include <QMessageBox> |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 19 | |
| 20 | #include "profileeditor.h" |
Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 21 | #include "addcontactpanel.h" |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 22 | #include "setaliasdialog.h" |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 23 | #include "startchatdialog.h" |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 24 | #include "invitationdialog.h" |
| 25 | #include "settingdialog.h" |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 26 | #include "chatdialog.h" |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 27 | #include "endorse-combobox-delegate.h" |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 28 | #include "browsecontactdialog.h" |
Yingdi Yu | 1043689 | 2013-11-10 16:26:52 -0800 | [diff] [blame] | 29 | #include "warningdialog.h" |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 30 | |
| 31 | #ifndef Q_MOC_RUN |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 32 | #include "contact-manager.h" |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 33 | #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 Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 42 | #endif |
Yingdi Yu | def9061 | 2013-10-09 22:34:42 -0700 | [diff] [blame] | 43 | |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 44 | |
Yingdi Yu | def9061 | 2013-10-09 22:34:42 -0700 | [diff] [blame] | 45 | namespace Ui { |
| 46 | class ContactPanel; |
| 47 | } |
| 48 | |
| 49 | class ContactPanel : public QDialog |
| 50 | { |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 51 | Q_OBJECT |
Yingdi Yu | def9061 | 2013-10-09 22:34:42 -0700 | [diff] [blame] | 52 | |
| 53 | public: |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 54 | explicit ContactPanel(ndn::shared_ptr<ndn::Face> face, |
| 55 | QWidget *parent = 0); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 56 | |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 57 | ~ContactPanel(); |
Yingdi Yu | def9061 | 2013-10-09 22:34:42 -0700 | [diff] [blame] | 58 | |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 59 | private: |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 60 | void |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 61 | createAction(); |
| 62 | |
| 63 | void |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 64 | openDB(); |
| 65 | |
| 66 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 67 | loadTrustAnchor(); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 68 | |
| 69 | void |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 70 | setLocalPrefix(int retry = 10); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 71 | |
| 72 | void |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 73 | onLocalPrefix(const ndn::Interest& interest, ndn::Data& data); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 74 | |
| 75 | void |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 76 | onLocalPrefixTimeout(const ndn::Interest& interest, int retry); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 77 | |
| 78 | void |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 79 | setInvitationListener(); |
| 80 | |
| 81 | void |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 82 | onInvitation(const ndn::Name& prefix, const ndn::Interest& interest); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 83 | |
| 84 | void |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 85 | 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 Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 95 | |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 96 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 97 | sendInterest(const ndn::Interest& interest, |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 98 | const ndn::OnDataValidated& onValidated, |
| 99 | const ndn::OnDataValidationFailed& onValidationFailed, |
| 100 | const chronos::TimeoutNotify& timeoutNotify, |
Yingdi Yu | 7630f64 | 2014-01-16 19:13:03 -0800 | [diff] [blame] | 101 | int retry = 1); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 102 | |
| 103 | void |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 104 | onTargetData(const ndn::Interest& interest, |
| 105 | ndn::Data& data, |
| 106 | const ndn::OnDataValidated& onValidated, |
| 107 | const ndn::OnDataValidationFailed& onValidationFailed); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 108 | |
| 109 | void |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 110 | onTargetTimeout(const ndn::Interest& interest, |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 111 | int retry, |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 112 | const ndn::OnDataValidated& onValidated, |
| 113 | const ndn::OnDataValidationFailed& onValidationFailed, |
| 114 | const chronos::TimeoutNotify& timeoutNotify); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 115 | |
| 116 | void |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 117 | collectEndorsement(); |
| 118 | |
| 119 | void |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 120 | onDnsEndorseeValidated(const ndn::shared_ptr<const ndn::Data>& data, int count); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 121 | |
| 122 | void |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 123 | onDnsEndorseeValidationFailed(const ndn::shared_ptr<const ndn::Data>& data, int count); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 124 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 125 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 126 | onDnsEndorseeTimeoutNotify(int count); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 127 | |
| 128 | void |
| 129 | updateCollectStatus(int count); |
| 130 | |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 131 | std::string |
| 132 | getRandomString(); |
| 133 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 134 | signals: |
| 135 | void |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 136 | refreshCertDirectory(); |
| 137 | |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 138 | private slots: |
| 139 | void |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 140 | showError(const QString& msg); |
| 141 | |
| 142 | void |
Yingdi Yu | eb98f7d | 2013-11-10 01:34:57 -0800 | [diff] [blame] | 143 | showWarning(const QString& msg); |
| 144 | |
| 145 | void |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 146 | updateSelection(const QItemSelection &selected, |
| 147 | const QItemSelection &deselected); |
| 148 | |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 149 | void |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 150 | updateDefaultIdentity(const QString& identity, |
| 151 | const QString& nickName); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 152 | |
| 153 | void |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 154 | openProfileEditor(); |
| 155 | |
Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 156 | void |
| 157 | openAddContactPanel(); |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 158 | |
| 159 | void |
| 160 | openBrowseContactDialog(); |
Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 161 | |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 162 | void |
| 163 | openSetAliasDialog(); |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 164 | |
| 165 | void |
| 166 | removeContactButton(); |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 167 | |
| 168 | void |
| 169 | openStartChatDialog(); |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 170 | |
| 171 | void |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 172 | openSettingDialog(); |
| 173 | |
| 174 | void |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 175 | refreshContactList(); |
| 176 | |
| 177 | void |
| 178 | showContextMenu(const QPoint& pos); |
| 179 | |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 180 | void |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 181 | startChatroom(const QString& chatroom); |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 182 | |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 183 | void |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 184 | 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 Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 191 | |
| 192 | void |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 193 | prepareInvitationReply(const ndn::Name& invitationInterest, const std::string& content); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 194 | |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 195 | void |
| 196 | isIntroducerChanged(int state); |
| 197 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 198 | void |
| 199 | addScopeClicked(); |
| 200 | |
| 201 | void |
| 202 | deleteScopeClicked(); |
| 203 | |
| 204 | void |
| 205 | saveScopeClicked(); |
| 206 | |
| 207 | void |
| 208 | endorseButtonClicked(); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 209 | |
| 210 | void |
| 211 | removeChatDialog(const ndn::Name& chatroomName); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 212 | |
Yingdi Yu | 6ea54e4 | 2013-11-12 17:50:21 -0800 | [diff] [blame] | 213 | void |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 214 | addContactIntoValidator(const ndn::Name& nameSpace); |
Yingdi Yu | 6ea54e4 | 2013-11-12 17:50:21 -0800 | [diff] [blame] | 215 | |
| 216 | void |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 217 | removeContactFromValidator(const ndn::Name& keyName); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 218 | |
| 219 | |
Yingdi Yu | def9061 | 2013-10-09 22:34:42 -0700 | [diff] [blame] | 220 | private: |
Yingdi Yu | eaa84e2 | 2014-01-16 10:30:26 -0800 | [diff] [blame] | 221 | |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 222 | Ui::ContactPanel *ui; |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 223 | WarningDialog* m_warningDialog; |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 224 | QStringListModel* m_contactListModel; |
| 225 | ProfileEditor* m_profileEditor; |
Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 226 | AddContactPanel* m_addContactPanel; |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 227 | BrowseContactDialog* m_browseContactDialog; |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 228 | SetAliasDialog* m_setAliasDialog; |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 229 | StartChatDialog* m_startChatDialog; |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 230 | InvitationDialog* m_invitationDialog; |
| 231 | SettingDialog* m_settingDialog; |
Yingdi Yu | 6df6125 | 2014-01-21 11:05:11 -0800 | [diff] [blame] | 232 | std::map<ndn::Name, ChatDialog*> m_chatDialogs; |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 233 | QAction* m_menuAlias; |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 234 | |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 235 | #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 Yu | accbda9 | 2013-12-27 08:44:12 +0800 | [diff] [blame] | 242 | |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 243 | 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 Yu | accbda9 | 2013-12-27 08:44:12 +0800 | [diff] [blame] | 246 | |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 247 | 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 Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 253 | |
| 254 | ndn::Name m_defaultIdentity; |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 255 | std::string m_nickName; |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 256 | ndn::Name m_localPrefix; |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 257 | ndn::Name m_inviteListenPrefix; |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 258 | |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 259 | ndn::shared_ptr<chronos::ContactItem> m_currentSelectedContact; |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 260 | QSqlTableModel* m_trustScopeModel; |
| 261 | QSqlTableModel* m_endorseDataModel; |
| 262 | EndorseComboBoxDelegate* m_endorseComboBoxDelegate; |
Yingdi Yu | def9061 | 2013-10-09 22:34:42 -0700 | [diff] [blame] | 263 | }; |
| 264 | |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 265 | void |
| 266 | ContactPanel::onInvitationValidated(const ndn::shared_ptr<const ndn::Interest>& interest) |
| 267 | { popChatInvitation(interest->getName()); } |
| 268 | |
| 269 | void |
| 270 | ContactPanel::onInvitationValidationFailed(const ndn::shared_ptr<const ndn::Interest>& interest) |
| 271 | {} |
| 272 | |
| 273 | void |
| 274 | ContactPanel::acceptInvitation(const ndn::Name& invitationInterest) |
| 275 | { |
| 276 | prepareInvitationReply(invitationInterest, m_localPrefix.toUri()); |
| 277 | startChatroom2(invitationInterest); |
| 278 | } |
| 279 | |
| 280 | void |
| 281 | ContactPanel::rejectInvitation(const ndn::Name& invitationInterest) |
| 282 | { prepareInvitationReply(invitationInterest, "nack"); } |
| 283 | |
| 284 | |
Yingdi Yu | def9061 | 2013-10-09 22:34:42 -0700 | [diff] [blame] | 285 | #endif // CONTACTPANEL_H |