blob: e9fafaa1dbf5e4c70f4395448804901e3fef2455 [file] [log] [blame]
Yingdi Yu9e0dc292013-10-10 11:39:45 -07001/* -*- 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 Yudef90612013-10-09 22:34:42 -070011#include "contactpanel.h"
12#include "ui_contactpanel.h"
13
Yingdi Yu01a942b2013-10-10 15:00:58 -070014
15#include <QStringList>
16#include <QItemSelectionModel>
17#include <QModelIndex>
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070018#include <QDir>
Yingdi Yu8dacdf22013-11-05 23:06:43 -080019#include <QtSql/QSqlRecord>
20#include <QtSql/QSqlField>
21#include <QtSql/QSqlError>
Yingdi Yu01a942b2013-10-10 15:00:58 -070022
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070023#ifndef Q_MOC_RUN
Yingdi Yu53eb8a72013-10-23 11:50:51 -070024#include <ndn.cxx/security/keychain.h>
Yingdi Yu53eb8a72013-10-23 11:50:51 -070025#include <ndn.cxx/security/identity/identity-manager.h>
Yingdi Yu100267f2013-10-21 15:01:40 -070026#include <ndn.cxx/common.h>
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070027#include <boost/filesystem.hpp>
Yingdi Yu53eb8a72013-10-23 11:50:51 -070028#include <boost/random/random_device.hpp>
29#include <boost/random/uniform_int_distribution.hpp>
Yingdi Yu42f66462013-10-31 17:38:22 -070030#include "panel-policy-manager.h"
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070031#include "logging.h"
32#include "exception.h"
33#endif
34
35namespace fs = boost::filesystem;
36using namespace ndn;
Yingdi Yu53eb8a72013-10-23 11:50:51 -070037
Yingdi Yu79c25a22013-10-21 13:38:38 -070038using namespace std;
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070039
40INIT_LOGGER("ContactPanel");
41
Yingdi Yu53eb8a72013-10-23 11:50:51 -070042Q_DECLARE_METATYPE(ndn::security::IdentityCertificate)
Yingdi Yu42f66462013-10-31 17:38:22 -070043Q_DECLARE_METATYPE(ChronosInvitation)
Yingdi Yu53eb8a72013-10-23 11:50:51 -070044
Yingdi Yub29f78c2013-11-09 20:12:31 -080045ContactPanel::ContactPanel(QWidget *parent)
Yingdi Yua50c3252013-11-03 15:05:26 -080046 : QDialog(parent)
47 , ui(new Ui::ContactPanel)
Yingdi Yub29f78c2013-11-09 20:12:31 -080048 , m_warningDialog(new WarningDialog)
Yingdi Yua50c3252013-11-03 15:05:26 -080049 , m_contactListModel(new QStringListModel)
50 , m_startChatDialog(new StartChatDialog)
51 , m_invitationDialog(new InvitationDialog)
52 , m_settingDialog(new SettingDialog)
Yingdi Yudef90612013-10-09 22:34:42 -070053{
Yingdi Yu53eb8a72013-10-23 11:50:51 -070054 qRegisterMetaType<ndn::security::IdentityCertificate>("IdentityCertificate");
Yingdi Yu42f66462013-10-31 17:38:22 -070055 qRegisterMetaType<ChronosInvitation>("ChronosInvitation");
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070056
Yingdi Yu42372442013-11-06 18:43:31 -080057 createAction();
58
Yingdi Yub29f78c2013-11-09 20:12:31 -080059 m_contactManager = Ptr<ContactManager>::Create();
Yingdi Yub35b8652013-11-07 11:32:40 -080060
Yingdi Yub29f78c2013-11-09 20:12:31 -080061 connect(&*m_contactManager, SIGNAL(noNdnConnection(const QString&)),
62 this, SLOT(showError(const QString&)));
63
64 m_contactManager->setWrapper();
65
Yingdi Yub35b8652013-11-07 11:32:40 -080066 openDB();
Yingdi Yu42372442013-11-06 18:43:31 -080067
Yingdi Yuc4d08d22013-10-23 23:07:29 -070068 refreshContactList();
Yingdi Yu01a942b2013-10-10 15:00:58 -070069
Yingdi Yuc4d08d22013-10-23 23:07:29 -070070 setKeychain();
Yingdi Yu42372442013-11-06 18:43:31 -080071
72 m_defaultIdentity = m_keychain->getDefaultIdentity();
Yingdi Yu10436892013-11-10 16:26:52 -080073 if(m_defaultIdentity.size() == 0)
74 showError(QString::fromStdString("certificate of ") + QString::fromStdString(m_defaultIdentity.toUri()) + " is missing!\nHave you installed the certificate?");
Yingdi Yu71ec9652013-11-09 22:18:26 -080075 Name defaultCertName = m_keychain->getIdentityManager()->getDefaultCertificateNameByIdentity(m_defaultIdentity);
76 if(defaultCertName.size() == 0)
Yingdi Yucf1bdcb2013-11-10 10:54:16 -080077 showError(QString::fromStdString("certificate of ") + QString::fromStdString(m_defaultIdentity.toUri()) + " is missing!\nHave you installed the certificate?");
Yingdi Yu10436892013-11-10 16:26:52 -080078
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 Yu71ec9652013-11-09 22:18:26 -080083
Yingdi Yu42372442013-11-06 18:43:31 -080084
Yingdi Yub35b8652013-11-07 11:32:40 -080085 m_profileEditor = new ProfileEditor(m_contactManager);
86 m_profileEditor->setCurrentIdentity(m_defaultIdentity);
87
Yingdi Yub29f78c2013-11-09 20:12:31 -080088 m_addContactPanel = new AddContactPanel(m_contactManager);
89 m_browseContactDialog = new BrowseContactDialog(m_contactManager);
90 m_setAliasDialog = new SetAliasDialog(m_contactManager);
Yingdi Yub35b8652013-11-07 11:32:40 -080091
92 ui->setupUi(this);
93
Yingdi Yub29f78c2013-11-09 20:12:31 -080094 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 Yu0a953c32013-11-10 10:32:18 -0800100 m_localPrefix = Name("/private/local");
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700101 setLocalPrefix();
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700102
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700103 setInvitationListener();
Yingdi Yu42372442013-11-06 18:43:31 -0800104
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800105 collectEndorsement();
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700106
107 ui->ContactList->setModel(m_contactListModel);
108
Yingdi Yuc26af3c2013-10-17 17:03:46 -0700109
Yingdi Yu42372442013-11-06 18:43:31 -0800110 connect(ui->ContactList->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700111 this, SLOT(updateSelection(const QItemSelection &, const QItemSelection &)));
Yingdi Yu01a942b2013-10-10 15:00:58 -0700112
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700113 connect(ui->ContactList, SIGNAL(customContextMenuRequested(const QPoint&)),
114 this, SLOT(showContextMenu(const QPoint&)));
Yingdi Yud59b5932013-10-16 13:16:49 -0700115
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700116 connect(ui->EditProfileButton, SIGNAL(clicked()),
117 this, SLOT(openProfileEditor()));
Yingdi Yud59b5932013-10-16 13:16:49 -0700118
Yingdi Yu71ec9652013-11-09 22:18:26 -0800119 connect(m_profileEditor, SIGNAL(noKeyOrCert(const QString&)),
Yingdi Yueb98f7d2013-11-10 01:34:57 -0800120 this, SLOT(showWarning(const QString&)));
Yingdi Yu71ec9652013-11-09 22:18:26 -0800121
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700122 connect(ui->AddContactButton, SIGNAL(clicked()),
Yingdi Yu908f8412013-11-09 00:03:26 -0800123 this, SLOT(openBrowseContactDialog()));
124
Yingdi Yu3cd30df2013-11-10 17:59:58 -0800125 connect(m_browseContactDialog, SIGNAL(directAddClicked()),
126 this, SLOT(openAddContactPanel()));
127
Yingdi Yu908f8412013-11-09 00:03:26 -0800128 connect(this, SIGNAL(refreshCertDirectory()),
129 m_browseContactDialog, SLOT(refreshList()));
130
131 connect(ui->DeleteContactButton, SIGNAL(clicked()),
132 this, SLOT(removeContactButton()));
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700133
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700134 connect(ui->settingButton, SIGNAL(clicked()),
135 this, SLOT(openSettingDialog()));
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700136
Yingdi Yu3cd30df2013-11-10 17:59:58 -0800137 connect(m_addContactPanel, SIGNAL(newContactAdded()),
138 this, SLOT(refreshContactList()));
Yingdi Yu908f8412013-11-09 00:03:26 -0800139 connect(m_browseContactDialog, SIGNAL(newContactAdded()),
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700140 this, SLOT(refreshContactList()));
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700141 connect(m_setAliasDialog, SIGNAL(aliasChanged()),
142 this, SLOT(refreshContactList()));
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700143
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700144 connect(m_startChatDialog, SIGNAL(chatroomConfirmed(const QString&, const QString&, bool)),
145 this, SLOT(startChatroom(const QString&, const QString&, bool)));
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700146
Yingdi Yu42f66462013-10-31 17:38:22 -0700147 connect(m_invitationDialog, SIGNAL(invitationAccepted(const ChronosInvitation&, const ndn::security::IdentityCertificate&)),
148 this, SLOT(acceptInvitation(const ChronosInvitation&, const ndn::security::IdentityCertificate&)));
149 connect(m_invitationDialog, SIGNAL(invitationRejected(const ChronosInvitation&)),
150 this, SLOT(rejectInvitation(const ChronosInvitation&)));
Yingdi Yu6ea54e42013-11-12 17:50:21 -0800151
152 connect(&*m_contactManager, SIGNAL(contactAdded(const ndn::Name&)),
153 this, SLOT(addContactIntoPanelPolicy(const ndn::Name&)));
154 connect(&*m_contactManager, SIGNAL(contactRemoved(const ndn::Name&)),
155 this, SLOT(removeContactFromPanelPolicy(const ndn::Name&)));
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700156
Yingdi Yu42372442013-11-06 18:43:31 -0800157 connect(m_settingDialog, SIGNAL(identitySet(const QString&, const QString&)),
158 this, SLOT(updateDefaultIdentity(const QString&, const QString&)));
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700159
160 connect(this, SIGNAL(newInvitationReady()),
161 this, SLOT(openInvitationDialog()));
Yingdi Yu100267f2013-10-21 15:01:40 -0700162
Yingdi Yua50c3252013-11-03 15:05:26 -0800163 connect(ui->isIntroducer, SIGNAL(stateChanged(int)),
164 this, SLOT(isIntroducerChanged(int)));
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800165
166 connect(ui->addScope, SIGNAL(clicked()),
167 this, SLOT(addScopeClicked()));
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800168 connect(ui->deleteScope, SIGNAL(clicked()),
169 this, SLOT(deleteScopeClicked()));
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800170 connect(ui->saveButton, SIGNAL(clicked()),
171 this, SLOT(saveScopeClicked()));
172
173 connect(ui->endorseButton, SIGNAL(clicked()),
174 this, SLOT(endorseButtonClicked()));
Yingdi Yudef90612013-10-09 22:34:42 -0700175}
176
177ContactPanel::~ContactPanel()
178{
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700179 delete ui;
180 delete m_contactListModel;
Yingdi Yu42372442013-11-06 18:43:31 -0800181 delete m_startChatDialog;
182 delete m_invitationDialog;
183 delete m_settingDialog;
184
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700185 delete m_profileEditor;
186 delete m_addContactPanel;
Yingdi Yu908f8412013-11-09 00:03:26 -0800187 delete m_browseContactDialog;
Yingdi Yu42372442013-11-06 18:43:31 -0800188 delete m_setAliasDialog;
189
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800190 delete m_trustScopeModel;
191 delete m_endorseDataModel;
Yingdi Yu42372442013-11-06 18:43:31 -0800192 delete m_endorseComboBoxDelegate;
Yingdi Yu79c25a22013-10-21 13:38:38 -0700193
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700194 delete m_menuInvite;
Yingdi Yu42372442013-11-06 18:43:31 -0800195 delete m_menuAlias;
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700196
197 map<Name, ChatDialog*>::iterator it = m_chatDialogs.begin();
198 for(; it != m_chatDialogs.end(); it++)
199 delete it->second;
Yingdi Yudef90612013-10-09 22:34:42 -0700200}
Yingdi Yu9e0dc292013-10-10 11:39:45 -0700201
Yingdi Yu01a942b2013-10-10 15:00:58 -0700202void
Yingdi Yu42372442013-11-06 18:43:31 -0800203ContactPanel::createAction()
204{
205 m_menuInvite = new QAction("&Chat", this);
206 m_menuAlias = new QAction("&Set Alias", this);
207}
208
209void
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700210ContactPanel::openDB()
211{
212 QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
213 QString path = (QDir::home().path());
214 path.append(QDir::separator()).append(".chronos").append(QDir::separator()).append("chronos.db");
215 db.setDatabaseName(path);
216 bool ok = db.open();
Yingdi Yu42372442013-11-06 18:43:31 -0800217 _LOG_DEBUG("DB opened: " << std::boolalpha << ok );
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800218
219 m_trustScopeModel = new QSqlTableModel;
220 m_endorseDataModel = new QSqlTableModel;
221 m_endorseComboBoxDelegate = new EndorseComboBoxDelegate;
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700222}
223
224void
225ContactPanel::setKeychain()
226{
Yingdi Yued8cfc42013-11-01 17:37:51 -0700227 m_panelPolicyManager = Ptr<PanelPolicyManager>::Create();
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700228
229 vector<Ptr<ContactItem> >::const_iterator it = m_contactList.begin();
230 for(; it != m_contactList.end(); it++)
Yingdi Yub35b8652013-11-07 11:32:40 -0800231 {
232 m_panelPolicyManager->addTrustAnchor((*it)->getSelfEndorseCertificate());
233 }
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700234
Yingdi Yued8cfc42013-11-01 17:37:51 -0700235 m_keychain = Ptr<security::Keychain>(new security::Keychain(Ptr<security::IdentityManager>::Create(),
236 m_panelPolicyManager,
237 NULL));
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700238}
239
240void
Yingdi Yu2ab22e72013-11-10 01:38:21 -0800241ContactPanel::setLocalPrefix(int retry)
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700242{
243 Ptr<Interest> interest = Ptr<Interest>(new Interest(Name("/local/ndn/prefix")));
244 interest->setChildSelector(Interest::CHILD_RIGHT);
245
246 Ptr<Closure> closure = Ptr<Closure>(new Closure(boost::bind(&ContactPanel::onLocalPrefixVerified,
247 this,
248 _1),
249 boost::bind(&ContactPanel::onLocalPrefixTimeout,
250 this,
251 _1,
Yingdi Yu2ab22e72013-11-10 01:38:21 -0800252 _2,
253 10),
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700254 boost::bind(&ContactPanel::onLocalPrefixVerified,
255 this,
256 _1)));
257
258 m_handler->sendInterest(interest, closure);
259}
260
261void
262ContactPanel::onLocalPrefixVerified(Ptr<Data> data)
263{
264 string originPrefix(data->content().buf(), data->content().size());
265 string prefix = QString::fromStdString (originPrefix).trimmed ().toUtf8().constData();
266 string randomSuffix = getRandomString();
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700267 m_localPrefix = Name(prefix);
Yingdi Yueb98f7d2013-11-10 01:34:57 -0800268
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700269}
270
271void
Yingdi Yu2ab22e72013-11-10 01:38:21 -0800272ContactPanel::onLocalPrefixTimeout(Ptr<Closure> closure, Ptr<Interest> interest, int retry)
Yingdi Yu42f66462013-10-31 17:38:22 -0700273{
Yingdi Yu2ab22e72013-11-10 01:38:21 -0800274 if(retry > 0)
Yingdi Yu0a953c32013-11-10 10:32:18 -0800275 {
276 setLocalPrefix(retry - 1);
277 return;
278 }
279 else{
280 m_localPrefix = Name("/private/local");
281 }
Yingdi Yu42f66462013-10-31 17:38:22 -0700282}
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700283
284void
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700285ContactPanel::setInvitationListener()
286{
Yingdi Yu42372442013-11-06 18:43:31 -0800287 m_inviteListenPrefix = Name("/ndn/broadcast/chronos/invitation");
288 m_inviteListenPrefix.append(m_defaultIdentity);
289 _LOG_DEBUG("Listening for invitation on prefix: " << m_inviteListenPrefix.toUri());
290 m_handler->setInterestFilter (m_inviteListenPrefix,
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700291 boost::bind(&ContactPanel::onInvitation,
292 this,
293 _1));
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700294}
295
296void
297ContactPanel::onInvitation(Ptr<Interest> interest)
298{
Yingdi Yu42372442013-11-06 18:43:31 -0800299 _LOG_DEBUG("Receive invitation!" << interest->getName().toUri());
Yingdi Yub35b8652013-11-07 11:32:40 -0800300
301 Ptr<ChronosInvitation> invitation = NULL;
302 try{
303 invitation = Ptr<ChronosInvitation>(new ChronosInvitation(interest->getName()));
304 }catch(exception& e){
305 _LOG_ERROR("Exception: " << e.what());
306 return;
307 }
308
Yingdi Yu42372442013-11-06 18:43:31 -0800309 Name chatroomName("/ndn/broadcast/chronos");
310 chatroomName.append(invitation->getChatroom());
311 map<Name, ChatDialog*>::iterator it = m_chatDialogs.find(chatroomName);
312 if(it != m_chatDialogs.end())
313 {
Yingdi Yub35b8652013-11-07 11:32:40 -0800314 _LOG_ERROR("Exisiting chatroom!");
Yingdi Yu42372442013-11-06 18:43:31 -0800315 return;
316 }
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700317
Yingdi Yu6b56f092013-11-10 11:54:02 -0800318 Ptr<security::Publickey> keyPtr = m_panelPolicyManager->getTrustedKey(invitation->getInviterCertificateName());
319 if(NULL != keyPtr && security::PolicyManager::verifySignature(invitation->getSignedBlob(), invitation->getSignatureBits(), *keyPtr))
320 {
321 Ptr<security::IdentityCertificate> certificate = Ptr<security::IdentityCertificate>::Create();
Yingdi Yu9f657242013-11-10 12:25:43 -0800322 // hack: incomplete certificate, we don't send it to the wire nor store it anywhere, we only use it to carry information
Yingdi Yu6b56f092013-11-10 11:54:02 -0800323 certificate->setName(invitation->getInviterCertificateName());
Yingdi Yu9f657242013-11-10 12:25:43 -0800324 bool findCert = false;
325 vector<Ptr<ContactItem> >::const_iterator it = m_contactList.begin();
326 for(; it != m_contactList.end(); it++)
327 {
328 if((*it)->getNameSpace() == invitation->getInviterNameSpace())
329 {
330 certificate->setNotBefore((*it)->getSelfEndorseCertificate().getNotBefore());
331 certificate->setNotAfter((*it)->getSelfEndorseCertificate().getNotAfter());
332 findCert = true;
333 break;
334 }
335 }
336 if(findCert == false)
337 {
338 _LOG_ERROR("No SelfEndorseCertificate found!");
339 return;
340 }
Yingdi Yu6b56f092013-11-10 11:54:02 -0800341 certificate->setPublicKeyInfo(*keyPtr);
342 popChatInvitation(invitation, invitation->getInviterNameSpace(), certificate);
343 return;
344 }
345
Yingdi Yued8cfc42013-11-01 17:37:51 -0700346 Ptr<Interest> newInterest = Ptr<Interest>(new Interest(invitation->getInviterCertificateName()));
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700347 Ptr<Closure> closure = Ptr<Closure>(new Closure(boost::bind(&ContactPanel::onInvitationCertVerified,
348 this,
349 _1,
Yingdi Yued8cfc42013-11-01 17:37:51 -0700350 invitation),
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700351 boost::bind(&ContactPanel::onTimeout,
352 this,
353 _1,
354 _2),
355 boost::bind(&ContactPanel::onUnverified,
356 this,
357 _1)));
358 m_handler->sendInterest(newInterest, closure);
359}
360
361void
Yingdi Yu42372442013-11-06 18:43:31 -0800362ContactPanel::onInvitationCertVerified(Ptr<Data> data,
363 Ptr<ChronosInvitation> invitation)
364{
365 using namespace ndn::security;
366 Ptr<IdentityCertificate> certificate = Ptr<IdentityCertificate>(new IdentityCertificate(*data));
367
368 if(PolicyManager::verifySignature(invitation->getSignedBlob(), invitation->getSignatureBits(), certificate->getPublicKeyInfo()))
369 {
370 Name keyName = certificate->getPublicKeyName();
371 Name inviterNameSpace = keyName.getPrefix(keyName.size() - 1);
372 popChatInvitation(invitation, inviterNameSpace, certificate);
373 }
374}
375
376void
377ContactPanel::onUnverified(Ptr<Data> data)
378{}
379
380void
381ContactPanel::onTimeout(Ptr<Closure> closure, Ptr<Interest> interest)
382{}
383
384void
385ContactPanel::popChatInvitation(Ptr<ChronosInvitation> invitation,
386 const Name& inviterNameSpace,
387 Ptr<security::IdentityCertificate> certificate)
388{
389 string alias;
390 vector<Ptr<ContactItem> >::iterator it = m_contactList.begin();
391 for(; it != m_contactList.end(); it++)
392 if((*it)->getNameSpace() == inviterNameSpace)
393 alias = (*it)->getAlias();
394
395 if(it != m_contactList.end())
396 return;
397
398 m_invitationDialog->setInvitation(alias, invitation, certificate);
399 emit newInvitationReady();
400}
401
402void
403ContactPanel::collectEndorsement()
404{
405 m_collectStatus = Ptr<vector<bool> >::Create();
406 m_collectStatus->assign(m_contactList.size(), false);
407
408 vector<Ptr<ContactItem> >::iterator it = m_contactList.begin();
409 int count = 0;
410 for(; it != m_contactList.end(); it++, count++)
411 {
412 Name interestName = (*it)->getNameSpace();
413 interestName.append("DNS").append(m_defaultIdentity).append("ENDORSEE");
414 Ptr<Interest> interest = Ptr<Interest>(new Interest(interestName));
415 interest->setChildSelector(Interest::CHILD_RIGHT);
416 interest->setInterestLifetime(1);
417
418 Ptr<Closure> closure = Ptr<Closure>(new Closure(boost::bind(&ContactPanel::onDnsEndorseeVerified,
419 this,
420 _1,
421 count),
422 boost::bind(&ContactPanel::onDnsEndorseeTimeout,
423 this,
424 _1,
425 _2,
426 count),
427 boost::bind(&ContactPanel::onDnsEndorseeUnverified,
428 this,
429 _1,
430 count)));
431
432 m_handler->sendInterest(interest, closure);
433 }
434}
435
436void
437ContactPanel::onDnsEndorseeVerified(Ptr<Data> data, int count)
438{
439 Ptr<Blob> contentBlob = Ptr<Blob>(new Blob(data->content().buf(), data->content().size()));
440 Ptr<Data> endorseData = Data::decodeFromWire(contentBlob);
441 EndorseCertificate endorseCertificate(*endorseData);
442
443 m_contactManager->getContactStorage()->updateCollectEndorse(endorseCertificate);
444
445 updateCollectStatus(count);
446}
447
448void
449ContactPanel::onDnsEndorseeTimeout(Ptr<Closure> closure, Ptr<Interest> interest, int count)
450{ updateCollectStatus(count); }
451
452void
453ContactPanel::onDnsEndorseeUnverified(Ptr<Data> data, int count)
454{ updateCollectStatus(count); }
455
456void
457ContactPanel::updateCollectStatus(int count)
458{
459 m_collectStatus->at(count) = true;
460 vector<bool>::const_iterator it = m_collectStatus->begin();
461 for(; it != m_collectStatus->end(); it++)
462 if(*it == false)
463 return;
464
465 m_contactManager->publishEndorsedDataInDns(m_defaultIdentity);
466}
467
468static std::string chars("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789");
469
470string
471ContactPanel::getRandomString()
472{
473 string randStr;
474 boost::random::random_device rng;
475 boost::random::uniform_int_distribution<> index_dist(0, chars.size() - 1);
476 for (int i = 0; i < 10; i ++)
477 {
478 randStr += chars[index_dist(rng)];
479 }
480 return randStr;
481}
482
483void
Yingdi Yub29f78c2013-11-09 20:12:31 -0800484ContactPanel::showError(const QString& msg){
485 QMessageBox::critical(this, tr("Chronos"), msg, QMessageBox::Ok);
486 exit(1);
487}
488
489void
Yingdi Yueb98f7d2013-11-10 01:34:57 -0800490ContactPanel::showWarning(const QString& msg){
491 QMessageBox::information(this, tr("Chronos"), msg);
492}
493
494void
Yingdi Yu01a942b2013-10-10 15:00:58 -0700495ContactPanel::updateSelection(const QItemSelection &selected,
496 const QItemSelection &deselected)
497{
498 QModelIndexList items = selected.indexes();
499 QString text = m_contactListModel->data(items.first(), Qt::DisplayRole).toString();
Yingdi Yu42372442013-11-06 18:43:31 -0800500 string alias = text.toStdString();
Yingdi Yu79c25a22013-10-21 13:38:38 -0700501
Yingdi Yu79c25a22013-10-21 13:38:38 -0700502 int i = 0;
503 for(; i < m_contactList.size(); i++)
504 {
505 if(alias == m_contactList[i]->getAlias())
506 break;
507 }
508
Yingdi Yua50c3252013-11-03 15:05:26 -0800509 m_currentSelectedContact = m_contactList[i];
Yingdi Yua0594092013-11-06 22:07:38 -0800510 ui->NameData->setText(QString::fromStdString(m_currentSelectedContact->getName()));
511 ui->NameSpaceData->setText(QString::fromStdString(m_currentSelectedContact->getNameSpace().toUri()));
512 ui->InstitutionData->setText(QString::fromStdString(m_currentSelectedContact->getInstitution()));
Yingdi Yu100267f2013-10-21 15:01:40 -0700513
Yingdi Yua50c3252013-11-03 15:05:26 -0800514 if(m_currentSelectedContact->isIntroducer())
515 {
516 ui->isIntroducer->setChecked(true);
517 ui->addScope->setEnabled(true);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800518 ui->deleteScope->setEnabled(true);
519 ui->trustScopeList->setEnabled(true);
520
521 string filter("contact_namespace = '");
522 filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'");
523
524 m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
525 m_trustScopeModel->setTable("TrustScope");
526 m_trustScopeModel->setFilter(filter.c_str());
527 m_trustScopeModel->select();
528 m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
529 m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact"));
530 m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope"));
531
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800532 ui->trustScopeList->setModel(m_trustScopeModel);
533 ui->trustScopeList->setColumnHidden(0, true);
534 ui->trustScopeList->setColumnHidden(1, true);
535 ui->trustScopeList->show();
Yingdi Yua50c3252013-11-03 15:05:26 -0800536 }
537 else
538 {
539 ui->isIntroducer->setChecked(false);
540 ui->addScope->setEnabled(false);
541 ui->deleteScope->setEnabled(false);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800542
543 string filter("contact_namespace = '");
544 filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'");
545
546 m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
547 m_trustScopeModel->setTable("TrustScope");
548 m_trustScopeModel->setFilter(filter.c_str());
549 m_trustScopeModel->select();
550 m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
551 m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact"));
552 m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope"));
553
554 ui->trustScopeList->setModel(m_trustScopeModel);
555 ui->trustScopeList->setColumnHidden(0, true);
556 ui->trustScopeList->setColumnHidden(1, true);
557 ui->trustScopeList->show();
558
559 ui->trustScopeList->setEnabled(false);
Yingdi Yua50c3252013-11-03 15:05:26 -0800560 }
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800561
562 string filter("profile_identity = '");
563 filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'");
564
565 m_endorseDataModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
566 m_endorseDataModel->setTable("ContactProfile");
567 m_endorseDataModel->setFilter(filter.c_str());
568 m_endorseDataModel->select();
569
570 m_endorseDataModel->setHeaderData(0, Qt::Horizontal, QObject::tr("Identity"));
571 m_endorseDataModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Type"));
572 m_endorseDataModel->setHeaderData(2, Qt::Horizontal, QObject::tr("Value"));
573 m_endorseDataModel->setHeaderData(3, Qt::Horizontal, QObject::tr("Endorse"));
574
575 ui->endorseList->setModel(m_endorseDataModel);
576 ui->endorseList->setColumnHidden(0, true);
577 ui->endorseList->resizeColumnToContents(1);
578 ui->endorseList->resizeColumnToContents(2);
579 ui->endorseList->setItemDelegateForColumn(3, m_endorseComboBoxDelegate);
580 ui->endorseList->show();
Yingdi Yu01a942b2013-10-10 15:00:58 -0700581}
Yingdi Yu9e0dc292013-10-10 11:39:45 -0700582
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700583void
Yingdi Yu42372442013-11-06 18:43:31 -0800584ContactPanel::updateDefaultIdentity(const QString& identity, const QString& nickName)
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700585{
Yingdi Yu71ec9652013-11-09 22:18:26 -0800586 // _LOG_DEBUG(identity.toStdString());
Yingdi Yueb98f7d2013-11-10 01:34:57 -0800587 Name defaultIdentity = Name(identity.toStdString());
588 Name defaultKeyName = m_keychain->getIdentityManager()->getPublicStorage()->getDefaultKeyNameForIdentity(defaultIdentity);
Yingdi Yu71ec9652013-11-09 22:18:26 -0800589 if(defaultKeyName.size() == 0)
Yingdi Yueb98f7d2013-11-10 01:34:57 -0800590 {
591 showWarning(QString::fromStdString("Corresponding key is missing!\nHave you created the key?"));
592 return;
593 }
Yingdi Yu71ec9652013-11-09 22:18:26 -0800594 Name defaultCertName = m_keychain->getIdentityManager()->getPublicStorage()->getDefaultCertificateNameForKey(defaultKeyName);
595 if(defaultCertName.size() == 0)
Yingdi Yueb98f7d2013-11-10 01:34:57 -0800596 {
597 showWarning(QString::fromStdString("Corresponding certificate is missing!\nHave you installed the certificate?"));
598 return;
599 }
600 m_defaultIdentity = defaultIdentity;
Yingdi Yub35b8652013-11-07 11:32:40 -0800601 m_profileEditor->setCurrentIdentity(m_defaultIdentity);
Yingdi Yu42372442013-11-06 18:43:31 -0800602 m_nickName = nickName.toStdString();
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700603 m_handler->clearInterestFilter(m_inviteListenPrefix);
Yingdi Yu908f8412013-11-09 00:03:26 -0800604 m_contactManager->setDefaultIdentity(m_defaultIdentity);
Yingdi Yu42372442013-11-06 18:43:31 -0800605 setInvitationListener();
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800606 collectEndorsement();
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700607}
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700608
609void
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700610ContactPanel::openProfileEditor()
Yingdi Yud59b5932013-10-16 13:16:49 -0700611{ m_profileEditor->show(); }
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700612
Yingdi Yud59b5932013-10-16 13:16:49 -0700613void
614ContactPanel::openAddContactPanel()
615{ m_addContactPanel->show(); }
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700616
Yingdi Yu79c25a22013-10-21 13:38:38 -0700617void
Yingdi Yu908f8412013-11-09 00:03:26 -0800618ContactPanel::openBrowseContactDialog()
619{
620 m_browseContactDialog->show();
621 emit refreshCertDirectory();
622}
623
624void
625ContactPanel::removeContactButton()
626{
627 QItemSelectionModel* selectionModel = ui->ContactList->selectionModel();
628 QModelIndexList selectedList = selectionModel->selectedIndexes();
629 QModelIndexList::iterator it = selectedList.begin();
630 for(; it != selectedList.end(); it++)
631 {
632 string alias = m_contactListModel->data(*it, Qt::DisplayRole).toString().toStdString();
633 vector<Ptr<ContactItem> >::iterator contactIt = m_contactList.begin();
634 for(; contactIt != m_contactList.end(); contactIt++)
635 {
636 if((*contactIt)->getAlias() == alias)
637 {
638 m_contactManager->getContactStorage()->removeContact((*contactIt)->getNameSpace());
639 m_contactList.erase(contactIt);
640 break;
641 }
642 }
643 }
644 refreshContactList();
645}
646
647void
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700648ContactPanel::openInvitationDialog()
649{ m_invitationDialog->show(); }
650
651void
Yingdi Yu6ea54e42013-11-12 17:50:21 -0800652ContactPanel::addContactIntoPanelPolicy(const Name& contactNameSpace)
653{
654 Ptr<ContactItem> contact = m_contactManager->getContact(contactNameSpace);
655 if(contact != NULL)
656 m_panelPolicyManager->addTrustAnchor(contact->getSelfEndorseCertificate());
657}
658
659void
660ContactPanel::removeContactFromPanelPolicy(const Name& keyName)
661{ m_panelPolicyManager->removeTrustAnchor(keyName); }
662
663void
Yingdi Yu79c25a22013-10-21 13:38:38 -0700664ContactPanel::refreshContactList()
665{
666 m_contactList = m_contactManager->getContactItemList();
667 QStringList contactNameList;
668 for(int i = 0; i < m_contactList.size(); i++)
Yingdi Yua0594092013-11-06 22:07:38 -0800669 contactNameList << QString::fromStdString(m_contactList[i]->getAlias());
Yingdi Yu79c25a22013-10-21 13:38:38 -0700670
671 m_contactListModel->setStringList(contactNameList);
672}
673
674void
675ContactPanel::showContextMenu(const QPoint& pos)
676{
677 QMenu menu(ui->ContactList);
678 menu.addAction(m_menuInvite);
Yingdi Yu100267f2013-10-21 15:01:40 -0700679 connect(m_menuInvite, SIGNAL(triggered()),
680 this, SLOT(openStartChatDialog()));
Yingdi Yua0594092013-11-06 22:07:38 -0800681 menu.addSeparator();
Yingdi Yu79c25a22013-10-21 13:38:38 -0700682 menu.addAction(m_menuAlias);
683 connect(m_menuAlias, SIGNAL(triggered()),
684 this, SLOT(openSetAliasDialog()));
685 menu.exec(ui->ContactList->mapToGlobal(pos));
686
687}
688
689void
690ContactPanel::openSetAliasDialog()
691{
Yingdi Yua50c3252013-11-03 15:05:26 -0800692 m_setAliasDialog->setTargetIdentity(m_currentSelectedContact->getNameSpace().toUri());
Yingdi Yu79c25a22013-10-21 13:38:38 -0700693 m_setAliasDialog->show();
694}
695
Yingdi Yu100267f2013-10-21 15:01:40 -0700696void
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700697ContactPanel::openSettingDialog()
698{
Yingdi Yu42372442013-11-06 18:43:31 -0800699 m_settingDialog->setIdentity(m_defaultIdentity.toUri(), m_nickName);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700700 m_settingDialog->show();
701}
702
703void
Yingdi Yu100267f2013-10-21 15:01:40 -0700704ContactPanel::openStartChatDialog()
705{
Yingdi Yu100267f2013-10-21 15:01:40 -0700706 Name chatroom("/ndn/broadcast/chronos");
Yingdi Yu42f66462013-10-31 17:38:22 -0700707 chatroom.append(string("chatroom-") + getRandomString());
Yingdi Yu100267f2013-10-21 15:01:40 -0700708
Yingdi Yua50c3252013-11-03 15:05:26 -0800709 m_startChatDialog->setInvitee(m_currentSelectedContact->getNameSpace().toUri(), chatroom.toUri());
Yingdi Yu100267f2013-10-21 15:01:40 -0700710 m_startChatDialog->show();
711}
712
Yingdi Yu42f66462013-10-31 17:38:22 -0700713// For inviter
Yingdi Yu100267f2013-10-21 15:01:40 -0700714void
715ContactPanel::startChatroom(const QString& chatroom, const QString& invitee, bool isIntroducer)
716{
Yingdi Yu42f66462013-10-31 17:38:22 -0700717 Name chatroomName(chatroom.toUtf8().constData());
Yingdi Yu6a5b9f62013-11-06 23:00:21 -0800718
719 Name inviteeNamespace(invitee.toStdString());
720 Ptr<ContactItem> inviteeItem = m_contactManager->getContact(inviteeNamespace);
721
Yingdi Yuc90deb12013-11-06 18:51:19 -0800722 ChatDialog* chatDialog = new ChatDialog(m_contactManager, chatroomName, m_localPrefix, m_defaultIdentity, m_nickName);
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700723 m_chatDialogs.insert(pair <Name, ChatDialog*> (chatroomName, chatDialog));
Yingdi Yu42372442013-11-06 18:43:31 -0800724
725 connect(chatDialog, SIGNAL(closeChatDialog(const ndn::Name&)),
726 this, SLOT(removeChatDialog(const ndn::Name&)));
Yingdi Yub29f78c2013-11-09 20:12:31 -0800727 connect(chatDialog, SIGNAL(noNdnConnection(const QString&)),
728 this, SLOT(showError(const QString&)));
Yingdi Yu3e87bd82013-11-10 10:47:44 -0800729 connect(chatDialog, SIGNAL(inivationRejection(const QString&)),
730 this, SLOT(showWarning(const QString&)));
Yingdi Yu42372442013-11-06 18:43:31 -0800731
Yingdi Yuc90deb12013-11-06 18:51:19 -0800732 // send invitation
Yingdi Yu42f66462013-10-31 17:38:22 -0700733 chatDialog->sendInvitation(inviteeItem, isIntroducer);
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700734
735 chatDialog->show();
Yingdi Yu100267f2013-10-21 15:01:40 -0700736}
737
Yingdi Yu42f66462013-10-31 17:38:22 -0700738// For Invitee
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700739void
Yingdi Yu42f66462013-10-31 17:38:22 -0700740ContactPanel::startChatroom2(const ChronosInvitation& invitation,
741 const security::IdentityCertificate& identityCertificate)
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700742{
Yingdi Yu6a5b9f62013-11-06 23:00:21 -0800743 Ptr<ContactItem> inviterItem = m_contactManager->getContact(invitation.getInviterNameSpace());
744
Yingdi Yu42f66462013-10-31 17:38:22 -0700745 Name chatroomName("/ndn/broadcast/chronos");
746 chatroomName.append(invitation.getChatroom());
Yingdi Yu6a5b9f62013-11-06 23:00:21 -0800747
Yingdi Yuc90deb12013-11-06 18:51:19 -0800748 ChatDialog* chatDialog = new ChatDialog(m_contactManager, chatroomName, m_localPrefix, m_defaultIdentity, m_nickName, true);
Yingdi Yua0594092013-11-06 22:07:38 -0800749
Yingdi Yu42372442013-11-06 18:43:31 -0800750 connect(chatDialog, SIGNAL(closeChatDialog(const ndn::Name&)),
751 this, SLOT(removeChatDialog(const ndn::Name&)));
Yingdi Yub29f78c2013-11-09 20:12:31 -0800752 connect(chatDialog, SIGNAL(noNdnConnection(const QString&)),
753 this, SLOT(showError(const QString&)));
Yingdi Yu3e87bd82013-11-10 10:47:44 -0800754 connect(chatDialog, SIGNAL(inivationRejection(const QString&)),
755 this, SLOT(showWarning(const QString&)));
Yingdi Yu42f66462013-10-31 17:38:22 -0700756
Yingdi Yuc90deb12013-11-06 18:51:19 -0800757 chatDialog->addChatDataRule(invitation.getInviterPrefix(), identityCertificate, true);
Yingdi Yua0594092013-11-06 22:07:38 -0800758 chatDialog->publishIntroCert(identityCertificate, true);
Yingdi Yu42f66462013-10-31 17:38:22 -0700759
Yingdi Yu42f66462013-10-31 17:38:22 -0700760 chatDialog->addTrustAnchor(inviterItem->getSelfEndorseCertificate());
761
762 m_chatDialogs.insert(pair <Name, ChatDialog*> (chatroomName, chatDialog));
763
764 chatDialog->show();
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700765}
766
767void
Yingdi Yu42f66462013-10-31 17:38:22 -0700768ContactPanel::acceptInvitation(const ChronosInvitation& invitation,
769 const security::IdentityCertificate& identityCertificate)
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700770{
771 string prefix = m_localPrefix.toUri();
Yingdi Yu42f66462013-10-31 17:38:22 -0700772 m_handler->publishDataByIdentity (invitation.getInterestName(), prefix);
Yingdi Yu42f66462013-10-31 17:38:22 -0700773 startChatroom2(invitation, identityCertificate);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700774}
775
776void
Yingdi Yu42f66462013-10-31 17:38:22 -0700777ContactPanel::rejectInvitation(const ChronosInvitation& invitation)
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700778{
Yingdi Yu97936352013-11-08 14:13:42 -0800779 string empty("nack");
Yingdi Yu42f66462013-10-31 17:38:22 -0700780 m_handler->publishDataByIdentity (invitation.getInterestName(), empty);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700781}
782
Yingdi Yua50c3252013-11-03 15:05:26 -0800783void
784ContactPanel::isIntroducerChanged(int state)
785{
786 if(state == Qt::Checked)
787 {
788 ui->addScope->setEnabled(true);
789 ui->deleteScope->setEnabled(true);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800790 ui->trustScopeList->setEnabled(true);
791
792 string filter("contact_namespace = '");
793 filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'");
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800794
795 m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
796 m_trustScopeModel->setTable("TrustScope");
797 m_trustScopeModel->setFilter(filter.c_str());
798 m_trustScopeModel->select();
799 m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
800 m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact"));
801 m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope"));
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800802
803 ui->trustScopeList->setModel(m_trustScopeModel);
804 ui->trustScopeList->setColumnHidden(0, true);
805 ui->trustScopeList->setColumnHidden(1, true);
806 ui->trustScopeList->show();
807
808 m_currentSelectedContact->setIsIntroducer(true);
Yingdi Yua50c3252013-11-03 15:05:26 -0800809 }
810 else
811 {
Yingdi Yua50c3252013-11-03 15:05:26 -0800812 ui->addScope->setEnabled(false);
813 ui->deleteScope->setEnabled(false);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800814
815 string filter("contact_namespace = '");
816 filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'");
817
818 m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
819 m_trustScopeModel->setTable("TrustScope");
820 m_trustScopeModel->setFilter(filter.c_str());
821 m_trustScopeModel->select();
822 m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
823 m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact"));
824 m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope"));
825
826 ui->trustScopeList->setModel(m_trustScopeModel);
827 ui->trustScopeList->setColumnHidden(0, true);
828 ui->trustScopeList->setColumnHidden(1, true);
829 ui->trustScopeList->show();
830
831 ui->trustScopeList->setEnabled(false);
832
833 m_currentSelectedContact->setIsIntroducer(false);
Yingdi Yua50c3252013-11-03 15:05:26 -0800834 }
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800835 m_contactManager->getContactStorage()->updateIsIntroducer(m_currentSelectedContact->getNameSpace(), m_currentSelectedContact->isIntroducer());
836}
837
838void
839ContactPanel::addScopeClicked()
840{
841 int rowCount = m_trustScopeModel->rowCount();
842 QSqlRecord record;
843 QSqlField identityField("contact_namespace", QVariant::String);
844 record.append(identityField);
845 record.setValue("contact_namespace", QString(m_currentSelectedContact->getNameSpace().toUri().c_str()));
846 m_trustScopeModel->insertRow(rowCount);
847 m_trustScopeModel->setRecord(rowCount, record);
848}
849
850void
851ContactPanel::deleteScopeClicked()
852{
853 QItemSelectionModel* selectionModel = ui->trustScopeList->selectionModel();
854 QModelIndexList indexList = selectionModel->selectedIndexes();
855
856 int i = indexList.size() - 1;
857 for(; i >= 0; i--)
858 m_trustScopeModel->removeRow(indexList[i].row());
859
860 m_trustScopeModel->submitAll();
861}
862
863void
864ContactPanel::saveScopeClicked()
Yingdi Yua0594092013-11-06 22:07:38 -0800865{ m_trustScopeModel->submitAll(); }
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800866
867void
868ContactPanel::endorseButtonClicked()
869{
870 m_endorseDataModel->submitAll();
871 m_contactManager->updateEndorseCertificate(m_currentSelectedContact->getNameSpace(), m_defaultIdentity);
Yingdi Yua50c3252013-11-03 15:05:26 -0800872}
Yingdi Yu100267f2013-10-21 15:01:40 -0700873
Yingdi Yu42372442013-11-06 18:43:31 -0800874void
875ContactPanel::removeChatDialog(const ndn::Name& chatroomName)
876{
877 map<Name, ChatDialog*>::iterator it = m_chatDialogs.find(chatroomName);
Yingdi Yua0594092013-11-06 22:07:38 -0800878
879 ChatDialog* deletedChat = NULL;
Yingdi Yu42372442013-11-06 18:43:31 -0800880 if(it != m_chatDialogs.end())
881 {
Yingdi Yu42372442013-11-06 18:43:31 -0800882 deletedChat = it->second;
883 m_chatDialogs.erase(it);
884 }
Yingdi Yua0594092013-11-06 22:07:38 -0800885 if (deletedChat != NULL)
886 delete deletedChat;
Yingdi Yu42372442013-11-06 18:43:31 -0800887}
888
Yingdi Yu9e0dc292013-10-10 11:39:45 -0700889#if WAF
890#include "contactpanel.moc"
891#include "contactpanel.cpp.moc"
892#endif