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 | ae8217c | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 73 | m_contactManager->setDefaultIdentity(m_defaultIdentity); |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 74 | m_nickName = m_defaultIdentity.get(-1).toUri(); |
| 75 | m_settingDialog->setIdentity(m_defaultIdentity.toUri(), m_nickName); |
| 76 | |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 77 | m_profileEditor = new ProfileEditor(m_contactManager); |
| 78 | m_profileEditor->setCurrentIdentity(m_defaultIdentity); |
| 79 | |
Yingdi Yu | 8e13583 | 2013-11-09 20:12:31 -0800 | [diff] [blame^] | 80 | m_addContactPanel = new AddContactPanel(m_contactManager); |
| 81 | m_browseContactDialog = new BrowseContactDialog(m_contactManager); |
| 82 | m_setAliasDialog = new SetAliasDialog(m_contactManager); |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 83 | |
| 84 | ui->setupUi(this); |
| 85 | |
Yingdi Yu | 8e13583 | 2013-11-09 20:12:31 -0800 | [diff] [blame^] | 86 | try{ |
| 87 | m_handler = Ptr<Wrapper>(new Wrapper(m_keychain)); |
| 88 | }catch(ndn::Error::ndnOperation& e){ |
| 89 | showError(QString::fromStdString("Cannot conect to ndnd!\n Have you started your ndnd?")); |
| 90 | } |
| 91 | |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 92 | |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 93 | setLocalPrefix(); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 94 | |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 95 | setInvitationListener(); |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 96 | |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 97 | collectEndorsement(); |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 98 | |
| 99 | ui->ContactList->setModel(m_contactListModel); |
| 100 | |
Yingdi Yu | 8f7325a | 2013-10-17 17:03:46 -0700 | [diff] [blame] | 101 | |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 102 | connect(ui->ContactList->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 103 | this, SLOT(updateSelection(const QItemSelection &, const QItemSelection &))); |
Yingdi Yu | 40eca75 | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 104 | |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 105 | connect(ui->ContactList, SIGNAL(customContextMenuRequested(const QPoint&)), |
| 106 | this, SLOT(showContextMenu(const QPoint&))); |
Yingdi Yu | 0269c87 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 107 | |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 108 | connect(ui->EditProfileButton, SIGNAL(clicked()), |
| 109 | this, SLOT(openProfileEditor())); |
Yingdi Yu | 0269c87 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 110 | |
Yingdi Yu | ae8217c | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 111 | // connect(ui->AddContactButton, SIGNAL(clicked()), |
| 112 | // this, SLOT(openAddContactPanel())); |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 113 | connect(ui->AddContactButton, SIGNAL(clicked()), |
Yingdi Yu | ae8217c | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 114 | this, SLOT(openBrowseContactDialog())); |
| 115 | |
| 116 | connect(this, SIGNAL(refreshCertDirectory()), |
| 117 | m_browseContactDialog, SLOT(refreshList())); |
| 118 | |
| 119 | connect(ui->DeleteContactButton, SIGNAL(clicked()), |
| 120 | this, SLOT(removeContactButton())); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 121 | |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 122 | connect(ui->settingButton, SIGNAL(clicked()), |
| 123 | this, SLOT(openSettingDialog())); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 124 | |
Yingdi Yu | ae8217c | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 125 | connect(m_browseContactDialog, SIGNAL(newContactAdded()), |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 126 | this, SLOT(refreshContactList())); |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 127 | connect(m_setAliasDialog, SIGNAL(aliasChanged()), |
| 128 | this, SLOT(refreshContactList())); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 129 | |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 130 | connect(m_startChatDialog, SIGNAL(chatroomConfirmed(const QString&, const QString&, bool)), |
| 131 | this, SLOT(startChatroom(const QString&, const QString&, bool))); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 132 | |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 133 | connect(m_invitationDialog, SIGNAL(invitationAccepted(const ChronosInvitation&, const ndn::security::IdentityCertificate&)), |
| 134 | this, SLOT(acceptInvitation(const ChronosInvitation&, const ndn::security::IdentityCertificate&))); |
| 135 | connect(m_invitationDialog, SIGNAL(invitationRejected(const ChronosInvitation&)), |
| 136 | this, SLOT(rejectInvitation(const ChronosInvitation&))); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 137 | |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 138 | connect(m_settingDialog, SIGNAL(identitySet(const QString&, const QString&)), |
| 139 | this, SLOT(updateDefaultIdentity(const QString&, const QString&))); |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 140 | |
| 141 | connect(this, SIGNAL(newInvitationReady()), |
| 142 | this, SLOT(openInvitationDialog())); |
Yingdi Yu | 595aadc | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 143 | |
Yingdi Yu | ec5e72a | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 144 | connect(ui->isIntroducer, SIGNAL(stateChanged(int)), |
| 145 | this, SLOT(isIntroducerChanged(int))); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 146 | |
| 147 | connect(ui->addScope, SIGNAL(clicked()), |
| 148 | this, SLOT(addScopeClicked())); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 149 | connect(ui->deleteScope, SIGNAL(clicked()), |
| 150 | this, SLOT(deleteScopeClicked())); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 151 | connect(ui->saveButton, SIGNAL(clicked()), |
| 152 | this, SLOT(saveScopeClicked())); |
| 153 | |
| 154 | connect(ui->endorseButton, SIGNAL(clicked()), |
| 155 | this, SLOT(endorseButtonClicked())); |
Yingdi Yu | 847aa86 | 2013-10-09 16:35:53 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | ContactPanel::~ContactPanel() |
| 159 | { |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 160 | delete ui; |
| 161 | delete m_contactListModel; |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 162 | delete m_startChatDialog; |
| 163 | delete m_invitationDialog; |
| 164 | delete m_settingDialog; |
| 165 | |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 166 | delete m_profileEditor; |
| 167 | delete m_addContactPanel; |
Yingdi Yu | ae8217c | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 168 | delete m_browseContactDialog; |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 169 | delete m_setAliasDialog; |
| 170 | |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 171 | delete m_trustScopeModel; |
| 172 | delete m_endorseDataModel; |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 173 | delete m_endorseComboBoxDelegate; |
Yingdi Yu | 2ac40fb | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 174 | |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 175 | delete m_menuInvite; |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 176 | delete m_menuAlias; |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 177 | |
| 178 | map<Name, ChatDialog*>::iterator it = m_chatDialogs.begin(); |
| 179 | for(; it != m_chatDialogs.end(); it++) |
| 180 | delete it->second; |
Yingdi Yu | 847aa86 | 2013-10-09 16:35:53 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Yingdi Yu | 40eca75 | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 183 | void |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 184 | ContactPanel::createAction() |
| 185 | { |
| 186 | m_menuInvite = new QAction("&Chat", this); |
| 187 | m_menuAlias = new QAction("&Set Alias", this); |
| 188 | } |
| 189 | |
| 190 | void |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 191 | ContactPanel::openDB() |
| 192 | { |
| 193 | QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); |
| 194 | QString path = (QDir::home().path()); |
| 195 | path.append(QDir::separator()).append(".chronos").append(QDir::separator()).append("chronos.db"); |
| 196 | db.setDatabaseName(path); |
| 197 | bool ok = db.open(); |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 198 | _LOG_DEBUG("DB opened: " << std::boolalpha << ok ); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 199 | |
| 200 | m_trustScopeModel = new QSqlTableModel; |
| 201 | m_endorseDataModel = new QSqlTableModel; |
| 202 | m_endorseComboBoxDelegate = new EndorseComboBoxDelegate; |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | void |
| 206 | ContactPanel::setKeychain() |
| 207 | { |
Yingdi Yu | 9b34b1f | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 208 | m_panelPolicyManager = Ptr<PanelPolicyManager>::Create(); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 209 | |
| 210 | vector<Ptr<ContactItem> >::const_iterator it = m_contactList.begin(); |
| 211 | for(; it != m_contactList.end(); it++) |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 212 | { |
| 213 | m_panelPolicyManager->addTrustAnchor((*it)->getSelfEndorseCertificate()); |
| 214 | } |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 215 | |
Yingdi Yu | 9b34b1f | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 216 | m_keychain = Ptr<security::Keychain>(new security::Keychain(Ptr<security::IdentityManager>::Create(), |
| 217 | m_panelPolicyManager, |
| 218 | NULL)); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | void |
| 222 | ContactPanel::setLocalPrefix() |
| 223 | { |
| 224 | Ptr<Interest> interest = Ptr<Interest>(new Interest(Name("/local/ndn/prefix"))); |
| 225 | interest->setChildSelector(Interest::CHILD_RIGHT); |
| 226 | |
| 227 | Ptr<Closure> closure = Ptr<Closure>(new Closure(boost::bind(&ContactPanel::onLocalPrefixVerified, |
| 228 | this, |
| 229 | _1), |
| 230 | boost::bind(&ContactPanel::onLocalPrefixTimeout, |
| 231 | this, |
| 232 | _1, |
| 233 | _2), |
| 234 | boost::bind(&ContactPanel::onLocalPrefixVerified, |
| 235 | this, |
| 236 | _1))); |
| 237 | |
| 238 | m_handler->sendInterest(interest, closure); |
| 239 | } |
| 240 | |
| 241 | void |
| 242 | ContactPanel::onLocalPrefixVerified(Ptr<Data> data) |
| 243 | { |
| 244 | string originPrefix(data->content().buf(), data->content().size()); |
| 245 | string prefix = QString::fromStdString (originPrefix).trimmed ().toUtf8().constData(); |
| 246 | string randomSuffix = getRandomString(); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 247 | m_localPrefix = Name(prefix); |
| 248 | } |
| 249 | |
| 250 | void |
| 251 | ContactPanel::onLocalPrefixTimeout(Ptr<Closure> closure, Ptr<Interest> interest) |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 252 | { |
| 253 | string randomSuffix = getRandomString(); |
| 254 | m_localPrefix = Name("/private/local"); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 255 | } |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 256 | |
| 257 | void |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 258 | ContactPanel::setInvitationListener() |
| 259 | { |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 260 | m_inviteListenPrefix = Name("/ndn/broadcast/chronos/invitation"); |
| 261 | m_inviteListenPrefix.append(m_defaultIdentity); |
| 262 | _LOG_DEBUG("Listening for invitation on prefix: " << m_inviteListenPrefix.toUri()); |
| 263 | m_handler->setInterestFilter (m_inviteListenPrefix, |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 264 | boost::bind(&ContactPanel::onInvitation, |
| 265 | this, |
| 266 | _1)); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | void |
| 270 | ContactPanel::onInvitation(Ptr<Interest> interest) |
| 271 | { |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 272 | _LOG_DEBUG("Receive invitation!" << interest->getName().toUri()); |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 273 | |
| 274 | Ptr<ChronosInvitation> invitation = NULL; |
| 275 | try{ |
| 276 | invitation = Ptr<ChronosInvitation>(new ChronosInvitation(interest->getName())); |
| 277 | }catch(exception& e){ |
| 278 | _LOG_ERROR("Exception: " << e.what()); |
| 279 | return; |
| 280 | } |
| 281 | |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 282 | Name chatroomName("/ndn/broadcast/chronos"); |
| 283 | chatroomName.append(invitation->getChatroom()); |
| 284 | map<Name, ChatDialog*>::iterator it = m_chatDialogs.find(chatroomName); |
| 285 | if(it != m_chatDialogs.end()) |
| 286 | { |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 287 | _LOG_ERROR("Exisiting chatroom!"); |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 288 | return; |
| 289 | } |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 290 | |
Yingdi Yu | 9b34b1f | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 291 | Ptr<Interest> newInterest = Ptr<Interest>(new Interest(invitation->getInviterCertificateName())); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 292 | Ptr<Closure> closure = Ptr<Closure>(new Closure(boost::bind(&ContactPanel::onInvitationCertVerified, |
| 293 | this, |
| 294 | _1, |
Yingdi Yu | 9b34b1f | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 295 | invitation), |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 296 | boost::bind(&ContactPanel::onTimeout, |
| 297 | this, |
| 298 | _1, |
| 299 | _2), |
| 300 | boost::bind(&ContactPanel::onUnverified, |
| 301 | this, |
| 302 | _1))); |
| 303 | m_handler->sendInterest(newInterest, closure); |
| 304 | } |
| 305 | |
| 306 | void |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 307 | ContactPanel::onInvitationCertVerified(Ptr<Data> data, |
| 308 | Ptr<ChronosInvitation> invitation) |
| 309 | { |
| 310 | using namespace ndn::security; |
| 311 | Ptr<IdentityCertificate> certificate = Ptr<IdentityCertificate>(new IdentityCertificate(*data)); |
| 312 | |
| 313 | if(PolicyManager::verifySignature(invitation->getSignedBlob(), invitation->getSignatureBits(), certificate->getPublicKeyInfo())) |
| 314 | { |
| 315 | Name keyName = certificate->getPublicKeyName(); |
| 316 | Name inviterNameSpace = keyName.getPrefix(keyName.size() - 1); |
| 317 | popChatInvitation(invitation, inviterNameSpace, certificate); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | void |
| 322 | ContactPanel::onUnverified(Ptr<Data> data) |
| 323 | {} |
| 324 | |
| 325 | void |
| 326 | ContactPanel::onTimeout(Ptr<Closure> closure, Ptr<Interest> interest) |
| 327 | {} |
| 328 | |
| 329 | void |
| 330 | ContactPanel::popChatInvitation(Ptr<ChronosInvitation> invitation, |
| 331 | const Name& inviterNameSpace, |
| 332 | Ptr<security::IdentityCertificate> certificate) |
| 333 | { |
| 334 | string alias; |
| 335 | vector<Ptr<ContactItem> >::iterator it = m_contactList.begin(); |
| 336 | for(; it != m_contactList.end(); it++) |
| 337 | if((*it)->getNameSpace() == inviterNameSpace) |
| 338 | alias = (*it)->getAlias(); |
| 339 | |
| 340 | if(it != m_contactList.end()) |
| 341 | return; |
| 342 | |
| 343 | m_invitationDialog->setInvitation(alias, invitation, certificate); |
| 344 | emit newInvitationReady(); |
| 345 | } |
| 346 | |
| 347 | void |
| 348 | ContactPanel::collectEndorsement() |
| 349 | { |
| 350 | m_collectStatus = Ptr<vector<bool> >::Create(); |
| 351 | m_collectStatus->assign(m_contactList.size(), false); |
| 352 | |
| 353 | vector<Ptr<ContactItem> >::iterator it = m_contactList.begin(); |
| 354 | int count = 0; |
| 355 | for(; it != m_contactList.end(); it++, count++) |
| 356 | { |
| 357 | Name interestName = (*it)->getNameSpace(); |
| 358 | interestName.append("DNS").append(m_defaultIdentity).append("ENDORSEE"); |
| 359 | Ptr<Interest> interest = Ptr<Interest>(new Interest(interestName)); |
| 360 | interest->setChildSelector(Interest::CHILD_RIGHT); |
| 361 | interest->setInterestLifetime(1); |
| 362 | |
| 363 | Ptr<Closure> closure = Ptr<Closure>(new Closure(boost::bind(&ContactPanel::onDnsEndorseeVerified, |
| 364 | this, |
| 365 | _1, |
| 366 | count), |
| 367 | boost::bind(&ContactPanel::onDnsEndorseeTimeout, |
| 368 | this, |
| 369 | _1, |
| 370 | _2, |
| 371 | count), |
| 372 | boost::bind(&ContactPanel::onDnsEndorseeUnverified, |
| 373 | this, |
| 374 | _1, |
| 375 | count))); |
| 376 | |
| 377 | m_handler->sendInterest(interest, closure); |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | void |
| 382 | ContactPanel::onDnsEndorseeVerified(Ptr<Data> data, int count) |
| 383 | { |
| 384 | Ptr<Blob> contentBlob = Ptr<Blob>(new Blob(data->content().buf(), data->content().size())); |
| 385 | Ptr<Data> endorseData = Data::decodeFromWire(contentBlob); |
| 386 | EndorseCertificate endorseCertificate(*endorseData); |
| 387 | |
| 388 | m_contactManager->getContactStorage()->updateCollectEndorse(endorseCertificate); |
| 389 | |
| 390 | updateCollectStatus(count); |
| 391 | } |
| 392 | |
| 393 | void |
| 394 | ContactPanel::onDnsEndorseeTimeout(Ptr<Closure> closure, Ptr<Interest> interest, int count) |
| 395 | { updateCollectStatus(count); } |
| 396 | |
| 397 | void |
| 398 | ContactPanel::onDnsEndorseeUnverified(Ptr<Data> data, int count) |
| 399 | { updateCollectStatus(count); } |
| 400 | |
| 401 | void |
| 402 | ContactPanel::updateCollectStatus(int count) |
| 403 | { |
| 404 | m_collectStatus->at(count) = true; |
| 405 | vector<bool>::const_iterator it = m_collectStatus->begin(); |
| 406 | for(; it != m_collectStatus->end(); it++) |
| 407 | if(*it == false) |
| 408 | return; |
| 409 | |
| 410 | m_contactManager->publishEndorsedDataInDns(m_defaultIdentity); |
| 411 | } |
| 412 | |
| 413 | static std::string chars("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789"); |
| 414 | |
| 415 | string |
| 416 | ContactPanel::getRandomString() |
| 417 | { |
| 418 | string randStr; |
| 419 | boost::random::random_device rng; |
| 420 | boost::random::uniform_int_distribution<> index_dist(0, chars.size() - 1); |
| 421 | for (int i = 0; i < 10; i ++) |
| 422 | { |
| 423 | randStr += chars[index_dist(rng)]; |
| 424 | } |
| 425 | return randStr; |
| 426 | } |
| 427 | |
| 428 | void |
Yingdi Yu | 8e13583 | 2013-11-09 20:12:31 -0800 | [diff] [blame^] | 429 | ContactPanel::showError(const QString& msg){ |
| 430 | QMessageBox::critical(this, tr("Chronos"), msg, QMessageBox::Ok); |
| 431 | exit(1); |
| 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 | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 526 | m_defaultIdentity = Name(identity.toStdString()); |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 527 | m_profileEditor->setCurrentIdentity(m_defaultIdentity); |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 528 | m_nickName = nickName.toStdString(); |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 529 | m_handler->clearInterestFilter(m_inviteListenPrefix); |
Yingdi Yu | ae8217c | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 530 | m_contactManager->setDefaultIdentity(m_defaultIdentity); |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 531 | setInvitationListener(); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 532 | collectEndorsement(); |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 533 | } |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 534 | |
| 535 | void |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 536 | ContactPanel::openProfileEditor() |
Yingdi Yu | 0269c87 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 537 | { m_profileEditor->show(); } |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 538 | |
Yingdi Yu | 0269c87 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 539 | void |
| 540 | ContactPanel::openAddContactPanel() |
| 541 | { m_addContactPanel->show(); } |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 542 | |
Yingdi Yu | 2ac40fb | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 543 | void |
Yingdi Yu | ae8217c | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 544 | ContactPanel::openBrowseContactDialog() |
| 545 | { |
| 546 | m_browseContactDialog->show(); |
| 547 | emit refreshCertDirectory(); |
| 548 | } |
| 549 | |
| 550 | void |
| 551 | ContactPanel::removeContactButton() |
| 552 | { |
| 553 | QItemSelectionModel* selectionModel = ui->ContactList->selectionModel(); |
| 554 | QModelIndexList selectedList = selectionModel->selectedIndexes(); |
| 555 | QModelIndexList::iterator it = selectedList.begin(); |
| 556 | for(; it != selectedList.end(); it++) |
| 557 | { |
| 558 | string alias = m_contactListModel->data(*it, Qt::DisplayRole).toString().toStdString(); |
| 559 | vector<Ptr<ContactItem> >::iterator contactIt = m_contactList.begin(); |
| 560 | for(; contactIt != m_contactList.end(); contactIt++) |
| 561 | { |
| 562 | if((*contactIt)->getAlias() == alias) |
| 563 | { |
| 564 | m_contactManager->getContactStorage()->removeContact((*contactIt)->getNameSpace()); |
| 565 | m_contactList.erase(contactIt); |
| 566 | break; |
| 567 | } |
| 568 | } |
| 569 | } |
| 570 | refreshContactList(); |
| 571 | } |
| 572 | |
| 573 | void |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 574 | ContactPanel::openInvitationDialog() |
| 575 | { m_invitationDialog->show(); } |
| 576 | |
| 577 | void |
Yingdi Yu | 2ac40fb | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 578 | ContactPanel::refreshContactList() |
| 579 | { |
| 580 | m_contactList = m_contactManager->getContactItemList(); |
| 581 | QStringList contactNameList; |
| 582 | for(int i = 0; i < m_contactList.size(); i++) |
Yingdi Yu | 83eae84 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 583 | contactNameList << QString::fromStdString(m_contactList[i]->getAlias()); |
Yingdi Yu | 2ac40fb | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 584 | |
| 585 | m_contactListModel->setStringList(contactNameList); |
| 586 | } |
| 587 | |
| 588 | void |
| 589 | ContactPanel::showContextMenu(const QPoint& pos) |
| 590 | { |
| 591 | QMenu menu(ui->ContactList); |
| 592 | menu.addAction(m_menuInvite); |
Yingdi Yu | 595aadc | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 593 | connect(m_menuInvite, SIGNAL(triggered()), |
| 594 | this, SLOT(openStartChatDialog())); |
Yingdi Yu | 83eae84 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 595 | menu.addSeparator(); |
Yingdi Yu | 2ac40fb | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 596 | menu.addAction(m_menuAlias); |
| 597 | connect(m_menuAlias, SIGNAL(triggered()), |
| 598 | this, SLOT(openSetAliasDialog())); |
| 599 | menu.exec(ui->ContactList->mapToGlobal(pos)); |
| 600 | |
| 601 | } |
| 602 | |
| 603 | void |
| 604 | ContactPanel::openSetAliasDialog() |
| 605 | { |
Yingdi Yu | ec5e72a | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 606 | m_setAliasDialog->setTargetIdentity(m_currentSelectedContact->getNameSpace().toUri()); |
Yingdi Yu | 2ac40fb | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 607 | m_setAliasDialog->show(); |
| 608 | } |
| 609 | |
Yingdi Yu | 595aadc | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 610 | void |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 611 | ContactPanel::openSettingDialog() |
| 612 | { |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 613 | m_settingDialog->setIdentity(m_defaultIdentity.toUri(), m_nickName); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 614 | m_settingDialog->show(); |
| 615 | } |
| 616 | |
| 617 | void |
Yingdi Yu | 595aadc | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 618 | ContactPanel::openStartChatDialog() |
| 619 | { |
Yingdi Yu | 595aadc | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 620 | Name chatroom("/ndn/broadcast/chronos"); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 621 | chatroom.append(string("chatroom-") + getRandomString()); |
Yingdi Yu | 595aadc | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 622 | |
Yingdi Yu | ec5e72a | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 623 | m_startChatDialog->setInvitee(m_currentSelectedContact->getNameSpace().toUri(), chatroom.toUri()); |
Yingdi Yu | 595aadc | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 624 | m_startChatDialog->show(); |
| 625 | } |
| 626 | |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 627 | // For inviter |
Yingdi Yu | 595aadc | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 628 | void |
| 629 | ContactPanel::startChatroom(const QString& chatroom, const QString& invitee, bool isIntroducer) |
| 630 | { |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 631 | Name chatroomName(chatroom.toUtf8().constData()); |
Yingdi Yu | 72781e5 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 632 | |
| 633 | Name inviteeNamespace(invitee.toStdString()); |
| 634 | Ptr<ContactItem> inviteeItem = m_contactManager->getContact(inviteeNamespace); |
| 635 | |
Yingdi Yu | e6476cd | 2013-11-06 18:51:19 -0800 | [diff] [blame] | 636 | 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] | 637 | m_chatDialogs.insert(pair <Name, ChatDialog*> (chatroomName, chatDialog)); |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 638 | |
| 639 | connect(chatDialog, SIGNAL(closeChatDialog(const ndn::Name&)), |
| 640 | this, SLOT(removeChatDialog(const ndn::Name&))); |
Yingdi Yu | 8e13583 | 2013-11-09 20:12:31 -0800 | [diff] [blame^] | 641 | connect(chatDialog, SIGNAL(noNdnConnection(const QString&)), |
| 642 | this, SLOT(showError(const QString&))); |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 643 | |
Yingdi Yu | e6476cd | 2013-11-06 18:51:19 -0800 | [diff] [blame] | 644 | // send invitation |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 645 | chatDialog->sendInvitation(inviteeItem, isIntroducer); |
Yingdi Yu | eda39aa | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 646 | |
| 647 | chatDialog->show(); |
Yingdi Yu | 595aadc | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 648 | } |
| 649 | |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 650 | // For Invitee |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 651 | void |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 652 | ContactPanel::startChatroom2(const ChronosInvitation& invitation, |
| 653 | const security::IdentityCertificate& identityCertificate) |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 654 | { |
Yingdi Yu | 72781e5 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 655 | Ptr<ContactItem> inviterItem = m_contactManager->getContact(invitation.getInviterNameSpace()); |
| 656 | |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 657 | Name chatroomName("/ndn/broadcast/chronos"); |
| 658 | chatroomName.append(invitation.getChatroom()); |
Yingdi Yu | 72781e5 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 659 | |
Yingdi Yu | e6476cd | 2013-11-06 18:51:19 -0800 | [diff] [blame] | 660 | 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] | 661 | |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 662 | connect(chatDialog, SIGNAL(closeChatDialog(const ndn::Name&)), |
| 663 | this, SLOT(removeChatDialog(const ndn::Name&))); |
Yingdi Yu | 8e13583 | 2013-11-09 20:12:31 -0800 | [diff] [blame^] | 664 | connect(chatDialog, SIGNAL(noNdnConnection(const QString&)), |
| 665 | this, SLOT(showError(const QString&))); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 666 | |
Yingdi Yu | e6476cd | 2013-11-06 18:51:19 -0800 | [diff] [blame] | 667 | chatDialog->addChatDataRule(invitation.getInviterPrefix(), identityCertificate, true); |
Yingdi Yu | 83eae84 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 668 | chatDialog->publishIntroCert(identityCertificate, true); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 669 | |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 670 | chatDialog->addTrustAnchor(inviterItem->getSelfEndorseCertificate()); |
| 671 | |
| 672 | m_chatDialogs.insert(pair <Name, ChatDialog*> (chatroomName, chatDialog)); |
| 673 | |
| 674 | chatDialog->show(); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | void |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 678 | ContactPanel::acceptInvitation(const ChronosInvitation& invitation, |
| 679 | const security::IdentityCertificate& identityCertificate) |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 680 | { |
| 681 | string prefix = m_localPrefix.toUri(); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 682 | m_handler->publishDataByIdentity (invitation.getInterestName(), prefix); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 683 | startChatroom2(invitation, identityCertificate); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | void |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 687 | ContactPanel::rejectInvitation(const ChronosInvitation& invitation) |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 688 | { |
Yingdi Yu | e9195fd | 2013-11-08 14:13:42 -0800 | [diff] [blame] | 689 | string empty("nack"); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 690 | m_handler->publishDataByIdentity (invitation.getInterestName(), empty); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 691 | } |
| 692 | |
Yingdi Yu | ec5e72a | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 693 | void |
| 694 | ContactPanel::isIntroducerChanged(int state) |
| 695 | { |
| 696 | if(state == Qt::Checked) |
| 697 | { |
| 698 | ui->addScope->setEnabled(true); |
| 699 | ui->deleteScope->setEnabled(true); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 700 | ui->trustScopeList->setEnabled(true); |
| 701 | |
| 702 | string filter("contact_namespace = '"); |
| 703 | filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'"); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 704 | |
| 705 | m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
| 706 | m_trustScopeModel->setTable("TrustScope"); |
| 707 | m_trustScopeModel->setFilter(filter.c_str()); |
| 708 | m_trustScopeModel->select(); |
| 709 | m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID")); |
| 710 | m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact")); |
| 711 | m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope")); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 712 | |
| 713 | ui->trustScopeList->setModel(m_trustScopeModel); |
| 714 | ui->trustScopeList->setColumnHidden(0, true); |
| 715 | ui->trustScopeList->setColumnHidden(1, true); |
| 716 | ui->trustScopeList->show(); |
| 717 | |
| 718 | m_currentSelectedContact->setIsIntroducer(true); |
Yingdi Yu | ec5e72a | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 719 | } |
| 720 | else |
| 721 | { |
Yingdi Yu | ec5e72a | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 722 | ui->addScope->setEnabled(false); |
| 723 | ui->deleteScope->setEnabled(false); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 724 | |
| 725 | string filter("contact_namespace = '"); |
| 726 | filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'"); |
| 727 | |
| 728 | m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
| 729 | m_trustScopeModel->setTable("TrustScope"); |
| 730 | m_trustScopeModel->setFilter(filter.c_str()); |
| 731 | m_trustScopeModel->select(); |
| 732 | m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID")); |
| 733 | m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact")); |
| 734 | m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope")); |
| 735 | |
| 736 | ui->trustScopeList->setModel(m_trustScopeModel); |
| 737 | ui->trustScopeList->setColumnHidden(0, true); |
| 738 | ui->trustScopeList->setColumnHidden(1, true); |
| 739 | ui->trustScopeList->show(); |
| 740 | |
| 741 | ui->trustScopeList->setEnabled(false); |
| 742 | |
| 743 | m_currentSelectedContact->setIsIntroducer(false); |
Yingdi Yu | ec5e72a | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 744 | } |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 745 | m_contactManager->getContactStorage()->updateIsIntroducer(m_currentSelectedContact->getNameSpace(), m_currentSelectedContact->isIntroducer()); |
| 746 | } |
| 747 | |
| 748 | void |
| 749 | ContactPanel::addScopeClicked() |
| 750 | { |
| 751 | int rowCount = m_trustScopeModel->rowCount(); |
| 752 | QSqlRecord record; |
| 753 | QSqlField identityField("contact_namespace", QVariant::String); |
| 754 | record.append(identityField); |
| 755 | record.setValue("contact_namespace", QString(m_currentSelectedContact->getNameSpace().toUri().c_str())); |
| 756 | m_trustScopeModel->insertRow(rowCount); |
| 757 | m_trustScopeModel->setRecord(rowCount, record); |
| 758 | } |
| 759 | |
| 760 | void |
| 761 | ContactPanel::deleteScopeClicked() |
| 762 | { |
| 763 | QItemSelectionModel* selectionModel = ui->trustScopeList->selectionModel(); |
| 764 | QModelIndexList indexList = selectionModel->selectedIndexes(); |
| 765 | |
| 766 | int i = indexList.size() - 1; |
| 767 | for(; i >= 0; i--) |
| 768 | m_trustScopeModel->removeRow(indexList[i].row()); |
| 769 | |
| 770 | m_trustScopeModel->submitAll(); |
| 771 | } |
| 772 | |
| 773 | void |
| 774 | ContactPanel::saveScopeClicked() |
Yingdi Yu | 83eae84 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 775 | { m_trustScopeModel->submitAll(); } |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 776 | |
| 777 | void |
| 778 | ContactPanel::endorseButtonClicked() |
| 779 | { |
| 780 | m_endorseDataModel->submitAll(); |
| 781 | m_contactManager->updateEndorseCertificate(m_currentSelectedContact->getNameSpace(), m_defaultIdentity); |
Yingdi Yu | ec5e72a | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 782 | } |
Yingdi Yu | 595aadc | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 783 | |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 784 | void |
| 785 | ContactPanel::removeChatDialog(const ndn::Name& chatroomName) |
| 786 | { |
| 787 | map<Name, ChatDialog*>::iterator it = m_chatDialogs.find(chatroomName); |
Yingdi Yu | 83eae84 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 788 | |
| 789 | ChatDialog* deletedChat = NULL; |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 790 | if(it != m_chatDialogs.end()) |
| 791 | { |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 792 | deletedChat = it->second; |
| 793 | m_chatDialogs.erase(it); |
| 794 | } |
Yingdi Yu | 83eae84 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 795 | if (deletedChat != NULL) |
| 796 | delete deletedChat; |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 797 | } |
| 798 | |
Yingdi Yu | 847aa86 | 2013-10-09 16:35:53 -0700 | [diff] [blame] | 799 | #if WAF |
| 800 | #include "contactpanel.moc" |
| 801 | #include "contactpanel.cpp.moc" |
| 802 | #endif |