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