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