blob: 4ee8d716a689b66a358d38e0524bb9eea6989a5f [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 Yu978b3ae2013-10-23 11:50:51 -0700151
Yingdi Yu46948282013-11-06 18:43:31 -0800152 connect(m_settingDialog, SIGNAL(identitySet(const QString&, const QString&)),
153 this, SLOT(updateDefaultIdentity(const QString&, const QString&)));
Yingdi Yueda39aa2013-10-23 23:07:29 -0700154
155 connect(this, SIGNAL(newInvitationReady()),
156 this, SLOT(openInvitationDialog()));
Yingdi Yu595aadc2013-10-21 15:01:40 -0700157
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800158 connect(ui->isIntroducer, SIGNAL(stateChanged(int)),
159 this, SLOT(isIntroducerChanged(int)));
Yingdi Yub2e747d2013-11-05 23:06:43 -0800160
161 connect(ui->addScope, SIGNAL(clicked()),
162 this, SLOT(addScopeClicked()));
Yingdi Yub2e747d2013-11-05 23:06:43 -0800163 connect(ui->deleteScope, SIGNAL(clicked()),
164 this, SLOT(deleteScopeClicked()));
Yingdi Yub2e747d2013-11-05 23:06:43 -0800165 connect(ui->saveButton, SIGNAL(clicked()),
166 this, SLOT(saveScopeClicked()));
167
168 connect(ui->endorseButton, SIGNAL(clicked()),
169 this, SLOT(endorseButtonClicked()));
Yingdi Yu847aa862013-10-09 16:35:53 -0700170}
171
172ContactPanel::~ContactPanel()
173{
Yingdi Yueda39aa2013-10-23 23:07:29 -0700174 delete ui;
175 delete m_contactListModel;
Yingdi Yu46948282013-11-06 18:43:31 -0800176 delete m_startChatDialog;
177 delete m_invitationDialog;
178 delete m_settingDialog;
179
Yingdi Yueda39aa2013-10-23 23:07:29 -0700180 delete m_profileEditor;
181 delete m_addContactPanel;
Yingdi Yuae8217c2013-11-09 00:03:26 -0800182 delete m_browseContactDialog;
Yingdi Yu46948282013-11-06 18:43:31 -0800183 delete m_setAliasDialog;
184
Yingdi Yub2e747d2013-11-05 23:06:43 -0800185 delete m_trustScopeModel;
186 delete m_endorseDataModel;
Yingdi Yu46948282013-11-06 18:43:31 -0800187 delete m_endorseComboBoxDelegate;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700188
Yingdi Yueda39aa2013-10-23 23:07:29 -0700189 delete m_menuInvite;
Yingdi Yu46948282013-11-06 18:43:31 -0800190 delete m_menuAlias;
Yingdi Yueda39aa2013-10-23 23:07:29 -0700191
192 map<Name, ChatDialog*>::iterator it = m_chatDialogs.begin();
193 for(; it != m_chatDialogs.end(); it++)
194 delete it->second;
Yingdi Yu847aa862013-10-09 16:35:53 -0700195}
196
Yingdi Yu40eca752013-10-10 15:00:58 -0700197void
Yingdi Yu46948282013-11-06 18:43:31 -0800198ContactPanel::createAction()
199{
200 m_menuInvite = new QAction("&Chat", this);
201 m_menuAlias = new QAction("&Set Alias", this);
202}
203
204void
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700205ContactPanel::openDB()
206{
207 QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
208 QString path = (QDir::home().path());
209 path.append(QDir::separator()).append(".chronos").append(QDir::separator()).append("chronos.db");
210 db.setDatabaseName(path);
211 bool ok = db.open();
Yingdi Yu46948282013-11-06 18:43:31 -0800212 _LOG_DEBUG("DB opened: " << std::boolalpha << ok );
Yingdi Yub2e747d2013-11-05 23:06:43 -0800213
214 m_trustScopeModel = new QSqlTableModel;
215 m_endorseDataModel = new QSqlTableModel;
216 m_endorseComboBoxDelegate = new EndorseComboBoxDelegate;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700217}
218
219void
220ContactPanel::setKeychain()
221{
Yingdi Yu9b34b1f2013-11-01 17:37:51 -0700222 m_panelPolicyManager = Ptr<PanelPolicyManager>::Create();
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700223
224 vector<Ptr<ContactItem> >::const_iterator it = m_contactList.begin();
225 for(; it != m_contactList.end(); it++)
Yingdi Yue35bdb82013-11-07 11:32:40 -0800226 {
227 m_panelPolicyManager->addTrustAnchor((*it)->getSelfEndorseCertificate());
228 }
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700229
Yingdi Yu9b34b1f2013-11-01 17:37:51 -0700230 m_keychain = Ptr<security::Keychain>(new security::Keychain(Ptr<security::IdentityManager>::Create(),
231 m_panelPolicyManager,
232 NULL));
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700233}
234
235void
Yingdi Yufdb8ab82013-11-10 01:38:21 -0800236ContactPanel::setLocalPrefix(int retry)
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700237{
238 Ptr<Interest> interest = Ptr<Interest>(new Interest(Name("/local/ndn/prefix")));
239 interest->setChildSelector(Interest::CHILD_RIGHT);
240
241 Ptr<Closure> closure = Ptr<Closure>(new Closure(boost::bind(&ContactPanel::onLocalPrefixVerified,
242 this,
243 _1),
244 boost::bind(&ContactPanel::onLocalPrefixTimeout,
245 this,
246 _1,
Yingdi Yufdb8ab82013-11-10 01:38:21 -0800247 _2,
248 10),
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700249 boost::bind(&ContactPanel::onLocalPrefixVerified,
250 this,
251 _1)));
252
253 m_handler->sendInterest(interest, closure);
254}
255
256void
257ContactPanel::onLocalPrefixVerified(Ptr<Data> data)
258{
259 string originPrefix(data->content().buf(), data->content().size());
260 string prefix = QString::fromStdString (originPrefix).trimmed ().toUtf8().constData();
261 string randomSuffix = getRandomString();
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700262 m_localPrefix = Name(prefix);
Yingdi Yue433a502013-11-10 01:34:57 -0800263
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700264}
265
266void
Yingdi Yufdb8ab82013-11-10 01:38:21 -0800267ContactPanel::onLocalPrefixTimeout(Ptr<Closure> closure, Ptr<Interest> interest, int retry)
Yingdi Yu7989eb22013-10-31 17:38:22 -0700268{
Yingdi Yufdb8ab82013-11-10 01:38:21 -0800269 if(retry > 0)
Yingdi Yua66183f2013-11-10 10:32:18 -0800270 {
271 setLocalPrefix(retry - 1);
272 return;
273 }
274 else{
275 m_localPrefix = Name("/private/local");
276 }
Yingdi Yu7989eb22013-10-31 17:38:22 -0700277}
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700278
279void
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700280ContactPanel::setInvitationListener()
281{
Yingdi Yu46948282013-11-06 18:43:31 -0800282 m_inviteListenPrefix = Name("/ndn/broadcast/chronos/invitation");
283 m_inviteListenPrefix.append(m_defaultIdentity);
284 _LOG_DEBUG("Listening for invitation on prefix: " << m_inviteListenPrefix.toUri());
285 m_handler->setInterestFilter (m_inviteListenPrefix,
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700286 boost::bind(&ContactPanel::onInvitation,
287 this,
288 _1));
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700289}
290
291void
292ContactPanel::onInvitation(Ptr<Interest> interest)
293{
Yingdi Yu46948282013-11-06 18:43:31 -0800294 _LOG_DEBUG("Receive invitation!" << interest->getName().toUri());
Yingdi Yue35bdb82013-11-07 11:32:40 -0800295
296 Ptr<ChronosInvitation> invitation = NULL;
297 try{
298 invitation = Ptr<ChronosInvitation>(new ChronosInvitation(interest->getName()));
299 }catch(exception& e){
300 _LOG_ERROR("Exception: " << e.what());
301 return;
302 }
303
Yingdi Yu46948282013-11-06 18:43:31 -0800304 Name chatroomName("/ndn/broadcast/chronos");
305 chatroomName.append(invitation->getChatroom());
306 map<Name, ChatDialog*>::iterator it = m_chatDialogs.find(chatroomName);
307 if(it != m_chatDialogs.end())
308 {
Yingdi Yue35bdb82013-11-07 11:32:40 -0800309 _LOG_ERROR("Exisiting chatroom!");
Yingdi Yu46948282013-11-06 18:43:31 -0800310 return;
311 }
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700312
Yingdi Yuaf305d72013-11-10 11:54:02 -0800313 Ptr<security::Publickey> keyPtr = m_panelPolicyManager->getTrustedKey(invitation->getInviterCertificateName());
314 if(NULL != keyPtr && security::PolicyManager::verifySignature(invitation->getSignedBlob(), invitation->getSignatureBits(), *keyPtr))
315 {
316 Ptr<security::IdentityCertificate> certificate = Ptr<security::IdentityCertificate>::Create();
Yingdi Yu1ecf81f2013-11-10 12:25:43 -0800317 // 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 -0800318 certificate->setName(invitation->getInviterCertificateName());
Yingdi Yu1ecf81f2013-11-10 12:25:43 -0800319 bool findCert = false;
320 vector<Ptr<ContactItem> >::const_iterator it = m_contactList.begin();
321 for(; it != m_contactList.end(); it++)
322 {
323 if((*it)->getNameSpace() == invitation->getInviterNameSpace())
324 {
325 certificate->setNotBefore((*it)->getSelfEndorseCertificate().getNotBefore());
326 certificate->setNotAfter((*it)->getSelfEndorseCertificate().getNotAfter());
327 findCert = true;
328 break;
329 }
330 }
331 if(findCert == false)
332 {
333 _LOG_ERROR("No SelfEndorseCertificate found!");
334 return;
335 }
Yingdi Yuaf305d72013-11-10 11:54:02 -0800336 certificate->setPublicKeyInfo(*keyPtr);
337 popChatInvitation(invitation, invitation->getInviterNameSpace(), certificate);
338 return;
339 }
340
Yingdi Yu9b34b1f2013-11-01 17:37:51 -0700341 Ptr<Interest> newInterest = Ptr<Interest>(new Interest(invitation->getInviterCertificateName()));
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700342 Ptr<Closure> closure = Ptr<Closure>(new Closure(boost::bind(&ContactPanel::onInvitationCertVerified,
343 this,
344 _1,
Yingdi Yu9b34b1f2013-11-01 17:37:51 -0700345 invitation),
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700346 boost::bind(&ContactPanel::onTimeout,
347 this,
348 _1,
349 _2),
350 boost::bind(&ContactPanel::onUnverified,
351 this,
352 _1)));
353 m_handler->sendInterest(newInterest, closure);
354}
355
356void
Yingdi Yu46948282013-11-06 18:43:31 -0800357ContactPanel::onInvitationCertVerified(Ptr<Data> data,
358 Ptr<ChronosInvitation> invitation)
359{
360 using namespace ndn::security;
361 Ptr<IdentityCertificate> certificate = Ptr<IdentityCertificate>(new IdentityCertificate(*data));
362
363 if(PolicyManager::verifySignature(invitation->getSignedBlob(), invitation->getSignatureBits(), certificate->getPublicKeyInfo()))
364 {
365 Name keyName = certificate->getPublicKeyName();
366 Name inviterNameSpace = keyName.getPrefix(keyName.size() - 1);
367 popChatInvitation(invitation, inviterNameSpace, certificate);
368 }
369}
370
371void
372ContactPanel::onUnverified(Ptr<Data> data)
373{}
374
375void
376ContactPanel::onTimeout(Ptr<Closure> closure, Ptr<Interest> interest)
377{}
378
379void
380ContactPanel::popChatInvitation(Ptr<ChronosInvitation> invitation,
381 const Name& inviterNameSpace,
382 Ptr<security::IdentityCertificate> certificate)
383{
384 string alias;
385 vector<Ptr<ContactItem> >::iterator it = m_contactList.begin();
386 for(; it != m_contactList.end(); it++)
387 if((*it)->getNameSpace() == inviterNameSpace)
388 alias = (*it)->getAlias();
389
390 if(it != m_contactList.end())
391 return;
392
393 m_invitationDialog->setInvitation(alias, invitation, certificate);
394 emit newInvitationReady();
395}
396
397void
398ContactPanel::collectEndorsement()
399{
400 m_collectStatus = Ptr<vector<bool> >::Create();
401 m_collectStatus->assign(m_contactList.size(), false);
402
403 vector<Ptr<ContactItem> >::iterator it = m_contactList.begin();
404 int count = 0;
405 for(; it != m_contactList.end(); it++, count++)
406 {
407 Name interestName = (*it)->getNameSpace();
408 interestName.append("DNS").append(m_defaultIdentity).append("ENDORSEE");
409 Ptr<Interest> interest = Ptr<Interest>(new Interest(interestName));
410 interest->setChildSelector(Interest::CHILD_RIGHT);
411 interest->setInterestLifetime(1);
412
413 Ptr<Closure> closure = Ptr<Closure>(new Closure(boost::bind(&ContactPanel::onDnsEndorseeVerified,
414 this,
415 _1,
416 count),
417 boost::bind(&ContactPanel::onDnsEndorseeTimeout,
418 this,
419 _1,
420 _2,
421 count),
422 boost::bind(&ContactPanel::onDnsEndorseeUnverified,
423 this,
424 _1,
425 count)));
426
427 m_handler->sendInterest(interest, closure);
428 }
429}
430
431void
432ContactPanel::onDnsEndorseeVerified(Ptr<Data> data, int count)
433{
434 Ptr<Blob> contentBlob = Ptr<Blob>(new Blob(data->content().buf(), data->content().size()));
435 Ptr<Data> endorseData = Data::decodeFromWire(contentBlob);
436 EndorseCertificate endorseCertificate(*endorseData);
437
438 m_contactManager->getContactStorage()->updateCollectEndorse(endorseCertificate);
439
440 updateCollectStatus(count);
441}
442
443void
444ContactPanel::onDnsEndorseeTimeout(Ptr<Closure> closure, Ptr<Interest> interest, int count)
445{ updateCollectStatus(count); }
446
447void
448ContactPanel::onDnsEndorseeUnverified(Ptr<Data> data, int count)
449{ updateCollectStatus(count); }
450
451void
452ContactPanel::updateCollectStatus(int count)
453{
454 m_collectStatus->at(count) = true;
455 vector<bool>::const_iterator it = m_collectStatus->begin();
456 for(; it != m_collectStatus->end(); it++)
457 if(*it == false)
458 return;
459
460 m_contactManager->publishEndorsedDataInDns(m_defaultIdentity);
461}
462
463static std::string chars("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789");
464
465string
466ContactPanel::getRandomString()
467{
468 string randStr;
469 boost::random::random_device rng;
470 boost::random::uniform_int_distribution<> index_dist(0, chars.size() - 1);
471 for (int i = 0; i < 10; i ++)
472 {
473 randStr += chars[index_dist(rng)];
474 }
475 return randStr;
476}
477
478void
Yingdi Yu8e135832013-11-09 20:12:31 -0800479ContactPanel::showError(const QString& msg){
480 QMessageBox::critical(this, tr("Chronos"), msg, QMessageBox::Ok);
481 exit(1);
482}
483
484void
Yingdi Yue433a502013-11-10 01:34:57 -0800485ContactPanel::showWarning(const QString& msg){
486 QMessageBox::information(this, tr("Chronos"), msg);
487}
488
489void
Yingdi Yu40eca752013-10-10 15:00:58 -0700490ContactPanel::updateSelection(const QItemSelection &selected,
491 const QItemSelection &deselected)
492{
493 QModelIndexList items = selected.indexes();
494 QString text = m_contactListModel->data(items.first(), Qt::DisplayRole).toString();
Yingdi Yu46948282013-11-06 18:43:31 -0800495 string alias = text.toStdString();
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700496
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700497 int i = 0;
498 for(; i < m_contactList.size(); i++)
499 {
500 if(alias == m_contactList[i]->getAlias())
501 break;
502 }
503
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800504 m_currentSelectedContact = m_contactList[i];
Yingdi Yu83eae842013-11-06 22:07:38 -0800505 ui->NameData->setText(QString::fromStdString(m_currentSelectedContact->getName()));
506 ui->NameSpaceData->setText(QString::fromStdString(m_currentSelectedContact->getNameSpace().toUri()));
507 ui->InstitutionData->setText(QString::fromStdString(m_currentSelectedContact->getInstitution()));
Yingdi Yu595aadc2013-10-21 15:01:40 -0700508
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800509 if(m_currentSelectedContact->isIntroducer())
510 {
511 ui->isIntroducer->setChecked(true);
512 ui->addScope->setEnabled(true);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800513 ui->deleteScope->setEnabled(true);
514 ui->trustScopeList->setEnabled(true);
515
516 string filter("contact_namespace = '");
517 filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'");
518
519 m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
520 m_trustScopeModel->setTable("TrustScope");
521 m_trustScopeModel->setFilter(filter.c_str());
522 m_trustScopeModel->select();
523 m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
524 m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact"));
525 m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope"));
526
Yingdi Yub2e747d2013-11-05 23:06:43 -0800527 ui->trustScopeList->setModel(m_trustScopeModel);
528 ui->trustScopeList->setColumnHidden(0, true);
529 ui->trustScopeList->setColumnHidden(1, true);
530 ui->trustScopeList->show();
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800531 }
532 else
533 {
534 ui->isIntroducer->setChecked(false);
535 ui->addScope->setEnabled(false);
536 ui->deleteScope->setEnabled(false);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800537
538 string filter("contact_namespace = '");
539 filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'");
540
541 m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
542 m_trustScopeModel->setTable("TrustScope");
543 m_trustScopeModel->setFilter(filter.c_str());
544 m_trustScopeModel->select();
545 m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
546 m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact"));
547 m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope"));
548
549 ui->trustScopeList->setModel(m_trustScopeModel);
550 ui->trustScopeList->setColumnHidden(0, true);
551 ui->trustScopeList->setColumnHidden(1, true);
552 ui->trustScopeList->show();
553
554 ui->trustScopeList->setEnabled(false);
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800555 }
Yingdi Yub2e747d2013-11-05 23:06:43 -0800556
557 string filter("profile_identity = '");
558 filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'");
559
560 m_endorseDataModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
561 m_endorseDataModel->setTable("ContactProfile");
562 m_endorseDataModel->setFilter(filter.c_str());
563 m_endorseDataModel->select();
564
565 m_endorseDataModel->setHeaderData(0, Qt::Horizontal, QObject::tr("Identity"));
566 m_endorseDataModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Type"));
567 m_endorseDataModel->setHeaderData(2, Qt::Horizontal, QObject::tr("Value"));
568 m_endorseDataModel->setHeaderData(3, Qt::Horizontal, QObject::tr("Endorse"));
569
570 ui->endorseList->setModel(m_endorseDataModel);
571 ui->endorseList->setColumnHidden(0, true);
572 ui->endorseList->resizeColumnToContents(1);
573 ui->endorseList->resizeColumnToContents(2);
574 ui->endorseList->setItemDelegateForColumn(3, m_endorseComboBoxDelegate);
575 ui->endorseList->show();
Yingdi Yu40eca752013-10-10 15:00:58 -0700576}
Yingdi Yu847aa862013-10-09 16:35:53 -0700577
Yingdi Yu3b318c12013-10-15 17:54:00 -0700578void
Yingdi Yu46948282013-11-06 18:43:31 -0800579ContactPanel::updateDefaultIdentity(const QString& identity, const QString& nickName)
Yingdi Yueda39aa2013-10-23 23:07:29 -0700580{
Yingdi Yu711f5892013-11-09 22:18:26 -0800581 // _LOG_DEBUG(identity.toStdString());
Yingdi Yue433a502013-11-10 01:34:57 -0800582 Name defaultIdentity = Name(identity.toStdString());
583 Name defaultKeyName = m_keychain->getIdentityManager()->getPublicStorage()->getDefaultKeyNameForIdentity(defaultIdentity);
Yingdi Yu711f5892013-11-09 22:18:26 -0800584 if(defaultKeyName.size() == 0)
Yingdi Yue433a502013-11-10 01:34:57 -0800585 {
586 showWarning(QString::fromStdString("Corresponding key is missing!\nHave you created the key?"));
587 return;
588 }
Yingdi Yu711f5892013-11-09 22:18:26 -0800589 Name defaultCertName = m_keychain->getIdentityManager()->getPublicStorage()->getDefaultCertificateNameForKey(defaultKeyName);
590 if(defaultCertName.size() == 0)
Yingdi Yue433a502013-11-10 01:34:57 -0800591 {
592 showWarning(QString::fromStdString("Corresponding certificate is missing!\nHave you installed the certificate?"));
593 return;
594 }
595 m_defaultIdentity = defaultIdentity;
Yingdi Yue35bdb82013-11-07 11:32:40 -0800596 m_profileEditor->setCurrentIdentity(m_defaultIdentity);
Yingdi Yu46948282013-11-06 18:43:31 -0800597 m_nickName = nickName.toStdString();
Yingdi Yueda39aa2013-10-23 23:07:29 -0700598 m_handler->clearInterestFilter(m_inviteListenPrefix);
Yingdi Yuae8217c2013-11-09 00:03:26 -0800599 m_contactManager->setDefaultIdentity(m_defaultIdentity);
Yingdi Yu46948282013-11-06 18:43:31 -0800600 setInvitationListener();
Yingdi Yub2e747d2013-11-05 23:06:43 -0800601 collectEndorsement();
Yingdi Yueda39aa2013-10-23 23:07:29 -0700602}
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700603
604void
Yingdi Yu3b318c12013-10-15 17:54:00 -0700605ContactPanel::openProfileEditor()
Yingdi Yu0269c872013-10-16 13:16:49 -0700606{ m_profileEditor->show(); }
Yingdi Yu3b318c12013-10-15 17:54:00 -0700607
Yingdi Yu0269c872013-10-16 13:16:49 -0700608void
609ContactPanel::openAddContactPanel()
610{ m_addContactPanel->show(); }
Yingdi Yu3b318c12013-10-15 17:54:00 -0700611
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700612void
Yingdi Yuae8217c2013-11-09 00:03:26 -0800613ContactPanel::openBrowseContactDialog()
614{
615 m_browseContactDialog->show();
616 emit refreshCertDirectory();
617}
618
619void
620ContactPanel::removeContactButton()
621{
622 QItemSelectionModel* selectionModel = ui->ContactList->selectionModel();
623 QModelIndexList selectedList = selectionModel->selectedIndexes();
624 QModelIndexList::iterator it = selectedList.begin();
625 for(; it != selectedList.end(); it++)
626 {
627 string alias = m_contactListModel->data(*it, Qt::DisplayRole).toString().toStdString();
628 vector<Ptr<ContactItem> >::iterator contactIt = m_contactList.begin();
629 for(; contactIt != m_contactList.end(); contactIt++)
630 {
631 if((*contactIt)->getAlias() == alias)
632 {
633 m_contactManager->getContactStorage()->removeContact((*contactIt)->getNameSpace());
634 m_contactList.erase(contactIt);
635 break;
636 }
637 }
638 }
639 refreshContactList();
640}
641
642void
Yingdi Yueda39aa2013-10-23 23:07:29 -0700643ContactPanel::openInvitationDialog()
644{ m_invitationDialog->show(); }
645
646void
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700647ContactPanel::refreshContactList()
648{
649 m_contactList = m_contactManager->getContactItemList();
650 QStringList contactNameList;
651 for(int i = 0; i < m_contactList.size(); i++)
Yingdi Yu83eae842013-11-06 22:07:38 -0800652 contactNameList << QString::fromStdString(m_contactList[i]->getAlias());
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700653
654 m_contactListModel->setStringList(contactNameList);
655}
656
657void
658ContactPanel::showContextMenu(const QPoint& pos)
659{
660 QMenu menu(ui->ContactList);
661 menu.addAction(m_menuInvite);
Yingdi Yu595aadc2013-10-21 15:01:40 -0700662 connect(m_menuInvite, SIGNAL(triggered()),
663 this, SLOT(openStartChatDialog()));
Yingdi Yu83eae842013-11-06 22:07:38 -0800664 menu.addSeparator();
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700665 menu.addAction(m_menuAlias);
666 connect(m_menuAlias, SIGNAL(triggered()),
667 this, SLOT(openSetAliasDialog()));
668 menu.exec(ui->ContactList->mapToGlobal(pos));
669
670}
671
672void
673ContactPanel::openSetAliasDialog()
674{
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800675 m_setAliasDialog->setTargetIdentity(m_currentSelectedContact->getNameSpace().toUri());
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700676 m_setAliasDialog->show();
677}
678
Yingdi Yu595aadc2013-10-21 15:01:40 -0700679void
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700680ContactPanel::openSettingDialog()
681{
Yingdi Yu46948282013-11-06 18:43:31 -0800682 m_settingDialog->setIdentity(m_defaultIdentity.toUri(), m_nickName);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700683 m_settingDialog->show();
684}
685
686void
Yingdi Yu595aadc2013-10-21 15:01:40 -0700687ContactPanel::openStartChatDialog()
688{
Yingdi Yu595aadc2013-10-21 15:01:40 -0700689 Name chatroom("/ndn/broadcast/chronos");
Yingdi Yu7989eb22013-10-31 17:38:22 -0700690 chatroom.append(string("chatroom-") + getRandomString());
Yingdi Yu595aadc2013-10-21 15:01:40 -0700691
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800692 m_startChatDialog->setInvitee(m_currentSelectedContact->getNameSpace().toUri(), chatroom.toUri());
Yingdi Yu595aadc2013-10-21 15:01:40 -0700693 m_startChatDialog->show();
694}
695
Yingdi Yu7989eb22013-10-31 17:38:22 -0700696// For inviter
Yingdi Yu595aadc2013-10-21 15:01:40 -0700697void
698ContactPanel::startChatroom(const QString& chatroom, const QString& invitee, bool isIntroducer)
699{
Yingdi Yu7989eb22013-10-31 17:38:22 -0700700 Name chatroomName(chatroom.toUtf8().constData());
Yingdi Yu72781e52013-11-06 23:00:21 -0800701
702 Name inviteeNamespace(invitee.toStdString());
703 Ptr<ContactItem> inviteeItem = m_contactManager->getContact(inviteeNamespace);
704
Yingdi Yue6476cd2013-11-06 18:51:19 -0800705 ChatDialog* chatDialog = new ChatDialog(m_contactManager, chatroomName, m_localPrefix, m_defaultIdentity, m_nickName);
Yingdi Yueda39aa2013-10-23 23:07:29 -0700706 m_chatDialogs.insert(pair <Name, ChatDialog*> (chatroomName, chatDialog));
Yingdi Yu46948282013-11-06 18:43:31 -0800707
708 connect(chatDialog, SIGNAL(closeChatDialog(const ndn::Name&)),
709 this, SLOT(removeChatDialog(const ndn::Name&)));
Yingdi Yu8e135832013-11-09 20:12:31 -0800710 connect(chatDialog, SIGNAL(noNdnConnection(const QString&)),
711 this, SLOT(showError(const QString&)));
Yingdi Yu0aca2652013-11-10 10:47:44 -0800712 connect(chatDialog, SIGNAL(inivationRejection(const QString&)),
713 this, SLOT(showWarning(const QString&)));
Yingdi Yu46948282013-11-06 18:43:31 -0800714
Yingdi Yue6476cd2013-11-06 18:51:19 -0800715 // send invitation
Yingdi Yu7989eb22013-10-31 17:38:22 -0700716 chatDialog->sendInvitation(inviteeItem, isIntroducer);
Yingdi Yueda39aa2013-10-23 23:07:29 -0700717
718 chatDialog->show();
Yingdi Yu595aadc2013-10-21 15:01:40 -0700719}
720
Yingdi Yu7989eb22013-10-31 17:38:22 -0700721// For Invitee
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700722void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700723ContactPanel::startChatroom2(const ChronosInvitation& invitation,
724 const security::IdentityCertificate& identityCertificate)
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700725{
Yingdi Yu72781e52013-11-06 23:00:21 -0800726 Ptr<ContactItem> inviterItem = m_contactManager->getContact(invitation.getInviterNameSpace());
727
Yingdi Yu7989eb22013-10-31 17:38:22 -0700728 Name chatroomName("/ndn/broadcast/chronos");
729 chatroomName.append(invitation.getChatroom());
Yingdi Yu72781e52013-11-06 23:00:21 -0800730
Yingdi Yue6476cd2013-11-06 18:51:19 -0800731 ChatDialog* chatDialog = new ChatDialog(m_contactManager, chatroomName, m_localPrefix, m_defaultIdentity, m_nickName, true);
Yingdi Yu83eae842013-11-06 22:07:38 -0800732
Yingdi Yu46948282013-11-06 18:43:31 -0800733 connect(chatDialog, SIGNAL(closeChatDialog(const ndn::Name&)),
734 this, SLOT(removeChatDialog(const ndn::Name&)));
Yingdi Yu8e135832013-11-09 20:12:31 -0800735 connect(chatDialog, SIGNAL(noNdnConnection(const QString&)),
736 this, SLOT(showError(const QString&)));
Yingdi Yu0aca2652013-11-10 10:47:44 -0800737 connect(chatDialog, SIGNAL(inivationRejection(const QString&)),
738 this, SLOT(showWarning(const QString&)));
Yingdi Yu7989eb22013-10-31 17:38:22 -0700739
Yingdi Yue6476cd2013-11-06 18:51:19 -0800740 chatDialog->addChatDataRule(invitation.getInviterPrefix(), identityCertificate, true);
Yingdi Yu83eae842013-11-06 22:07:38 -0800741 chatDialog->publishIntroCert(identityCertificate, true);
Yingdi Yu7989eb22013-10-31 17:38:22 -0700742
Yingdi Yu7989eb22013-10-31 17:38:22 -0700743 chatDialog->addTrustAnchor(inviterItem->getSelfEndorseCertificate());
744
745 m_chatDialogs.insert(pair <Name, ChatDialog*> (chatroomName, chatDialog));
746
747 chatDialog->show();
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700748}
749
750void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700751ContactPanel::acceptInvitation(const ChronosInvitation& invitation,
752 const security::IdentityCertificate& identityCertificate)
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700753{
754 string prefix = m_localPrefix.toUri();
Yingdi Yu7989eb22013-10-31 17:38:22 -0700755 m_handler->publishDataByIdentity (invitation.getInterestName(), prefix);
Yingdi Yu7989eb22013-10-31 17:38:22 -0700756 startChatroom2(invitation, identityCertificate);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700757}
758
759void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700760ContactPanel::rejectInvitation(const ChronosInvitation& invitation)
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700761{
Yingdi Yue9195fd2013-11-08 14:13:42 -0800762 string empty("nack");
Yingdi Yu7989eb22013-10-31 17:38:22 -0700763 m_handler->publishDataByIdentity (invitation.getInterestName(), empty);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700764}
765
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800766void
767ContactPanel::isIntroducerChanged(int state)
768{
769 if(state == Qt::Checked)
770 {
771 ui->addScope->setEnabled(true);
772 ui->deleteScope->setEnabled(true);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800773 ui->trustScopeList->setEnabled(true);
774
775 string filter("contact_namespace = '");
776 filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'");
Yingdi Yub2e747d2013-11-05 23:06:43 -0800777
778 m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
779 m_trustScopeModel->setTable("TrustScope");
780 m_trustScopeModel->setFilter(filter.c_str());
781 m_trustScopeModel->select();
782 m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
783 m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact"));
784 m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope"));
Yingdi Yub2e747d2013-11-05 23:06:43 -0800785
786 ui->trustScopeList->setModel(m_trustScopeModel);
787 ui->trustScopeList->setColumnHidden(0, true);
788 ui->trustScopeList->setColumnHidden(1, true);
789 ui->trustScopeList->show();
790
791 m_currentSelectedContact->setIsIntroducer(true);
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800792 }
793 else
794 {
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800795 ui->addScope->setEnabled(false);
796 ui->deleteScope->setEnabled(false);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800797
798 string filter("contact_namespace = '");
799 filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'");
800
801 m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
802 m_trustScopeModel->setTable("TrustScope");
803 m_trustScopeModel->setFilter(filter.c_str());
804 m_trustScopeModel->select();
805 m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
806 m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact"));
807 m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope"));
808
809 ui->trustScopeList->setModel(m_trustScopeModel);
810 ui->trustScopeList->setColumnHidden(0, true);
811 ui->trustScopeList->setColumnHidden(1, true);
812 ui->trustScopeList->show();
813
814 ui->trustScopeList->setEnabled(false);
815
816 m_currentSelectedContact->setIsIntroducer(false);
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800817 }
Yingdi Yub2e747d2013-11-05 23:06:43 -0800818 m_contactManager->getContactStorage()->updateIsIntroducer(m_currentSelectedContact->getNameSpace(), m_currentSelectedContact->isIntroducer());
819}
820
821void
822ContactPanel::addScopeClicked()
823{
824 int rowCount = m_trustScopeModel->rowCount();
825 QSqlRecord record;
826 QSqlField identityField("contact_namespace", QVariant::String);
827 record.append(identityField);
828 record.setValue("contact_namespace", QString(m_currentSelectedContact->getNameSpace().toUri().c_str()));
829 m_trustScopeModel->insertRow(rowCount);
830 m_trustScopeModel->setRecord(rowCount, record);
831}
832
833void
834ContactPanel::deleteScopeClicked()
835{
836 QItemSelectionModel* selectionModel = ui->trustScopeList->selectionModel();
837 QModelIndexList indexList = selectionModel->selectedIndexes();
838
839 int i = indexList.size() - 1;
840 for(; i >= 0; i--)
841 m_trustScopeModel->removeRow(indexList[i].row());
842
843 m_trustScopeModel->submitAll();
844}
845
846void
847ContactPanel::saveScopeClicked()
Yingdi Yu83eae842013-11-06 22:07:38 -0800848{ m_trustScopeModel->submitAll(); }
Yingdi Yub2e747d2013-11-05 23:06:43 -0800849
850void
851ContactPanel::endorseButtonClicked()
852{
853 m_endorseDataModel->submitAll();
854 m_contactManager->updateEndorseCertificate(m_currentSelectedContact->getNameSpace(), m_defaultIdentity);
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800855}
Yingdi Yu595aadc2013-10-21 15:01:40 -0700856
Yingdi Yu46948282013-11-06 18:43:31 -0800857void
858ContactPanel::removeChatDialog(const ndn::Name& chatroomName)
859{
860 map<Name, ChatDialog*>::iterator it = m_chatDialogs.find(chatroomName);
Yingdi Yu83eae842013-11-06 22:07:38 -0800861
862 ChatDialog* deletedChat = NULL;
Yingdi Yu46948282013-11-06 18:43:31 -0800863 if(it != m_chatDialogs.end())
864 {
Yingdi Yu46948282013-11-06 18:43:31 -0800865 deletedChat = it->second;
866 m_chatDialogs.erase(it);
867 }
Yingdi Yu83eae842013-11-06 22:07:38 -0800868 if (deletedChat != NULL)
869 delete deletedChat;
Yingdi Yu46948282013-11-06 18:43:31 -0800870}
871
Yingdi Yu847aa862013-10-09 16:35:53 -0700872#if WAF
873#include "contactpanel.moc"
874#include "contactpanel.cpp.moc"
875#endif