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 | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 24 | #include <ndn-cpp-dev/security/validator.hpp> |
Yingdi Yu | b6fb030 | 2014-01-21 11:05:11 -0800 | [diff] [blame] | 25 | #include <ndn-cpp-dev/security/signature-sha256-with-rsa.hpp> |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 26 | #include <boost/filesystem.hpp> |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 27 | #include <boost/random/random_device.hpp> |
| 28 | #include <boost/random/uniform_int_distribution.hpp> |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 29 | #include "logging.h" |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 30 | #endif |
| 31 | |
| 32 | namespace fs = boost::filesystem; |
| 33 | using namespace ndn; |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 34 | using namespace chronos; |
Yingdi Yu | 2ac40fb | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 35 | using namespace std; |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 36 | |
| 37 | INIT_LOGGER("ContactPanel"); |
| 38 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 39 | Q_DECLARE_METATYPE(ndn::IdentityCertificate) |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 40 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 41 | ContactPanel::ContactPanel(shared_ptr<Face> face, |
| 42 | QWidget *parent) |
Yingdi Yu | ec5e72a | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 43 | : QDialog(parent) |
| 44 | , ui(new Ui::ContactPanel) |
Yingdi Yu | 8e13583 | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 45 | , m_warningDialog(new WarningDialog) |
Yingdi Yu | ec5e72a | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 46 | , m_contactListModel(new QStringListModel) |
| 47 | , m_startChatDialog(new StartChatDialog) |
| 48 | , m_invitationDialog(new InvitationDialog) |
| 49 | , m_settingDialog(new SettingDialog) |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 50 | , m_keyChain(new KeyChain) |
| 51 | , m_face(face) |
| 52 | , m_ioService(face->ioService()) |
| 53 | , m_contactManager(new ContactManager(m_face)) |
Yingdi Yu | 847aa86 | 2013-10-09 16:35:53 -0700 | [diff] [blame] | 54 | { |
Yingdi Yu | 6eabbd7 | 2013-12-27 08:44:12 +0800 | [diff] [blame] | 55 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 56 | qRegisterMetaType<ndn::IdentityCertificate>("IdentityCertificate"); |
Yingdi Yu | 6eabbd7 | 2013-12-27 08:44:12 +0800 | [diff] [blame] | 57 | |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 58 | createAction(); |
| 59 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 60 | #ifdef WITH_SECURITY |
| 61 | m_panelValidator = make_shared<chronos::ValidatorPanel>(); |
| 62 | m_invitationValidator = make_shared<chronos::ValidatorInvitation>(); |
| 63 | #else |
| 64 | m_panelValidator = make_shared<ndn::ValidatorNull>(); |
| 65 | m_invitationValidator = make_shared<ndn::ValidatorNull>(); |
| 66 | #endif |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 67 | |
Yingdi Yu | 8e13583 | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 68 | connect(&*m_contactManager, SIGNAL(noNdnConnection(const QString&)), |
| 69 | this, SLOT(showError(const QString&))); |
Yingdi Yu | 8e13583 | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 70 | |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 71 | openDB(); |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 72 | |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 73 | refreshContactList(); |
Yingdi Yu | 40eca75 | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 74 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 75 | loadTrustAnchor(); |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 76 | |
Yingdi Yu | f8f572d | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 77 | m_defaultIdentity = m_keyChain->getDefaultIdentity(); |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 78 | |
Yingdi Yu | b5a0fd3 | 2013-11-10 16:26:52 -0800 | [diff] [blame] | 79 | if(m_defaultIdentity.size() == 0) |
| 80 | 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] | 81 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 82 | m_keyChain->createIdentity(m_defaultIdentity); |
Yingdi Yu | b5a0fd3 | 2013-11-10 16:26:52 -0800 | [diff] [blame] | 83 | |
| 84 | m_contactManager->setDefaultIdentity(m_defaultIdentity); |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 85 | m_nickName = m_defaultIdentity.get(-1).toEscapedString(); |
Yingdi Yu | b5a0fd3 | 2013-11-10 16:26:52 -0800 | [diff] [blame] | 86 | m_settingDialog->setIdentity(m_defaultIdentity.toUri(), m_nickName); |
Yingdi Yu | 711f589 | 2013-11-09 22:18:26 -0800 | [diff] [blame] | 87 | |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 88 | |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 89 | m_profileEditor = new ProfileEditor(m_contactManager); |
| 90 | m_profileEditor->setCurrentIdentity(m_defaultIdentity); |
| 91 | |
Yingdi Yu | 8e13583 | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 92 | m_addContactPanel = new AddContactPanel(m_contactManager); |
| 93 | m_browseContactDialog = new BrowseContactDialog(m_contactManager); |
| 94 | m_setAliasDialog = new SetAliasDialog(m_contactManager); |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 95 | |
| 96 | ui->setupUi(this); |
| 97 | |
Yingdi Yu | 8e13583 | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 98 | |
Yingdi Yu | a66183f | 2013-11-10 10:32:18 -0800 | [diff] [blame] | 99 | m_localPrefix = Name("/private/local"); |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 100 | setLocalPrefix(); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 101 | |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 102 | setInvitationListener(); |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 103 | |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 104 | collectEndorsement(); |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 105 | |
| 106 | ui->ContactList->setModel(m_contactListModel); |
| 107 | |
Yingdi Yu | 8f7325a | 2013-10-17 17:03:46 -0700 | [diff] [blame] | 108 | |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 109 | connect(ui->ContactList->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 110 | this, SLOT(updateSelection(const QItemSelection &, const QItemSelection &))); |
Yingdi Yu | 40eca75 | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 111 | |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 112 | connect(ui->ContactList, SIGNAL(customContextMenuRequested(const QPoint&)), |
| 113 | this, SLOT(showContextMenu(const QPoint&))); |
Yingdi Yu | 0269c87 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 114 | |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 115 | connect(ui->EditProfileButton, SIGNAL(clicked()), |
| 116 | this, SLOT(openProfileEditor())); |
Yingdi Yu | 0269c87 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 117 | |
Yingdi Yu | 711f589 | 2013-11-09 22:18:26 -0800 | [diff] [blame] | 118 | connect(m_profileEditor, SIGNAL(noKeyOrCert(const QString&)), |
Yingdi Yu | e433a50 | 2013-11-10 01:34:57 -0800 | [diff] [blame] | 119 | this, SLOT(showWarning(const QString&))); |
Yingdi Yu | 711f589 | 2013-11-09 22:18:26 -0800 | [diff] [blame] | 120 | |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 121 | connect(ui->AddContactButton, SIGNAL(clicked()), |
Yingdi Yu | ae8217c | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 122 | this, SLOT(openBrowseContactDialog())); |
| 123 | |
Yingdi Yu | 9d7dfc2 | 2013-11-10 17:59:58 -0800 | [diff] [blame] | 124 | connect(m_browseContactDialog, SIGNAL(directAddClicked()), |
| 125 | this, SLOT(openAddContactPanel())); |
| 126 | |
Yingdi Yu | ae8217c | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 127 | connect(this, SIGNAL(refreshCertDirectory()), |
| 128 | m_browseContactDialog, SLOT(refreshList())); |
| 129 | |
| 130 | connect(ui->DeleteContactButton, SIGNAL(clicked()), |
| 131 | this, SLOT(removeContactButton())); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 132 | |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 133 | connect(ui->settingButton, SIGNAL(clicked()), |
| 134 | this, SLOT(openSettingDialog())); |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 135 | |
| 136 | connect(ui->chatButton, SIGNAL(clicked()), |
| 137 | this, SLOT(openStartChatDialog())); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 138 | |
Yingdi Yu | 9d7dfc2 | 2013-11-10 17:59:58 -0800 | [diff] [blame] | 139 | connect(m_addContactPanel, SIGNAL(newContactAdded()), |
| 140 | this, SLOT(refreshContactList())); |
Yingdi Yu | ae8217c | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 141 | connect(m_browseContactDialog, SIGNAL(newContactAdded()), |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 142 | this, SLOT(refreshContactList())); |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 143 | connect(m_setAliasDialog, SIGNAL(aliasChanged()), |
| 144 | this, SLOT(refreshContactList())); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 145 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 146 | connect(m_startChatDialog, SIGNAL(chatroomConfirmed(const QString&)), |
| 147 | this, SLOT(startChatroom(const QString&))); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 148 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 149 | connect(m_invitationDialog, SIGNAL(invitationAccepted(const ndn::Name&)), |
| 150 | this, SLOT(acceptInvitation(const ndn::Name&))); |
| 151 | connect(m_invitationDialog, SIGNAL(invitationRejected(const ndn::Name&)), |
| 152 | this, SLOT(rejectInvitation(const ndn::Name&))); |
Yingdi Yu | 7223269 | 2013-11-12 17:50:21 -0800 | [diff] [blame] | 153 | |
| 154 | connect(&*m_contactManager, SIGNAL(contactAdded(const ndn::Name&)), |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 155 | this, SLOT(addContactIntoValidator(const ndn::Name&))); |
Yingdi Yu | 7223269 | 2013-11-12 17:50:21 -0800 | [diff] [blame] | 156 | connect(&*m_contactManager, SIGNAL(contactRemoved(const ndn::Name&)), |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 157 | this, SLOT(removeContactFromValidator(const ndn::Name&))); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 158 | |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 159 | connect(m_settingDialog, SIGNAL(identitySet(const QString&, const QString&)), |
| 160 | this, SLOT(updateDefaultIdentity(const QString&, const QString&))); |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 161 | |
Yingdi Yu | ec5e72a | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 162 | connect(ui->isIntroducer, SIGNAL(stateChanged(int)), |
| 163 | this, SLOT(isIntroducerChanged(int))); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 164 | |
| 165 | connect(ui->addScope, SIGNAL(clicked()), |
| 166 | this, SLOT(addScopeClicked())); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 167 | connect(ui->deleteScope, SIGNAL(clicked()), |
| 168 | this, SLOT(deleteScopeClicked())); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 169 | connect(ui->saveButton, SIGNAL(clicked()), |
| 170 | this, SLOT(saveScopeClicked())); |
| 171 | |
| 172 | connect(ui->endorseButton, SIGNAL(clicked()), |
| 173 | this, SLOT(endorseButtonClicked())); |
Yingdi Yu | 847aa86 | 2013-10-09 16:35:53 -0700 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | ContactPanel::~ContactPanel() |
| 177 | { |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 178 | delete ui; |
| 179 | delete m_contactListModel; |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 180 | delete m_startChatDialog; |
| 181 | delete m_invitationDialog; |
| 182 | delete m_settingDialog; |
| 183 | |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 184 | delete m_profileEditor; |
| 185 | delete m_addContactPanel; |
Yingdi Yu | ae8217c | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 186 | delete m_browseContactDialog; |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 187 | delete m_setAliasDialog; |
| 188 | |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 189 | delete m_trustScopeModel; |
| 190 | delete m_endorseDataModel; |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 191 | delete m_endorseComboBoxDelegate; |
Yingdi Yu | 2ac40fb | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 192 | |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 193 | delete m_menuAlias; |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 194 | |
| 195 | map<Name, ChatDialog*>::iterator it = m_chatDialogs.begin(); |
| 196 | for(; it != m_chatDialogs.end(); it++) |
| 197 | delete it->second; |
Yingdi Yu | 6eabbd7 | 2013-12-27 08:44:12 +0800 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | void |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 201 | ContactPanel::createAction() |
| 202 | { |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 203 | m_menuAlias = new QAction("&Set Alias", this); |
| 204 | } |
| 205 | |
| 206 | void |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 207 | ContactPanel::openDB() |
| 208 | { |
| 209 | QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); |
| 210 | QString path = (QDir::home().path()); |
| 211 | path.append(QDir::separator()).append(".chronos").append(QDir::separator()).append("chronos.db"); |
| 212 | db.setDatabaseName(path); |
| 213 | bool ok = db.open(); |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 214 | _LOG_DEBUG("DB opened: " << std::boolalpha << ok ); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 215 | |
| 216 | m_trustScopeModel = new QSqlTableModel; |
| 217 | m_endorseDataModel = new QSqlTableModel; |
| 218 | m_endorseComboBoxDelegate = new EndorseComboBoxDelegate; |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | void |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 222 | ContactPanel::loadTrustAnchor() |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 223 | { |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 224 | #ifdef WITH_SECURITY |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 225 | vector<shared_ptr<ContactItem> >::const_iterator it = m_contactList.begin(); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 226 | for(; it != m_contactList.end(); it++) |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 227 | { |
Yingdi Yu | 6eabbd7 | 2013-12-27 08:44:12 +0800 | [diff] [blame] | 228 | _LOG_DEBUG("load contact: " << (*it)->getNameSpace().toUri()); |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 229 | m_invitationValidator->addTrustAnchor((*it)->getSelfEndorseCertificate()); |
| 230 | m_panelValidator->addTrustAnchor((*it)->getSelfEndorseCertificate()); |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 231 | } |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 232 | #endif |
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 | { |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 238 | Name interestName("/local/ndn/prefix"); |
| 239 | Interest interest(interestName); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 240 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 241 | m_face->expressInterest(interest, |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 242 | bind(&ContactPanel::onLocalPrefix, this, _1, _2), |
| 243 | bind(&ContactPanel::onLocalPrefixTimeout, this, _1, 10)); |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 244 | |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | void |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 248 | ContactPanel::onLocalPrefix(const Interest& interest, Data& data) |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 249 | { |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 250 | string originPrefix(reinterpret_cast<const char*>(data.getContent().value()), data.getContent().value_size()); |
| 251 | string prefix = QString::fromStdString (originPrefix).trimmed ().toStdString(); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 252 | m_localPrefix = Name(prefix); |
| 253 | } |
| 254 | |
| 255 | void |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 256 | ContactPanel::onLocalPrefixTimeout(const Interest& interest, int retry) |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 257 | { |
Yingdi Yu | fdb8ab8 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 258 | if(retry > 0) |
Yingdi Yu | a66183f | 2013-11-10 10:32:18 -0800 | [diff] [blame] | 259 | { |
| 260 | setLocalPrefix(retry - 1); |
| 261 | return; |
| 262 | } |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 263 | else |
Yingdi Yu | a66183f | 2013-11-10 10:32:18 -0800 | [diff] [blame] | 264 | m_localPrefix = Name("/private/local"); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 265 | } |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 266 | |
| 267 | void |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 268 | ContactPanel::setInvitationListener() |
| 269 | { |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 270 | m_inviteListenPrefix = Name("/ndn/broadcast/chronos/invitation"); |
| 271 | m_inviteListenPrefix.append(m_defaultIdentity); |
| 272 | _LOG_DEBUG("Listening for invitation on prefix: " << m_inviteListenPrefix.toUri()); |
Yingdi Yu | f8f572d | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 273 | m_invitationListenerId = m_face->setInterestFilter(m_inviteListenPrefix, |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 274 | bind(&ContactPanel::onInvitation, this, _1, _2), |
| 275 | bind(&ContactPanel::onInvitationRegisterFailed, this, _1, _2)); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | void |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 279 | ContactPanel::sendInterest(const Interest& interest, |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 280 | const OnDataValidated& onValidated, |
| 281 | const OnDataValidationFailed& onValidationFailed, |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 282 | const TimeoutNotify& timeoutNotify, |
Yingdi Yu | 68de61d | 2014-01-16 19:13:03 -0800 | [diff] [blame] | 283 | int retry /* = 1 */) |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 284 | { |
| 285 | m_face->expressInterest(interest, |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 286 | bind(&ContactPanel::onTargetData, |
| 287 | this, _1, _2, onValidated, onValidationFailed), |
| 288 | bind(&ContactPanel::onTargetTimeout, |
| 289 | this, _1, retry, onValidated, onValidationFailed, timeoutNotify)); |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | void |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 293 | ContactPanel::onTargetData(const ndn::Interest& interest, |
| 294 | Data& data, |
| 295 | const OnDataValidated& onValidated, |
| 296 | const OnDataValidationFailed& onValidationFailed) |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 297 | { |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 298 | m_panelValidator->validate(data, onValidated, onValidationFailed); |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | void |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 302 | ContactPanel::onTargetTimeout(const ndn::Interest& interest, |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 303 | int retry, |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 304 | const OnDataValidated& onValidated, |
| 305 | const OnDataValidationFailed& onValidationFailed, |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 306 | const TimeoutNotify& timeoutNotify) |
| 307 | { |
| 308 | if(retry > 0) |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 309 | sendInterest(interest, onValidated, onValidationFailed, timeoutNotify, retry-1); |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 310 | else |
| 311 | { |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 312 | _LOG_DEBUG("Interest: " << interest.getName() << " eventually times out!"); |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 313 | timeoutNotify(); |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | void |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 318 | ContactPanel::onInvitationRegisterFailed(const Name& prefix, const string& msg) |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 319 | { |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 320 | showError(QString::fromStdString("Cannot register invitation listening prefix! " + msg)); |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | void |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 324 | ContactPanel::onInvitation(const Name& prefix, const Interest& interest) |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 325 | { |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 326 | _LOG_DEBUG("Receive invitation!" << interest.getName() << " " << prefix); |
Yingdi Yu | 6eabbd7 | 2013-12-27 08:44:12 +0800 | [diff] [blame] | 327 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 328 | OnInterestValidated onValidated = bind(&ContactPanel::onInvitationValidated, this, _1); |
| 329 | OnInterestValidationFailed onValidationFailed = bind(&ContactPanel::onInvitationValidationFailed, this, _1); |
| 330 | m_invitationValidator->validate(interest, onValidated, onValidationFailed); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | void |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 334 | ContactPanel::popChatInvitation(const Name& interestName) |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 335 | { |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 336 | Invitation invitation(interestName); |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 337 | string alias; |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 338 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 339 | vector<shared_ptr<ContactItem> >::iterator it = m_contactList.begin(); |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 340 | for(; it != m_contactList.end(); it++) |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 341 | if((*it)->getNameSpace() == invitation.getInviteeNameSpace()) |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 342 | alias = (*it)->getAlias(); |
| 343 | |
| 344 | if(it != m_contactList.end()) |
| 345 | return; |
| 346 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 347 | m_invitationDialog->setInvitation(alias, interestName); |
| 348 | m_invitationDialog->show(); |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | void |
| 352 | ContactPanel::collectEndorsement() |
| 353 | { |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 354 | #ifdef WITH_SECURITY |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 355 | m_collectStatus = make_shared<vector<bool> >(); |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 356 | m_collectStatus->assign(m_contactList.size(), false); |
| 357 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 358 | vector<shared_ptr<ContactItem> >::iterator it = m_contactList.begin(); |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 359 | int count = 0; |
| 360 | for(; it != m_contactList.end(); it++, count++) |
| 361 | { |
| 362 | Name interestName = (*it)->getNameSpace(); |
| 363 | interestName.append("DNS").append(m_defaultIdentity).append("ENDORSEE"); |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 364 | Interest interest(interestName); |
Yingdi Yu | f8f572d | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 365 | interest.setInterestLifetime(1000); |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 366 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 367 | OnDataValidated onValidated = bind(&ContactPanel::onDnsEndorseeValidated, this, _1, count); |
| 368 | OnDataValidationFailed onValidationFailed = bind(&ContactPanel::onDnsEndorseeValidationFailed, this, _1, count); |
| 369 | TimeoutNotify timeoutNotify = bind(&ContactPanel::onDnsEndorseeTimeoutNotify, this, count); |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 370 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 371 | sendInterest(interest, onValidated, onValidationFailed, timeoutNotify, 0); |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 372 | } |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 373 | #endif |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | void |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 377 | ContactPanel::onDnsEndorseeValidated(const shared_ptr<const Data>& data, int count) |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 378 | { |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 379 | Data endorseData; |
Yingdi Yu | f8f572d | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 380 | endorseData.wireDecode(Block(data->getContent().value(), data->getContent().value_size())); |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 381 | EndorseCertificate endorseCertificate(endorseData); |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 382 | |
| 383 | m_contactManager->getContactStorage()->updateCollectEndorse(endorseCertificate); |
| 384 | |
| 385 | updateCollectStatus(count); |
| 386 | } |
| 387 | |
| 388 | void |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 389 | ContactPanel::onDnsEndorseeTimeoutNotify(int count) |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 390 | { updateCollectStatus(count); } |
| 391 | |
| 392 | void |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 393 | ContactPanel::onDnsEndorseeValidationFailed(const shared_ptr<const Data>& data, int count) |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 394 | { updateCollectStatus(count); } |
| 395 | |
| 396 | void |
| 397 | ContactPanel::updateCollectStatus(int count) |
| 398 | { |
| 399 | m_collectStatus->at(count) = true; |
| 400 | vector<bool>::const_iterator it = m_collectStatus->begin(); |
| 401 | for(; it != m_collectStatus->end(); it++) |
| 402 | if(*it == false) |
| 403 | return; |
| 404 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 405 | m_contactManager->publishCollectEndorsedDataInDNS(m_defaultIdentity); |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | static std::string chars("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789"); |
| 409 | |
| 410 | string |
| 411 | ContactPanel::getRandomString() |
| 412 | { |
| 413 | string randStr; |
| 414 | boost::random::random_device rng; |
| 415 | boost::random::uniform_int_distribution<> index_dist(0, chars.size() - 1); |
| 416 | for (int i = 0; i < 10; i ++) |
| 417 | { |
| 418 | randStr += chars[index_dist(rng)]; |
| 419 | } |
| 420 | return randStr; |
| 421 | } |
| 422 | |
| 423 | void |
Yingdi Yu | 8e13583 | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 424 | ContactPanel::showError(const QString& msg){ |
| 425 | QMessageBox::critical(this, tr("Chronos"), msg, QMessageBox::Ok); |
| 426 | exit(1); |
| 427 | } |
| 428 | |
| 429 | void |
Yingdi Yu | e433a50 | 2013-11-10 01:34:57 -0800 | [diff] [blame] | 430 | ContactPanel::showWarning(const QString& msg){ |
| 431 | QMessageBox::information(this, tr("Chronos"), msg); |
| 432 | } |
| 433 | |
| 434 | void |
Yingdi Yu | 40eca75 | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 435 | ContactPanel::updateSelection(const QItemSelection &selected, |
| 436 | const QItemSelection &deselected) |
| 437 | { |
| 438 | QModelIndexList items = selected.indexes(); |
| 439 | QString text = m_contactListModel->data(items.first(), Qt::DisplayRole).toString(); |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 440 | string alias = text.toStdString(); |
Yingdi Yu | 2ac40fb | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 441 | |
Yingdi Yu | 2ac40fb | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 442 | int i = 0; |
| 443 | for(; i < m_contactList.size(); i++) |
| 444 | { |
| 445 | if(alias == m_contactList[i]->getAlias()) |
| 446 | break; |
| 447 | } |
| 448 | |
Yingdi Yu | ec5e72a | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 449 | m_currentSelectedContact = m_contactList[i]; |
Yingdi Yu | 83eae84 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 450 | ui->NameData->setText(QString::fromStdString(m_currentSelectedContact->getName())); |
| 451 | ui->NameSpaceData->setText(QString::fromStdString(m_currentSelectedContact->getNameSpace().toUri())); |
| 452 | ui->InstitutionData->setText(QString::fromStdString(m_currentSelectedContact->getInstitution())); |
Yingdi Yu | 595aadc | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 453 | |
Yingdi Yu | ec5e72a | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 454 | if(m_currentSelectedContact->isIntroducer()) |
| 455 | { |
| 456 | ui->isIntroducer->setChecked(true); |
| 457 | ui->addScope->setEnabled(true); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 458 | ui->deleteScope->setEnabled(true); |
| 459 | ui->trustScopeList->setEnabled(true); |
| 460 | |
| 461 | string filter("contact_namespace = '"); |
| 462 | filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'"); |
| 463 | |
| 464 | m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
| 465 | m_trustScopeModel->setTable("TrustScope"); |
| 466 | m_trustScopeModel->setFilter(filter.c_str()); |
| 467 | m_trustScopeModel->select(); |
| 468 | m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID")); |
| 469 | m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact")); |
| 470 | m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope")); |
| 471 | |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 472 | ui->trustScopeList->setModel(m_trustScopeModel); |
| 473 | ui->trustScopeList->setColumnHidden(0, true); |
| 474 | ui->trustScopeList->setColumnHidden(1, true); |
| 475 | ui->trustScopeList->show(); |
Yingdi Yu | ec5e72a | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 476 | } |
| 477 | else |
| 478 | { |
| 479 | ui->isIntroducer->setChecked(false); |
| 480 | ui->addScope->setEnabled(false); |
| 481 | ui->deleteScope->setEnabled(false); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 482 | |
| 483 | string filter("contact_namespace = '"); |
| 484 | filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'"); |
| 485 | |
| 486 | m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
| 487 | m_trustScopeModel->setTable("TrustScope"); |
| 488 | m_trustScopeModel->setFilter(filter.c_str()); |
| 489 | m_trustScopeModel->select(); |
| 490 | m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID")); |
| 491 | m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact")); |
| 492 | m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope")); |
| 493 | |
| 494 | ui->trustScopeList->setModel(m_trustScopeModel); |
| 495 | ui->trustScopeList->setColumnHidden(0, true); |
| 496 | ui->trustScopeList->setColumnHidden(1, true); |
| 497 | ui->trustScopeList->show(); |
| 498 | |
| 499 | ui->trustScopeList->setEnabled(false); |
Yingdi Yu | ec5e72a | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 500 | } |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 501 | |
| 502 | string filter("profile_identity = '"); |
| 503 | filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'"); |
| 504 | |
| 505 | m_endorseDataModel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
| 506 | m_endorseDataModel->setTable("ContactProfile"); |
| 507 | m_endorseDataModel->setFilter(filter.c_str()); |
| 508 | m_endorseDataModel->select(); |
| 509 | |
| 510 | m_endorseDataModel->setHeaderData(0, Qt::Horizontal, QObject::tr("Identity")); |
| 511 | m_endorseDataModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Type")); |
| 512 | m_endorseDataModel->setHeaderData(2, Qt::Horizontal, QObject::tr("Value")); |
| 513 | m_endorseDataModel->setHeaderData(3, Qt::Horizontal, QObject::tr("Endorse")); |
| 514 | |
| 515 | ui->endorseList->setModel(m_endorseDataModel); |
| 516 | ui->endorseList->setColumnHidden(0, true); |
| 517 | ui->endorseList->resizeColumnToContents(1); |
| 518 | ui->endorseList->resizeColumnToContents(2); |
| 519 | ui->endorseList->setItemDelegateForColumn(3, m_endorseComboBoxDelegate); |
| 520 | ui->endorseList->show(); |
Yingdi Yu | 40eca75 | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 521 | } |
Yingdi Yu | 847aa86 | 2013-10-09 16:35:53 -0700 | [diff] [blame] | 522 | |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 523 | void |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 524 | ContactPanel::updateDefaultIdentity(const QString& identity, const QString& nickName) |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 525 | { |
Yingdi Yu | 711f589 | 2013-11-09 22:18:26 -0800 | [diff] [blame] | 526 | // _LOG_DEBUG(identity.toStdString()); |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 527 | Name defaultIdentity(identity.toStdString()); |
| 528 | Name defaultCertName = m_keyChain->createIdentity(defaultIdentity); |
| 529 | |
Yingdi Yu | e433a50 | 2013-11-10 01:34:57 -0800 | [diff] [blame] | 530 | m_defaultIdentity = defaultIdentity; |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 531 | m_profileEditor->setCurrentIdentity(m_defaultIdentity); |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 532 | m_nickName = nickName.toStdString(); |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 533 | |
Yingdi Yu | f8f572d | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 534 | m_face->unsetInterestFilter(m_invitationListenerId); |
Yingdi Yu | ae8217c | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 535 | m_contactManager->setDefaultIdentity(m_defaultIdentity); |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 536 | setInvitationListener(); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 537 | collectEndorsement(); |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 538 | } |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 539 | |
| 540 | void |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 541 | ContactPanel::openProfileEditor() |
Yingdi Yu | 0269c87 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 542 | { m_profileEditor->show(); } |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 543 | |
Yingdi Yu | 0269c87 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 544 | void |
| 545 | ContactPanel::openAddContactPanel() |
| 546 | { m_addContactPanel->show(); } |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 547 | |
Yingdi Yu | 2ac40fb | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 548 | void |
Yingdi Yu | ae8217c | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 549 | ContactPanel::openBrowseContactDialog() |
| 550 | { |
| 551 | m_browseContactDialog->show(); |
| 552 | emit refreshCertDirectory(); |
| 553 | } |
| 554 | |
| 555 | void |
| 556 | ContactPanel::removeContactButton() |
| 557 | { |
| 558 | QItemSelectionModel* selectionModel = ui->ContactList->selectionModel(); |
| 559 | QModelIndexList selectedList = selectionModel->selectedIndexes(); |
| 560 | QModelIndexList::iterator it = selectedList.begin(); |
| 561 | for(; it != selectedList.end(); it++) |
| 562 | { |
| 563 | string alias = m_contactListModel->data(*it, Qt::DisplayRole).toString().toStdString(); |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 564 | vector<shared_ptr<ContactItem> >::iterator contactIt = m_contactList.begin(); |
Yingdi Yu | ae8217c | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 565 | for(; contactIt != m_contactList.end(); contactIt++) |
| 566 | { |
| 567 | if((*contactIt)->getAlias() == alias) |
| 568 | { |
| 569 | m_contactManager->getContactStorage()->removeContact((*contactIt)->getNameSpace()); |
| 570 | m_contactList.erase(contactIt); |
| 571 | break; |
| 572 | } |
| 573 | } |
| 574 | } |
| 575 | refreshContactList(); |
| 576 | } |
| 577 | |
| 578 | void |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 579 | ContactPanel::addContactIntoValidator(const Name& contactNameSpace) |
Yingdi Yu | 7223269 | 2013-11-12 17:50:21 -0800 | [diff] [blame] | 580 | { |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 581 | #ifdef WITH_SECURITY |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 582 | shared_ptr<ContactItem> contact = m_contactManager->getContact(contactNameSpace); |
Yingdi Yu | 93adb1a | 2014-01-16 10:30:26 -0800 | [diff] [blame] | 583 | if(static_cast<bool>(contact)) |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 584 | { |
| 585 | m_panelValidator->addTrustAnchor(contact->getSelfEndorseCertificate()); |
| 586 | m_invitationValidator->addTrustAnchor(contact->getSelfEndorseCertificate()); |
| 587 | } |
| 588 | #endif |
Yingdi Yu | 7223269 | 2013-11-12 17:50:21 -0800 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | void |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 592 | ContactPanel::removeContactFromValidator(const Name& keyName) |
| 593 | { |
| 594 | #ifdef WITH_SECURITY |
| 595 | m_panelValidator->removeTrustAnchor(keyName); |
| 596 | m_invitationValidator->removeTrustAnchor(keyName); |
| 597 | #endif |
| 598 | } |
Yingdi Yu | 7223269 | 2013-11-12 17:50:21 -0800 | [diff] [blame] | 599 | |
| 600 | void |
Yingdi Yu | 2ac40fb | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 601 | ContactPanel::refreshContactList() |
| 602 | { |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 603 | m_contactList.clear(); |
| 604 | m_contactManager->getContactItemList(m_contactList); |
Yingdi Yu | 2ac40fb | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 605 | QStringList contactNameList; |
| 606 | for(int i = 0; i < m_contactList.size(); i++) |
Yingdi Yu | 83eae84 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 607 | contactNameList << QString::fromStdString(m_contactList[i]->getAlias()); |
Yingdi Yu | 2ac40fb | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 608 | |
| 609 | m_contactListModel->setStringList(contactNameList); |
| 610 | } |
| 611 | |
| 612 | void |
| 613 | ContactPanel::showContextMenu(const QPoint& pos) |
| 614 | { |
| 615 | QMenu menu(ui->ContactList); |
Yingdi Yu | 2ac40fb | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 616 | menu.addAction(m_menuAlias); |
| 617 | connect(m_menuAlias, SIGNAL(triggered()), |
| 618 | this, SLOT(openSetAliasDialog())); |
| 619 | menu.exec(ui->ContactList->mapToGlobal(pos)); |
| 620 | |
| 621 | } |
| 622 | |
| 623 | void |
| 624 | ContactPanel::openSetAliasDialog() |
| 625 | { |
Yingdi Yu | ec5e72a | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 626 | m_setAliasDialog->setTargetIdentity(m_currentSelectedContact->getNameSpace().toUri()); |
Yingdi Yu | 2ac40fb | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 627 | m_setAliasDialog->show(); |
| 628 | } |
| 629 | |
Yingdi Yu | 595aadc | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 630 | void |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 631 | ContactPanel::openSettingDialog() |
| 632 | { |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 633 | m_settingDialog->setIdentity(m_defaultIdentity.toUri(), m_nickName); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 634 | m_settingDialog->show(); |
| 635 | } |
| 636 | |
| 637 | void |
Yingdi Yu | 595aadc | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 638 | ContactPanel::openStartChatDialog() |
| 639 | { |
Yingdi Yu | 595aadc | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 640 | Name chatroom("/ndn/broadcast/chronos"); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 641 | chatroom.append(string("chatroom-") + getRandomString()); |
Yingdi Yu | 595aadc | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 642 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 643 | m_startChatDialog->setChatroom(chatroom.toUri()); |
Yingdi Yu | 595aadc | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 644 | m_startChatDialog->show(); |
| 645 | } |
| 646 | |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 647 | // For inviter |
Yingdi Yu | 595aadc | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 648 | void |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 649 | ContactPanel::startChatroom(const QString& chatroom) |
Yingdi Yu | 595aadc | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 650 | { |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 651 | Name chatroomName(chatroom.toStdString()); |
Yingdi Yu | 72781e5 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 652 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 653 | ChatDialog* chatDialog = new ChatDialog(m_contactManager, m_face, chatroomName, m_localPrefix, m_defaultIdentity, m_nickName); |
| 654 | m_chatDialogs[chatroomName] = chatDialog; |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 655 | connect(chatDialog, SIGNAL(closeChatDialog(const ndn::Name&)), |
| 656 | this, SLOT(removeChatDialog(const ndn::Name&))); |
Yingdi Yu | 8e13583 | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 657 | connect(chatDialog, SIGNAL(noNdnConnection(const QString&)), |
| 658 | this, SLOT(showError(const QString&))); |
Yingdi Yu | 0aca265 | 2013-11-10 10:47:44 -0800 | [diff] [blame] | 659 | connect(chatDialog, SIGNAL(inivationRejection(const QString&)), |
| 660 | this, SLOT(showWarning(const QString&))); |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 661 | |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 662 | chatDialog->show(); |
Yingdi Yu | 595aadc | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 665 | // For Invitee |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 666 | void |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 667 | ContactPanel::startChatroom2(const Name& invitationInterest) |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 668 | { |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 669 | Invitation invitation(invitationInterest); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 670 | Name chatroomName("/ndn/broadcast/chronos"); |
| 671 | chatroomName.append(invitation.getChatroom()); |
Yingdi Yu | 72781e5 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 672 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 673 | ChatDialog* chatDialog = new ChatDialog(m_contactManager, m_face, chatroomName, m_localPrefix, m_defaultIdentity, m_nickName); |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 674 | connect(chatDialog, SIGNAL(closeChatDialog(const ndn::Name&)), |
| 675 | this, SLOT(removeChatDialog(const ndn::Name&))); |
Yingdi Yu | 8e13583 | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 676 | connect(chatDialog, SIGNAL(noNdnConnection(const QString&)), |
| 677 | this, SLOT(showError(const QString&))); |
Yingdi Yu | 0aca265 | 2013-11-10 10:47:44 -0800 | [diff] [blame] | 678 | connect(chatDialog, SIGNAL(inivationRejection(const QString&)), |
| 679 | this, SLOT(showWarning(const QString&))); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 680 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 681 | Block signatureBlock = invitationInterest.get(-1).blockFromValue(); |
| 682 | Block signatureInfo = invitationInterest.get(-2).blockFromValue(); |
| 683 | Signature signature(signatureInfo, signatureBlock); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 684 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 685 | SignatureSha256WithRsa sig(signature); |
| 686 | Name keyLocatorName = sig.getKeyLocator().getName(); |
| 687 | Name inviter = IdentityCertificate::certificateNameToPublicKeyName(keyLocatorName).getPrefix(-1); |
| 688 | |
| 689 | #ifdef WITH_SECURITY |
| 690 | shared_ptr<IdentityCertificate> idCert = m_invitationValidator->getValidatedDskCertificate(keyLocatorName); |
| 691 | chatDialog->addChatDataRule(invitation.getInviterRoutingPrefix(), *idCert, true); |
| 692 | chatDialog->publishIntroCert(*idCert, true); |
| 693 | shared_ptr<ContactItem> inviterItem = m_contactManager->getContact(inviter); |
| 694 | chatDialog->addTrustAnchor(inviterItem->getSelfEndorseCertificate()); |
| 695 | #endif |
| 696 | |
| 697 | m_chatDialogs[chatroomName] = chatDialog; |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 698 | |
| 699 | chatDialog->show(); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | void |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 703 | ContactPanel::prepareInvitationReply(const Name& invitationInterest, const string& content) |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 704 | { |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 705 | Invitation invitation(invitationInterest); |
| 706 | |
| 707 | Name dataName = invitationInterest; |
| 708 | dataName.appendVersion(); |
| 709 | |
Yingdi Yu | 6eabbd7 | 2013-12-27 08:44:12 +0800 | [diff] [blame] | 710 | Data data(dataName); |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 711 | data.setContent(reinterpret_cast<const uint8_t*>(content.c_str()), content.size()); |
| 712 | data.setFreshnessPeriod(1000); |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 713 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 714 | m_keyChain->signByIdentity(data, invitation.getInviteeNameSpace()); |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 715 | |
Yingdi Yu | f8f572d | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 716 | m_face->put(data); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Yingdi Yu | ec5e72a | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 719 | void |
| 720 | ContactPanel::isIntroducerChanged(int state) |
| 721 | { |
| 722 | if(state == Qt::Checked) |
| 723 | { |
| 724 | ui->addScope->setEnabled(true); |
| 725 | ui->deleteScope->setEnabled(true); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 726 | ui->trustScopeList->setEnabled(true); |
| 727 | |
| 728 | string filter("contact_namespace = '"); |
| 729 | filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'"); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 730 | |
| 731 | m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
| 732 | m_trustScopeModel->setTable("TrustScope"); |
| 733 | m_trustScopeModel->setFilter(filter.c_str()); |
| 734 | m_trustScopeModel->select(); |
| 735 | m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID")); |
| 736 | m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact")); |
| 737 | m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope")); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 738 | |
| 739 | ui->trustScopeList->setModel(m_trustScopeModel); |
| 740 | ui->trustScopeList->setColumnHidden(0, true); |
| 741 | ui->trustScopeList->setColumnHidden(1, true); |
| 742 | ui->trustScopeList->show(); |
| 743 | |
| 744 | m_currentSelectedContact->setIsIntroducer(true); |
Yingdi Yu | ec5e72a | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 745 | } |
| 746 | else |
| 747 | { |
Yingdi Yu | ec5e72a | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 748 | ui->addScope->setEnabled(false); |
| 749 | ui->deleteScope->setEnabled(false); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 750 | |
| 751 | string filter("contact_namespace = '"); |
| 752 | filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'"); |
| 753 | |
| 754 | m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
| 755 | m_trustScopeModel->setTable("TrustScope"); |
| 756 | m_trustScopeModel->setFilter(filter.c_str()); |
| 757 | m_trustScopeModel->select(); |
| 758 | m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID")); |
| 759 | m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact")); |
| 760 | m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope")); |
| 761 | |
| 762 | ui->trustScopeList->setModel(m_trustScopeModel); |
| 763 | ui->trustScopeList->setColumnHidden(0, true); |
| 764 | ui->trustScopeList->setColumnHidden(1, true); |
| 765 | ui->trustScopeList->show(); |
| 766 | |
| 767 | ui->trustScopeList->setEnabled(false); |
| 768 | |
| 769 | m_currentSelectedContact->setIsIntroducer(false); |
Yingdi Yu | ec5e72a | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 770 | } |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 771 | m_contactManager->getContactStorage()->updateIsIntroducer(m_currentSelectedContact->getNameSpace(), m_currentSelectedContact->isIntroducer()); |
| 772 | } |
| 773 | |
| 774 | void |
| 775 | ContactPanel::addScopeClicked() |
| 776 | { |
| 777 | int rowCount = m_trustScopeModel->rowCount(); |
| 778 | QSqlRecord record; |
| 779 | QSqlField identityField("contact_namespace", QVariant::String); |
| 780 | record.append(identityField); |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 781 | record.setValue("contact_namespace", QString::fromStdString(m_currentSelectedContact->getNameSpace().toUri())); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 782 | m_trustScopeModel->insertRow(rowCount); |
| 783 | m_trustScopeModel->setRecord(rowCount, record); |
| 784 | } |
| 785 | |
| 786 | void |
| 787 | ContactPanel::deleteScopeClicked() |
| 788 | { |
| 789 | QItemSelectionModel* selectionModel = ui->trustScopeList->selectionModel(); |
| 790 | QModelIndexList indexList = selectionModel->selectedIndexes(); |
| 791 | |
| 792 | int i = indexList.size() - 1; |
| 793 | for(; i >= 0; i--) |
| 794 | m_trustScopeModel->removeRow(indexList[i].row()); |
| 795 | |
| 796 | m_trustScopeModel->submitAll(); |
| 797 | } |
| 798 | |
| 799 | void |
| 800 | ContactPanel::saveScopeClicked() |
Yingdi Yu | 83eae84 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 801 | { m_trustScopeModel->submitAll(); } |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 802 | |
| 803 | void |
| 804 | ContactPanel::endorseButtonClicked() |
| 805 | { |
| 806 | m_endorseDataModel->submitAll(); |
| 807 | m_contactManager->updateEndorseCertificate(m_currentSelectedContact->getNameSpace(), m_defaultIdentity); |
Yingdi Yu | ec5e72a | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 808 | } |
Yingdi Yu | 595aadc | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 809 | |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 810 | void |
| 811 | ContactPanel::removeChatDialog(const ndn::Name& chatroomName) |
| 812 | { |
| 813 | map<Name, ChatDialog*>::iterator it = m_chatDialogs.find(chatroomName); |
Yingdi Yu | 83eae84 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 814 | |
| 815 | ChatDialog* deletedChat = NULL; |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 816 | if(it != m_chatDialogs.end()) |
| 817 | { |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 818 | deletedChat = it->second; |
| 819 | m_chatDialogs.erase(it); |
| 820 | } |
Yingdi Yu | 83eae84 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 821 | if (deletedChat != NULL) |
| 822 | delete deletedChat; |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 823 | } |
| 824 | |
Yingdi Yu | 847aa86 | 2013-10-09 16:35:53 -0700 | [diff] [blame] | 825 | #if WAF |
| 826 | #include "contactpanel.moc" |
| 827 | #include "contactpanel.cpp.moc" |
| 828 | #endif |