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