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