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