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); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 221 | m_localPrefix.append(randomSuffix); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | void |
| 225 | ContactPanel::onLocalPrefixTimeout(Ptr<Closure> closure, Ptr<Interest> interest) |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 226 | { |
| 227 | string randomSuffix = getRandomString(); |
| 228 | m_localPrefix = Name("/private/local"); |
| 229 | m_localPrefix.append(randomSuffix); |
| 230 | } |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 231 | |
| 232 | void |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 233 | ContactPanel::setInvitationListener() |
| 234 | { |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame^] | 235 | m_inviteListenPrefix = Name("/ndn/broadcast/chronos/invitation"); |
| 236 | m_inviteListenPrefix.append(m_defaultIdentity); |
| 237 | _LOG_DEBUG("Listening for invitation on prefix: " << m_inviteListenPrefix.toUri()); |
| 238 | m_handler->setInterestFilter (m_inviteListenPrefix, |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 239 | boost::bind(&ContactPanel::onInvitation, |
| 240 | this, |
| 241 | _1)); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | void |
| 245 | ContactPanel::onInvitation(Ptr<Interest> interest) |
| 246 | { |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame^] | 247 | _LOG_DEBUG("Receive invitation!" << interest->getName().toUri()); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 248 | |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame^] | 249 | Ptr<ChronosInvitation> invitation = Ptr<ChronosInvitation>(new ChronosInvitation(interest->getName())); |
| 250 | |
| 251 | Name chatroomName("/ndn/broadcast/chronos"); |
| 252 | chatroomName.append(invitation->getChatroom()); |
| 253 | map<Name, ChatDialog*>::iterator it = m_chatDialogs.find(chatroomName); |
| 254 | if(it != m_chatDialogs.end()) |
| 255 | { |
| 256 | _LOG_DEBUG("Exisiting chatroom!"); |
| 257 | return; |
| 258 | } |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 259 | |
Yingdi Yu | ed8cfc4 | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 260 | Ptr<Interest> newInterest = Ptr<Interest>(new Interest(invitation->getInviterCertificateName())); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 261 | Ptr<Closure> closure = Ptr<Closure>(new Closure(boost::bind(&ContactPanel::onInvitationCertVerified, |
| 262 | this, |
| 263 | _1, |
Yingdi Yu | ed8cfc4 | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 264 | invitation), |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 265 | boost::bind(&ContactPanel::onTimeout, |
| 266 | this, |
| 267 | _1, |
| 268 | _2), |
| 269 | boost::bind(&ContactPanel::onUnverified, |
| 270 | this, |
| 271 | _1))); |
| 272 | m_handler->sendInterest(newInterest, closure); |
| 273 | } |
| 274 | |
| 275 | void |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame^] | 276 | ContactPanel::onInvitationCertVerified(Ptr<Data> data, |
| 277 | Ptr<ChronosInvitation> invitation) |
| 278 | { |
| 279 | using namespace ndn::security; |
| 280 | Ptr<IdentityCertificate> certificate = Ptr<IdentityCertificate>(new IdentityCertificate(*data)); |
| 281 | |
| 282 | if(PolicyManager::verifySignature(invitation->getSignedBlob(), invitation->getSignatureBits(), certificate->getPublicKeyInfo())) |
| 283 | { |
| 284 | Name keyName = certificate->getPublicKeyName(); |
| 285 | Name inviterNameSpace = keyName.getPrefix(keyName.size() - 1); |
| 286 | popChatInvitation(invitation, inviterNameSpace, certificate); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | void |
| 291 | ContactPanel::onUnverified(Ptr<Data> data) |
| 292 | {} |
| 293 | |
| 294 | void |
| 295 | ContactPanel::onTimeout(Ptr<Closure> closure, Ptr<Interest> interest) |
| 296 | {} |
| 297 | |
| 298 | void |
| 299 | ContactPanel::popChatInvitation(Ptr<ChronosInvitation> invitation, |
| 300 | const Name& inviterNameSpace, |
| 301 | Ptr<security::IdentityCertificate> certificate) |
| 302 | { |
| 303 | string alias; |
| 304 | vector<Ptr<ContactItem> >::iterator it = m_contactList.begin(); |
| 305 | for(; it != m_contactList.end(); it++) |
| 306 | if((*it)->getNameSpace() == inviterNameSpace) |
| 307 | alias = (*it)->getAlias(); |
| 308 | |
| 309 | if(it != m_contactList.end()) |
| 310 | return; |
| 311 | |
| 312 | m_invitationDialog->setInvitation(alias, invitation, certificate); |
| 313 | emit newInvitationReady(); |
| 314 | } |
| 315 | |
| 316 | void |
| 317 | ContactPanel::collectEndorsement() |
| 318 | { |
| 319 | m_collectStatus = Ptr<vector<bool> >::Create(); |
| 320 | m_collectStatus->assign(m_contactList.size(), false); |
| 321 | |
| 322 | vector<Ptr<ContactItem> >::iterator it = m_contactList.begin(); |
| 323 | int count = 0; |
| 324 | for(; it != m_contactList.end(); it++, count++) |
| 325 | { |
| 326 | Name interestName = (*it)->getNameSpace(); |
| 327 | interestName.append("DNS").append(m_defaultIdentity).append("ENDORSEE"); |
| 328 | Ptr<Interest> interest = Ptr<Interest>(new Interest(interestName)); |
| 329 | interest->setChildSelector(Interest::CHILD_RIGHT); |
| 330 | interest->setInterestLifetime(1); |
| 331 | |
| 332 | Ptr<Closure> closure = Ptr<Closure>(new Closure(boost::bind(&ContactPanel::onDnsEndorseeVerified, |
| 333 | this, |
| 334 | _1, |
| 335 | count), |
| 336 | boost::bind(&ContactPanel::onDnsEndorseeTimeout, |
| 337 | this, |
| 338 | _1, |
| 339 | _2, |
| 340 | count), |
| 341 | boost::bind(&ContactPanel::onDnsEndorseeUnverified, |
| 342 | this, |
| 343 | _1, |
| 344 | count))); |
| 345 | |
| 346 | m_handler->sendInterest(interest, closure); |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | void |
| 351 | ContactPanel::onDnsEndorseeVerified(Ptr<Data> data, int count) |
| 352 | { |
| 353 | Ptr<Blob> contentBlob = Ptr<Blob>(new Blob(data->content().buf(), data->content().size())); |
| 354 | Ptr<Data> endorseData = Data::decodeFromWire(contentBlob); |
| 355 | EndorseCertificate endorseCertificate(*endorseData); |
| 356 | |
| 357 | m_contactManager->getContactStorage()->updateCollectEndorse(endorseCertificate); |
| 358 | |
| 359 | updateCollectStatus(count); |
| 360 | } |
| 361 | |
| 362 | void |
| 363 | ContactPanel::onDnsEndorseeTimeout(Ptr<Closure> closure, Ptr<Interest> interest, int count) |
| 364 | { updateCollectStatus(count); } |
| 365 | |
| 366 | void |
| 367 | ContactPanel::onDnsEndorseeUnverified(Ptr<Data> data, int count) |
| 368 | { updateCollectStatus(count); } |
| 369 | |
| 370 | void |
| 371 | ContactPanel::updateCollectStatus(int count) |
| 372 | { |
| 373 | m_collectStatus->at(count) = true; |
| 374 | vector<bool>::const_iterator it = m_collectStatus->begin(); |
| 375 | for(; it != m_collectStatus->end(); it++) |
| 376 | if(*it == false) |
| 377 | return; |
| 378 | |
| 379 | m_contactManager->publishEndorsedDataInDns(m_defaultIdentity); |
| 380 | } |
| 381 | |
| 382 | static std::string chars("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789"); |
| 383 | |
| 384 | string |
| 385 | ContactPanel::getRandomString() |
| 386 | { |
| 387 | string randStr; |
| 388 | boost::random::random_device rng; |
| 389 | boost::random::uniform_int_distribution<> index_dist(0, chars.size() - 1); |
| 390 | for (int i = 0; i < 10; i ++) |
| 391 | { |
| 392 | randStr += chars[index_dist(rng)]; |
| 393 | } |
| 394 | return randStr; |
| 395 | } |
| 396 | |
| 397 | void |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 398 | ContactPanel::updateSelection(const QItemSelection &selected, |
| 399 | const QItemSelection &deselected) |
| 400 | { |
| 401 | QModelIndexList items = selected.indexes(); |
| 402 | QString text = m_contactListModel->data(items.first(), Qt::DisplayRole).toString(); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame^] | 403 | string alias = text.toStdString(); |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 404 | |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 405 | int i = 0; |
| 406 | for(; i < m_contactList.size(); i++) |
| 407 | { |
| 408 | if(alias == m_contactList[i]->getAlias()) |
| 409 | break; |
| 410 | } |
| 411 | |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 412 | m_currentSelectedContact = m_contactList[i]; |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame^] | 413 | QString name = QString::fromStdString(m_currentSelectedContact->getName()); |
| 414 | QString institution = QString::fromStdString(m_currentSelectedContact->getInstitution()); |
| 415 | QString nameSpace = QString::fromStdString(m_currentSelectedContact->getNameSpace().toUri()); |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 416 | ui->NameData->setText(name); |
| 417 | ui->NameSpaceData->setText(nameSpace); |
| 418 | ui->InstitutionData->setText(institution); |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 419 | |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 420 | if(m_currentSelectedContact->isIntroducer()) |
| 421 | { |
| 422 | ui->isIntroducer->setChecked(true); |
| 423 | ui->addScope->setEnabled(true); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 424 | ui->deleteScope->setEnabled(true); |
| 425 | ui->trustScopeList->setEnabled(true); |
| 426 | |
| 427 | string filter("contact_namespace = '"); |
| 428 | filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'"); |
| 429 | |
| 430 | m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
| 431 | m_trustScopeModel->setTable("TrustScope"); |
| 432 | m_trustScopeModel->setFilter(filter.c_str()); |
| 433 | m_trustScopeModel->select(); |
| 434 | m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID")); |
| 435 | m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact")); |
| 436 | m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope")); |
| 437 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 438 | ui->trustScopeList->setModel(m_trustScopeModel); |
| 439 | ui->trustScopeList->setColumnHidden(0, true); |
| 440 | ui->trustScopeList->setColumnHidden(1, true); |
| 441 | ui->trustScopeList->show(); |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 442 | } |
| 443 | else |
| 444 | { |
| 445 | ui->isIntroducer->setChecked(false); |
| 446 | ui->addScope->setEnabled(false); |
| 447 | ui->deleteScope->setEnabled(false); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 448 | |
| 449 | string filter("contact_namespace = '"); |
| 450 | filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'"); |
| 451 | |
| 452 | m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
| 453 | m_trustScopeModel->setTable("TrustScope"); |
| 454 | m_trustScopeModel->setFilter(filter.c_str()); |
| 455 | m_trustScopeModel->select(); |
| 456 | m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID")); |
| 457 | m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact")); |
| 458 | m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope")); |
| 459 | |
| 460 | ui->trustScopeList->setModel(m_trustScopeModel); |
| 461 | ui->trustScopeList->setColumnHidden(0, true); |
| 462 | ui->trustScopeList->setColumnHidden(1, true); |
| 463 | ui->trustScopeList->show(); |
| 464 | |
| 465 | ui->trustScopeList->setEnabled(false); |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 466 | } |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 467 | |
| 468 | string filter("profile_identity = '"); |
| 469 | filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'"); |
| 470 | |
| 471 | m_endorseDataModel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
| 472 | m_endorseDataModel->setTable("ContactProfile"); |
| 473 | m_endorseDataModel->setFilter(filter.c_str()); |
| 474 | m_endorseDataModel->select(); |
| 475 | |
| 476 | m_endorseDataModel->setHeaderData(0, Qt::Horizontal, QObject::tr("Identity")); |
| 477 | m_endorseDataModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Type")); |
| 478 | m_endorseDataModel->setHeaderData(2, Qt::Horizontal, QObject::tr("Value")); |
| 479 | m_endorseDataModel->setHeaderData(3, Qt::Horizontal, QObject::tr("Endorse")); |
| 480 | |
| 481 | ui->endorseList->setModel(m_endorseDataModel); |
| 482 | ui->endorseList->setColumnHidden(0, true); |
| 483 | ui->endorseList->resizeColumnToContents(1); |
| 484 | ui->endorseList->resizeColumnToContents(2); |
| 485 | ui->endorseList->setItemDelegateForColumn(3, m_endorseComboBoxDelegate); |
| 486 | ui->endorseList->show(); |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 487 | } |
Yingdi Yu | 9e0dc29 | 2013-10-10 11:39:45 -0700 | [diff] [blame] | 488 | |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 489 | void |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame^] | 490 | ContactPanel::updateDefaultIdentity(const QString& identity, const QString& nickName) |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 491 | { |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame^] | 492 | m_defaultIdentity = Name(identity.toStdString()); |
| 493 | m_nickName = nickName.toStdString(); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 494 | m_handler->clearInterestFilter(m_inviteListenPrefix); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame^] | 495 | setInvitationListener(); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 496 | collectEndorsement(); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 497 | } |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 498 | |
| 499 | void |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 500 | ContactPanel::openProfileEditor() |
Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 501 | { m_profileEditor->show(); } |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 502 | |
Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 503 | void |
| 504 | ContactPanel::openAddContactPanel() |
| 505 | { m_addContactPanel->show(); } |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 506 | |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 507 | void |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 508 | ContactPanel::openInvitationDialog() |
| 509 | { m_invitationDialog->show(); } |
| 510 | |
| 511 | void |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 512 | ContactPanel::refreshContactList() |
| 513 | { |
| 514 | m_contactList = m_contactManager->getContactItemList(); |
| 515 | QStringList contactNameList; |
| 516 | for(int i = 0; i < m_contactList.size(); i++) |
| 517 | contactNameList << QString::fromUtf8(m_contactList[i]->getAlias().c_str()); |
| 518 | |
| 519 | m_contactListModel->setStringList(contactNameList); |
| 520 | } |
| 521 | |
| 522 | void |
| 523 | ContactPanel::showContextMenu(const QPoint& pos) |
| 524 | { |
| 525 | QMenu menu(ui->ContactList); |
| 526 | menu.addAction(m_menuInvite); |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 527 | connect(m_menuInvite, SIGNAL(triggered()), |
| 528 | this, SLOT(openStartChatDialog())); |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 529 | menu.addAction(m_menuAlias); |
| 530 | connect(m_menuAlias, SIGNAL(triggered()), |
| 531 | this, SLOT(openSetAliasDialog())); |
| 532 | menu.exec(ui->ContactList->mapToGlobal(pos)); |
| 533 | |
| 534 | } |
| 535 | |
| 536 | void |
| 537 | ContactPanel::openSetAliasDialog() |
| 538 | { |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 539 | m_setAliasDialog->setTargetIdentity(m_currentSelectedContact->getNameSpace().toUri()); |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 540 | m_setAliasDialog->show(); |
| 541 | } |
| 542 | |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 543 | void |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 544 | ContactPanel::openSettingDialog() |
| 545 | { |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame^] | 546 | m_settingDialog->setIdentity(m_defaultIdentity.toUri(), m_nickName); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 547 | m_settingDialog->show(); |
| 548 | } |
| 549 | |
| 550 | void |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 551 | ContactPanel::openStartChatDialog() |
| 552 | { |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 553 | // TimeInterval ti = time::NowUnixTimestamp(); |
| 554 | // ostringstream oss; |
| 555 | // oss << ti.total_seconds(); |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 556 | |
| 557 | Name chatroom("/ndn/broadcast/chronos"); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 558 | chatroom.append(string("chatroom-") + getRandomString()); |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 559 | |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 560 | m_startChatDialog->setInvitee(m_currentSelectedContact->getNameSpace().toUri(), chatroom.toUri()); |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 561 | m_startChatDialog->show(); |
| 562 | } |
| 563 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 564 | // For inviter |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 565 | void |
| 566 | ContactPanel::startChatroom(const QString& chatroom, const QString& invitee, bool isIntroducer) |
| 567 | { |
| 568 | _LOG_DEBUG("room: " << chatroom.toUtf8().constData()); |
| 569 | _LOG_DEBUG("invitee: " << invitee.toUtf8().constData()); |
| 570 | _LOG_DEBUG("introducer: " << std::boolalpha << isIntroducer); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 571 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 572 | Name chatroomName(chatroom.toUtf8().constData()); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame^] | 573 | Name prefix = m_localPrefix.getPrefix(m_localPrefix.size()-1); |
| 574 | ChatDialog* chatDialog = new ChatDialog(m_contactManager, chatroomName, prefix, m_defaultIdentity, m_nickName); |
| 575 | // ChatDialog* chatDialog = new ChatDialog(m_contactManager, chatroomName, m_localPrefix, m_defaultIdentity); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 576 | m_chatDialogs.insert(pair <Name, ChatDialog*> (chatroomName, chatDialog)); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame^] | 577 | |
| 578 | connect(chatDialog, SIGNAL(closeChatDialog(const ndn::Name&)), |
| 579 | this, SLOT(removeChatDialog(const ndn::Name&))); |
| 580 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 581 | //TODO: send invitation |
| 582 | Name inviteeNamespace(invitee.toUtf8().constData()); |
| 583 | Ptr<ContactItem> inviteeItem = m_contactManager->getContact(inviteeNamespace); |
| 584 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 585 | chatDialog->sendInvitation(inviteeItem, isIntroducer); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 586 | |
| 587 | chatDialog->show(); |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 588 | } |
| 589 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 590 | // For Invitee |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 591 | void |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 592 | ContactPanel::startChatroom2(const ChronosInvitation& invitation, |
| 593 | const security::IdentityCertificate& identityCertificate) |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 594 | { |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 595 | _LOG_DEBUG("room: " << invitation.getChatroom().toUri()); |
| 596 | _LOG_DEBUG("inviter: " << invitation.getInviterNameSpace().toUri()); |
| 597 | |
| 598 | Name chatroomName("/ndn/broadcast/chronos"); |
| 599 | chatroomName.append(invitation.getChatroom()); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame^] | 600 | Name prefix = m_localPrefix.getPrefix(m_localPrefix.size()-1); |
| 601 | ChatDialog* chatDialog = new ChatDialog(m_contactManager, chatroomName, prefix, m_defaultIdentity, m_nickName, true); |
| 602 | // ChatDialog* chatDialog = new ChatDialog(m_contactManager, chatroomName, m_localPrefix, m_defaultIdentity); |
| 603 | connect(chatDialog, SIGNAL(closeChatDialog(const ndn::Name&)), |
| 604 | this, SLOT(removeChatDialog(const ndn::Name&))); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 605 | |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame^] | 606 | Name inviterPrefix = invitation.getInviterPrefix().getPrefix(invitation.getInviterPrefix().size()-1); |
| 607 | chatDialog->addChatDataRule(inviterPrefix, identityCertificate, true); |
| 608 | // chatDialog->addChatDataRule(invitation.getInviterPrefix(), identityCertificate, true); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 609 | |
| 610 | Ptr<ContactItem> inviterItem = m_contactManager->getContact(invitation.getInviterNameSpace()); |
| 611 | chatDialog->addTrustAnchor(inviterItem->getSelfEndorseCertificate()); |
| 612 | |
| 613 | m_chatDialogs.insert(pair <Name, ChatDialog*> (chatroomName, chatDialog)); |
| 614 | |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame^] | 615 | |
| 616 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 617 | chatDialog->show(); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | void |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 621 | ContactPanel::acceptInvitation(const ChronosInvitation& invitation, |
| 622 | const security::IdentityCertificate& identityCertificate) |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 623 | { |
| 624 | string prefix = m_localPrefix.toUri(); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 625 | |
| 626 | m_handler->publishDataByIdentity (invitation.getInterestName(), prefix); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 627 | //TODO:: open chat dialog |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 628 | _LOG_DEBUG("TO open chat dialog"); |
| 629 | startChatroom2(invitation, identityCertificate); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | void |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 633 | ContactPanel::rejectInvitation(const ChronosInvitation& invitation) |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 634 | { |
| 635 | string empty; |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 636 | m_handler->publishDataByIdentity (invitation.getInterestName(), empty); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 637 | } |
| 638 | |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 639 | void |
| 640 | ContactPanel::isIntroducerChanged(int state) |
| 641 | { |
| 642 | if(state == Qt::Checked) |
| 643 | { |
| 644 | ui->addScope->setEnabled(true); |
| 645 | ui->deleteScope->setEnabled(true); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 646 | ui->trustScopeList->setEnabled(true); |
| 647 | |
| 648 | string filter("contact_namespace = '"); |
| 649 | filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'"); |
| 650 | _LOG_DEBUG("filter: " << filter); |
| 651 | |
| 652 | m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
| 653 | m_trustScopeModel->setTable("TrustScope"); |
| 654 | m_trustScopeModel->setFilter(filter.c_str()); |
| 655 | m_trustScopeModel->select(); |
| 656 | m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID")); |
| 657 | m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact")); |
| 658 | m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope")); |
| 659 | _LOG_DEBUG("row count: " << m_trustScopeModel->rowCount()); |
| 660 | |
| 661 | |
| 662 | ui->trustScopeList->setModel(m_trustScopeModel); |
| 663 | ui->trustScopeList->setColumnHidden(0, true); |
| 664 | ui->trustScopeList->setColumnHidden(1, true); |
| 665 | ui->trustScopeList->show(); |
| 666 | |
| 667 | m_currentSelectedContact->setIsIntroducer(true); |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 668 | } |
| 669 | else |
| 670 | { |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 671 | ui->addScope->setEnabled(false); |
| 672 | ui->deleteScope->setEnabled(false); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 673 | |
| 674 | string filter("contact_namespace = '"); |
| 675 | filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'"); |
| 676 | |
| 677 | m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
| 678 | m_trustScopeModel->setTable("TrustScope"); |
| 679 | m_trustScopeModel->setFilter(filter.c_str()); |
| 680 | m_trustScopeModel->select(); |
| 681 | m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID")); |
| 682 | m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact")); |
| 683 | m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope")); |
| 684 | |
| 685 | ui->trustScopeList->setModel(m_trustScopeModel); |
| 686 | ui->trustScopeList->setColumnHidden(0, true); |
| 687 | ui->trustScopeList->setColumnHidden(1, true); |
| 688 | ui->trustScopeList->show(); |
| 689 | |
| 690 | ui->trustScopeList->setEnabled(false); |
| 691 | |
| 692 | m_currentSelectedContact->setIsIntroducer(false); |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 693 | } |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 694 | m_contactManager->getContactStorage()->updateIsIntroducer(m_currentSelectedContact->getNameSpace(), m_currentSelectedContact->isIntroducer()); |
| 695 | } |
| 696 | |
| 697 | void |
| 698 | ContactPanel::addScopeClicked() |
| 699 | { |
| 700 | int rowCount = m_trustScopeModel->rowCount(); |
| 701 | QSqlRecord record; |
| 702 | QSqlField identityField("contact_namespace", QVariant::String); |
| 703 | record.append(identityField); |
| 704 | record.setValue("contact_namespace", QString(m_currentSelectedContact->getNameSpace().toUri().c_str())); |
| 705 | m_trustScopeModel->insertRow(rowCount); |
| 706 | m_trustScopeModel->setRecord(rowCount, record); |
| 707 | } |
| 708 | |
| 709 | void |
| 710 | ContactPanel::deleteScopeClicked() |
| 711 | { |
| 712 | QItemSelectionModel* selectionModel = ui->trustScopeList->selectionModel(); |
| 713 | QModelIndexList indexList = selectionModel->selectedIndexes(); |
| 714 | |
| 715 | int i = indexList.size() - 1; |
| 716 | for(; i >= 0; i--) |
| 717 | m_trustScopeModel->removeRow(indexList[i].row()); |
| 718 | |
| 719 | m_trustScopeModel->submitAll(); |
| 720 | } |
| 721 | |
| 722 | void |
| 723 | ContactPanel::saveScopeClicked() |
| 724 | { |
| 725 | m_trustScopeModel->submitAll(); |
| 726 | } |
| 727 | |
| 728 | void |
| 729 | ContactPanel::endorseButtonClicked() |
| 730 | { |
| 731 | m_endorseDataModel->submitAll(); |
| 732 | m_contactManager->updateEndorseCertificate(m_currentSelectedContact->getNameSpace(), m_defaultIdentity); |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 733 | } |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 734 | |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame^] | 735 | void |
| 736 | ContactPanel::removeChatDialog(const ndn::Name& chatroomName) |
| 737 | { |
| 738 | map<Name, ChatDialog*>::iterator it = m_chatDialogs.find(chatroomName); |
| 739 | _LOG_DEBUG("about to leave 2!"); |
| 740 | ChatDialog* deletedChat; |
| 741 | if(it != m_chatDialogs.end()) |
| 742 | { |
| 743 | _LOG_DEBUG("about to leave 3!"); |
| 744 | deletedChat = it->second; |
| 745 | m_chatDialogs.erase(it); |
| 746 | } |
| 747 | delete deletedChat; |
| 748 | } |
| 749 | |
Yingdi Yu | 9e0dc29 | 2013-10-10 11:39:45 -0700 | [diff] [blame] | 750 | #if WAF |
| 751 | #include "contactpanel.moc" |
| 752 | #include "contactpanel.cpp.moc" |
| 753 | #endif |