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