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 | #include "contactpanel.h" |
| 12 | #include "ui_contactpanel.h" |
| 13 | |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 14 | |
| 15 | #include <QStringList> |
| 16 | #include <QItemSelectionModel> |
| 17 | #include <QModelIndex> |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 18 | #include <QDir> |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 19 | #include <QtSql/QSqlRecord> |
| 20 | #include <QtSql/QSqlField> |
| 21 | #include <QtSql/QSqlError> |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 22 | |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 23 | #ifndef Q_MOC_RUN |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 24 | #include <ndn.cxx/security/keychain.h> |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 25 | #include <ndn.cxx/security/identity/identity-manager.h> |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 26 | #include <ndn.cxx/common.h> |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 27 | #include <boost/filesystem.hpp> |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 28 | #include <boost/random/random_device.hpp> |
| 29 | #include <boost/random/uniform_int_distribution.hpp> |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 30 | #include "panel-policy-manager.h" |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 31 | #include "logging.h" |
| 32 | #include "exception.h" |
| 33 | #endif |
| 34 | |
| 35 | namespace fs = boost::filesystem; |
| 36 | using namespace ndn; |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 37 | |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 38 | using namespace std; |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 39 | |
| 40 | INIT_LOGGER("ContactPanel"); |
| 41 | |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 42 | Q_DECLARE_METATYPE(ndn::security::IdentityCertificate) |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 43 | Q_DECLARE_METATYPE(ChronosInvitation) |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 44 | |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 45 | ContactPanel::ContactPanel(QWidget *parent) |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 46 | : QDialog(parent) |
| 47 | , ui(new Ui::ContactPanel) |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 48 | , m_warningDialog(new WarningDialog) |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 49 | , m_contactListModel(new QStringListModel) |
| 50 | , m_startChatDialog(new StartChatDialog) |
| 51 | , m_invitationDialog(new InvitationDialog) |
| 52 | , m_settingDialog(new SettingDialog) |
Yingdi Yu | def9061 | 2013-10-09 22:34:42 -0700 | [diff] [blame] | 53 | { |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 54 | qRegisterMetaType<ndn::security::IdentityCertificate>("IdentityCertificate"); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 55 | qRegisterMetaType<ChronosInvitation>("ChronosInvitation"); |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 56 | |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 57 | createAction(); |
| 58 | |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 59 | m_contactManager = Ptr<ContactManager>::Create(); |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 60 | |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 61 | connect(&*m_contactManager, SIGNAL(noNdnConnection(const QString&)), |
| 62 | this, SLOT(showError(const QString&))); |
| 63 | |
| 64 | m_contactManager->setWrapper(); |
| 65 | |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 66 | openDB(); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 67 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 68 | refreshContactList(); |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 69 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 70 | setKeychain(); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 71 | |
| 72 | m_defaultIdentity = m_keychain->getDefaultIdentity(); |
Yingdi Yu | 1043689 | 2013-11-10 16:26:52 -0800 | [diff] [blame] | 73 | if(m_defaultIdentity.size() == 0) |
| 74 | showError(QString::fromStdString("certificate of ") + QString::fromStdString(m_defaultIdentity.toUri()) + " is missing!\nHave you installed the certificate?"); |
Yingdi Yu | 71ec965 | 2013-11-09 22:18:26 -0800 | [diff] [blame] | 75 | Name defaultCertName = m_keychain->getIdentityManager()->getDefaultCertificateNameByIdentity(m_defaultIdentity); |
| 76 | if(defaultCertName.size() == 0) |
Yingdi Yu | cf1bdcb | 2013-11-10 10:54:16 -0800 | [diff] [blame] | 77 | showError(QString::fromStdString("certificate of ") + QString::fromStdString(m_defaultIdentity.toUri()) + " is missing!\nHave you installed the certificate?"); |
Yingdi Yu | 1043689 | 2013-11-10 16:26:52 -0800 | [diff] [blame] | 78 | |
| 79 | |
| 80 | m_contactManager->setDefaultIdentity(m_defaultIdentity); |
| 81 | m_nickName = m_defaultIdentity.get(-1).toUri(); |
| 82 | m_settingDialog->setIdentity(m_defaultIdentity.toUri(), m_nickName); |
Yingdi Yu | 71ec965 | 2013-11-09 22:18:26 -0800 | [diff] [blame] | 83 | |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 84 | |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 85 | m_profileEditor = new ProfileEditor(m_contactManager); |
| 86 | m_profileEditor->setCurrentIdentity(m_defaultIdentity); |
| 87 | |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 88 | m_addContactPanel = new AddContactPanel(m_contactManager); |
| 89 | m_browseContactDialog = new BrowseContactDialog(m_contactManager); |
| 90 | m_setAliasDialog = new SetAliasDialog(m_contactManager); |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 91 | |
| 92 | ui->setupUi(this); |
| 93 | |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 94 | try{ |
| 95 | m_handler = Ptr<Wrapper>(new Wrapper(m_keychain)); |
| 96 | }catch(ndn::Error::ndnOperation& e){ |
| 97 | showError(QString::fromStdString("Cannot conect to ndnd!\n Have you started your ndnd?")); |
| 98 | } |
| 99 | |
Yingdi Yu | 0a953c3 | 2013-11-10 10:32:18 -0800 | [diff] [blame] | 100 | m_localPrefix = Name("/private/local"); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 101 | setLocalPrefix(); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 102 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 103 | setInvitationListener(); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 104 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 105 | collectEndorsement(); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 106 | |
| 107 | ui->ContactList->setModel(m_contactListModel); |
| 108 | |
Yingdi Yu | c26af3c | 2013-10-17 17:03:46 -0700 | [diff] [blame] | 109 | |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 110 | connect(ui->ContactList->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 111 | this, SLOT(updateSelection(const QItemSelection &, const QItemSelection &))); |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 112 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 113 | connect(ui->ContactList, SIGNAL(customContextMenuRequested(const QPoint&)), |
| 114 | this, SLOT(showContextMenu(const QPoint&))); |
Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 115 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 116 | connect(ui->EditProfileButton, SIGNAL(clicked()), |
| 117 | this, SLOT(openProfileEditor())); |
Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 118 | |
Yingdi Yu | 71ec965 | 2013-11-09 22:18:26 -0800 | [diff] [blame] | 119 | connect(m_profileEditor, SIGNAL(noKeyOrCert(const QString&)), |
Yingdi Yu | eb98f7d | 2013-11-10 01:34:57 -0800 | [diff] [blame] | 120 | this, SLOT(showWarning(const QString&))); |
Yingdi Yu | 71ec965 | 2013-11-09 22:18:26 -0800 | [diff] [blame] | 121 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 122 | connect(ui->AddContactButton, SIGNAL(clicked()), |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 123 | this, SLOT(openBrowseContactDialog())); |
| 124 | |
Yingdi Yu | 3cd30df | 2013-11-10 17:59:58 -0800 | [diff] [blame] | 125 | connect(m_browseContactDialog, SIGNAL(directAddClicked()), |
| 126 | this, SLOT(openAddContactPanel())); |
| 127 | |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 128 | connect(this, SIGNAL(refreshCertDirectory()), |
| 129 | m_browseContactDialog, SLOT(refreshList())); |
| 130 | |
| 131 | connect(ui->DeleteContactButton, SIGNAL(clicked()), |
| 132 | this, SLOT(removeContactButton())); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 133 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 134 | connect(ui->settingButton, SIGNAL(clicked()), |
| 135 | this, SLOT(openSettingDialog())); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 136 | |
Yingdi Yu | 3cd30df | 2013-11-10 17:59:58 -0800 | [diff] [blame] | 137 | connect(m_addContactPanel, SIGNAL(newContactAdded()), |
| 138 | this, SLOT(refreshContactList())); |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 139 | connect(m_browseContactDialog, SIGNAL(newContactAdded()), |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 140 | this, SLOT(refreshContactList())); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 141 | connect(m_setAliasDialog, SIGNAL(aliasChanged()), |
| 142 | this, SLOT(refreshContactList())); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 143 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 144 | connect(m_startChatDialog, SIGNAL(chatroomConfirmed(const QString&, const QString&, bool)), |
| 145 | this, SLOT(startChatroom(const QString&, const QString&, bool))); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 146 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 147 | connect(m_invitationDialog, SIGNAL(invitationAccepted(const ChronosInvitation&, const ndn::security::IdentityCertificate&)), |
| 148 | this, SLOT(acceptInvitation(const ChronosInvitation&, const ndn::security::IdentityCertificate&))); |
| 149 | connect(m_invitationDialog, SIGNAL(invitationRejected(const ChronosInvitation&)), |
| 150 | this, SLOT(rejectInvitation(const ChronosInvitation&))); |
Yingdi Yu | 6ea54e4 | 2013-11-12 17:50:21 -0800 | [diff] [blame] | 151 | |
| 152 | connect(&*m_contactManager, SIGNAL(contactAdded(const ndn::Name&)), |
| 153 | this, SLOT(addContactIntoPanelPolicy(const ndn::Name&))); |
| 154 | connect(&*m_contactManager, SIGNAL(contactRemoved(const ndn::Name&)), |
| 155 | this, SLOT(removeContactFromPanelPolicy(const ndn::Name&))); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 156 | |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 157 | connect(m_settingDialog, SIGNAL(identitySet(const QString&, const QString&)), |
| 158 | this, SLOT(updateDefaultIdentity(const QString&, const QString&))); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 159 | |
| 160 | connect(this, SIGNAL(newInvitationReady()), |
| 161 | this, SLOT(openInvitationDialog())); |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 162 | |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 163 | connect(ui->isIntroducer, SIGNAL(stateChanged(int)), |
| 164 | this, SLOT(isIntroducerChanged(int))); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 165 | |
| 166 | connect(ui->addScope, SIGNAL(clicked()), |
| 167 | this, SLOT(addScopeClicked())); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 168 | connect(ui->deleteScope, SIGNAL(clicked()), |
| 169 | this, SLOT(deleteScopeClicked())); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 170 | connect(ui->saveButton, SIGNAL(clicked()), |
| 171 | this, SLOT(saveScopeClicked())); |
| 172 | |
| 173 | connect(ui->endorseButton, SIGNAL(clicked()), |
| 174 | this, SLOT(endorseButtonClicked())); |
Yingdi Yu | def9061 | 2013-10-09 22:34:42 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | ContactPanel::~ContactPanel() |
| 178 | { |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 179 | delete ui; |
| 180 | delete m_contactListModel; |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 181 | delete m_startChatDialog; |
| 182 | delete m_invitationDialog; |
| 183 | delete m_settingDialog; |
| 184 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 185 | delete m_profileEditor; |
| 186 | delete m_addContactPanel; |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 187 | delete m_browseContactDialog; |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 188 | delete m_setAliasDialog; |
| 189 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 190 | delete m_trustScopeModel; |
| 191 | delete m_endorseDataModel; |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 192 | delete m_endorseComboBoxDelegate; |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 193 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 194 | delete m_menuInvite; |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 195 | delete m_menuAlias; |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 196 | |
| 197 | map<Name, ChatDialog*>::iterator it = m_chatDialogs.begin(); |
| 198 | for(; it != m_chatDialogs.end(); it++) |
| 199 | delete it->second; |
Yingdi Yu | def9061 | 2013-10-09 22:34:42 -0700 | [diff] [blame] | 200 | } |
Yingdi Yu | 9e0dc29 | 2013-10-10 11:39:45 -0700 | [diff] [blame] | 201 | |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 202 | void |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 203 | ContactPanel::createAction() |
| 204 | { |
| 205 | m_menuInvite = new QAction("&Chat", this); |
| 206 | m_menuAlias = new QAction("&Set Alias", this); |
| 207 | } |
| 208 | |
| 209 | void |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 210 | ContactPanel::openDB() |
| 211 | { |
| 212 | QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); |
| 213 | QString path = (QDir::home().path()); |
| 214 | path.append(QDir::separator()).append(".chronos").append(QDir::separator()).append("chronos.db"); |
| 215 | db.setDatabaseName(path); |
| 216 | bool ok = db.open(); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 217 | _LOG_DEBUG("DB opened: " << std::boolalpha << ok ); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 218 | |
| 219 | m_trustScopeModel = new QSqlTableModel; |
| 220 | m_endorseDataModel = new QSqlTableModel; |
| 221 | m_endorseComboBoxDelegate = new EndorseComboBoxDelegate; |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | void |
| 225 | ContactPanel::setKeychain() |
| 226 | { |
Yingdi Yu | ed8cfc4 | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 227 | m_panelPolicyManager = Ptr<PanelPolicyManager>::Create(); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 228 | |
| 229 | vector<Ptr<ContactItem> >::const_iterator it = m_contactList.begin(); |
| 230 | for(; it != m_contactList.end(); it++) |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 231 | { |
| 232 | m_panelPolicyManager->addTrustAnchor((*it)->getSelfEndorseCertificate()); |
| 233 | } |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 234 | |
Yingdi Yu | ed8cfc4 | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 235 | m_keychain = Ptr<security::Keychain>(new security::Keychain(Ptr<security::IdentityManager>::Create(), |
| 236 | m_panelPolicyManager, |
| 237 | NULL)); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | void |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 241 | ContactPanel::setLocalPrefix(int retry) |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 242 | { |
| 243 | Ptr<Interest> interest = Ptr<Interest>(new Interest(Name("/local/ndn/prefix"))); |
| 244 | interest->setChildSelector(Interest::CHILD_RIGHT); |
| 245 | |
| 246 | Ptr<Closure> closure = Ptr<Closure>(new Closure(boost::bind(&ContactPanel::onLocalPrefixVerified, |
| 247 | this, |
| 248 | _1), |
| 249 | boost::bind(&ContactPanel::onLocalPrefixTimeout, |
| 250 | this, |
| 251 | _1, |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 252 | _2, |
| 253 | 10), |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 254 | boost::bind(&ContactPanel::onLocalPrefixVerified, |
| 255 | this, |
| 256 | _1))); |
| 257 | |
| 258 | m_handler->sendInterest(interest, closure); |
| 259 | } |
| 260 | |
| 261 | void |
| 262 | ContactPanel::onLocalPrefixVerified(Ptr<Data> data) |
| 263 | { |
| 264 | string originPrefix(data->content().buf(), data->content().size()); |
| 265 | string prefix = QString::fromStdString (originPrefix).trimmed ().toUtf8().constData(); |
| 266 | string randomSuffix = getRandomString(); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 267 | m_localPrefix = Name(prefix); |
Yingdi Yu | eb98f7d | 2013-11-10 01:34:57 -0800 | [diff] [blame] | 268 | |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | void |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 272 | ContactPanel::onLocalPrefixTimeout(Ptr<Closure> closure, Ptr<Interest> interest, int retry) |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 273 | { |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 274 | if(retry > 0) |
Yingdi Yu | 0a953c3 | 2013-11-10 10:32:18 -0800 | [diff] [blame] | 275 | { |
| 276 | setLocalPrefix(retry - 1); |
| 277 | return; |
| 278 | } |
| 279 | else{ |
| 280 | m_localPrefix = Name("/private/local"); |
| 281 | } |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 282 | } |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 283 | |
| 284 | void |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 285 | ContactPanel::setInvitationListener() |
| 286 | { |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 287 | m_inviteListenPrefix = Name("/ndn/broadcast/chronos/invitation"); |
| 288 | m_inviteListenPrefix.append(m_defaultIdentity); |
| 289 | _LOG_DEBUG("Listening for invitation on prefix: " << m_inviteListenPrefix.toUri()); |
| 290 | m_handler->setInterestFilter (m_inviteListenPrefix, |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 291 | boost::bind(&ContactPanel::onInvitation, |
| 292 | this, |
| 293 | _1)); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | void |
| 297 | ContactPanel::onInvitation(Ptr<Interest> interest) |
| 298 | { |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 299 | _LOG_DEBUG("Receive invitation!" << interest->getName().toUri()); |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 300 | |
| 301 | Ptr<ChronosInvitation> invitation = NULL; |
| 302 | try{ |
| 303 | invitation = Ptr<ChronosInvitation>(new ChronosInvitation(interest->getName())); |
| 304 | }catch(exception& e){ |
| 305 | _LOG_ERROR("Exception: " << e.what()); |
| 306 | return; |
| 307 | } |
| 308 | |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 309 | Name chatroomName("/ndn/broadcast/chronos"); |
| 310 | chatroomName.append(invitation->getChatroom()); |
| 311 | map<Name, ChatDialog*>::iterator it = m_chatDialogs.find(chatroomName); |
| 312 | if(it != m_chatDialogs.end()) |
| 313 | { |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 314 | _LOG_ERROR("Exisiting chatroom!"); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 315 | return; |
| 316 | } |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 317 | |
Yingdi Yu | 6b56f09 | 2013-11-10 11:54:02 -0800 | [diff] [blame] | 318 | Ptr<security::Publickey> keyPtr = m_panelPolicyManager->getTrustedKey(invitation->getInviterCertificateName()); |
| 319 | if(NULL != keyPtr && security::PolicyManager::verifySignature(invitation->getSignedBlob(), invitation->getSignatureBits(), *keyPtr)) |
| 320 | { |
| 321 | Ptr<security::IdentityCertificate> certificate = Ptr<security::IdentityCertificate>::Create(); |
Yingdi Yu | 9f65724 | 2013-11-10 12:25:43 -0800 | [diff] [blame] | 322 | // hack: incomplete certificate, we don't send it to the wire nor store it anywhere, we only use it to carry information |
Yingdi Yu | 6b56f09 | 2013-11-10 11:54:02 -0800 | [diff] [blame] | 323 | certificate->setName(invitation->getInviterCertificateName()); |
Yingdi Yu | 9f65724 | 2013-11-10 12:25:43 -0800 | [diff] [blame] | 324 | bool findCert = false; |
| 325 | vector<Ptr<ContactItem> >::const_iterator it = m_contactList.begin(); |
| 326 | for(; it != m_contactList.end(); it++) |
| 327 | { |
| 328 | if((*it)->getNameSpace() == invitation->getInviterNameSpace()) |
| 329 | { |
| 330 | certificate->setNotBefore((*it)->getSelfEndorseCertificate().getNotBefore()); |
| 331 | certificate->setNotAfter((*it)->getSelfEndorseCertificate().getNotAfter()); |
| 332 | findCert = true; |
| 333 | break; |
| 334 | } |
| 335 | } |
| 336 | if(findCert == false) |
| 337 | { |
| 338 | _LOG_ERROR("No SelfEndorseCertificate found!"); |
| 339 | return; |
| 340 | } |
Yingdi Yu | 6b56f09 | 2013-11-10 11:54:02 -0800 | [diff] [blame] | 341 | certificate->setPublicKeyInfo(*keyPtr); |
| 342 | popChatInvitation(invitation, invitation->getInviterNameSpace(), certificate); |
| 343 | return; |
| 344 | } |
| 345 | |
Yingdi Yu | ed8cfc4 | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 346 | Ptr<Interest> newInterest = Ptr<Interest>(new Interest(invitation->getInviterCertificateName())); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 347 | Ptr<Closure> closure = Ptr<Closure>(new Closure(boost::bind(&ContactPanel::onInvitationCertVerified, |
| 348 | this, |
| 349 | _1, |
Yingdi Yu | ed8cfc4 | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 350 | invitation), |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 351 | boost::bind(&ContactPanel::onTimeout, |
| 352 | this, |
| 353 | _1, |
| 354 | _2), |
| 355 | boost::bind(&ContactPanel::onUnverified, |
| 356 | this, |
| 357 | _1))); |
| 358 | m_handler->sendInterest(newInterest, closure); |
| 359 | } |
| 360 | |
| 361 | void |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 362 | ContactPanel::onInvitationCertVerified(Ptr<Data> data, |
| 363 | Ptr<ChronosInvitation> invitation) |
| 364 | { |
| 365 | using namespace ndn::security; |
| 366 | Ptr<IdentityCertificate> certificate = Ptr<IdentityCertificate>(new IdentityCertificate(*data)); |
| 367 | |
| 368 | if(PolicyManager::verifySignature(invitation->getSignedBlob(), invitation->getSignatureBits(), certificate->getPublicKeyInfo())) |
| 369 | { |
| 370 | Name keyName = certificate->getPublicKeyName(); |
| 371 | Name inviterNameSpace = keyName.getPrefix(keyName.size() - 1); |
| 372 | popChatInvitation(invitation, inviterNameSpace, certificate); |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | void |
| 377 | ContactPanel::onUnverified(Ptr<Data> data) |
| 378 | {} |
| 379 | |
| 380 | void |
| 381 | ContactPanel::onTimeout(Ptr<Closure> closure, Ptr<Interest> interest) |
| 382 | {} |
| 383 | |
| 384 | void |
| 385 | ContactPanel::popChatInvitation(Ptr<ChronosInvitation> invitation, |
| 386 | const Name& inviterNameSpace, |
| 387 | Ptr<security::IdentityCertificate> certificate) |
| 388 | { |
| 389 | string alias; |
| 390 | vector<Ptr<ContactItem> >::iterator it = m_contactList.begin(); |
| 391 | for(; it != m_contactList.end(); it++) |
| 392 | if((*it)->getNameSpace() == inviterNameSpace) |
| 393 | alias = (*it)->getAlias(); |
| 394 | |
| 395 | if(it != m_contactList.end()) |
| 396 | return; |
| 397 | |
| 398 | m_invitationDialog->setInvitation(alias, invitation, certificate); |
| 399 | emit newInvitationReady(); |
| 400 | } |
| 401 | |
| 402 | void |
| 403 | ContactPanel::collectEndorsement() |
| 404 | { |
| 405 | m_collectStatus = Ptr<vector<bool> >::Create(); |
| 406 | m_collectStatus->assign(m_contactList.size(), false); |
| 407 | |
| 408 | vector<Ptr<ContactItem> >::iterator it = m_contactList.begin(); |
| 409 | int count = 0; |
| 410 | for(; it != m_contactList.end(); it++, count++) |
| 411 | { |
| 412 | Name interestName = (*it)->getNameSpace(); |
| 413 | interestName.append("DNS").append(m_defaultIdentity).append("ENDORSEE"); |
| 414 | Ptr<Interest> interest = Ptr<Interest>(new Interest(interestName)); |
| 415 | interest->setChildSelector(Interest::CHILD_RIGHT); |
| 416 | interest->setInterestLifetime(1); |
| 417 | |
| 418 | Ptr<Closure> closure = Ptr<Closure>(new Closure(boost::bind(&ContactPanel::onDnsEndorseeVerified, |
| 419 | this, |
| 420 | _1, |
| 421 | count), |
| 422 | boost::bind(&ContactPanel::onDnsEndorseeTimeout, |
| 423 | this, |
| 424 | _1, |
| 425 | _2, |
| 426 | count), |
| 427 | boost::bind(&ContactPanel::onDnsEndorseeUnverified, |
| 428 | this, |
| 429 | _1, |
| 430 | count))); |
| 431 | |
| 432 | m_handler->sendInterest(interest, closure); |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | void |
| 437 | ContactPanel::onDnsEndorseeVerified(Ptr<Data> data, int count) |
| 438 | { |
| 439 | Ptr<Blob> contentBlob = Ptr<Blob>(new Blob(data->content().buf(), data->content().size())); |
| 440 | Ptr<Data> endorseData = Data::decodeFromWire(contentBlob); |
| 441 | EndorseCertificate endorseCertificate(*endorseData); |
| 442 | |
| 443 | m_contactManager->getContactStorage()->updateCollectEndorse(endorseCertificate); |
| 444 | |
| 445 | updateCollectStatus(count); |
| 446 | } |
| 447 | |
| 448 | void |
| 449 | ContactPanel::onDnsEndorseeTimeout(Ptr<Closure> closure, Ptr<Interest> interest, int count) |
| 450 | { updateCollectStatus(count); } |
| 451 | |
| 452 | void |
| 453 | ContactPanel::onDnsEndorseeUnverified(Ptr<Data> data, int count) |
| 454 | { updateCollectStatus(count); } |
| 455 | |
| 456 | void |
| 457 | ContactPanel::updateCollectStatus(int count) |
| 458 | { |
| 459 | m_collectStatus->at(count) = true; |
| 460 | vector<bool>::const_iterator it = m_collectStatus->begin(); |
| 461 | for(; it != m_collectStatus->end(); it++) |
| 462 | if(*it == false) |
| 463 | return; |
| 464 | |
| 465 | m_contactManager->publishEndorsedDataInDns(m_defaultIdentity); |
| 466 | } |
| 467 | |
| 468 | static std::string chars("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789"); |
| 469 | |
| 470 | string |
| 471 | ContactPanel::getRandomString() |
| 472 | { |
| 473 | string randStr; |
| 474 | boost::random::random_device rng; |
| 475 | boost::random::uniform_int_distribution<> index_dist(0, chars.size() - 1); |
| 476 | for (int i = 0; i < 10; i ++) |
| 477 | { |
| 478 | randStr += chars[index_dist(rng)]; |
| 479 | } |
| 480 | return randStr; |
| 481 | } |
| 482 | |
| 483 | void |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 484 | ContactPanel::showError(const QString& msg){ |
| 485 | QMessageBox::critical(this, tr("Chronos"), msg, QMessageBox::Ok); |
| 486 | exit(1); |
| 487 | } |
| 488 | |
| 489 | void |
Yingdi Yu | eb98f7d | 2013-11-10 01:34:57 -0800 | [diff] [blame] | 490 | ContactPanel::showWarning(const QString& msg){ |
| 491 | QMessageBox::information(this, tr("Chronos"), msg); |
| 492 | } |
| 493 | |
| 494 | void |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 495 | ContactPanel::updateSelection(const QItemSelection &selected, |
| 496 | const QItemSelection &deselected) |
| 497 | { |
| 498 | QModelIndexList items = selected.indexes(); |
| 499 | QString text = m_contactListModel->data(items.first(), Qt::DisplayRole).toString(); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 500 | string alias = text.toStdString(); |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 501 | |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 502 | int i = 0; |
| 503 | for(; i < m_contactList.size(); i++) |
| 504 | { |
| 505 | if(alias == m_contactList[i]->getAlias()) |
| 506 | break; |
| 507 | } |
| 508 | |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 509 | m_currentSelectedContact = m_contactList[i]; |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 510 | ui->NameData->setText(QString::fromStdString(m_currentSelectedContact->getName())); |
| 511 | ui->NameSpaceData->setText(QString::fromStdString(m_currentSelectedContact->getNameSpace().toUri())); |
| 512 | ui->InstitutionData->setText(QString::fromStdString(m_currentSelectedContact->getInstitution())); |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 513 | |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 514 | if(m_currentSelectedContact->isIntroducer()) |
| 515 | { |
| 516 | ui->isIntroducer->setChecked(true); |
| 517 | ui->addScope->setEnabled(true); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 518 | ui->deleteScope->setEnabled(true); |
| 519 | ui->trustScopeList->setEnabled(true); |
| 520 | |
| 521 | string filter("contact_namespace = '"); |
| 522 | filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'"); |
| 523 | |
| 524 | m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
| 525 | m_trustScopeModel->setTable("TrustScope"); |
| 526 | m_trustScopeModel->setFilter(filter.c_str()); |
| 527 | m_trustScopeModel->select(); |
| 528 | m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID")); |
| 529 | m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact")); |
| 530 | m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope")); |
| 531 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 532 | ui->trustScopeList->setModel(m_trustScopeModel); |
| 533 | ui->trustScopeList->setColumnHidden(0, true); |
| 534 | ui->trustScopeList->setColumnHidden(1, true); |
| 535 | ui->trustScopeList->show(); |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 536 | } |
| 537 | else |
| 538 | { |
| 539 | ui->isIntroducer->setChecked(false); |
| 540 | ui->addScope->setEnabled(false); |
| 541 | ui->deleteScope->setEnabled(false); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 542 | |
| 543 | string filter("contact_namespace = '"); |
| 544 | filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'"); |
| 545 | |
| 546 | m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
| 547 | m_trustScopeModel->setTable("TrustScope"); |
| 548 | m_trustScopeModel->setFilter(filter.c_str()); |
| 549 | m_trustScopeModel->select(); |
| 550 | m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID")); |
| 551 | m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact")); |
| 552 | m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope")); |
| 553 | |
| 554 | ui->trustScopeList->setModel(m_trustScopeModel); |
| 555 | ui->trustScopeList->setColumnHidden(0, true); |
| 556 | ui->trustScopeList->setColumnHidden(1, true); |
| 557 | ui->trustScopeList->show(); |
| 558 | |
| 559 | ui->trustScopeList->setEnabled(false); |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 560 | } |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 561 | |
| 562 | string filter("profile_identity = '"); |
| 563 | filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'"); |
| 564 | |
| 565 | m_endorseDataModel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
| 566 | m_endorseDataModel->setTable("ContactProfile"); |
| 567 | m_endorseDataModel->setFilter(filter.c_str()); |
| 568 | m_endorseDataModel->select(); |
| 569 | |
| 570 | m_endorseDataModel->setHeaderData(0, Qt::Horizontal, QObject::tr("Identity")); |
| 571 | m_endorseDataModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Type")); |
| 572 | m_endorseDataModel->setHeaderData(2, Qt::Horizontal, QObject::tr("Value")); |
| 573 | m_endorseDataModel->setHeaderData(3, Qt::Horizontal, QObject::tr("Endorse")); |
| 574 | |
| 575 | ui->endorseList->setModel(m_endorseDataModel); |
| 576 | ui->endorseList->setColumnHidden(0, true); |
| 577 | ui->endorseList->resizeColumnToContents(1); |
| 578 | ui->endorseList->resizeColumnToContents(2); |
| 579 | ui->endorseList->setItemDelegateForColumn(3, m_endorseComboBoxDelegate); |
| 580 | ui->endorseList->show(); |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 581 | } |
Yingdi Yu | 9e0dc29 | 2013-10-10 11:39:45 -0700 | [diff] [blame] | 582 | |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 583 | void |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 584 | ContactPanel::updateDefaultIdentity(const QString& identity, const QString& nickName) |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 585 | { |
Yingdi Yu | 71ec965 | 2013-11-09 22:18:26 -0800 | [diff] [blame] | 586 | // _LOG_DEBUG(identity.toStdString()); |
Yingdi Yu | eb98f7d | 2013-11-10 01:34:57 -0800 | [diff] [blame] | 587 | Name defaultIdentity = Name(identity.toStdString()); |
| 588 | Name defaultKeyName = m_keychain->getIdentityManager()->getPublicStorage()->getDefaultKeyNameForIdentity(defaultIdentity); |
Yingdi Yu | 71ec965 | 2013-11-09 22:18:26 -0800 | [diff] [blame] | 589 | if(defaultKeyName.size() == 0) |
Yingdi Yu | eb98f7d | 2013-11-10 01:34:57 -0800 | [diff] [blame] | 590 | { |
| 591 | showWarning(QString::fromStdString("Corresponding key is missing!\nHave you created the key?")); |
| 592 | return; |
| 593 | } |
Yingdi Yu | 71ec965 | 2013-11-09 22:18:26 -0800 | [diff] [blame] | 594 | Name defaultCertName = m_keychain->getIdentityManager()->getPublicStorage()->getDefaultCertificateNameForKey(defaultKeyName); |
| 595 | if(defaultCertName.size() == 0) |
Yingdi Yu | eb98f7d | 2013-11-10 01:34:57 -0800 | [diff] [blame] | 596 | { |
| 597 | showWarning(QString::fromStdString("Corresponding certificate is missing!\nHave you installed the certificate?")); |
| 598 | return; |
| 599 | } |
| 600 | m_defaultIdentity = defaultIdentity; |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 601 | m_profileEditor->setCurrentIdentity(m_defaultIdentity); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 602 | m_nickName = nickName.toStdString(); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 603 | m_handler->clearInterestFilter(m_inviteListenPrefix); |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 604 | m_contactManager->setDefaultIdentity(m_defaultIdentity); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 605 | setInvitationListener(); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 606 | collectEndorsement(); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 607 | } |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 608 | |
| 609 | void |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 610 | ContactPanel::openProfileEditor() |
Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 611 | { m_profileEditor->show(); } |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 612 | |
Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 613 | void |
| 614 | ContactPanel::openAddContactPanel() |
| 615 | { m_addContactPanel->show(); } |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 616 | |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 617 | void |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 618 | ContactPanel::openBrowseContactDialog() |
| 619 | { |
| 620 | m_browseContactDialog->show(); |
| 621 | emit refreshCertDirectory(); |
| 622 | } |
| 623 | |
| 624 | void |
| 625 | ContactPanel::removeContactButton() |
| 626 | { |
| 627 | QItemSelectionModel* selectionModel = ui->ContactList->selectionModel(); |
| 628 | QModelIndexList selectedList = selectionModel->selectedIndexes(); |
| 629 | QModelIndexList::iterator it = selectedList.begin(); |
| 630 | for(; it != selectedList.end(); it++) |
| 631 | { |
| 632 | string alias = m_contactListModel->data(*it, Qt::DisplayRole).toString().toStdString(); |
| 633 | vector<Ptr<ContactItem> >::iterator contactIt = m_contactList.begin(); |
| 634 | for(; contactIt != m_contactList.end(); contactIt++) |
| 635 | { |
| 636 | if((*contactIt)->getAlias() == alias) |
| 637 | { |
| 638 | m_contactManager->getContactStorage()->removeContact((*contactIt)->getNameSpace()); |
| 639 | m_contactList.erase(contactIt); |
| 640 | break; |
| 641 | } |
| 642 | } |
| 643 | } |
| 644 | refreshContactList(); |
| 645 | } |
| 646 | |
| 647 | void |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 648 | ContactPanel::openInvitationDialog() |
| 649 | { m_invitationDialog->show(); } |
| 650 | |
| 651 | void |
Yingdi Yu | 6ea54e4 | 2013-11-12 17:50:21 -0800 | [diff] [blame] | 652 | ContactPanel::addContactIntoPanelPolicy(const Name& contactNameSpace) |
| 653 | { |
| 654 | Ptr<ContactItem> contact = m_contactManager->getContact(contactNameSpace); |
| 655 | if(contact != NULL) |
| 656 | m_panelPolicyManager->addTrustAnchor(contact->getSelfEndorseCertificate()); |
| 657 | } |
| 658 | |
| 659 | void |
| 660 | ContactPanel::removeContactFromPanelPolicy(const Name& keyName) |
| 661 | { m_panelPolicyManager->removeTrustAnchor(keyName); } |
| 662 | |
| 663 | void |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 664 | ContactPanel::refreshContactList() |
| 665 | { |
| 666 | m_contactList = m_contactManager->getContactItemList(); |
| 667 | QStringList contactNameList; |
| 668 | for(int i = 0; i < m_contactList.size(); i++) |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 669 | contactNameList << QString::fromStdString(m_contactList[i]->getAlias()); |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 670 | |
| 671 | m_contactListModel->setStringList(contactNameList); |
| 672 | } |
| 673 | |
| 674 | void |
| 675 | ContactPanel::showContextMenu(const QPoint& pos) |
| 676 | { |
| 677 | QMenu menu(ui->ContactList); |
| 678 | menu.addAction(m_menuInvite); |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 679 | connect(m_menuInvite, SIGNAL(triggered()), |
| 680 | this, SLOT(openStartChatDialog())); |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 681 | menu.addSeparator(); |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 682 | menu.addAction(m_menuAlias); |
| 683 | connect(m_menuAlias, SIGNAL(triggered()), |
| 684 | this, SLOT(openSetAliasDialog())); |
| 685 | menu.exec(ui->ContactList->mapToGlobal(pos)); |
| 686 | |
| 687 | } |
| 688 | |
| 689 | void |
| 690 | ContactPanel::openSetAliasDialog() |
| 691 | { |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 692 | m_setAliasDialog->setTargetIdentity(m_currentSelectedContact->getNameSpace().toUri()); |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 693 | m_setAliasDialog->show(); |
| 694 | } |
| 695 | |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 696 | void |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 697 | ContactPanel::openSettingDialog() |
| 698 | { |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 699 | m_settingDialog->setIdentity(m_defaultIdentity.toUri(), m_nickName); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 700 | m_settingDialog->show(); |
| 701 | } |
| 702 | |
| 703 | void |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 704 | ContactPanel::openStartChatDialog() |
| 705 | { |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 706 | Name chatroom("/ndn/broadcast/chronos"); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 707 | chatroom.append(string("chatroom-") + getRandomString()); |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 708 | |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 709 | m_startChatDialog->setInvitee(m_currentSelectedContact->getNameSpace().toUri(), chatroom.toUri()); |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 710 | m_startChatDialog->show(); |
| 711 | } |
| 712 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 713 | // For inviter |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 714 | void |
| 715 | ContactPanel::startChatroom(const QString& chatroom, const QString& invitee, bool isIntroducer) |
| 716 | { |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 717 | Name chatroomName(chatroom.toUtf8().constData()); |
Yingdi Yu | 6a5b9f6 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 718 | |
| 719 | Name inviteeNamespace(invitee.toStdString()); |
| 720 | Ptr<ContactItem> inviteeItem = m_contactManager->getContact(inviteeNamespace); |
| 721 | |
Yingdi Yu | c90deb1 | 2013-11-06 18:51:19 -0800 | [diff] [blame] | 722 | ChatDialog* chatDialog = new ChatDialog(m_contactManager, chatroomName, m_localPrefix, m_defaultIdentity, m_nickName); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 723 | m_chatDialogs.insert(pair <Name, ChatDialog*> (chatroomName, chatDialog)); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 724 | |
| 725 | connect(chatDialog, SIGNAL(closeChatDialog(const ndn::Name&)), |
| 726 | this, SLOT(removeChatDialog(const ndn::Name&))); |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 727 | connect(chatDialog, SIGNAL(noNdnConnection(const QString&)), |
| 728 | this, SLOT(showError(const QString&))); |
Yingdi Yu | 3e87bd8 | 2013-11-10 10:47:44 -0800 | [diff] [blame] | 729 | connect(chatDialog, SIGNAL(inivationRejection(const QString&)), |
| 730 | this, SLOT(showWarning(const QString&))); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 731 | |
Yingdi Yu | c90deb1 | 2013-11-06 18:51:19 -0800 | [diff] [blame] | 732 | // send invitation |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 733 | chatDialog->sendInvitation(inviteeItem, isIntroducer); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 734 | |
| 735 | chatDialog->show(); |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 736 | } |
| 737 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 738 | // For Invitee |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 739 | void |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 740 | ContactPanel::startChatroom2(const ChronosInvitation& invitation, |
| 741 | const security::IdentityCertificate& identityCertificate) |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 742 | { |
Yingdi Yu | 6a5b9f6 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 743 | Ptr<ContactItem> inviterItem = m_contactManager->getContact(invitation.getInviterNameSpace()); |
| 744 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 745 | Name chatroomName("/ndn/broadcast/chronos"); |
| 746 | chatroomName.append(invitation.getChatroom()); |
Yingdi Yu | 6a5b9f6 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 747 | |
Yingdi Yu | c90deb1 | 2013-11-06 18:51:19 -0800 | [diff] [blame] | 748 | ChatDialog* chatDialog = new ChatDialog(m_contactManager, chatroomName, m_localPrefix, m_defaultIdentity, m_nickName, true); |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 749 | |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 750 | connect(chatDialog, SIGNAL(closeChatDialog(const ndn::Name&)), |
| 751 | this, SLOT(removeChatDialog(const ndn::Name&))); |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 752 | connect(chatDialog, SIGNAL(noNdnConnection(const QString&)), |
| 753 | this, SLOT(showError(const QString&))); |
Yingdi Yu | 3e87bd8 | 2013-11-10 10:47:44 -0800 | [diff] [blame] | 754 | connect(chatDialog, SIGNAL(inivationRejection(const QString&)), |
| 755 | this, SLOT(showWarning(const QString&))); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 756 | |
Yingdi Yu | c90deb1 | 2013-11-06 18:51:19 -0800 | [diff] [blame] | 757 | chatDialog->addChatDataRule(invitation.getInviterPrefix(), identityCertificate, true); |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 758 | chatDialog->publishIntroCert(identityCertificate, true); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 759 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 760 | chatDialog->addTrustAnchor(inviterItem->getSelfEndorseCertificate()); |
| 761 | |
| 762 | m_chatDialogs.insert(pair <Name, ChatDialog*> (chatroomName, chatDialog)); |
| 763 | |
| 764 | chatDialog->show(); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | void |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 768 | ContactPanel::acceptInvitation(const ChronosInvitation& invitation, |
| 769 | const security::IdentityCertificate& identityCertificate) |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 770 | { |
| 771 | string prefix = m_localPrefix.toUri(); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 772 | m_handler->publishDataByIdentity (invitation.getInterestName(), prefix); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 773 | startChatroom2(invitation, identityCertificate); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | void |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 777 | ContactPanel::rejectInvitation(const ChronosInvitation& invitation) |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 778 | { |
Yingdi Yu | 9793635 | 2013-11-08 14:13:42 -0800 | [diff] [blame] | 779 | string empty("nack"); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 780 | m_handler->publishDataByIdentity (invitation.getInterestName(), empty); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 781 | } |
| 782 | |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 783 | void |
| 784 | ContactPanel::isIntroducerChanged(int state) |
| 785 | { |
| 786 | if(state == Qt::Checked) |
| 787 | { |
| 788 | ui->addScope->setEnabled(true); |
| 789 | ui->deleteScope->setEnabled(true); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 790 | ui->trustScopeList->setEnabled(true); |
| 791 | |
| 792 | string filter("contact_namespace = '"); |
| 793 | filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'"); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 794 | |
| 795 | m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
| 796 | m_trustScopeModel->setTable("TrustScope"); |
| 797 | m_trustScopeModel->setFilter(filter.c_str()); |
| 798 | m_trustScopeModel->select(); |
| 799 | m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID")); |
| 800 | m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact")); |
| 801 | m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope")); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 802 | |
| 803 | ui->trustScopeList->setModel(m_trustScopeModel); |
| 804 | ui->trustScopeList->setColumnHidden(0, true); |
| 805 | ui->trustScopeList->setColumnHidden(1, true); |
| 806 | ui->trustScopeList->show(); |
| 807 | |
| 808 | m_currentSelectedContact->setIsIntroducer(true); |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 809 | } |
| 810 | else |
| 811 | { |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 812 | ui->addScope->setEnabled(false); |
| 813 | ui->deleteScope->setEnabled(false); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 814 | |
| 815 | string filter("contact_namespace = '"); |
| 816 | filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'"); |
| 817 | |
| 818 | m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
| 819 | m_trustScopeModel->setTable("TrustScope"); |
| 820 | m_trustScopeModel->setFilter(filter.c_str()); |
| 821 | m_trustScopeModel->select(); |
| 822 | m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID")); |
| 823 | m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact")); |
| 824 | m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope")); |
| 825 | |
| 826 | ui->trustScopeList->setModel(m_trustScopeModel); |
| 827 | ui->trustScopeList->setColumnHidden(0, true); |
| 828 | ui->trustScopeList->setColumnHidden(1, true); |
| 829 | ui->trustScopeList->show(); |
| 830 | |
| 831 | ui->trustScopeList->setEnabled(false); |
| 832 | |
| 833 | m_currentSelectedContact->setIsIntroducer(false); |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 834 | } |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 835 | m_contactManager->getContactStorage()->updateIsIntroducer(m_currentSelectedContact->getNameSpace(), m_currentSelectedContact->isIntroducer()); |
| 836 | } |
| 837 | |
| 838 | void |
| 839 | ContactPanel::addScopeClicked() |
| 840 | { |
| 841 | int rowCount = m_trustScopeModel->rowCount(); |
| 842 | QSqlRecord record; |
| 843 | QSqlField identityField("contact_namespace", QVariant::String); |
| 844 | record.append(identityField); |
| 845 | record.setValue("contact_namespace", QString(m_currentSelectedContact->getNameSpace().toUri().c_str())); |
| 846 | m_trustScopeModel->insertRow(rowCount); |
| 847 | m_trustScopeModel->setRecord(rowCount, record); |
| 848 | } |
| 849 | |
| 850 | void |
| 851 | ContactPanel::deleteScopeClicked() |
| 852 | { |
| 853 | QItemSelectionModel* selectionModel = ui->trustScopeList->selectionModel(); |
| 854 | QModelIndexList indexList = selectionModel->selectedIndexes(); |
| 855 | |
| 856 | int i = indexList.size() - 1; |
| 857 | for(; i >= 0; i--) |
| 858 | m_trustScopeModel->removeRow(indexList[i].row()); |
| 859 | |
| 860 | m_trustScopeModel->submitAll(); |
| 861 | } |
| 862 | |
| 863 | void |
| 864 | ContactPanel::saveScopeClicked() |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 865 | { m_trustScopeModel->submitAll(); } |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 866 | |
| 867 | void |
| 868 | ContactPanel::endorseButtonClicked() |
| 869 | { |
| 870 | m_endorseDataModel->submitAll(); |
| 871 | m_contactManager->updateEndorseCertificate(m_currentSelectedContact->getNameSpace(), m_defaultIdentity); |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 872 | } |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 873 | |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 874 | void |
| 875 | ContactPanel::removeChatDialog(const ndn::Name& chatroomName) |
| 876 | { |
| 877 | map<Name, ChatDialog*>::iterator it = m_chatDialogs.find(chatroomName); |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 878 | |
| 879 | ChatDialog* deletedChat = NULL; |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 880 | if(it != m_chatDialogs.end()) |
| 881 | { |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 882 | deletedChat = it->second; |
| 883 | m_chatDialogs.erase(it); |
| 884 | } |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 885 | if (deletedChat != NULL) |
| 886 | delete deletedChat; |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 887 | } |
| 888 | |
Yingdi Yu | 9e0dc29 | 2013-10-10 11:39:45 -0700 | [diff] [blame] | 889 | #if WAF |
| 890 | #include "contactpanel.moc" |
| 891 | #include "contactpanel.cpp.moc" |
| 892 | #endif |