blob: adcb32d49fd48810680adc4e556f21bbd68191fa [file] [log] [blame]
Yingdi Yu9e0dc292013-10-10 11:39:45 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 * Yingdi Yu
5 *
6 * BSD license, See the LICENSE file for more information
7 *
8 * Author: Yingdi Yu <yingdi@cs.ucla.edu>
9 */
10
Yingdi Yudef90612013-10-09 22:34:42 -070011#include "contactpanel.h"
12#include "ui_contactpanel.h"
13
Yingdi Yu01a942b2013-10-10 15:00:58 -070014
15#include <QStringList>
16#include <QItemSelectionModel>
17#include <QModelIndex>
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070018#include <QDir>
Yingdi Yu8dacdf22013-11-05 23:06:43 -080019#include <QtSql/QSqlRecord>
20#include <QtSql/QSqlField>
21#include <QtSql/QSqlError>
Yingdi Yu01a942b2013-10-10 15:00:58 -070022
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070023#ifndef Q_MOC_RUN
Yingdi Yu53eb8a72013-10-23 11:50:51 -070024#include <ndn.cxx/security/keychain.h>
Yingdi Yu53eb8a72013-10-23 11:50:51 -070025#include <ndn.cxx/security/identity/identity-manager.h>
Yingdi Yu100267f2013-10-21 15:01:40 -070026#include <ndn.cxx/common.h>
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070027#include <boost/filesystem.hpp>
Yingdi Yu53eb8a72013-10-23 11:50:51 -070028#include <boost/random/random_device.hpp>
29#include <boost/random/uniform_int_distribution.hpp>
Yingdi Yu42f66462013-10-31 17:38:22 -070030#include "panel-policy-manager.h"
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070031#include "logging.h"
32#include "exception.h"
33#endif
34
35namespace fs = boost::filesystem;
36using namespace ndn;
Yingdi Yu53eb8a72013-10-23 11:50:51 -070037
Yingdi Yu79c25a22013-10-21 13:38:38 -070038using namespace std;
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070039
40INIT_LOGGER("ContactPanel");
41
Yingdi Yu53eb8a72013-10-23 11:50:51 -070042Q_DECLARE_METATYPE(ndn::security::IdentityCertificate)
Yingdi Yu42f66462013-10-31 17:38:22 -070043Q_DECLARE_METATYPE(ChronosInvitation)
Yingdi Yu53eb8a72013-10-23 11:50:51 -070044
Yingdi Yub29f78c2013-11-09 20:12:31 -080045ContactPanel::ContactPanel(QWidget *parent)
Yingdi Yua50c3252013-11-03 15:05:26 -080046 : QDialog(parent)
47 , ui(new Ui::ContactPanel)
Yingdi Yub29f78c2013-11-09 20:12:31 -080048 , m_warningDialog(new WarningDialog)
Yingdi Yua50c3252013-11-03 15:05:26 -080049 , m_contactListModel(new QStringListModel)
50 , m_startChatDialog(new StartChatDialog)
51 , m_invitationDialog(new InvitationDialog)
52 , m_settingDialog(new SettingDialog)
Yingdi Yudef90612013-10-09 22:34:42 -070053{
Yingdi Yu53eb8a72013-10-23 11:50:51 -070054 qRegisterMetaType<ndn::security::IdentityCertificate>("IdentityCertificate");
Yingdi Yu42f66462013-10-31 17:38:22 -070055 qRegisterMetaType<ChronosInvitation>("ChronosInvitation");
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070056
Yingdi Yu42372442013-11-06 18:43:31 -080057 createAction();
58
Yingdi Yub29f78c2013-11-09 20:12:31 -080059 m_contactManager = Ptr<ContactManager>::Create();
Yingdi Yub35b8652013-11-07 11:32:40 -080060
Yingdi Yub29f78c2013-11-09 20:12:31 -080061 connect(&*m_contactManager, SIGNAL(noNdnConnection(const QString&)),
62 this, SLOT(showError(const QString&)));
63
64 m_contactManager->setWrapper();
65
Yingdi Yub35b8652013-11-07 11:32:40 -080066 openDB();
Yingdi Yu42372442013-11-06 18:43:31 -080067
Yingdi Yuc4d08d22013-10-23 23:07:29 -070068 refreshContactList();
Yingdi Yu01a942b2013-10-10 15:00:58 -070069
Yingdi Yuc4d08d22013-10-23 23:07:29 -070070 setKeychain();
Yingdi Yu42372442013-11-06 18:43:31 -080071
72 m_defaultIdentity = m_keychain->getDefaultIdentity();
Yingdi Yu10436892013-11-10 16:26:52 -080073 if(m_defaultIdentity.size() == 0)
74 showError(QString::fromStdString("certificate of ") + QString::fromStdString(m_defaultIdentity.toUri()) + " is missing!\nHave you installed the certificate?");
Yingdi Yu71ec9652013-11-09 22:18:26 -080075 Name defaultCertName = m_keychain->getIdentityManager()->getDefaultCertificateNameByIdentity(m_defaultIdentity);
76 if(defaultCertName.size() == 0)
Yingdi Yucf1bdcb2013-11-10 10:54:16 -080077 showError(QString::fromStdString("certificate of ") + QString::fromStdString(m_defaultIdentity.toUri()) + " is missing!\nHave you installed the certificate?");
Yingdi Yu10436892013-11-10 16:26:52 -080078
79
80 m_contactManager->setDefaultIdentity(m_defaultIdentity);
81 m_nickName = m_defaultIdentity.get(-1).toUri();
82 m_settingDialog->setIdentity(m_defaultIdentity.toUri(), m_nickName);
Yingdi Yu71ec9652013-11-09 22:18:26 -080083
Yingdi Yu42372442013-11-06 18:43:31 -080084
Yingdi Yub35b8652013-11-07 11:32:40 -080085 m_profileEditor = new ProfileEditor(m_contactManager);
86 m_profileEditor->setCurrentIdentity(m_defaultIdentity);
87
Yingdi Yub29f78c2013-11-09 20:12:31 -080088 m_addContactPanel = new AddContactPanel(m_contactManager);
89 m_browseContactDialog = new BrowseContactDialog(m_contactManager);
90 m_setAliasDialog = new SetAliasDialog(m_contactManager);
Yingdi Yub35b8652013-11-07 11:32:40 -080091
92 ui->setupUi(this);
93
Yingdi Yub29f78c2013-11-09 20:12:31 -080094 try{
95 m_handler = Ptr<Wrapper>(new Wrapper(m_keychain));
96 }catch(ndn::Error::ndnOperation& e){
97 showError(QString::fromStdString("Cannot conect to ndnd!\n Have you started your ndnd?"));
98 }
99
Yingdi Yu0a953c32013-11-10 10:32:18 -0800100 m_localPrefix = Name("/private/local");
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700101 setLocalPrefix();
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700102
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700103 setInvitationListener();
Yingdi Yu42372442013-11-06 18:43:31 -0800104
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800105 collectEndorsement();
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700106
107 ui->ContactList->setModel(m_contactListModel);
108
Yingdi Yuc26af3c2013-10-17 17:03:46 -0700109
Yingdi Yu42372442013-11-06 18:43:31 -0800110 connect(ui->ContactList->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700111 this, SLOT(updateSelection(const QItemSelection &, const QItemSelection &)));
Yingdi Yu01a942b2013-10-10 15:00:58 -0700112
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700113 connect(ui->ContactList, SIGNAL(customContextMenuRequested(const QPoint&)),
114 this, SLOT(showContextMenu(const QPoint&)));
Yingdi Yud59b5932013-10-16 13:16:49 -0700115
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700116 connect(ui->EditProfileButton, SIGNAL(clicked()),
117 this, SLOT(openProfileEditor()));
Yingdi Yud59b5932013-10-16 13:16:49 -0700118
Yingdi Yu71ec9652013-11-09 22:18:26 -0800119 connect(m_profileEditor, SIGNAL(noKeyOrCert(const QString&)),
Yingdi Yueb98f7d2013-11-10 01:34:57 -0800120 this, SLOT(showWarning(const QString&)));
Yingdi Yu71ec9652013-11-09 22:18:26 -0800121
Yingdi Yu908f8412013-11-09 00:03:26 -0800122 // connect(ui->AddContactButton, SIGNAL(clicked()),
123 // this, SLOT(openAddContactPanel()));
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700124 connect(ui->AddContactButton, SIGNAL(clicked()),
Yingdi Yu908f8412013-11-09 00:03:26 -0800125 this, SLOT(openBrowseContactDialog()));
126
127 connect(this, SIGNAL(refreshCertDirectory()),
128 m_browseContactDialog, SLOT(refreshList()));
129
130 connect(ui->DeleteContactButton, SIGNAL(clicked()),
131 this, SLOT(removeContactButton()));
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700132
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700133 connect(ui->settingButton, SIGNAL(clicked()),
134 this, SLOT(openSettingDialog()));
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700135
Yingdi Yu908f8412013-11-09 00:03:26 -0800136 connect(m_browseContactDialog, SIGNAL(newContactAdded()),
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700137 this, SLOT(refreshContactList()));
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700138 connect(m_setAliasDialog, SIGNAL(aliasChanged()),
139 this, SLOT(refreshContactList()));
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700140
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700141 connect(m_startChatDialog, SIGNAL(chatroomConfirmed(const QString&, const QString&, bool)),
142 this, SLOT(startChatroom(const QString&, const QString&, bool)));
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700143
Yingdi Yu42f66462013-10-31 17:38:22 -0700144 connect(m_invitationDialog, SIGNAL(invitationAccepted(const ChronosInvitation&, const ndn::security::IdentityCertificate&)),
145 this, SLOT(acceptInvitation(const ChronosInvitation&, const ndn::security::IdentityCertificate&)));
146 connect(m_invitationDialog, SIGNAL(invitationRejected(const ChronosInvitation&)),
147 this, SLOT(rejectInvitation(const ChronosInvitation&)));
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700148
Yingdi Yu42372442013-11-06 18:43:31 -0800149 connect(m_settingDialog, SIGNAL(identitySet(const QString&, const QString&)),
150 this, SLOT(updateDefaultIdentity(const QString&, const QString&)));
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700151
152 connect(this, SIGNAL(newInvitationReady()),
153 this, SLOT(openInvitationDialog()));
Yingdi Yu100267f2013-10-21 15:01:40 -0700154
Yingdi Yua50c3252013-11-03 15:05:26 -0800155 connect(ui->isIntroducer, SIGNAL(stateChanged(int)),
156 this, SLOT(isIntroducerChanged(int)));
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800157
158 connect(ui->addScope, SIGNAL(clicked()),
159 this, SLOT(addScopeClicked()));
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800160 connect(ui->deleteScope, SIGNAL(clicked()),
161 this, SLOT(deleteScopeClicked()));
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800162 connect(ui->saveButton, SIGNAL(clicked()),
163 this, SLOT(saveScopeClicked()));
164
165 connect(ui->endorseButton, SIGNAL(clicked()),
166 this, SLOT(endorseButtonClicked()));
Yingdi Yudef90612013-10-09 22:34:42 -0700167}
168
169ContactPanel::~ContactPanel()
170{
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700171 delete ui;
172 delete m_contactListModel;
Yingdi Yu42372442013-11-06 18:43:31 -0800173 delete m_startChatDialog;
174 delete m_invitationDialog;
175 delete m_settingDialog;
176
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700177 delete m_profileEditor;
178 delete m_addContactPanel;
Yingdi Yu908f8412013-11-09 00:03:26 -0800179 delete m_browseContactDialog;
Yingdi Yu42372442013-11-06 18:43:31 -0800180 delete m_setAliasDialog;
181
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800182 delete m_trustScopeModel;
183 delete m_endorseDataModel;
Yingdi Yu42372442013-11-06 18:43:31 -0800184 delete m_endorseComboBoxDelegate;
Yingdi Yu79c25a22013-10-21 13:38:38 -0700185
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700186 delete m_menuInvite;
Yingdi Yu42372442013-11-06 18:43:31 -0800187 delete m_menuAlias;
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700188
189 map<Name, ChatDialog*>::iterator it = m_chatDialogs.begin();
190 for(; it != m_chatDialogs.end(); it++)
191 delete it->second;
Yingdi Yudef90612013-10-09 22:34:42 -0700192}
Yingdi Yu9e0dc292013-10-10 11:39:45 -0700193
Yingdi Yu01a942b2013-10-10 15:00:58 -0700194void
Yingdi Yu42372442013-11-06 18:43:31 -0800195ContactPanel::createAction()
196{
197 m_menuInvite = new QAction("&Chat", this);
198 m_menuAlias = new QAction("&Set Alias", this);
199}
200
201void
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700202ContactPanel::openDB()
203{
204 QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
205 QString path = (QDir::home().path());
206 path.append(QDir::separator()).append(".chronos").append(QDir::separator()).append("chronos.db");
207 db.setDatabaseName(path);
208 bool ok = db.open();
Yingdi Yu42372442013-11-06 18:43:31 -0800209 _LOG_DEBUG("DB opened: " << std::boolalpha << ok );
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800210
211 m_trustScopeModel = new QSqlTableModel;
212 m_endorseDataModel = new QSqlTableModel;
213 m_endorseComboBoxDelegate = new EndorseComboBoxDelegate;
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700214}
215
216void
217ContactPanel::setKeychain()
218{
Yingdi Yued8cfc42013-11-01 17:37:51 -0700219 m_panelPolicyManager = Ptr<PanelPolicyManager>::Create();
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700220
221 vector<Ptr<ContactItem> >::const_iterator it = m_contactList.begin();
222 for(; it != m_contactList.end(); it++)
Yingdi Yub35b8652013-11-07 11:32:40 -0800223 {
224 m_panelPolicyManager->addTrustAnchor((*it)->getSelfEndorseCertificate());
225 }
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700226
Yingdi Yued8cfc42013-11-01 17:37:51 -0700227 m_keychain = Ptr<security::Keychain>(new security::Keychain(Ptr<security::IdentityManager>::Create(),
228 m_panelPolicyManager,
229 NULL));
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700230}
231
232void
Yingdi Yu2ab22e72013-11-10 01:38:21 -0800233ContactPanel::setLocalPrefix(int retry)
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700234{
235 Ptr<Interest> interest = Ptr<Interest>(new Interest(Name("/local/ndn/prefix")));
236 interest->setChildSelector(Interest::CHILD_RIGHT);
237
238 Ptr<Closure> closure = Ptr<Closure>(new Closure(boost::bind(&ContactPanel::onLocalPrefixVerified,
239 this,
240 _1),
241 boost::bind(&ContactPanel::onLocalPrefixTimeout,
242 this,
243 _1,
Yingdi Yu2ab22e72013-11-10 01:38:21 -0800244 _2,
245 10),
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700246 boost::bind(&ContactPanel::onLocalPrefixVerified,
247 this,
248 _1)));
249
250 m_handler->sendInterest(interest, closure);
251}
252
253void
254ContactPanel::onLocalPrefixVerified(Ptr<Data> data)
255{
256 string originPrefix(data->content().buf(), data->content().size());
257 string prefix = QString::fromStdString (originPrefix).trimmed ().toUtf8().constData();
258 string randomSuffix = getRandomString();
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700259 m_localPrefix = Name(prefix);
Yingdi Yueb98f7d2013-11-10 01:34:57 -0800260
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700261}
262
263void
Yingdi Yu2ab22e72013-11-10 01:38:21 -0800264ContactPanel::onLocalPrefixTimeout(Ptr<Closure> closure, Ptr<Interest> interest, int retry)
Yingdi Yu42f66462013-10-31 17:38:22 -0700265{
Yingdi Yu2ab22e72013-11-10 01:38:21 -0800266 if(retry > 0)
Yingdi Yu0a953c32013-11-10 10:32:18 -0800267 {
268 setLocalPrefix(retry - 1);
269 return;
270 }
271 else{
272 m_localPrefix = Name("/private/local");
273 }
Yingdi Yu42f66462013-10-31 17:38:22 -0700274}
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700275
276void
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700277ContactPanel::setInvitationListener()
278{
Yingdi Yu42372442013-11-06 18:43:31 -0800279 m_inviteListenPrefix = Name("/ndn/broadcast/chronos/invitation");
280 m_inviteListenPrefix.append(m_defaultIdentity);
281 _LOG_DEBUG("Listening for invitation on prefix: " << m_inviteListenPrefix.toUri());
282 m_handler->setInterestFilter (m_inviteListenPrefix,
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700283 boost::bind(&ContactPanel::onInvitation,
284 this,
285 _1));
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700286}
287
288void
289ContactPanel::onInvitation(Ptr<Interest> interest)
290{
Yingdi Yu42372442013-11-06 18:43:31 -0800291 _LOG_DEBUG("Receive invitation!" << interest->getName().toUri());
Yingdi Yub35b8652013-11-07 11:32:40 -0800292
293 Ptr<ChronosInvitation> invitation = NULL;
294 try{
295 invitation = Ptr<ChronosInvitation>(new ChronosInvitation(interest->getName()));
296 }catch(exception& e){
297 _LOG_ERROR("Exception: " << e.what());
298 return;
299 }
300
Yingdi Yu42372442013-11-06 18:43:31 -0800301 Name chatroomName("/ndn/broadcast/chronos");
302 chatroomName.append(invitation->getChatroom());
303 map<Name, ChatDialog*>::iterator it = m_chatDialogs.find(chatroomName);
304 if(it != m_chatDialogs.end())
305 {
Yingdi Yub35b8652013-11-07 11:32:40 -0800306 _LOG_ERROR("Exisiting chatroom!");
Yingdi Yu42372442013-11-06 18:43:31 -0800307 return;
308 }
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700309
Yingdi Yu6b56f092013-11-10 11:54:02 -0800310 Ptr<security::Publickey> keyPtr = m_panelPolicyManager->getTrustedKey(invitation->getInviterCertificateName());
311 if(NULL != keyPtr && security::PolicyManager::verifySignature(invitation->getSignedBlob(), invitation->getSignatureBits(), *keyPtr))
312 {
313 Ptr<security::IdentityCertificate> certificate = Ptr<security::IdentityCertificate>::Create();
Yingdi Yu9f657242013-11-10 12:25:43 -0800314 // hack: incomplete certificate, we don't send it to the wire nor store it anywhere, we only use it to carry information
Yingdi Yu6b56f092013-11-10 11:54:02 -0800315 certificate->setName(invitation->getInviterCertificateName());
Yingdi Yu9f657242013-11-10 12:25:43 -0800316 bool findCert = false;
317 vector<Ptr<ContactItem> >::const_iterator it = m_contactList.begin();
318 for(; it != m_contactList.end(); it++)
319 {
320 if((*it)->getNameSpace() == invitation->getInviterNameSpace())
321 {
322 certificate->setNotBefore((*it)->getSelfEndorseCertificate().getNotBefore());
323 certificate->setNotAfter((*it)->getSelfEndorseCertificate().getNotAfter());
324 findCert = true;
325 break;
326 }
327 }
328 if(findCert == false)
329 {
330 _LOG_ERROR("No SelfEndorseCertificate found!");
331 return;
332 }
Yingdi Yu6b56f092013-11-10 11:54:02 -0800333 certificate->setPublicKeyInfo(*keyPtr);
334 popChatInvitation(invitation, invitation->getInviterNameSpace(), certificate);
335 return;
336 }
337
Yingdi Yued8cfc42013-11-01 17:37:51 -0700338 Ptr<Interest> newInterest = Ptr<Interest>(new Interest(invitation->getInviterCertificateName()));
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700339 Ptr<Closure> closure = Ptr<Closure>(new Closure(boost::bind(&ContactPanel::onInvitationCertVerified,
340 this,
341 _1,
Yingdi Yued8cfc42013-11-01 17:37:51 -0700342 invitation),
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700343 boost::bind(&ContactPanel::onTimeout,
344 this,
345 _1,
346 _2),
347 boost::bind(&ContactPanel::onUnverified,
348 this,
349 _1)));
350 m_handler->sendInterest(newInterest, closure);
351}
352
353void
Yingdi Yu42372442013-11-06 18:43:31 -0800354ContactPanel::onInvitationCertVerified(Ptr<Data> data,
355 Ptr<ChronosInvitation> invitation)
356{
357 using namespace ndn::security;
358 Ptr<IdentityCertificate> certificate = Ptr<IdentityCertificate>(new IdentityCertificate(*data));
359
360 if(PolicyManager::verifySignature(invitation->getSignedBlob(), invitation->getSignatureBits(), certificate->getPublicKeyInfo()))
361 {
362 Name keyName = certificate->getPublicKeyName();
363 Name inviterNameSpace = keyName.getPrefix(keyName.size() - 1);
364 popChatInvitation(invitation, inviterNameSpace, certificate);
365 }
366}
367
368void
369ContactPanel::onUnverified(Ptr<Data> data)
370{}
371
372void
373ContactPanel::onTimeout(Ptr<Closure> closure, Ptr<Interest> interest)
374{}
375
376void
377ContactPanel::popChatInvitation(Ptr<ChronosInvitation> invitation,
378 const Name& inviterNameSpace,
379 Ptr<security::IdentityCertificate> certificate)
380{
381 string alias;
382 vector<Ptr<ContactItem> >::iterator it = m_contactList.begin();
383 for(; it != m_contactList.end(); it++)
384 if((*it)->getNameSpace() == inviterNameSpace)
385 alias = (*it)->getAlias();
386
387 if(it != m_contactList.end())
388 return;
389
390 m_invitationDialog->setInvitation(alias, invitation, certificate);
391 emit newInvitationReady();
392}
393
394void
395ContactPanel::collectEndorsement()
396{
397 m_collectStatus = Ptr<vector<bool> >::Create();
398 m_collectStatus->assign(m_contactList.size(), false);
399
400 vector<Ptr<ContactItem> >::iterator it = m_contactList.begin();
401 int count = 0;
402 for(; it != m_contactList.end(); it++, count++)
403 {
404 Name interestName = (*it)->getNameSpace();
405 interestName.append("DNS").append(m_defaultIdentity).append("ENDORSEE");
406 Ptr<Interest> interest = Ptr<Interest>(new Interest(interestName));
407 interest->setChildSelector(Interest::CHILD_RIGHT);
408 interest->setInterestLifetime(1);
409
410 Ptr<Closure> closure = Ptr<Closure>(new Closure(boost::bind(&ContactPanel::onDnsEndorseeVerified,
411 this,
412 _1,
413 count),
414 boost::bind(&ContactPanel::onDnsEndorseeTimeout,
415 this,
416 _1,
417 _2,
418 count),
419 boost::bind(&ContactPanel::onDnsEndorseeUnverified,
420 this,
421 _1,
422 count)));
423
424 m_handler->sendInterest(interest, closure);
425 }
426}
427
428void
429ContactPanel::onDnsEndorseeVerified(Ptr<Data> data, int count)
430{
431 Ptr<Blob> contentBlob = Ptr<Blob>(new Blob(data->content().buf(), data->content().size()));
432 Ptr<Data> endorseData = Data::decodeFromWire(contentBlob);
433 EndorseCertificate endorseCertificate(*endorseData);
434
435 m_contactManager->getContactStorage()->updateCollectEndorse(endorseCertificate);
436
437 updateCollectStatus(count);
438}
439
440void
441ContactPanel::onDnsEndorseeTimeout(Ptr<Closure> closure, Ptr<Interest> interest, int count)
442{ updateCollectStatus(count); }
443
444void
445ContactPanel::onDnsEndorseeUnverified(Ptr<Data> data, int count)
446{ updateCollectStatus(count); }
447
448void
449ContactPanel::updateCollectStatus(int count)
450{
451 m_collectStatus->at(count) = true;
452 vector<bool>::const_iterator it = m_collectStatus->begin();
453 for(; it != m_collectStatus->end(); it++)
454 if(*it == false)
455 return;
456
457 m_contactManager->publishEndorsedDataInDns(m_defaultIdentity);
458}
459
460static std::string chars("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789");
461
462string
463ContactPanel::getRandomString()
464{
465 string randStr;
466 boost::random::random_device rng;
467 boost::random::uniform_int_distribution<> index_dist(0, chars.size() - 1);
468 for (int i = 0; i < 10; i ++)
469 {
470 randStr += chars[index_dist(rng)];
471 }
472 return randStr;
473}
474
475void
Yingdi Yub29f78c2013-11-09 20:12:31 -0800476ContactPanel::showError(const QString& msg){
477 QMessageBox::critical(this, tr("Chronos"), msg, QMessageBox::Ok);
478 exit(1);
479}
480
481void
Yingdi Yueb98f7d2013-11-10 01:34:57 -0800482ContactPanel::showWarning(const QString& msg){
483 QMessageBox::information(this, tr("Chronos"), msg);
484}
485
486void
Yingdi Yu01a942b2013-10-10 15:00:58 -0700487ContactPanel::updateSelection(const QItemSelection &selected,
488 const QItemSelection &deselected)
489{
490 QModelIndexList items = selected.indexes();
491 QString text = m_contactListModel->data(items.first(), Qt::DisplayRole).toString();
Yingdi Yu42372442013-11-06 18:43:31 -0800492 string alias = text.toStdString();
Yingdi Yu79c25a22013-10-21 13:38:38 -0700493
Yingdi Yu79c25a22013-10-21 13:38:38 -0700494 int i = 0;
495 for(; i < m_contactList.size(); i++)
496 {
497 if(alias == m_contactList[i]->getAlias())
498 break;
499 }
500
Yingdi Yua50c3252013-11-03 15:05:26 -0800501 m_currentSelectedContact = m_contactList[i];
Yingdi Yua0594092013-11-06 22:07:38 -0800502 ui->NameData->setText(QString::fromStdString(m_currentSelectedContact->getName()));
503 ui->NameSpaceData->setText(QString::fromStdString(m_currentSelectedContact->getNameSpace().toUri()));
504 ui->InstitutionData->setText(QString::fromStdString(m_currentSelectedContact->getInstitution()));
Yingdi Yu100267f2013-10-21 15:01:40 -0700505
Yingdi Yua50c3252013-11-03 15:05:26 -0800506 if(m_currentSelectedContact->isIntroducer())
507 {
508 ui->isIntroducer->setChecked(true);
509 ui->addScope->setEnabled(true);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800510 ui->deleteScope->setEnabled(true);
511 ui->trustScopeList->setEnabled(true);
512
513 string filter("contact_namespace = '");
514 filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'");
515
516 m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
517 m_trustScopeModel->setTable("TrustScope");
518 m_trustScopeModel->setFilter(filter.c_str());
519 m_trustScopeModel->select();
520 m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
521 m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact"));
522 m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope"));
523
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800524 ui->trustScopeList->setModel(m_trustScopeModel);
525 ui->trustScopeList->setColumnHidden(0, true);
526 ui->trustScopeList->setColumnHidden(1, true);
527 ui->trustScopeList->show();
Yingdi Yua50c3252013-11-03 15:05:26 -0800528 }
529 else
530 {
531 ui->isIntroducer->setChecked(false);
532 ui->addScope->setEnabled(false);
533 ui->deleteScope->setEnabled(false);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800534
535 string filter("contact_namespace = '");
536 filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'");
537
538 m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
539 m_trustScopeModel->setTable("TrustScope");
540 m_trustScopeModel->setFilter(filter.c_str());
541 m_trustScopeModel->select();
542 m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
543 m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact"));
544 m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope"));
545
546 ui->trustScopeList->setModel(m_trustScopeModel);
547 ui->trustScopeList->setColumnHidden(0, true);
548 ui->trustScopeList->setColumnHidden(1, true);
549 ui->trustScopeList->show();
550
551 ui->trustScopeList->setEnabled(false);
Yingdi Yua50c3252013-11-03 15:05:26 -0800552 }
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800553
554 string filter("profile_identity = '");
555 filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'");
556
557 m_endorseDataModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
558 m_endorseDataModel->setTable("ContactProfile");
559 m_endorseDataModel->setFilter(filter.c_str());
560 m_endorseDataModel->select();
561
562 m_endorseDataModel->setHeaderData(0, Qt::Horizontal, QObject::tr("Identity"));
563 m_endorseDataModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Type"));
564 m_endorseDataModel->setHeaderData(2, Qt::Horizontal, QObject::tr("Value"));
565 m_endorseDataModel->setHeaderData(3, Qt::Horizontal, QObject::tr("Endorse"));
566
567 ui->endorseList->setModel(m_endorseDataModel);
568 ui->endorseList->setColumnHidden(0, true);
569 ui->endorseList->resizeColumnToContents(1);
570 ui->endorseList->resizeColumnToContents(2);
571 ui->endorseList->setItemDelegateForColumn(3, m_endorseComboBoxDelegate);
572 ui->endorseList->show();
Yingdi Yu01a942b2013-10-10 15:00:58 -0700573}
Yingdi Yu9e0dc292013-10-10 11:39:45 -0700574
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700575void
Yingdi Yu42372442013-11-06 18:43:31 -0800576ContactPanel::updateDefaultIdentity(const QString& identity, const QString& nickName)
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700577{
Yingdi Yu71ec9652013-11-09 22:18:26 -0800578 // _LOG_DEBUG(identity.toStdString());
Yingdi Yueb98f7d2013-11-10 01:34:57 -0800579 Name defaultIdentity = Name(identity.toStdString());
580 Name defaultKeyName = m_keychain->getIdentityManager()->getPublicStorage()->getDefaultKeyNameForIdentity(defaultIdentity);
Yingdi Yu71ec9652013-11-09 22:18:26 -0800581 if(defaultKeyName.size() == 0)
Yingdi Yueb98f7d2013-11-10 01:34:57 -0800582 {
583 showWarning(QString::fromStdString("Corresponding key is missing!\nHave you created the key?"));
584 return;
585 }
Yingdi Yu71ec9652013-11-09 22:18:26 -0800586 Name defaultCertName = m_keychain->getIdentityManager()->getPublicStorage()->getDefaultCertificateNameForKey(defaultKeyName);
587 if(defaultCertName.size() == 0)
Yingdi Yueb98f7d2013-11-10 01:34:57 -0800588 {
589 showWarning(QString::fromStdString("Corresponding certificate is missing!\nHave you installed the certificate?"));
590 return;
591 }
592 m_defaultIdentity = defaultIdentity;
Yingdi Yub35b8652013-11-07 11:32:40 -0800593 m_profileEditor->setCurrentIdentity(m_defaultIdentity);
Yingdi Yu42372442013-11-06 18:43:31 -0800594 m_nickName = nickName.toStdString();
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700595 m_handler->clearInterestFilter(m_inviteListenPrefix);
Yingdi Yu908f8412013-11-09 00:03:26 -0800596 m_contactManager->setDefaultIdentity(m_defaultIdentity);
Yingdi Yu42372442013-11-06 18:43:31 -0800597 setInvitationListener();
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800598 collectEndorsement();
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700599}
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700600
601void
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700602ContactPanel::openProfileEditor()
Yingdi Yud59b5932013-10-16 13:16:49 -0700603{ m_profileEditor->show(); }
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700604
Yingdi Yud59b5932013-10-16 13:16:49 -0700605void
606ContactPanel::openAddContactPanel()
607{ m_addContactPanel->show(); }
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700608
Yingdi Yu79c25a22013-10-21 13:38:38 -0700609void
Yingdi Yu908f8412013-11-09 00:03:26 -0800610ContactPanel::openBrowseContactDialog()
611{
612 m_browseContactDialog->show();
613 emit refreshCertDirectory();
614}
615
616void
617ContactPanel::removeContactButton()
618{
619 QItemSelectionModel* selectionModel = ui->ContactList->selectionModel();
620 QModelIndexList selectedList = selectionModel->selectedIndexes();
621 QModelIndexList::iterator it = selectedList.begin();
622 for(; it != selectedList.end(); it++)
623 {
624 string alias = m_contactListModel->data(*it, Qt::DisplayRole).toString().toStdString();
625 vector<Ptr<ContactItem> >::iterator contactIt = m_contactList.begin();
626 for(; contactIt != m_contactList.end(); contactIt++)
627 {
628 if((*contactIt)->getAlias() == alias)
629 {
630 m_contactManager->getContactStorage()->removeContact((*contactIt)->getNameSpace());
631 m_contactList.erase(contactIt);
632 break;
633 }
634 }
635 }
636 refreshContactList();
637}
638
639void
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700640ContactPanel::openInvitationDialog()
641{ m_invitationDialog->show(); }
642
643void
Yingdi Yu79c25a22013-10-21 13:38:38 -0700644ContactPanel::refreshContactList()
645{
646 m_contactList = m_contactManager->getContactItemList();
647 QStringList contactNameList;
648 for(int i = 0; i < m_contactList.size(); i++)
Yingdi Yua0594092013-11-06 22:07:38 -0800649 contactNameList << QString::fromStdString(m_contactList[i]->getAlias());
Yingdi Yu79c25a22013-10-21 13:38:38 -0700650
651 m_contactListModel->setStringList(contactNameList);
652}
653
654void
655ContactPanel::showContextMenu(const QPoint& pos)
656{
657 QMenu menu(ui->ContactList);
658 menu.addAction(m_menuInvite);
Yingdi Yu100267f2013-10-21 15:01:40 -0700659 connect(m_menuInvite, SIGNAL(triggered()),
660 this, SLOT(openStartChatDialog()));
Yingdi Yua0594092013-11-06 22:07:38 -0800661 menu.addSeparator();
Yingdi Yu79c25a22013-10-21 13:38:38 -0700662 menu.addAction(m_menuAlias);
663 connect(m_menuAlias, SIGNAL(triggered()),
664 this, SLOT(openSetAliasDialog()));
665 menu.exec(ui->ContactList->mapToGlobal(pos));
666
667}
668
669void
670ContactPanel::openSetAliasDialog()
671{
Yingdi Yua50c3252013-11-03 15:05:26 -0800672 m_setAliasDialog->setTargetIdentity(m_currentSelectedContact->getNameSpace().toUri());
Yingdi Yu79c25a22013-10-21 13:38:38 -0700673 m_setAliasDialog->show();
674}
675
Yingdi Yu100267f2013-10-21 15:01:40 -0700676void
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700677ContactPanel::openSettingDialog()
678{
Yingdi Yu42372442013-11-06 18:43:31 -0800679 m_settingDialog->setIdentity(m_defaultIdentity.toUri(), m_nickName);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700680 m_settingDialog->show();
681}
682
683void
Yingdi Yu100267f2013-10-21 15:01:40 -0700684ContactPanel::openStartChatDialog()
685{
Yingdi Yu100267f2013-10-21 15:01:40 -0700686 Name chatroom("/ndn/broadcast/chronos");
Yingdi Yu42f66462013-10-31 17:38:22 -0700687 chatroom.append(string("chatroom-") + getRandomString());
Yingdi Yu100267f2013-10-21 15:01:40 -0700688
Yingdi Yua50c3252013-11-03 15:05:26 -0800689 m_startChatDialog->setInvitee(m_currentSelectedContact->getNameSpace().toUri(), chatroom.toUri());
Yingdi Yu100267f2013-10-21 15:01:40 -0700690 m_startChatDialog->show();
691}
692
Yingdi Yu42f66462013-10-31 17:38:22 -0700693// For inviter
Yingdi Yu100267f2013-10-21 15:01:40 -0700694void
695ContactPanel::startChatroom(const QString& chatroom, const QString& invitee, bool isIntroducer)
696{
Yingdi Yu42f66462013-10-31 17:38:22 -0700697 Name chatroomName(chatroom.toUtf8().constData());
Yingdi Yu6a5b9f62013-11-06 23:00:21 -0800698
699 Name inviteeNamespace(invitee.toStdString());
700 Ptr<ContactItem> inviteeItem = m_contactManager->getContact(inviteeNamespace);
701
Yingdi Yuc90deb12013-11-06 18:51:19 -0800702 ChatDialog* chatDialog = new ChatDialog(m_contactManager, chatroomName, m_localPrefix, m_defaultIdentity, m_nickName);
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700703 m_chatDialogs.insert(pair <Name, ChatDialog*> (chatroomName, chatDialog));
Yingdi Yu42372442013-11-06 18:43:31 -0800704
705 connect(chatDialog, SIGNAL(closeChatDialog(const ndn::Name&)),
706 this, SLOT(removeChatDialog(const ndn::Name&)));
Yingdi Yub29f78c2013-11-09 20:12:31 -0800707 connect(chatDialog, SIGNAL(noNdnConnection(const QString&)),
708 this, SLOT(showError(const QString&)));
Yingdi Yu3e87bd82013-11-10 10:47:44 -0800709 connect(chatDialog, SIGNAL(inivationRejection(const QString&)),
710 this, SLOT(showWarning(const QString&)));
Yingdi Yu42372442013-11-06 18:43:31 -0800711
Yingdi Yuc90deb12013-11-06 18:51:19 -0800712 // send invitation
Yingdi Yu42f66462013-10-31 17:38:22 -0700713 chatDialog->sendInvitation(inviteeItem, isIntroducer);
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700714
715 chatDialog->show();
Yingdi Yu100267f2013-10-21 15:01:40 -0700716}
717
Yingdi Yu42f66462013-10-31 17:38:22 -0700718// For Invitee
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700719void
Yingdi Yu42f66462013-10-31 17:38:22 -0700720ContactPanel::startChatroom2(const ChronosInvitation& invitation,
721 const security::IdentityCertificate& identityCertificate)
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700722{
Yingdi Yu6a5b9f62013-11-06 23:00:21 -0800723 Ptr<ContactItem> inviterItem = m_contactManager->getContact(invitation.getInviterNameSpace());
724
Yingdi Yu42f66462013-10-31 17:38:22 -0700725 Name chatroomName("/ndn/broadcast/chronos");
726 chatroomName.append(invitation.getChatroom());
Yingdi Yu6a5b9f62013-11-06 23:00:21 -0800727
Yingdi Yuc90deb12013-11-06 18:51:19 -0800728 ChatDialog* chatDialog = new ChatDialog(m_contactManager, chatroomName, m_localPrefix, m_defaultIdentity, m_nickName, true);
Yingdi Yua0594092013-11-06 22:07:38 -0800729
Yingdi Yu42372442013-11-06 18:43:31 -0800730 connect(chatDialog, SIGNAL(closeChatDialog(const ndn::Name&)),
731 this, SLOT(removeChatDialog(const ndn::Name&)));
Yingdi Yub29f78c2013-11-09 20:12:31 -0800732 connect(chatDialog, SIGNAL(noNdnConnection(const QString&)),
733 this, SLOT(showError(const QString&)));
Yingdi Yu3e87bd82013-11-10 10:47:44 -0800734 connect(chatDialog, SIGNAL(inivationRejection(const QString&)),
735 this, SLOT(showWarning(const QString&)));
Yingdi Yu42f66462013-10-31 17:38:22 -0700736
Yingdi Yuc90deb12013-11-06 18:51:19 -0800737 chatDialog->addChatDataRule(invitation.getInviterPrefix(), identityCertificate, true);
Yingdi Yua0594092013-11-06 22:07:38 -0800738 chatDialog->publishIntroCert(identityCertificate, true);
Yingdi Yu42f66462013-10-31 17:38:22 -0700739
Yingdi Yu42f66462013-10-31 17:38:22 -0700740 chatDialog->addTrustAnchor(inviterItem->getSelfEndorseCertificate());
741
742 m_chatDialogs.insert(pair <Name, ChatDialog*> (chatroomName, chatDialog));
743
744 chatDialog->show();
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700745}
746
747void
Yingdi Yu42f66462013-10-31 17:38:22 -0700748ContactPanel::acceptInvitation(const ChronosInvitation& invitation,
749 const security::IdentityCertificate& identityCertificate)
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700750{
751 string prefix = m_localPrefix.toUri();
Yingdi Yu42f66462013-10-31 17:38:22 -0700752 m_handler->publishDataByIdentity (invitation.getInterestName(), prefix);
Yingdi Yu42f66462013-10-31 17:38:22 -0700753 startChatroom2(invitation, identityCertificate);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700754}
755
756void
Yingdi Yu42f66462013-10-31 17:38:22 -0700757ContactPanel::rejectInvitation(const ChronosInvitation& invitation)
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700758{
Yingdi Yu97936352013-11-08 14:13:42 -0800759 string empty("nack");
Yingdi Yu42f66462013-10-31 17:38:22 -0700760 m_handler->publishDataByIdentity (invitation.getInterestName(), empty);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700761}
762
Yingdi Yua50c3252013-11-03 15:05:26 -0800763void
764ContactPanel::isIntroducerChanged(int state)
765{
766 if(state == Qt::Checked)
767 {
768 ui->addScope->setEnabled(true);
769 ui->deleteScope->setEnabled(true);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800770 ui->trustScopeList->setEnabled(true);
771
772 string filter("contact_namespace = '");
773 filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'");
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800774
775 m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
776 m_trustScopeModel->setTable("TrustScope");
777 m_trustScopeModel->setFilter(filter.c_str());
778 m_trustScopeModel->select();
779 m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
780 m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact"));
781 m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope"));
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800782
783 ui->trustScopeList->setModel(m_trustScopeModel);
784 ui->trustScopeList->setColumnHidden(0, true);
785 ui->trustScopeList->setColumnHidden(1, true);
786 ui->trustScopeList->show();
787
788 m_currentSelectedContact->setIsIntroducer(true);
Yingdi Yua50c3252013-11-03 15:05:26 -0800789 }
790 else
791 {
Yingdi Yua50c3252013-11-03 15:05:26 -0800792 ui->addScope->setEnabled(false);
793 ui->deleteScope->setEnabled(false);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800794
795 string filter("contact_namespace = '");
796 filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'");
797
798 m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
799 m_trustScopeModel->setTable("TrustScope");
800 m_trustScopeModel->setFilter(filter.c_str());
801 m_trustScopeModel->select();
802 m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
803 m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact"));
804 m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope"));
805
806 ui->trustScopeList->setModel(m_trustScopeModel);
807 ui->trustScopeList->setColumnHidden(0, true);
808 ui->trustScopeList->setColumnHidden(1, true);
809 ui->trustScopeList->show();
810
811 ui->trustScopeList->setEnabled(false);
812
813 m_currentSelectedContact->setIsIntroducer(false);
Yingdi Yua50c3252013-11-03 15:05:26 -0800814 }
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800815 m_contactManager->getContactStorage()->updateIsIntroducer(m_currentSelectedContact->getNameSpace(), m_currentSelectedContact->isIntroducer());
816}
817
818void
819ContactPanel::addScopeClicked()
820{
821 int rowCount = m_trustScopeModel->rowCount();
822 QSqlRecord record;
823 QSqlField identityField("contact_namespace", QVariant::String);
824 record.append(identityField);
825 record.setValue("contact_namespace", QString(m_currentSelectedContact->getNameSpace().toUri().c_str()));
826 m_trustScopeModel->insertRow(rowCount);
827 m_trustScopeModel->setRecord(rowCount, record);
828}
829
830void
831ContactPanel::deleteScopeClicked()
832{
833 QItemSelectionModel* selectionModel = ui->trustScopeList->selectionModel();
834 QModelIndexList indexList = selectionModel->selectedIndexes();
835
836 int i = indexList.size() - 1;
837 for(; i >= 0; i--)
838 m_trustScopeModel->removeRow(indexList[i].row());
839
840 m_trustScopeModel->submitAll();
841}
842
843void
844ContactPanel::saveScopeClicked()
Yingdi Yua0594092013-11-06 22:07:38 -0800845{ m_trustScopeModel->submitAll(); }
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800846
847void
848ContactPanel::endorseButtonClicked()
849{
850 m_endorseDataModel->submitAll();
851 m_contactManager->updateEndorseCertificate(m_currentSelectedContact->getNameSpace(), m_defaultIdentity);
Yingdi Yua50c3252013-11-03 15:05:26 -0800852}
Yingdi Yu100267f2013-10-21 15:01:40 -0700853
Yingdi Yu42372442013-11-06 18:43:31 -0800854void
855ContactPanel::removeChatDialog(const ndn::Name& chatroomName)
856{
857 map<Name, ChatDialog*>::iterator it = m_chatDialogs.find(chatroomName);
Yingdi Yua0594092013-11-06 22:07:38 -0800858
859 ChatDialog* deletedChat = NULL;
Yingdi Yu42372442013-11-06 18:43:31 -0800860 if(it != m_chatDialogs.end())
861 {
Yingdi Yu42372442013-11-06 18:43:31 -0800862 deletedChat = it->second;
863 m_chatDialogs.erase(it);
864 }
Yingdi Yua0594092013-11-06 22:07:38 -0800865 if (deletedChat != NULL)
866 delete deletedChat;
Yingdi Yu42372442013-11-06 18:43:31 -0800867}
868
Yingdi Yu9e0dc292013-10-10 11:39:45 -0700869#if WAF
870#include "contactpanel.moc"
871#include "contactpanel.cpp.moc"
872#endif