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