blob: 8e7de21f6e81c8610e40d400d4acec6a98cd4aff [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 Yuae8217c2013-11-09 00:03:26 -080073 m_contactManager->setDefaultIdentity(m_defaultIdentity);
Yingdi Yu46948282013-11-06 18:43:31 -080074 m_nickName = m_defaultIdentity.get(-1).toUri();
75 m_settingDialog->setIdentity(m_defaultIdentity.toUri(), m_nickName);
Yingdi Yu711f5892013-11-09 22:18:26 -080076 Name defaultCertName = m_keychain->getIdentityManager()->getDefaultCertificateNameByIdentity(m_defaultIdentity);
77 if(defaultCertName.size() == 0)
Yingdi Yuf0b9ea92013-11-10 10:54:16 -080078 showError(QString::fromStdString("certificate of ") + QString::fromStdString(m_defaultIdentity.toUri()) + " is missing!\nHave you installed the certificate?");
Yingdi Yu711f5892013-11-09 22:18:26 -080079
Yingdi Yu46948282013-11-06 18:43:31 -080080
Yingdi Yue35bdb82013-11-07 11:32:40 -080081 m_profileEditor = new ProfileEditor(m_contactManager);
82 m_profileEditor->setCurrentIdentity(m_defaultIdentity);
83
Yingdi Yu8e135832013-11-09 20:12:31 -080084 m_addContactPanel = new AddContactPanel(m_contactManager);
85 m_browseContactDialog = new BrowseContactDialog(m_contactManager);
86 m_setAliasDialog = new SetAliasDialog(m_contactManager);
Yingdi Yue35bdb82013-11-07 11:32:40 -080087
88 ui->setupUi(this);
89
Yingdi Yu8e135832013-11-09 20:12:31 -080090 try{
91 m_handler = Ptr<Wrapper>(new Wrapper(m_keychain));
92 }catch(ndn::Error::ndnOperation& e){
93 showError(QString::fromStdString("Cannot conect to ndnd!\n Have you started your ndnd?"));
94 }
95
Yingdi Yua66183f2013-11-10 10:32:18 -080096 m_localPrefix = Name("/private/local");
Yingdi Yueda39aa2013-10-23 23:07:29 -070097 setLocalPrefix();
Yingdi Yu978b3ae2013-10-23 11:50:51 -070098
Yingdi Yueda39aa2013-10-23 23:07:29 -070099 setInvitationListener();
Yingdi Yu46948282013-11-06 18:43:31 -0800100
Yingdi Yub2e747d2013-11-05 23:06:43 -0800101 collectEndorsement();
Yingdi Yueda39aa2013-10-23 23:07:29 -0700102
103 ui->ContactList->setModel(m_contactListModel);
104
Yingdi Yu8f7325a2013-10-17 17:03:46 -0700105
Yingdi Yu46948282013-11-06 18:43:31 -0800106 connect(ui->ContactList->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
Yingdi Yueda39aa2013-10-23 23:07:29 -0700107 this, SLOT(updateSelection(const QItemSelection &, const QItemSelection &)));
Yingdi Yu40eca752013-10-10 15:00:58 -0700108
Yingdi Yueda39aa2013-10-23 23:07:29 -0700109 connect(ui->ContactList, SIGNAL(customContextMenuRequested(const QPoint&)),
110 this, SLOT(showContextMenu(const QPoint&)));
Yingdi Yu0269c872013-10-16 13:16:49 -0700111
Yingdi Yueda39aa2013-10-23 23:07:29 -0700112 connect(ui->EditProfileButton, SIGNAL(clicked()),
113 this, SLOT(openProfileEditor()));
Yingdi Yu0269c872013-10-16 13:16:49 -0700114
Yingdi Yu711f5892013-11-09 22:18:26 -0800115 connect(m_profileEditor, SIGNAL(noKeyOrCert(const QString&)),
Yingdi Yue433a502013-11-10 01:34:57 -0800116 this, SLOT(showWarning(const QString&)));
Yingdi Yu711f5892013-11-09 22:18:26 -0800117
Yingdi Yuae8217c2013-11-09 00:03:26 -0800118 // connect(ui->AddContactButton, SIGNAL(clicked()),
119 // this, SLOT(openAddContactPanel()));
Yingdi Yueda39aa2013-10-23 23:07:29 -0700120 connect(ui->AddContactButton, SIGNAL(clicked()),
Yingdi Yuae8217c2013-11-09 00:03:26 -0800121 this, SLOT(openBrowseContactDialog()));
122
123 connect(this, SIGNAL(refreshCertDirectory()),
124 m_browseContactDialog, SLOT(refreshList()));
125
126 connect(ui->DeleteContactButton, SIGNAL(clicked()),
127 this, SLOT(removeContactButton()));
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700128
Yingdi Yueda39aa2013-10-23 23:07:29 -0700129 connect(ui->settingButton, SIGNAL(clicked()),
130 this, SLOT(openSettingDialog()));
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700131
Yingdi Yuae8217c2013-11-09 00:03:26 -0800132 connect(m_browseContactDialog, SIGNAL(newContactAdded()),
Yingdi Yueda39aa2013-10-23 23:07:29 -0700133 this, SLOT(refreshContactList()));
Yingdi Yueda39aa2013-10-23 23:07:29 -0700134 connect(m_setAliasDialog, SIGNAL(aliasChanged()),
135 this, SLOT(refreshContactList()));
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700136
Yingdi Yueda39aa2013-10-23 23:07:29 -0700137 connect(m_startChatDialog, SIGNAL(chatroomConfirmed(const QString&, const QString&, bool)),
138 this, SLOT(startChatroom(const QString&, const QString&, bool)));
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700139
Yingdi Yu7989eb22013-10-31 17:38:22 -0700140 connect(m_invitationDialog, SIGNAL(invitationAccepted(const ChronosInvitation&, const ndn::security::IdentityCertificate&)),
141 this, SLOT(acceptInvitation(const ChronosInvitation&, const ndn::security::IdentityCertificate&)));
142 connect(m_invitationDialog, SIGNAL(invitationRejected(const ChronosInvitation&)),
143 this, SLOT(rejectInvitation(const ChronosInvitation&)));
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700144
Yingdi Yu46948282013-11-06 18:43:31 -0800145 connect(m_settingDialog, SIGNAL(identitySet(const QString&, const QString&)),
146 this, SLOT(updateDefaultIdentity(const QString&, const QString&)));
Yingdi Yueda39aa2013-10-23 23:07:29 -0700147
148 connect(this, SIGNAL(newInvitationReady()),
149 this, SLOT(openInvitationDialog()));
Yingdi Yu595aadc2013-10-21 15:01:40 -0700150
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800151 connect(ui->isIntroducer, SIGNAL(stateChanged(int)),
152 this, SLOT(isIntroducerChanged(int)));
Yingdi Yub2e747d2013-11-05 23:06:43 -0800153
154 connect(ui->addScope, SIGNAL(clicked()),
155 this, SLOT(addScopeClicked()));
Yingdi Yub2e747d2013-11-05 23:06:43 -0800156 connect(ui->deleteScope, SIGNAL(clicked()),
157 this, SLOT(deleteScopeClicked()));
Yingdi Yub2e747d2013-11-05 23:06:43 -0800158 connect(ui->saveButton, SIGNAL(clicked()),
159 this, SLOT(saveScopeClicked()));
160
161 connect(ui->endorseButton, SIGNAL(clicked()),
162 this, SLOT(endorseButtonClicked()));
Yingdi Yu847aa862013-10-09 16:35:53 -0700163}
164
165ContactPanel::~ContactPanel()
166{
Yingdi Yueda39aa2013-10-23 23:07:29 -0700167 delete ui;
168 delete m_contactListModel;
Yingdi Yu46948282013-11-06 18:43:31 -0800169 delete m_startChatDialog;
170 delete m_invitationDialog;
171 delete m_settingDialog;
172
Yingdi Yueda39aa2013-10-23 23:07:29 -0700173 delete m_profileEditor;
174 delete m_addContactPanel;
Yingdi Yuae8217c2013-11-09 00:03:26 -0800175 delete m_browseContactDialog;
Yingdi Yu46948282013-11-06 18:43:31 -0800176 delete m_setAliasDialog;
177
Yingdi Yub2e747d2013-11-05 23:06:43 -0800178 delete m_trustScopeModel;
179 delete m_endorseDataModel;
Yingdi Yu46948282013-11-06 18:43:31 -0800180 delete m_endorseComboBoxDelegate;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700181
Yingdi Yueda39aa2013-10-23 23:07:29 -0700182 delete m_menuInvite;
Yingdi Yu46948282013-11-06 18:43:31 -0800183 delete m_menuAlias;
Yingdi Yueda39aa2013-10-23 23:07:29 -0700184
185 map<Name, ChatDialog*>::iterator it = m_chatDialogs.begin();
186 for(; it != m_chatDialogs.end(); it++)
187 delete it->second;
Yingdi Yu847aa862013-10-09 16:35:53 -0700188}
189
Yingdi Yu40eca752013-10-10 15:00:58 -0700190void
Yingdi Yu46948282013-11-06 18:43:31 -0800191ContactPanel::createAction()
192{
193 m_menuInvite = new QAction("&Chat", this);
194 m_menuAlias = new QAction("&Set Alias", this);
195}
196
197void
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700198ContactPanel::openDB()
199{
200 QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
201 QString path = (QDir::home().path());
202 path.append(QDir::separator()).append(".chronos").append(QDir::separator()).append("chronos.db");
203 db.setDatabaseName(path);
204 bool ok = db.open();
Yingdi Yu46948282013-11-06 18:43:31 -0800205 _LOG_DEBUG("DB opened: " << std::boolalpha << ok );
Yingdi Yub2e747d2013-11-05 23:06:43 -0800206
207 m_trustScopeModel = new QSqlTableModel;
208 m_endorseDataModel = new QSqlTableModel;
209 m_endorseComboBoxDelegate = new EndorseComboBoxDelegate;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700210}
211
212void
213ContactPanel::setKeychain()
214{
Yingdi Yu9b34b1f2013-11-01 17:37:51 -0700215 m_panelPolicyManager = Ptr<PanelPolicyManager>::Create();
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700216
217 vector<Ptr<ContactItem> >::const_iterator it = m_contactList.begin();
218 for(; it != m_contactList.end(); it++)
Yingdi Yue35bdb82013-11-07 11:32:40 -0800219 {
220 m_panelPolicyManager->addTrustAnchor((*it)->getSelfEndorseCertificate());
221 }
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700222
Yingdi Yu9b34b1f2013-11-01 17:37:51 -0700223 m_keychain = Ptr<security::Keychain>(new security::Keychain(Ptr<security::IdentityManager>::Create(),
224 m_panelPolicyManager,
225 NULL));
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700226}
227
228void
Yingdi Yufdb8ab82013-11-10 01:38:21 -0800229ContactPanel::setLocalPrefix(int retry)
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700230{
231 Ptr<Interest> interest = Ptr<Interest>(new Interest(Name("/local/ndn/prefix")));
232 interest->setChildSelector(Interest::CHILD_RIGHT);
233
234 Ptr<Closure> closure = Ptr<Closure>(new Closure(boost::bind(&ContactPanel::onLocalPrefixVerified,
235 this,
236 _1),
237 boost::bind(&ContactPanel::onLocalPrefixTimeout,
238 this,
239 _1,
Yingdi Yufdb8ab82013-11-10 01:38:21 -0800240 _2,
241 10),
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700242 boost::bind(&ContactPanel::onLocalPrefixVerified,
243 this,
244 _1)));
245
246 m_handler->sendInterest(interest, closure);
247}
248
249void
250ContactPanel::onLocalPrefixVerified(Ptr<Data> data)
251{
252 string originPrefix(data->content().buf(), data->content().size());
253 string prefix = QString::fromStdString (originPrefix).trimmed ().toUtf8().constData();
254 string randomSuffix = getRandomString();
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700255 m_localPrefix = Name(prefix);
Yingdi Yue433a502013-11-10 01:34:57 -0800256
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700257}
258
259void
Yingdi Yufdb8ab82013-11-10 01:38:21 -0800260ContactPanel::onLocalPrefixTimeout(Ptr<Closure> closure, Ptr<Interest> interest, int retry)
Yingdi Yu7989eb22013-10-31 17:38:22 -0700261{
Yingdi Yufdb8ab82013-11-10 01:38:21 -0800262 if(retry > 0)
Yingdi Yua66183f2013-11-10 10:32:18 -0800263 {
264 setLocalPrefix(retry - 1);
265 return;
266 }
267 else{
268 m_localPrefix = Name("/private/local");
269 }
Yingdi Yu7989eb22013-10-31 17:38:22 -0700270}
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700271
272void
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700273ContactPanel::setInvitationListener()
274{
Yingdi Yu46948282013-11-06 18:43:31 -0800275 m_inviteListenPrefix = Name("/ndn/broadcast/chronos/invitation");
276 m_inviteListenPrefix.append(m_defaultIdentity);
277 _LOG_DEBUG("Listening for invitation on prefix: " << m_inviteListenPrefix.toUri());
278 m_handler->setInterestFilter (m_inviteListenPrefix,
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700279 boost::bind(&ContactPanel::onInvitation,
280 this,
281 _1));
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700282}
283
284void
285ContactPanel::onInvitation(Ptr<Interest> interest)
286{
Yingdi Yu46948282013-11-06 18:43:31 -0800287 _LOG_DEBUG("Receive invitation!" << interest->getName().toUri());
Yingdi Yue35bdb82013-11-07 11:32:40 -0800288
289 Ptr<ChronosInvitation> invitation = NULL;
290 try{
291 invitation = Ptr<ChronosInvitation>(new ChronosInvitation(interest->getName()));
292 }catch(exception& e){
293 _LOG_ERROR("Exception: " << e.what());
294 return;
295 }
296
Yingdi Yu46948282013-11-06 18:43:31 -0800297 Name chatroomName("/ndn/broadcast/chronos");
298 chatroomName.append(invitation->getChatroom());
299 map<Name, ChatDialog*>::iterator it = m_chatDialogs.find(chatroomName);
300 if(it != m_chatDialogs.end())
301 {
Yingdi Yue35bdb82013-11-07 11:32:40 -0800302 _LOG_ERROR("Exisiting chatroom!");
Yingdi Yu46948282013-11-06 18:43:31 -0800303 return;
304 }
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700305
Yingdi Yuaf305d72013-11-10 11:54:02 -0800306 Ptr<security::Publickey> keyPtr = m_panelPolicyManager->getTrustedKey(invitation->getInviterCertificateName());
307 if(NULL != keyPtr && security::PolicyManager::verifySignature(invitation->getSignedBlob(), invitation->getSignatureBits(), *keyPtr))
308 {
309 Ptr<security::IdentityCertificate> certificate = Ptr<security::IdentityCertificate>::Create();
310 // hack: incomplete certificate, we don't send it to the wire nor store it anywhere
311 certificate->setName(invitation->getInviterCertificateName());
312 certificate->setPublicKeyInfo(*keyPtr);
313 popChatInvitation(invitation, invitation->getInviterNameSpace(), certificate);
314 return;
315 }
316
Yingdi Yu9b34b1f2013-11-01 17:37:51 -0700317 Ptr<Interest> newInterest = Ptr<Interest>(new Interest(invitation->getInviterCertificateName()));
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700318 Ptr<Closure> closure = Ptr<Closure>(new Closure(boost::bind(&ContactPanel::onInvitationCertVerified,
319 this,
320 _1,
Yingdi Yu9b34b1f2013-11-01 17:37:51 -0700321 invitation),
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700322 boost::bind(&ContactPanel::onTimeout,
323 this,
324 _1,
325 _2),
326 boost::bind(&ContactPanel::onUnverified,
327 this,
328 _1)));
329 m_handler->sendInterest(newInterest, closure);
330}
331
332void
Yingdi Yu46948282013-11-06 18:43:31 -0800333ContactPanel::onInvitationCertVerified(Ptr<Data> data,
334 Ptr<ChronosInvitation> invitation)
335{
336 using namespace ndn::security;
337 Ptr<IdentityCertificate> certificate = Ptr<IdentityCertificate>(new IdentityCertificate(*data));
338
339 if(PolicyManager::verifySignature(invitation->getSignedBlob(), invitation->getSignatureBits(), certificate->getPublicKeyInfo()))
340 {
341 Name keyName = certificate->getPublicKeyName();
342 Name inviterNameSpace = keyName.getPrefix(keyName.size() - 1);
343 popChatInvitation(invitation, inviterNameSpace, certificate);
344 }
345}
346
347void
348ContactPanel::onUnverified(Ptr<Data> data)
349{}
350
351void
352ContactPanel::onTimeout(Ptr<Closure> closure, Ptr<Interest> interest)
353{}
354
355void
356ContactPanel::popChatInvitation(Ptr<ChronosInvitation> invitation,
357 const Name& inviterNameSpace,
358 Ptr<security::IdentityCertificate> certificate)
359{
360 string alias;
361 vector<Ptr<ContactItem> >::iterator it = m_contactList.begin();
362 for(; it != m_contactList.end(); it++)
363 if((*it)->getNameSpace() == inviterNameSpace)
364 alias = (*it)->getAlias();
365
366 if(it != m_contactList.end())
367 return;
368
369 m_invitationDialog->setInvitation(alias, invitation, certificate);
370 emit newInvitationReady();
371}
372
373void
374ContactPanel::collectEndorsement()
375{
376 m_collectStatus = Ptr<vector<bool> >::Create();
377 m_collectStatus->assign(m_contactList.size(), false);
378
379 vector<Ptr<ContactItem> >::iterator it = m_contactList.begin();
380 int count = 0;
381 for(; it != m_contactList.end(); it++, count++)
382 {
383 Name interestName = (*it)->getNameSpace();
384 interestName.append("DNS").append(m_defaultIdentity).append("ENDORSEE");
385 Ptr<Interest> interest = Ptr<Interest>(new Interest(interestName));
386 interest->setChildSelector(Interest::CHILD_RIGHT);
387 interest->setInterestLifetime(1);
388
389 Ptr<Closure> closure = Ptr<Closure>(new Closure(boost::bind(&ContactPanel::onDnsEndorseeVerified,
390 this,
391 _1,
392 count),
393 boost::bind(&ContactPanel::onDnsEndorseeTimeout,
394 this,
395 _1,
396 _2,
397 count),
398 boost::bind(&ContactPanel::onDnsEndorseeUnverified,
399 this,
400 _1,
401 count)));
402
403 m_handler->sendInterest(interest, closure);
404 }
405}
406
407void
408ContactPanel::onDnsEndorseeVerified(Ptr<Data> data, int count)
409{
410 Ptr<Blob> contentBlob = Ptr<Blob>(new Blob(data->content().buf(), data->content().size()));
411 Ptr<Data> endorseData = Data::decodeFromWire(contentBlob);
412 EndorseCertificate endorseCertificate(*endorseData);
413
414 m_contactManager->getContactStorage()->updateCollectEndorse(endorseCertificate);
415
416 updateCollectStatus(count);
417}
418
419void
420ContactPanel::onDnsEndorseeTimeout(Ptr<Closure> closure, Ptr<Interest> interest, int count)
421{ updateCollectStatus(count); }
422
423void
424ContactPanel::onDnsEndorseeUnverified(Ptr<Data> data, int count)
425{ updateCollectStatus(count); }
426
427void
428ContactPanel::updateCollectStatus(int count)
429{
430 m_collectStatus->at(count) = true;
431 vector<bool>::const_iterator it = m_collectStatus->begin();
432 for(; it != m_collectStatus->end(); it++)
433 if(*it == false)
434 return;
435
436 m_contactManager->publishEndorsedDataInDns(m_defaultIdentity);
437}
438
439static std::string chars("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789");
440
441string
442ContactPanel::getRandomString()
443{
444 string randStr;
445 boost::random::random_device rng;
446 boost::random::uniform_int_distribution<> index_dist(0, chars.size() - 1);
447 for (int i = 0; i < 10; i ++)
448 {
449 randStr += chars[index_dist(rng)];
450 }
451 return randStr;
452}
453
454void
Yingdi Yu8e135832013-11-09 20:12:31 -0800455ContactPanel::showError(const QString& msg){
456 QMessageBox::critical(this, tr("Chronos"), msg, QMessageBox::Ok);
457 exit(1);
458}
459
460void
Yingdi Yue433a502013-11-10 01:34:57 -0800461ContactPanel::showWarning(const QString& msg){
462 QMessageBox::information(this, tr("Chronos"), msg);
463}
464
465void
Yingdi Yu40eca752013-10-10 15:00:58 -0700466ContactPanel::updateSelection(const QItemSelection &selected,
467 const QItemSelection &deselected)
468{
469 QModelIndexList items = selected.indexes();
470 QString text = m_contactListModel->data(items.first(), Qt::DisplayRole).toString();
Yingdi Yu46948282013-11-06 18:43:31 -0800471 string alias = text.toStdString();
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700472
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700473 int i = 0;
474 for(; i < m_contactList.size(); i++)
475 {
476 if(alias == m_contactList[i]->getAlias())
477 break;
478 }
479
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800480 m_currentSelectedContact = m_contactList[i];
Yingdi Yu83eae842013-11-06 22:07:38 -0800481 ui->NameData->setText(QString::fromStdString(m_currentSelectedContact->getName()));
482 ui->NameSpaceData->setText(QString::fromStdString(m_currentSelectedContact->getNameSpace().toUri()));
483 ui->InstitutionData->setText(QString::fromStdString(m_currentSelectedContact->getInstitution()));
Yingdi Yu595aadc2013-10-21 15:01:40 -0700484
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800485 if(m_currentSelectedContact->isIntroducer())
486 {
487 ui->isIntroducer->setChecked(true);
488 ui->addScope->setEnabled(true);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800489 ui->deleteScope->setEnabled(true);
490 ui->trustScopeList->setEnabled(true);
491
492 string filter("contact_namespace = '");
493 filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'");
494
495 m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
496 m_trustScopeModel->setTable("TrustScope");
497 m_trustScopeModel->setFilter(filter.c_str());
498 m_trustScopeModel->select();
499 m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
500 m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact"));
501 m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope"));
502
Yingdi Yub2e747d2013-11-05 23:06:43 -0800503 ui->trustScopeList->setModel(m_trustScopeModel);
504 ui->trustScopeList->setColumnHidden(0, true);
505 ui->trustScopeList->setColumnHidden(1, true);
506 ui->trustScopeList->show();
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800507 }
508 else
509 {
510 ui->isIntroducer->setChecked(false);
511 ui->addScope->setEnabled(false);
512 ui->deleteScope->setEnabled(false);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800513
514 string filter("contact_namespace = '");
515 filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'");
516
517 m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
518 m_trustScopeModel->setTable("TrustScope");
519 m_trustScopeModel->setFilter(filter.c_str());
520 m_trustScopeModel->select();
521 m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
522 m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact"));
523 m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope"));
524
525 ui->trustScopeList->setModel(m_trustScopeModel);
526 ui->trustScopeList->setColumnHidden(0, true);
527 ui->trustScopeList->setColumnHidden(1, true);
528 ui->trustScopeList->show();
529
530 ui->trustScopeList->setEnabled(false);
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800531 }
Yingdi Yub2e747d2013-11-05 23:06:43 -0800532
533 string filter("profile_identity = '");
534 filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'");
535
536 m_endorseDataModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
537 m_endorseDataModel->setTable("ContactProfile");
538 m_endorseDataModel->setFilter(filter.c_str());
539 m_endorseDataModel->select();
540
541 m_endorseDataModel->setHeaderData(0, Qt::Horizontal, QObject::tr("Identity"));
542 m_endorseDataModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Type"));
543 m_endorseDataModel->setHeaderData(2, Qt::Horizontal, QObject::tr("Value"));
544 m_endorseDataModel->setHeaderData(3, Qt::Horizontal, QObject::tr("Endorse"));
545
546 ui->endorseList->setModel(m_endorseDataModel);
547 ui->endorseList->setColumnHidden(0, true);
548 ui->endorseList->resizeColumnToContents(1);
549 ui->endorseList->resizeColumnToContents(2);
550 ui->endorseList->setItemDelegateForColumn(3, m_endorseComboBoxDelegate);
551 ui->endorseList->show();
Yingdi Yu40eca752013-10-10 15:00:58 -0700552}
Yingdi Yu847aa862013-10-09 16:35:53 -0700553
Yingdi Yu3b318c12013-10-15 17:54:00 -0700554void
Yingdi Yu46948282013-11-06 18:43:31 -0800555ContactPanel::updateDefaultIdentity(const QString& identity, const QString& nickName)
Yingdi Yueda39aa2013-10-23 23:07:29 -0700556{
Yingdi Yu711f5892013-11-09 22:18:26 -0800557 // _LOG_DEBUG(identity.toStdString());
Yingdi Yue433a502013-11-10 01:34:57 -0800558 Name defaultIdentity = Name(identity.toStdString());
559 Name defaultKeyName = m_keychain->getIdentityManager()->getPublicStorage()->getDefaultKeyNameForIdentity(defaultIdentity);
Yingdi Yu711f5892013-11-09 22:18:26 -0800560 if(defaultKeyName.size() == 0)
Yingdi Yue433a502013-11-10 01:34:57 -0800561 {
562 showWarning(QString::fromStdString("Corresponding key is missing!\nHave you created the key?"));
563 return;
564 }
Yingdi Yu711f5892013-11-09 22:18:26 -0800565 Name defaultCertName = m_keychain->getIdentityManager()->getPublicStorage()->getDefaultCertificateNameForKey(defaultKeyName);
566 if(defaultCertName.size() == 0)
Yingdi Yue433a502013-11-10 01:34:57 -0800567 {
568 showWarning(QString::fromStdString("Corresponding certificate is missing!\nHave you installed the certificate?"));
569 return;
570 }
571 m_defaultIdentity = defaultIdentity;
Yingdi Yue35bdb82013-11-07 11:32:40 -0800572 m_profileEditor->setCurrentIdentity(m_defaultIdentity);
Yingdi Yu46948282013-11-06 18:43:31 -0800573 m_nickName = nickName.toStdString();
Yingdi Yueda39aa2013-10-23 23:07:29 -0700574 m_handler->clearInterestFilter(m_inviteListenPrefix);
Yingdi Yuae8217c2013-11-09 00:03:26 -0800575 m_contactManager->setDefaultIdentity(m_defaultIdentity);
Yingdi Yu46948282013-11-06 18:43:31 -0800576 setInvitationListener();
Yingdi Yub2e747d2013-11-05 23:06:43 -0800577 collectEndorsement();
Yingdi Yueda39aa2013-10-23 23:07:29 -0700578}
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700579
580void
Yingdi Yu3b318c12013-10-15 17:54:00 -0700581ContactPanel::openProfileEditor()
Yingdi Yu0269c872013-10-16 13:16:49 -0700582{ m_profileEditor->show(); }
Yingdi Yu3b318c12013-10-15 17:54:00 -0700583
Yingdi Yu0269c872013-10-16 13:16:49 -0700584void
585ContactPanel::openAddContactPanel()
586{ m_addContactPanel->show(); }
Yingdi Yu3b318c12013-10-15 17:54:00 -0700587
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700588void
Yingdi Yuae8217c2013-11-09 00:03:26 -0800589ContactPanel::openBrowseContactDialog()
590{
591 m_browseContactDialog->show();
592 emit refreshCertDirectory();
593}
594
595void
596ContactPanel::removeContactButton()
597{
598 QItemSelectionModel* selectionModel = ui->ContactList->selectionModel();
599 QModelIndexList selectedList = selectionModel->selectedIndexes();
600 QModelIndexList::iterator it = selectedList.begin();
601 for(; it != selectedList.end(); it++)
602 {
603 string alias = m_contactListModel->data(*it, Qt::DisplayRole).toString().toStdString();
604 vector<Ptr<ContactItem> >::iterator contactIt = m_contactList.begin();
605 for(; contactIt != m_contactList.end(); contactIt++)
606 {
607 if((*contactIt)->getAlias() == alias)
608 {
609 m_contactManager->getContactStorage()->removeContact((*contactIt)->getNameSpace());
610 m_contactList.erase(contactIt);
611 break;
612 }
613 }
614 }
615 refreshContactList();
616}
617
618void
Yingdi Yueda39aa2013-10-23 23:07:29 -0700619ContactPanel::openInvitationDialog()
620{ m_invitationDialog->show(); }
621
622void
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700623ContactPanel::refreshContactList()
624{
625 m_contactList = m_contactManager->getContactItemList();
626 QStringList contactNameList;
627 for(int i = 0; i < m_contactList.size(); i++)
Yingdi Yu83eae842013-11-06 22:07:38 -0800628 contactNameList << QString::fromStdString(m_contactList[i]->getAlias());
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700629
630 m_contactListModel->setStringList(contactNameList);
631}
632
633void
634ContactPanel::showContextMenu(const QPoint& pos)
635{
636 QMenu menu(ui->ContactList);
637 menu.addAction(m_menuInvite);
Yingdi Yu595aadc2013-10-21 15:01:40 -0700638 connect(m_menuInvite, SIGNAL(triggered()),
639 this, SLOT(openStartChatDialog()));
Yingdi Yu83eae842013-11-06 22:07:38 -0800640 menu.addSeparator();
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700641 menu.addAction(m_menuAlias);
642 connect(m_menuAlias, SIGNAL(triggered()),
643 this, SLOT(openSetAliasDialog()));
644 menu.exec(ui->ContactList->mapToGlobal(pos));
645
646}
647
648void
649ContactPanel::openSetAliasDialog()
650{
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800651 m_setAliasDialog->setTargetIdentity(m_currentSelectedContact->getNameSpace().toUri());
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700652 m_setAliasDialog->show();
653}
654
Yingdi Yu595aadc2013-10-21 15:01:40 -0700655void
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700656ContactPanel::openSettingDialog()
657{
Yingdi Yu46948282013-11-06 18:43:31 -0800658 m_settingDialog->setIdentity(m_defaultIdentity.toUri(), m_nickName);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700659 m_settingDialog->show();
660}
661
662void
Yingdi Yu595aadc2013-10-21 15:01:40 -0700663ContactPanel::openStartChatDialog()
664{
Yingdi Yu595aadc2013-10-21 15:01:40 -0700665 Name chatroom("/ndn/broadcast/chronos");
Yingdi Yu7989eb22013-10-31 17:38:22 -0700666 chatroom.append(string("chatroom-") + getRandomString());
Yingdi Yu595aadc2013-10-21 15:01:40 -0700667
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800668 m_startChatDialog->setInvitee(m_currentSelectedContact->getNameSpace().toUri(), chatroom.toUri());
Yingdi Yu595aadc2013-10-21 15:01:40 -0700669 m_startChatDialog->show();
670}
671
Yingdi Yu7989eb22013-10-31 17:38:22 -0700672// For inviter
Yingdi Yu595aadc2013-10-21 15:01:40 -0700673void
674ContactPanel::startChatroom(const QString& chatroom, const QString& invitee, bool isIntroducer)
675{
Yingdi Yu7989eb22013-10-31 17:38:22 -0700676 Name chatroomName(chatroom.toUtf8().constData());
Yingdi Yu72781e52013-11-06 23:00:21 -0800677
678 Name inviteeNamespace(invitee.toStdString());
679 Ptr<ContactItem> inviteeItem = m_contactManager->getContact(inviteeNamespace);
680
Yingdi Yue6476cd2013-11-06 18:51:19 -0800681 ChatDialog* chatDialog = new ChatDialog(m_contactManager, chatroomName, m_localPrefix, m_defaultIdentity, m_nickName);
Yingdi Yueda39aa2013-10-23 23:07:29 -0700682 m_chatDialogs.insert(pair <Name, ChatDialog*> (chatroomName, chatDialog));
Yingdi Yu46948282013-11-06 18:43:31 -0800683
684 connect(chatDialog, SIGNAL(closeChatDialog(const ndn::Name&)),
685 this, SLOT(removeChatDialog(const ndn::Name&)));
Yingdi Yu8e135832013-11-09 20:12:31 -0800686 connect(chatDialog, SIGNAL(noNdnConnection(const QString&)),
687 this, SLOT(showError(const QString&)));
Yingdi Yu0aca2652013-11-10 10:47:44 -0800688 connect(chatDialog, SIGNAL(inivationRejection(const QString&)),
689 this, SLOT(showWarning(const QString&)));
Yingdi Yu46948282013-11-06 18:43:31 -0800690
Yingdi Yue6476cd2013-11-06 18:51:19 -0800691 // send invitation
Yingdi Yu7989eb22013-10-31 17:38:22 -0700692 chatDialog->sendInvitation(inviteeItem, isIntroducer);
Yingdi Yueda39aa2013-10-23 23:07:29 -0700693
694 chatDialog->show();
Yingdi Yu595aadc2013-10-21 15:01:40 -0700695}
696
Yingdi Yu7989eb22013-10-31 17:38:22 -0700697// For Invitee
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700698void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700699ContactPanel::startChatroom2(const ChronosInvitation& invitation,
700 const security::IdentityCertificate& identityCertificate)
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700701{
Yingdi Yu72781e52013-11-06 23:00:21 -0800702 Ptr<ContactItem> inviterItem = m_contactManager->getContact(invitation.getInviterNameSpace());
703
Yingdi Yu7989eb22013-10-31 17:38:22 -0700704 Name chatroomName("/ndn/broadcast/chronos");
705 chatroomName.append(invitation.getChatroom());
Yingdi Yu72781e52013-11-06 23:00:21 -0800706
Yingdi Yue6476cd2013-11-06 18:51:19 -0800707 ChatDialog* chatDialog = new ChatDialog(m_contactManager, chatroomName, m_localPrefix, m_defaultIdentity, m_nickName, true);
Yingdi Yu83eae842013-11-06 22:07:38 -0800708
Yingdi Yu46948282013-11-06 18:43:31 -0800709 connect(chatDialog, SIGNAL(closeChatDialog(const ndn::Name&)),
710 this, SLOT(removeChatDialog(const ndn::Name&)));
Yingdi Yu8e135832013-11-09 20:12:31 -0800711 connect(chatDialog, SIGNAL(noNdnConnection(const QString&)),
712 this, SLOT(showError(const QString&)));
Yingdi Yu0aca2652013-11-10 10:47:44 -0800713 connect(chatDialog, SIGNAL(inivationRejection(const QString&)),
714 this, SLOT(showWarning(const QString&)));
Yingdi Yu7989eb22013-10-31 17:38:22 -0700715
Yingdi Yue6476cd2013-11-06 18:51:19 -0800716 chatDialog->addChatDataRule(invitation.getInviterPrefix(), identityCertificate, true);
Yingdi Yu83eae842013-11-06 22:07:38 -0800717 chatDialog->publishIntroCert(identityCertificate, true);
Yingdi Yu7989eb22013-10-31 17:38:22 -0700718
Yingdi Yu7989eb22013-10-31 17:38:22 -0700719 chatDialog->addTrustAnchor(inviterItem->getSelfEndorseCertificate());
720
721 m_chatDialogs.insert(pair <Name, ChatDialog*> (chatroomName, chatDialog));
722
723 chatDialog->show();
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700724}
725
726void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700727ContactPanel::acceptInvitation(const ChronosInvitation& invitation,
728 const security::IdentityCertificate& identityCertificate)
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700729{
730 string prefix = m_localPrefix.toUri();
Yingdi Yu7989eb22013-10-31 17:38:22 -0700731 m_handler->publishDataByIdentity (invitation.getInterestName(), prefix);
Yingdi Yu7989eb22013-10-31 17:38:22 -0700732 startChatroom2(invitation, identityCertificate);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700733}
734
735void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700736ContactPanel::rejectInvitation(const ChronosInvitation& invitation)
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700737{
Yingdi Yue9195fd2013-11-08 14:13:42 -0800738 string empty("nack");
Yingdi Yu7989eb22013-10-31 17:38:22 -0700739 m_handler->publishDataByIdentity (invitation.getInterestName(), empty);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700740}
741
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800742void
743ContactPanel::isIntroducerChanged(int state)
744{
745 if(state == Qt::Checked)
746 {
747 ui->addScope->setEnabled(true);
748 ui->deleteScope->setEnabled(true);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800749 ui->trustScopeList->setEnabled(true);
750
751 string filter("contact_namespace = '");
752 filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'");
Yingdi Yub2e747d2013-11-05 23:06:43 -0800753
754 m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
755 m_trustScopeModel->setTable("TrustScope");
756 m_trustScopeModel->setFilter(filter.c_str());
757 m_trustScopeModel->select();
758 m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
759 m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact"));
760 m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope"));
Yingdi Yub2e747d2013-11-05 23:06:43 -0800761
762 ui->trustScopeList->setModel(m_trustScopeModel);
763 ui->trustScopeList->setColumnHidden(0, true);
764 ui->trustScopeList->setColumnHidden(1, true);
765 ui->trustScopeList->show();
766
767 m_currentSelectedContact->setIsIntroducer(true);
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800768 }
769 else
770 {
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800771 ui->addScope->setEnabled(false);
772 ui->deleteScope->setEnabled(false);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800773
774 string filter("contact_namespace = '");
775 filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'");
776
777 m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
778 m_trustScopeModel->setTable("TrustScope");
779 m_trustScopeModel->setFilter(filter.c_str());
780 m_trustScopeModel->select();
781 m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
782 m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact"));
783 m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope"));
784
785 ui->trustScopeList->setModel(m_trustScopeModel);
786 ui->trustScopeList->setColumnHidden(0, true);
787 ui->trustScopeList->setColumnHidden(1, true);
788 ui->trustScopeList->show();
789
790 ui->trustScopeList->setEnabled(false);
791
792 m_currentSelectedContact->setIsIntroducer(false);
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800793 }
Yingdi Yub2e747d2013-11-05 23:06:43 -0800794 m_contactManager->getContactStorage()->updateIsIntroducer(m_currentSelectedContact->getNameSpace(), m_currentSelectedContact->isIntroducer());
795}
796
797void
798ContactPanel::addScopeClicked()
799{
800 int rowCount = m_trustScopeModel->rowCount();
801 QSqlRecord record;
802 QSqlField identityField("contact_namespace", QVariant::String);
803 record.append(identityField);
804 record.setValue("contact_namespace", QString(m_currentSelectedContact->getNameSpace().toUri().c_str()));
805 m_trustScopeModel->insertRow(rowCount);
806 m_trustScopeModel->setRecord(rowCount, record);
807}
808
809void
810ContactPanel::deleteScopeClicked()
811{
812 QItemSelectionModel* selectionModel = ui->trustScopeList->selectionModel();
813 QModelIndexList indexList = selectionModel->selectedIndexes();
814
815 int i = indexList.size() - 1;
816 for(; i >= 0; i--)
817 m_trustScopeModel->removeRow(indexList[i].row());
818
819 m_trustScopeModel->submitAll();
820}
821
822void
823ContactPanel::saveScopeClicked()
Yingdi Yu83eae842013-11-06 22:07:38 -0800824{ m_trustScopeModel->submitAll(); }
Yingdi Yub2e747d2013-11-05 23:06:43 -0800825
826void
827ContactPanel::endorseButtonClicked()
828{
829 m_endorseDataModel->submitAll();
830 m_contactManager->updateEndorseCertificate(m_currentSelectedContact->getNameSpace(), m_defaultIdentity);
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800831}
Yingdi Yu595aadc2013-10-21 15:01:40 -0700832
Yingdi Yu46948282013-11-06 18:43:31 -0800833void
834ContactPanel::removeChatDialog(const ndn::Name& chatroomName)
835{
836 map<Name, ChatDialog*>::iterator it = m_chatDialogs.find(chatroomName);
Yingdi Yu83eae842013-11-06 22:07:38 -0800837
838 ChatDialog* deletedChat = NULL;
Yingdi Yu46948282013-11-06 18:43:31 -0800839 if(it != m_chatDialogs.end())
840 {
Yingdi Yu46948282013-11-06 18:43:31 -0800841 deletedChat = it->second;
842 m_chatDialogs.erase(it);
843 }
Yingdi Yu83eae842013-11-06 22:07:38 -0800844 if (deletedChat != NULL)
845 delete deletedChat;
Yingdi Yu46948282013-11-06 18:43:31 -0800846}
847
Yingdi Yu847aa862013-10-09 16:35:53 -0700848#if WAF
849#include "contactpanel.moc"
850#include "contactpanel.cpp.moc"
851#endif