blob: e9fafaa1dbf5e4c70f4395448804901e3fef2455 [file] [log] [blame]
Yingdi Yu847aa862013-10-09 16:35:53 -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
11#include "contactpanel.h"
12#include "ui_contactpanel.h"
13
Yingdi Yu40eca752013-10-10 15:00:58 -070014
15#include <QStringList>
16#include <QItemSelectionModel>
17#include <QModelIndex>
Yingdi Yu3b318c12013-10-15 17:54:00 -070018#include <QDir>
Yingdi Yub2e747d2013-11-05 23:06:43 -080019#include <QtSql/QSqlRecord>
20#include <QtSql/QSqlField>
21#include <QtSql/QSqlError>
Yingdi Yu40eca752013-10-10 15:00:58 -070022
Yingdi Yu3b318c12013-10-15 17:54:00 -070023#ifndef Q_MOC_RUN
Yingdi Yu978b3ae2013-10-23 11:50:51 -070024#include <ndn.cxx/security/keychain.h>
Yingdi Yu978b3ae2013-10-23 11:50:51 -070025#include <ndn.cxx/security/identity/identity-manager.h>
Yingdi Yu595aadc2013-10-21 15:01:40 -070026#include <ndn.cxx/common.h>
Yingdi Yu3b318c12013-10-15 17:54:00 -070027#include <boost/filesystem.hpp>
Yingdi Yu978b3ae2013-10-23 11:50:51 -070028#include <boost/random/random_device.hpp>
29#include <boost/random/uniform_int_distribution.hpp>
Yingdi Yu7989eb22013-10-31 17:38:22 -070030#include "panel-policy-manager.h"
Yingdi Yu3b318c12013-10-15 17:54:00 -070031#include "logging.h"
32#include "exception.h"
33#endif
34
35namespace fs = boost::filesystem;
36using namespace ndn;
Yingdi Yu978b3ae2013-10-23 11:50:51 -070037
Yingdi Yu2ac40fb2013-10-21 13:38:38 -070038using namespace std;
Yingdi Yu3b318c12013-10-15 17:54:00 -070039
40INIT_LOGGER("ContactPanel");
41
Yingdi Yu978b3ae2013-10-23 11:50:51 -070042Q_DECLARE_METATYPE(ndn::security::IdentityCertificate)
Yingdi Yu7989eb22013-10-31 17:38:22 -070043Q_DECLARE_METATYPE(ChronosInvitation)
Yingdi Yu978b3ae2013-10-23 11:50:51 -070044
Yingdi Yu8e135832013-11-09 20:12:31 -080045ContactPanel::ContactPanel(QWidget *parent)
Yingdi Yuec5e72a2013-11-03 15:05:26 -080046 : QDialog(parent)
47 , ui(new Ui::ContactPanel)
Yingdi Yu8e135832013-11-09 20:12:31 -080048 , m_warningDialog(new WarningDialog)
Yingdi Yuec5e72a2013-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 Yu847aa862013-10-09 16:35:53 -070053{
Yingdi Yu978b3ae2013-10-23 11:50:51 -070054 qRegisterMetaType<ndn::security::IdentityCertificate>("IdentityCertificate");
Yingdi Yu7989eb22013-10-31 17:38:22 -070055 qRegisterMetaType<ChronosInvitation>("ChronosInvitation");
Yingdi Yu3b318c12013-10-15 17:54:00 -070056
Yingdi Yu46948282013-11-06 18:43:31 -080057 createAction();
58
Yingdi Yu8e135832013-11-09 20:12:31 -080059 m_contactManager = Ptr<ContactManager>::Create();
Yingdi Yue35bdb82013-11-07 11:32:40 -080060
Yingdi Yu8e135832013-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 Yue35bdb82013-11-07 11:32:40 -080066 openDB();
Yingdi Yu46948282013-11-06 18:43:31 -080067
Yingdi Yueda39aa2013-10-23 23:07:29 -070068 refreshContactList();
Yingdi Yu40eca752013-10-10 15:00:58 -070069
Yingdi Yueda39aa2013-10-23 23:07:29 -070070 setKeychain();
Yingdi Yu46948282013-11-06 18:43:31 -080071
72 m_defaultIdentity = m_keychain->getDefaultIdentity();
Yingdi Yub5a0fd32013-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 Yu711f5892013-11-09 22:18:26 -080075 Name defaultCertName = m_keychain->getIdentityManager()->getDefaultCertificateNameByIdentity(m_defaultIdentity);
76 if(defaultCertName.size() == 0)
Yingdi Yuf0b9ea92013-11-10 10:54:16 -080077 showError(QString::fromStdString("certificate of ") + QString::fromStdString(m_defaultIdentity.toUri()) + " is missing!\nHave you installed the certificate?");
Yingdi Yub5a0fd32013-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 Yu711f5892013-11-09 22:18:26 -080083
Yingdi Yu46948282013-11-06 18:43:31 -080084
Yingdi Yue35bdb82013-11-07 11:32:40 -080085 m_profileEditor = new ProfileEditor(m_contactManager);
86 m_profileEditor->setCurrentIdentity(m_defaultIdentity);
87
Yingdi Yu8e135832013-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 Yue35bdb82013-11-07 11:32:40 -080091
92 ui->setupUi(this);
93
Yingdi Yu8e135832013-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 Yua66183f2013-11-10 10:32:18 -0800100 m_localPrefix = Name("/private/local");
Yingdi Yueda39aa2013-10-23 23:07:29 -0700101 setLocalPrefix();
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700102
Yingdi Yueda39aa2013-10-23 23:07:29 -0700103 setInvitationListener();
Yingdi Yu46948282013-11-06 18:43:31 -0800104
Yingdi Yub2e747d2013-11-05 23:06:43 -0800105 collectEndorsement();
Yingdi Yueda39aa2013-10-23 23:07:29 -0700106
107 ui->ContactList->setModel(m_contactListModel);
108
Yingdi Yu8f7325a2013-10-17 17:03:46 -0700109
Yingdi Yu46948282013-11-06 18:43:31 -0800110 connect(ui->ContactList->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
Yingdi Yueda39aa2013-10-23 23:07:29 -0700111 this, SLOT(updateSelection(const QItemSelection &, const QItemSelection &)));
Yingdi Yu40eca752013-10-10 15:00:58 -0700112
Yingdi Yueda39aa2013-10-23 23:07:29 -0700113 connect(ui->ContactList, SIGNAL(customContextMenuRequested(const QPoint&)),
114 this, SLOT(showContextMenu(const QPoint&)));
Yingdi Yu0269c872013-10-16 13:16:49 -0700115
Yingdi Yueda39aa2013-10-23 23:07:29 -0700116 connect(ui->EditProfileButton, SIGNAL(clicked()),
117 this, SLOT(openProfileEditor()));
Yingdi Yu0269c872013-10-16 13:16:49 -0700118
Yingdi Yu711f5892013-11-09 22:18:26 -0800119 connect(m_profileEditor, SIGNAL(noKeyOrCert(const QString&)),
Yingdi Yue433a502013-11-10 01:34:57 -0800120 this, SLOT(showWarning(const QString&)));
Yingdi Yu711f5892013-11-09 22:18:26 -0800121
Yingdi Yueda39aa2013-10-23 23:07:29 -0700122 connect(ui->AddContactButton, SIGNAL(clicked()),
Yingdi Yuae8217c2013-11-09 00:03:26 -0800123 this, SLOT(openBrowseContactDialog()));
124
Yingdi Yu9d7dfc22013-11-10 17:59:58 -0800125 connect(m_browseContactDialog, SIGNAL(directAddClicked()),
126 this, SLOT(openAddContactPanel()));
127
Yingdi Yuae8217c2013-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 Yu978b3ae2013-10-23 11:50:51 -0700133
Yingdi Yueda39aa2013-10-23 23:07:29 -0700134 connect(ui->settingButton, SIGNAL(clicked()),
135 this, SLOT(openSettingDialog()));
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700136
Yingdi Yu9d7dfc22013-11-10 17:59:58 -0800137 connect(m_addContactPanel, SIGNAL(newContactAdded()),
138 this, SLOT(refreshContactList()));
Yingdi Yuae8217c2013-11-09 00:03:26 -0800139 connect(m_browseContactDialog, SIGNAL(newContactAdded()),
Yingdi Yueda39aa2013-10-23 23:07:29 -0700140 this, SLOT(refreshContactList()));
Yingdi Yueda39aa2013-10-23 23:07:29 -0700141 connect(m_setAliasDialog, SIGNAL(aliasChanged()),
142 this, SLOT(refreshContactList()));
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700143
Yingdi Yueda39aa2013-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 Yu978b3ae2013-10-23 11:50:51 -0700146
Yingdi Yu7989eb22013-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 Yu72232692013-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 Yu978b3ae2013-10-23 11:50:51 -0700156
Yingdi Yu46948282013-11-06 18:43:31 -0800157 connect(m_settingDialog, SIGNAL(identitySet(const QString&, const QString&)),
158 this, SLOT(updateDefaultIdentity(const QString&, const QString&)));
Yingdi Yueda39aa2013-10-23 23:07:29 -0700159
160 connect(this, SIGNAL(newInvitationReady()),
161 this, SLOT(openInvitationDialog()));
Yingdi Yu595aadc2013-10-21 15:01:40 -0700162
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800163 connect(ui->isIntroducer, SIGNAL(stateChanged(int)),
164 this, SLOT(isIntroducerChanged(int)));
Yingdi Yub2e747d2013-11-05 23:06:43 -0800165
166 connect(ui->addScope, SIGNAL(clicked()),
167 this, SLOT(addScopeClicked()));
Yingdi Yub2e747d2013-11-05 23:06:43 -0800168 connect(ui->deleteScope, SIGNAL(clicked()),
169 this, SLOT(deleteScopeClicked()));
Yingdi Yub2e747d2013-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 Yu847aa862013-10-09 16:35:53 -0700175}
176
177ContactPanel::~ContactPanel()
178{
Yingdi Yueda39aa2013-10-23 23:07:29 -0700179 delete ui;
180 delete m_contactListModel;
Yingdi Yu46948282013-11-06 18:43:31 -0800181 delete m_startChatDialog;
182 delete m_invitationDialog;
183 delete m_settingDialog;
184
Yingdi Yueda39aa2013-10-23 23:07:29 -0700185 delete m_profileEditor;
186 delete m_addContactPanel;
Yingdi Yuae8217c2013-11-09 00:03:26 -0800187 delete m_browseContactDialog;
Yingdi Yu46948282013-11-06 18:43:31 -0800188 delete m_setAliasDialog;
189
Yingdi Yub2e747d2013-11-05 23:06:43 -0800190 delete m_trustScopeModel;
191 delete m_endorseDataModel;
Yingdi Yu46948282013-11-06 18:43:31 -0800192 delete m_endorseComboBoxDelegate;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700193
Yingdi Yueda39aa2013-10-23 23:07:29 -0700194 delete m_menuInvite;
Yingdi Yu46948282013-11-06 18:43:31 -0800195 delete m_menuAlias;
Yingdi Yueda39aa2013-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 Yu847aa862013-10-09 16:35:53 -0700200}
201
Yingdi Yu40eca752013-10-10 15:00:58 -0700202void
Yingdi Yu46948282013-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 Yu978b3ae2013-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 Yu46948282013-11-06 18:43:31 -0800217 _LOG_DEBUG("DB opened: " << std::boolalpha << ok );
Yingdi Yub2e747d2013-11-05 23:06:43 -0800218
219 m_trustScopeModel = new QSqlTableModel;
220 m_endorseDataModel = new QSqlTableModel;
221 m_endorseComboBoxDelegate = new EndorseComboBoxDelegate;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700222}
223
224void
225ContactPanel::setKeychain()
226{
Yingdi Yu9b34b1f2013-11-01 17:37:51 -0700227 m_panelPolicyManager = Ptr<PanelPolicyManager>::Create();
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700228
229 vector<Ptr<ContactItem> >::const_iterator it = m_contactList.begin();
230 for(; it != m_contactList.end(); it++)
Yingdi Yue35bdb82013-11-07 11:32:40 -0800231 {
232 m_panelPolicyManager->addTrustAnchor((*it)->getSelfEndorseCertificate());
233 }
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700234
Yingdi Yu9b34b1f2013-11-01 17:37:51 -0700235 m_keychain = Ptr<security::Keychain>(new security::Keychain(Ptr<security::IdentityManager>::Create(),
236 m_panelPolicyManager,
237 NULL));
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700238}
239
240void
Yingdi Yufdb8ab82013-11-10 01:38:21 -0800241ContactPanel::setLocalPrefix(int retry)
Yingdi Yu978b3ae2013-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 Yufdb8ab82013-11-10 01:38:21 -0800252 _2,
253 10),
Yingdi Yu978b3ae2013-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 Yu978b3ae2013-10-23 11:50:51 -0700267 m_localPrefix = Name(prefix);
Yingdi Yue433a502013-11-10 01:34:57 -0800268
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700269}
270
271void
Yingdi Yufdb8ab82013-11-10 01:38:21 -0800272ContactPanel::onLocalPrefixTimeout(Ptr<Closure> closure, Ptr<Interest> interest, int retry)
Yingdi Yu7989eb22013-10-31 17:38:22 -0700273{
Yingdi Yufdb8ab82013-11-10 01:38:21 -0800274 if(retry > 0)
Yingdi Yua66183f2013-11-10 10:32:18 -0800275 {
276 setLocalPrefix(retry - 1);
277 return;
278 }
279 else{
280 m_localPrefix = Name("/private/local");
281 }
Yingdi Yu7989eb22013-10-31 17:38:22 -0700282}
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700283
284void
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700285ContactPanel::setInvitationListener()
286{
Yingdi Yu46948282013-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 Yu978b3ae2013-10-23 11:50:51 -0700291 boost::bind(&ContactPanel::onInvitation,
292 this,
293 _1));
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700294}
295
296void
297ContactPanel::onInvitation(Ptr<Interest> interest)
298{
Yingdi Yu46948282013-11-06 18:43:31 -0800299 _LOG_DEBUG("Receive invitation!" << interest->getName().toUri());
Yingdi Yue35bdb82013-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 Yu46948282013-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 Yue35bdb82013-11-07 11:32:40 -0800314 _LOG_ERROR("Exisiting chatroom!");
Yingdi Yu46948282013-11-06 18:43:31 -0800315 return;
316 }
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700317
Yingdi Yuaf305d72013-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 Yu1ecf81f2013-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 Yuaf305d72013-11-10 11:54:02 -0800323 certificate->setName(invitation->getInviterCertificateName());
Yingdi Yu1ecf81f2013-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 Yuaf305d72013-11-10 11:54:02 -0800341 certificate->setPublicKeyInfo(*keyPtr);
342 popChatInvitation(invitation, invitation->getInviterNameSpace(), certificate);
343 return;
344 }
345
Yingdi Yu9b34b1f2013-11-01 17:37:51 -0700346 Ptr<Interest> newInterest = Ptr<Interest>(new Interest(invitation->getInviterCertificateName()));
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700347 Ptr<Closure> closure = Ptr<Closure>(new Closure(boost::bind(&ContactPanel::onInvitationCertVerified,
348 this,
349 _1,
Yingdi Yu9b34b1f2013-11-01 17:37:51 -0700350 invitation),
Yingdi Yu978b3ae2013-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 Yu46948282013-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 Yu8e135832013-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 Yue433a502013-11-10 01:34:57 -0800490ContactPanel::showWarning(const QString& msg){
491 QMessageBox::information(this, tr("Chronos"), msg);
492}
493
494void
Yingdi Yu40eca752013-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 Yu46948282013-11-06 18:43:31 -0800500 string alias = text.toStdString();
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700501
Yingdi Yu2ac40fb2013-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 Yuec5e72a2013-11-03 15:05:26 -0800509 m_currentSelectedContact = m_contactList[i];
Yingdi Yu83eae842013-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 Yu595aadc2013-10-21 15:01:40 -0700513
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800514 if(m_currentSelectedContact->isIntroducer())
515 {
516 ui->isIntroducer->setChecked(true);
517 ui->addScope->setEnabled(true);
Yingdi Yub2e747d2013-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 Yub2e747d2013-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 Yuec5e72a2013-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 Yub2e747d2013-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 Yuec5e72a2013-11-03 15:05:26 -0800560 }
Yingdi Yub2e747d2013-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 Yu40eca752013-10-10 15:00:58 -0700581}
Yingdi Yu847aa862013-10-09 16:35:53 -0700582
Yingdi Yu3b318c12013-10-15 17:54:00 -0700583void
Yingdi Yu46948282013-11-06 18:43:31 -0800584ContactPanel::updateDefaultIdentity(const QString& identity, const QString& nickName)
Yingdi Yueda39aa2013-10-23 23:07:29 -0700585{
Yingdi Yu711f5892013-11-09 22:18:26 -0800586 // _LOG_DEBUG(identity.toStdString());
Yingdi Yue433a502013-11-10 01:34:57 -0800587 Name defaultIdentity = Name(identity.toStdString());
588 Name defaultKeyName = m_keychain->getIdentityManager()->getPublicStorage()->getDefaultKeyNameForIdentity(defaultIdentity);
Yingdi Yu711f5892013-11-09 22:18:26 -0800589 if(defaultKeyName.size() == 0)
Yingdi Yue433a502013-11-10 01:34:57 -0800590 {
591 showWarning(QString::fromStdString("Corresponding key is missing!\nHave you created the key?"));
592 return;
593 }
Yingdi Yu711f5892013-11-09 22:18:26 -0800594 Name defaultCertName = m_keychain->getIdentityManager()->getPublicStorage()->getDefaultCertificateNameForKey(defaultKeyName);
595 if(defaultCertName.size() == 0)
Yingdi Yue433a502013-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 Yue35bdb82013-11-07 11:32:40 -0800601 m_profileEditor->setCurrentIdentity(m_defaultIdentity);
Yingdi Yu46948282013-11-06 18:43:31 -0800602 m_nickName = nickName.toStdString();
Yingdi Yueda39aa2013-10-23 23:07:29 -0700603 m_handler->clearInterestFilter(m_inviteListenPrefix);
Yingdi Yuae8217c2013-11-09 00:03:26 -0800604 m_contactManager->setDefaultIdentity(m_defaultIdentity);
Yingdi Yu46948282013-11-06 18:43:31 -0800605 setInvitationListener();
Yingdi Yub2e747d2013-11-05 23:06:43 -0800606 collectEndorsement();
Yingdi Yueda39aa2013-10-23 23:07:29 -0700607}
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700608
609void
Yingdi Yu3b318c12013-10-15 17:54:00 -0700610ContactPanel::openProfileEditor()
Yingdi Yu0269c872013-10-16 13:16:49 -0700611{ m_profileEditor->show(); }
Yingdi Yu3b318c12013-10-15 17:54:00 -0700612
Yingdi Yu0269c872013-10-16 13:16:49 -0700613void
614ContactPanel::openAddContactPanel()
615{ m_addContactPanel->show(); }
Yingdi Yu3b318c12013-10-15 17:54:00 -0700616
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700617void
Yingdi Yuae8217c2013-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 Yueda39aa2013-10-23 23:07:29 -0700648ContactPanel::openInvitationDialog()
649{ m_invitationDialog->show(); }
650
651void
Yingdi Yu72232692013-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 Yu2ac40fb2013-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 Yu83eae842013-11-06 22:07:38 -0800669 contactNameList << QString::fromStdString(m_contactList[i]->getAlias());
Yingdi Yu2ac40fb2013-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 Yu595aadc2013-10-21 15:01:40 -0700679 connect(m_menuInvite, SIGNAL(triggered()),
680 this, SLOT(openStartChatDialog()));
Yingdi Yu83eae842013-11-06 22:07:38 -0800681 menu.addSeparator();
Yingdi Yu2ac40fb2013-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 Yuec5e72a2013-11-03 15:05:26 -0800692 m_setAliasDialog->setTargetIdentity(m_currentSelectedContact->getNameSpace().toUri());
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700693 m_setAliasDialog->show();
694}
695
Yingdi Yu595aadc2013-10-21 15:01:40 -0700696void
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700697ContactPanel::openSettingDialog()
698{
Yingdi Yu46948282013-11-06 18:43:31 -0800699 m_settingDialog->setIdentity(m_defaultIdentity.toUri(), m_nickName);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700700 m_settingDialog->show();
701}
702
703void
Yingdi Yu595aadc2013-10-21 15:01:40 -0700704ContactPanel::openStartChatDialog()
705{
Yingdi Yu595aadc2013-10-21 15:01:40 -0700706 Name chatroom("/ndn/broadcast/chronos");
Yingdi Yu7989eb22013-10-31 17:38:22 -0700707 chatroom.append(string("chatroom-") + getRandomString());
Yingdi Yu595aadc2013-10-21 15:01:40 -0700708
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800709 m_startChatDialog->setInvitee(m_currentSelectedContact->getNameSpace().toUri(), chatroom.toUri());
Yingdi Yu595aadc2013-10-21 15:01:40 -0700710 m_startChatDialog->show();
711}
712
Yingdi Yu7989eb22013-10-31 17:38:22 -0700713// For inviter
Yingdi Yu595aadc2013-10-21 15:01:40 -0700714void
715ContactPanel::startChatroom(const QString& chatroom, const QString& invitee, bool isIntroducer)
716{
Yingdi Yu7989eb22013-10-31 17:38:22 -0700717 Name chatroomName(chatroom.toUtf8().constData());
Yingdi Yu72781e52013-11-06 23:00:21 -0800718
719 Name inviteeNamespace(invitee.toStdString());
720 Ptr<ContactItem> inviteeItem = m_contactManager->getContact(inviteeNamespace);
721
Yingdi Yue6476cd2013-11-06 18:51:19 -0800722 ChatDialog* chatDialog = new ChatDialog(m_contactManager, chatroomName, m_localPrefix, m_defaultIdentity, m_nickName);
Yingdi Yueda39aa2013-10-23 23:07:29 -0700723 m_chatDialogs.insert(pair <Name, ChatDialog*> (chatroomName, chatDialog));
Yingdi Yu46948282013-11-06 18:43:31 -0800724
725 connect(chatDialog, SIGNAL(closeChatDialog(const ndn::Name&)),
726 this, SLOT(removeChatDialog(const ndn::Name&)));
Yingdi Yu8e135832013-11-09 20:12:31 -0800727 connect(chatDialog, SIGNAL(noNdnConnection(const QString&)),
728 this, SLOT(showError(const QString&)));
Yingdi Yu0aca2652013-11-10 10:47:44 -0800729 connect(chatDialog, SIGNAL(inivationRejection(const QString&)),
730 this, SLOT(showWarning(const QString&)));
Yingdi Yu46948282013-11-06 18:43:31 -0800731
Yingdi Yue6476cd2013-11-06 18:51:19 -0800732 // send invitation
Yingdi Yu7989eb22013-10-31 17:38:22 -0700733 chatDialog->sendInvitation(inviteeItem, isIntroducer);
Yingdi Yueda39aa2013-10-23 23:07:29 -0700734
735 chatDialog->show();
Yingdi Yu595aadc2013-10-21 15:01:40 -0700736}
737
Yingdi Yu7989eb22013-10-31 17:38:22 -0700738// For Invitee
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700739void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700740ContactPanel::startChatroom2(const ChronosInvitation& invitation,
741 const security::IdentityCertificate& identityCertificate)
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700742{
Yingdi Yu72781e52013-11-06 23:00:21 -0800743 Ptr<ContactItem> inviterItem = m_contactManager->getContact(invitation.getInviterNameSpace());
744
Yingdi Yu7989eb22013-10-31 17:38:22 -0700745 Name chatroomName("/ndn/broadcast/chronos");
746 chatroomName.append(invitation.getChatroom());
Yingdi Yu72781e52013-11-06 23:00:21 -0800747
Yingdi Yue6476cd2013-11-06 18:51:19 -0800748 ChatDialog* chatDialog = new ChatDialog(m_contactManager, chatroomName, m_localPrefix, m_defaultIdentity, m_nickName, true);
Yingdi Yu83eae842013-11-06 22:07:38 -0800749
Yingdi Yu46948282013-11-06 18:43:31 -0800750 connect(chatDialog, SIGNAL(closeChatDialog(const ndn::Name&)),
751 this, SLOT(removeChatDialog(const ndn::Name&)));
Yingdi Yu8e135832013-11-09 20:12:31 -0800752 connect(chatDialog, SIGNAL(noNdnConnection(const QString&)),
753 this, SLOT(showError(const QString&)));
Yingdi Yu0aca2652013-11-10 10:47:44 -0800754 connect(chatDialog, SIGNAL(inivationRejection(const QString&)),
755 this, SLOT(showWarning(const QString&)));
Yingdi Yu7989eb22013-10-31 17:38:22 -0700756
Yingdi Yue6476cd2013-11-06 18:51:19 -0800757 chatDialog->addChatDataRule(invitation.getInviterPrefix(), identityCertificate, true);
Yingdi Yu83eae842013-11-06 22:07:38 -0800758 chatDialog->publishIntroCert(identityCertificate, true);
Yingdi Yu7989eb22013-10-31 17:38:22 -0700759
Yingdi Yu7989eb22013-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 Yu978b3ae2013-10-23 11:50:51 -0700765}
766
767void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700768ContactPanel::acceptInvitation(const ChronosInvitation& invitation,
769 const security::IdentityCertificate& identityCertificate)
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700770{
771 string prefix = m_localPrefix.toUri();
Yingdi Yu7989eb22013-10-31 17:38:22 -0700772 m_handler->publishDataByIdentity (invitation.getInterestName(), prefix);
Yingdi Yu7989eb22013-10-31 17:38:22 -0700773 startChatroom2(invitation, identityCertificate);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700774}
775
776void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700777ContactPanel::rejectInvitation(const ChronosInvitation& invitation)
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700778{
Yingdi Yue9195fd2013-11-08 14:13:42 -0800779 string empty("nack");
Yingdi Yu7989eb22013-10-31 17:38:22 -0700780 m_handler->publishDataByIdentity (invitation.getInterestName(), empty);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700781}
782
Yingdi Yuec5e72a2013-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 Yub2e747d2013-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 Yub2e747d2013-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 Yub2e747d2013-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 Yuec5e72a2013-11-03 15:05:26 -0800809 }
810 else
811 {
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800812 ui->addScope->setEnabled(false);
813 ui->deleteScope->setEnabled(false);
Yingdi Yub2e747d2013-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 Yuec5e72a2013-11-03 15:05:26 -0800834 }
Yingdi Yub2e747d2013-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 Yu83eae842013-11-06 22:07:38 -0800865{ m_trustScopeModel->submitAll(); }
Yingdi Yub2e747d2013-11-05 23:06:43 -0800866
867void
868ContactPanel::endorseButtonClicked()
869{
870 m_endorseDataModel->submitAll();
871 m_contactManager->updateEndorseCertificate(m_currentSelectedContact->getNameSpace(), m_defaultIdentity);
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800872}
Yingdi Yu595aadc2013-10-21 15:01:40 -0700873
Yingdi Yu46948282013-11-06 18:43:31 -0800874void
875ContactPanel::removeChatDialog(const ndn::Name& chatroomName)
876{
877 map<Name, ChatDialog*>::iterator it = m_chatDialogs.find(chatroomName);
Yingdi Yu83eae842013-11-06 22:07:38 -0800878
879 ChatDialog* deletedChat = NULL;
Yingdi Yu46948282013-11-06 18:43:31 -0800880 if(it != m_chatDialogs.end())
881 {
Yingdi Yu46948282013-11-06 18:43:31 -0800882 deletedChat = it->second;
883 m_chatDialogs.erase(it);
884 }
Yingdi Yu83eae842013-11-06 22:07:38 -0800885 if (deletedChat != NULL)
886 delete deletedChat;
Yingdi Yu46948282013-11-06 18:43:31 -0800887}
888
Yingdi Yu847aa862013-10-09 16:35:53 -0700889#if WAF
890#include "contactpanel.moc"
891#include "contactpanel.cpp.moc"
892#endif