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