blob: dd5233435dadd2c29c51c17c8a05d8f14c8342e6 [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 Yu908f8412013-11-09 00:03:26 -080073 m_contactManager->setDefaultIdentity(m_defaultIdentity);
Yingdi Yu42372442013-11-06 18:43:31 -080074 m_nickName = m_defaultIdentity.get(-1).toUri();
75 m_settingDialog->setIdentity(m_defaultIdentity.toUri(), m_nickName);
Yingdi Yu71ec9652013-11-09 22:18:26 -080076 Name defaultCertName = m_keychain->getIdentityManager()->getDefaultCertificateNameByIdentity(m_defaultIdentity);
77 if(defaultCertName.size() == 0)
78 showError(QString::fromStdString("Corresponding certificate is missing!\nHave you installed the certificate?"));
79
Yingdi Yu42372442013-11-06 18:43:31 -080080
Yingdi Yub35b8652013-11-07 11:32:40 -080081 m_profileEditor = new ProfileEditor(m_contactManager);
82 m_profileEditor->setCurrentIdentity(m_defaultIdentity);
83
Yingdi Yub29f78c2013-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 Yub35b8652013-11-07 11:32:40 -080087
88 ui->setupUi(this);
89
Yingdi Yub29f78c2013-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 Yu0a953c32013-11-10 10:32:18 -080096 m_localPrefix = Name("/private/local");
Yingdi Yuc4d08d22013-10-23 23:07:29 -070097 setLocalPrefix();
Yingdi Yu53eb8a72013-10-23 11:50:51 -070098
Yingdi Yuc4d08d22013-10-23 23:07:29 -070099 setInvitationListener();
Yingdi Yu42372442013-11-06 18:43:31 -0800100
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800101 collectEndorsement();
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700102
103 ui->ContactList->setModel(m_contactListModel);
104
Yingdi Yuc26af3c2013-10-17 17:03:46 -0700105
Yingdi Yu42372442013-11-06 18:43:31 -0800106 connect(ui->ContactList->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700107 this, SLOT(updateSelection(const QItemSelection &, const QItemSelection &)));
Yingdi Yu01a942b2013-10-10 15:00:58 -0700108
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700109 connect(ui->ContactList, SIGNAL(customContextMenuRequested(const QPoint&)),
110 this, SLOT(showContextMenu(const QPoint&)));
Yingdi Yud59b5932013-10-16 13:16:49 -0700111
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700112 connect(ui->EditProfileButton, SIGNAL(clicked()),
113 this, SLOT(openProfileEditor()));
Yingdi Yud59b5932013-10-16 13:16:49 -0700114
Yingdi Yu71ec9652013-11-09 22:18:26 -0800115 connect(m_profileEditor, SIGNAL(noKeyOrCert(const QString&)),
Yingdi Yueb98f7d2013-11-10 01:34:57 -0800116 this, SLOT(showWarning(const QString&)));
Yingdi Yu71ec9652013-11-09 22:18:26 -0800117
Yingdi Yu908f8412013-11-09 00:03:26 -0800118 // connect(ui->AddContactButton, SIGNAL(clicked()),
119 // this, SLOT(openAddContactPanel()));
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700120 connect(ui->AddContactButton, SIGNAL(clicked()),
Yingdi Yu908f8412013-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 Yu53eb8a72013-10-23 11:50:51 -0700128
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700129 connect(ui->settingButton, SIGNAL(clicked()),
130 this, SLOT(openSettingDialog()));
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700131
Yingdi Yu908f8412013-11-09 00:03:26 -0800132 connect(m_browseContactDialog, SIGNAL(newContactAdded()),
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700133 this, SLOT(refreshContactList()));
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700134 connect(m_setAliasDialog, SIGNAL(aliasChanged()),
135 this, SLOT(refreshContactList()));
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700136
Yingdi Yuc4d08d22013-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 Yu53eb8a72013-10-23 11:50:51 -0700139
Yingdi Yu42f66462013-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 Yu53eb8a72013-10-23 11:50:51 -0700144
Yingdi Yu42372442013-11-06 18:43:31 -0800145 connect(m_settingDialog, SIGNAL(identitySet(const QString&, const QString&)),
146 this, SLOT(updateDefaultIdentity(const QString&, const QString&)));
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700147
148 connect(this, SIGNAL(newInvitationReady()),
149 this, SLOT(openInvitationDialog()));
Yingdi Yu100267f2013-10-21 15:01:40 -0700150
Yingdi Yua50c3252013-11-03 15:05:26 -0800151 connect(ui->isIntroducer, SIGNAL(stateChanged(int)),
152 this, SLOT(isIntroducerChanged(int)));
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800153
154 connect(ui->addScope, SIGNAL(clicked()),
155 this, SLOT(addScopeClicked()));
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800156 connect(ui->deleteScope, SIGNAL(clicked()),
157 this, SLOT(deleteScopeClicked()));
Yingdi Yu8dacdf22013-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 Yudef90612013-10-09 22:34:42 -0700163}
164
165ContactPanel::~ContactPanel()
166{
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700167 delete ui;
168 delete m_contactListModel;
Yingdi Yu42372442013-11-06 18:43:31 -0800169 delete m_startChatDialog;
170 delete m_invitationDialog;
171 delete m_settingDialog;
172
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700173 delete m_profileEditor;
174 delete m_addContactPanel;
Yingdi Yu908f8412013-11-09 00:03:26 -0800175 delete m_browseContactDialog;
Yingdi Yu42372442013-11-06 18:43:31 -0800176 delete m_setAliasDialog;
177
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800178 delete m_trustScopeModel;
179 delete m_endorseDataModel;
Yingdi Yu42372442013-11-06 18:43:31 -0800180 delete m_endorseComboBoxDelegate;
Yingdi Yu79c25a22013-10-21 13:38:38 -0700181
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700182 delete m_menuInvite;
Yingdi Yu42372442013-11-06 18:43:31 -0800183 delete m_menuAlias;
Yingdi Yuc4d08d22013-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 Yudef90612013-10-09 22:34:42 -0700188}
Yingdi Yu9e0dc292013-10-10 11:39:45 -0700189
Yingdi Yu01a942b2013-10-10 15:00:58 -0700190void
Yingdi Yu42372442013-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 Yu53eb8a72013-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 Yu42372442013-11-06 18:43:31 -0800205 _LOG_DEBUG("DB opened: " << std::boolalpha << ok );
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800206
207 m_trustScopeModel = new QSqlTableModel;
208 m_endorseDataModel = new QSqlTableModel;
209 m_endorseComboBoxDelegate = new EndorseComboBoxDelegate;
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700210}
211
212void
213ContactPanel::setKeychain()
214{
Yingdi Yued8cfc42013-11-01 17:37:51 -0700215 m_panelPolicyManager = Ptr<PanelPolicyManager>::Create();
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700216
217 vector<Ptr<ContactItem> >::const_iterator it = m_contactList.begin();
218 for(; it != m_contactList.end(); it++)
Yingdi Yub35b8652013-11-07 11:32:40 -0800219 {
220 m_panelPolicyManager->addTrustAnchor((*it)->getSelfEndorseCertificate());
221 }
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700222
Yingdi Yued8cfc42013-11-01 17:37:51 -0700223 m_keychain = Ptr<security::Keychain>(new security::Keychain(Ptr<security::IdentityManager>::Create(),
224 m_panelPolicyManager,
225 NULL));
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700226}
227
228void
Yingdi Yu2ab22e72013-11-10 01:38:21 -0800229ContactPanel::setLocalPrefix(int retry)
Yingdi Yu53eb8a72013-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 Yu2ab22e72013-11-10 01:38:21 -0800240 _2,
241 10),
Yingdi Yu53eb8a72013-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 Yu53eb8a72013-10-23 11:50:51 -0700255 m_localPrefix = Name(prefix);
Yingdi Yueb98f7d2013-11-10 01:34:57 -0800256
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700257}
258
259void
Yingdi Yu2ab22e72013-11-10 01:38:21 -0800260ContactPanel::onLocalPrefixTimeout(Ptr<Closure> closure, Ptr<Interest> interest, int retry)
Yingdi Yu42f66462013-10-31 17:38:22 -0700261{
Yingdi Yu2ab22e72013-11-10 01:38:21 -0800262 if(retry > 0)
Yingdi Yu0a953c32013-11-10 10:32:18 -0800263 {
264 setLocalPrefix(retry - 1);
265 return;
266 }
267 else{
268 m_localPrefix = Name("/private/local");
269 }
Yingdi Yu42f66462013-10-31 17:38:22 -0700270}
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700271
272void
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700273ContactPanel::setInvitationListener()
274{
Yingdi Yu42372442013-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 Yu53eb8a72013-10-23 11:50:51 -0700279 boost::bind(&ContactPanel::onInvitation,
280 this,
281 _1));
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700282}
283
284void
285ContactPanel::onInvitation(Ptr<Interest> interest)
286{
Yingdi Yu42372442013-11-06 18:43:31 -0800287 _LOG_DEBUG("Receive invitation!" << interest->getName().toUri());
Yingdi Yub35b8652013-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 Yu42372442013-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 Yub35b8652013-11-07 11:32:40 -0800302 _LOG_ERROR("Exisiting chatroom!");
Yingdi Yu42372442013-11-06 18:43:31 -0800303 return;
304 }
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700305
Yingdi Yued8cfc42013-11-01 17:37:51 -0700306 Ptr<Interest> newInterest = Ptr<Interest>(new Interest(invitation->getInviterCertificateName()));
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700307 Ptr<Closure> closure = Ptr<Closure>(new Closure(boost::bind(&ContactPanel::onInvitationCertVerified,
308 this,
309 _1,
Yingdi Yued8cfc42013-11-01 17:37:51 -0700310 invitation),
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700311 boost::bind(&ContactPanel::onTimeout,
312 this,
313 _1,
314 _2),
315 boost::bind(&ContactPanel::onUnverified,
316 this,
317 _1)));
318 m_handler->sendInterest(newInterest, closure);
319}
320
321void
Yingdi Yu42372442013-11-06 18:43:31 -0800322ContactPanel::onInvitationCertVerified(Ptr<Data> data,
323 Ptr<ChronosInvitation> invitation)
324{
325 using namespace ndn::security;
326 Ptr<IdentityCertificate> certificate = Ptr<IdentityCertificate>(new IdentityCertificate(*data));
327
328 if(PolicyManager::verifySignature(invitation->getSignedBlob(), invitation->getSignatureBits(), certificate->getPublicKeyInfo()))
329 {
330 Name keyName = certificate->getPublicKeyName();
331 Name inviterNameSpace = keyName.getPrefix(keyName.size() - 1);
332 popChatInvitation(invitation, inviterNameSpace, certificate);
333 }
334}
335
336void
337ContactPanel::onUnverified(Ptr<Data> data)
338{}
339
340void
341ContactPanel::onTimeout(Ptr<Closure> closure, Ptr<Interest> interest)
342{}
343
344void
345ContactPanel::popChatInvitation(Ptr<ChronosInvitation> invitation,
346 const Name& inviterNameSpace,
347 Ptr<security::IdentityCertificate> certificate)
348{
349 string alias;
350 vector<Ptr<ContactItem> >::iterator it = m_contactList.begin();
351 for(; it != m_contactList.end(); it++)
352 if((*it)->getNameSpace() == inviterNameSpace)
353 alias = (*it)->getAlias();
354
355 if(it != m_contactList.end())
356 return;
357
358 m_invitationDialog->setInvitation(alias, invitation, certificate);
359 emit newInvitationReady();
360}
361
362void
363ContactPanel::collectEndorsement()
364{
365 m_collectStatus = Ptr<vector<bool> >::Create();
366 m_collectStatus->assign(m_contactList.size(), false);
367
368 vector<Ptr<ContactItem> >::iterator it = m_contactList.begin();
369 int count = 0;
370 for(; it != m_contactList.end(); it++, count++)
371 {
372 Name interestName = (*it)->getNameSpace();
373 interestName.append("DNS").append(m_defaultIdentity).append("ENDORSEE");
374 Ptr<Interest> interest = Ptr<Interest>(new Interest(interestName));
375 interest->setChildSelector(Interest::CHILD_RIGHT);
376 interest->setInterestLifetime(1);
377
378 Ptr<Closure> closure = Ptr<Closure>(new Closure(boost::bind(&ContactPanel::onDnsEndorseeVerified,
379 this,
380 _1,
381 count),
382 boost::bind(&ContactPanel::onDnsEndorseeTimeout,
383 this,
384 _1,
385 _2,
386 count),
387 boost::bind(&ContactPanel::onDnsEndorseeUnverified,
388 this,
389 _1,
390 count)));
391
392 m_handler->sendInterest(interest, closure);
393 }
394}
395
396void
397ContactPanel::onDnsEndorseeVerified(Ptr<Data> data, int count)
398{
399 Ptr<Blob> contentBlob = Ptr<Blob>(new Blob(data->content().buf(), data->content().size()));
400 Ptr<Data> endorseData = Data::decodeFromWire(contentBlob);
401 EndorseCertificate endorseCertificate(*endorseData);
402
403 m_contactManager->getContactStorage()->updateCollectEndorse(endorseCertificate);
404
405 updateCollectStatus(count);
406}
407
408void
409ContactPanel::onDnsEndorseeTimeout(Ptr<Closure> closure, Ptr<Interest> interest, int count)
410{ updateCollectStatus(count); }
411
412void
413ContactPanel::onDnsEndorseeUnverified(Ptr<Data> data, int count)
414{ updateCollectStatus(count); }
415
416void
417ContactPanel::updateCollectStatus(int count)
418{
419 m_collectStatus->at(count) = true;
420 vector<bool>::const_iterator it = m_collectStatus->begin();
421 for(; it != m_collectStatus->end(); it++)
422 if(*it == false)
423 return;
424
425 m_contactManager->publishEndorsedDataInDns(m_defaultIdentity);
426}
427
428static std::string chars("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789");
429
430string
431ContactPanel::getRandomString()
432{
433 string randStr;
434 boost::random::random_device rng;
435 boost::random::uniform_int_distribution<> index_dist(0, chars.size() - 1);
436 for (int i = 0; i < 10; i ++)
437 {
438 randStr += chars[index_dist(rng)];
439 }
440 return randStr;
441}
442
443void
Yingdi Yub29f78c2013-11-09 20:12:31 -0800444ContactPanel::showError(const QString& msg){
445 QMessageBox::critical(this, tr("Chronos"), msg, QMessageBox::Ok);
446 exit(1);
447}
448
449void
Yingdi Yueb98f7d2013-11-10 01:34:57 -0800450ContactPanel::showWarning(const QString& msg){
451 QMessageBox::information(this, tr("Chronos"), msg);
452}
453
454void
Yingdi Yu01a942b2013-10-10 15:00:58 -0700455ContactPanel::updateSelection(const QItemSelection &selected,
456 const QItemSelection &deselected)
457{
458 QModelIndexList items = selected.indexes();
459 QString text = m_contactListModel->data(items.first(), Qt::DisplayRole).toString();
Yingdi Yu42372442013-11-06 18:43:31 -0800460 string alias = text.toStdString();
Yingdi Yu79c25a22013-10-21 13:38:38 -0700461
Yingdi Yu79c25a22013-10-21 13:38:38 -0700462 int i = 0;
463 for(; i < m_contactList.size(); i++)
464 {
465 if(alias == m_contactList[i]->getAlias())
466 break;
467 }
468
Yingdi Yua50c3252013-11-03 15:05:26 -0800469 m_currentSelectedContact = m_contactList[i];
Yingdi Yua0594092013-11-06 22:07:38 -0800470 ui->NameData->setText(QString::fromStdString(m_currentSelectedContact->getName()));
471 ui->NameSpaceData->setText(QString::fromStdString(m_currentSelectedContact->getNameSpace().toUri()));
472 ui->InstitutionData->setText(QString::fromStdString(m_currentSelectedContact->getInstitution()));
Yingdi Yu100267f2013-10-21 15:01:40 -0700473
Yingdi Yua50c3252013-11-03 15:05:26 -0800474 if(m_currentSelectedContact->isIntroducer())
475 {
476 ui->isIntroducer->setChecked(true);
477 ui->addScope->setEnabled(true);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800478 ui->deleteScope->setEnabled(true);
479 ui->trustScopeList->setEnabled(true);
480
481 string filter("contact_namespace = '");
482 filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'");
483
484 m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
485 m_trustScopeModel->setTable("TrustScope");
486 m_trustScopeModel->setFilter(filter.c_str());
487 m_trustScopeModel->select();
488 m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
489 m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact"));
490 m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope"));
491
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800492 ui->trustScopeList->setModel(m_trustScopeModel);
493 ui->trustScopeList->setColumnHidden(0, true);
494 ui->trustScopeList->setColumnHidden(1, true);
495 ui->trustScopeList->show();
Yingdi Yua50c3252013-11-03 15:05:26 -0800496 }
497 else
498 {
499 ui->isIntroducer->setChecked(false);
500 ui->addScope->setEnabled(false);
501 ui->deleteScope->setEnabled(false);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800502
503 string filter("contact_namespace = '");
504 filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'");
505
506 m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
507 m_trustScopeModel->setTable("TrustScope");
508 m_trustScopeModel->setFilter(filter.c_str());
509 m_trustScopeModel->select();
510 m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
511 m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact"));
512 m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope"));
513
514 ui->trustScopeList->setModel(m_trustScopeModel);
515 ui->trustScopeList->setColumnHidden(0, true);
516 ui->trustScopeList->setColumnHidden(1, true);
517 ui->trustScopeList->show();
518
519 ui->trustScopeList->setEnabled(false);
Yingdi Yua50c3252013-11-03 15:05:26 -0800520 }
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800521
522 string filter("profile_identity = '");
523 filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'");
524
525 m_endorseDataModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
526 m_endorseDataModel->setTable("ContactProfile");
527 m_endorseDataModel->setFilter(filter.c_str());
528 m_endorseDataModel->select();
529
530 m_endorseDataModel->setHeaderData(0, Qt::Horizontal, QObject::tr("Identity"));
531 m_endorseDataModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Type"));
532 m_endorseDataModel->setHeaderData(2, Qt::Horizontal, QObject::tr("Value"));
533 m_endorseDataModel->setHeaderData(3, Qt::Horizontal, QObject::tr("Endorse"));
534
535 ui->endorseList->setModel(m_endorseDataModel);
536 ui->endorseList->setColumnHidden(0, true);
537 ui->endorseList->resizeColumnToContents(1);
538 ui->endorseList->resizeColumnToContents(2);
539 ui->endorseList->setItemDelegateForColumn(3, m_endorseComboBoxDelegate);
540 ui->endorseList->show();
Yingdi Yu01a942b2013-10-10 15:00:58 -0700541}
Yingdi Yu9e0dc292013-10-10 11:39:45 -0700542
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700543void
Yingdi Yu42372442013-11-06 18:43:31 -0800544ContactPanel::updateDefaultIdentity(const QString& identity, const QString& nickName)
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700545{
Yingdi Yu71ec9652013-11-09 22:18:26 -0800546 // _LOG_DEBUG(identity.toStdString());
Yingdi Yueb98f7d2013-11-10 01:34:57 -0800547 Name defaultIdentity = Name(identity.toStdString());
548 Name defaultKeyName = m_keychain->getIdentityManager()->getPublicStorage()->getDefaultKeyNameForIdentity(defaultIdentity);
Yingdi Yu71ec9652013-11-09 22:18:26 -0800549 if(defaultKeyName.size() == 0)
Yingdi Yueb98f7d2013-11-10 01:34:57 -0800550 {
551 showWarning(QString::fromStdString("Corresponding key is missing!\nHave you created the key?"));
552 return;
553 }
Yingdi Yu71ec9652013-11-09 22:18:26 -0800554 Name defaultCertName = m_keychain->getIdentityManager()->getPublicStorage()->getDefaultCertificateNameForKey(defaultKeyName);
555 if(defaultCertName.size() == 0)
Yingdi Yueb98f7d2013-11-10 01:34:57 -0800556 {
557 showWarning(QString::fromStdString("Corresponding certificate is missing!\nHave you installed the certificate?"));
558 return;
559 }
560 m_defaultIdentity = defaultIdentity;
Yingdi Yub35b8652013-11-07 11:32:40 -0800561 m_profileEditor->setCurrentIdentity(m_defaultIdentity);
Yingdi Yu42372442013-11-06 18:43:31 -0800562 m_nickName = nickName.toStdString();
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700563 m_handler->clearInterestFilter(m_inviteListenPrefix);
Yingdi Yu908f8412013-11-09 00:03:26 -0800564 m_contactManager->setDefaultIdentity(m_defaultIdentity);
Yingdi Yu42372442013-11-06 18:43:31 -0800565 setInvitationListener();
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800566 collectEndorsement();
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700567}
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700568
569void
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700570ContactPanel::openProfileEditor()
Yingdi Yud59b5932013-10-16 13:16:49 -0700571{ m_profileEditor->show(); }
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700572
Yingdi Yud59b5932013-10-16 13:16:49 -0700573void
574ContactPanel::openAddContactPanel()
575{ m_addContactPanel->show(); }
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700576
Yingdi Yu79c25a22013-10-21 13:38:38 -0700577void
Yingdi Yu908f8412013-11-09 00:03:26 -0800578ContactPanel::openBrowseContactDialog()
579{
580 m_browseContactDialog->show();
581 emit refreshCertDirectory();
582}
583
584void
585ContactPanel::removeContactButton()
586{
587 QItemSelectionModel* selectionModel = ui->ContactList->selectionModel();
588 QModelIndexList selectedList = selectionModel->selectedIndexes();
589 QModelIndexList::iterator it = selectedList.begin();
590 for(; it != selectedList.end(); it++)
591 {
592 string alias = m_contactListModel->data(*it, Qt::DisplayRole).toString().toStdString();
593 vector<Ptr<ContactItem> >::iterator contactIt = m_contactList.begin();
594 for(; contactIt != m_contactList.end(); contactIt++)
595 {
596 if((*contactIt)->getAlias() == alias)
597 {
598 m_contactManager->getContactStorage()->removeContact((*contactIt)->getNameSpace());
599 m_contactList.erase(contactIt);
600 break;
601 }
602 }
603 }
604 refreshContactList();
605}
606
607void
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700608ContactPanel::openInvitationDialog()
609{ m_invitationDialog->show(); }
610
611void
Yingdi Yu79c25a22013-10-21 13:38:38 -0700612ContactPanel::refreshContactList()
613{
614 m_contactList = m_contactManager->getContactItemList();
615 QStringList contactNameList;
616 for(int i = 0; i < m_contactList.size(); i++)
Yingdi Yua0594092013-11-06 22:07:38 -0800617 contactNameList << QString::fromStdString(m_contactList[i]->getAlias());
Yingdi Yu79c25a22013-10-21 13:38:38 -0700618
619 m_contactListModel->setStringList(contactNameList);
620}
621
622void
623ContactPanel::showContextMenu(const QPoint& pos)
624{
625 QMenu menu(ui->ContactList);
626 menu.addAction(m_menuInvite);
Yingdi Yu100267f2013-10-21 15:01:40 -0700627 connect(m_menuInvite, SIGNAL(triggered()),
628 this, SLOT(openStartChatDialog()));
Yingdi Yua0594092013-11-06 22:07:38 -0800629 menu.addSeparator();
Yingdi Yu79c25a22013-10-21 13:38:38 -0700630 menu.addAction(m_menuAlias);
631 connect(m_menuAlias, SIGNAL(triggered()),
632 this, SLOT(openSetAliasDialog()));
633 menu.exec(ui->ContactList->mapToGlobal(pos));
634
635}
636
637void
638ContactPanel::openSetAliasDialog()
639{
Yingdi Yua50c3252013-11-03 15:05:26 -0800640 m_setAliasDialog->setTargetIdentity(m_currentSelectedContact->getNameSpace().toUri());
Yingdi Yu79c25a22013-10-21 13:38:38 -0700641 m_setAliasDialog->show();
642}
643
Yingdi Yu100267f2013-10-21 15:01:40 -0700644void
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700645ContactPanel::openSettingDialog()
646{
Yingdi Yu42372442013-11-06 18:43:31 -0800647 m_settingDialog->setIdentity(m_defaultIdentity.toUri(), m_nickName);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700648 m_settingDialog->show();
649}
650
651void
Yingdi Yu100267f2013-10-21 15:01:40 -0700652ContactPanel::openStartChatDialog()
653{
Yingdi Yu100267f2013-10-21 15:01:40 -0700654 Name chatroom("/ndn/broadcast/chronos");
Yingdi Yu42f66462013-10-31 17:38:22 -0700655 chatroom.append(string("chatroom-") + getRandomString());
Yingdi Yu100267f2013-10-21 15:01:40 -0700656
Yingdi Yua50c3252013-11-03 15:05:26 -0800657 m_startChatDialog->setInvitee(m_currentSelectedContact->getNameSpace().toUri(), chatroom.toUri());
Yingdi Yu100267f2013-10-21 15:01:40 -0700658 m_startChatDialog->show();
659}
660
Yingdi Yu42f66462013-10-31 17:38:22 -0700661// For inviter
Yingdi Yu100267f2013-10-21 15:01:40 -0700662void
663ContactPanel::startChatroom(const QString& chatroom, const QString& invitee, bool isIntroducer)
664{
Yingdi Yu42f66462013-10-31 17:38:22 -0700665 Name chatroomName(chatroom.toUtf8().constData());
Yingdi Yu6a5b9f62013-11-06 23:00:21 -0800666
667 Name inviteeNamespace(invitee.toStdString());
668 Ptr<ContactItem> inviteeItem = m_contactManager->getContact(inviteeNamespace);
669
Yingdi Yuc90deb12013-11-06 18:51:19 -0800670 ChatDialog* chatDialog = new ChatDialog(m_contactManager, chatroomName, m_localPrefix, m_defaultIdentity, m_nickName);
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700671 m_chatDialogs.insert(pair <Name, ChatDialog*> (chatroomName, chatDialog));
Yingdi Yu42372442013-11-06 18:43:31 -0800672
673 connect(chatDialog, SIGNAL(closeChatDialog(const ndn::Name&)),
674 this, SLOT(removeChatDialog(const ndn::Name&)));
Yingdi Yub29f78c2013-11-09 20:12:31 -0800675 connect(chatDialog, SIGNAL(noNdnConnection(const QString&)),
676 this, SLOT(showError(const QString&)));
Yingdi Yu3e87bd82013-11-10 10:47:44 -0800677 connect(chatDialog, SIGNAL(inivationRejection(const QString&)),
678 this, SLOT(showWarning(const QString&)));
Yingdi Yu42372442013-11-06 18:43:31 -0800679
Yingdi Yuc90deb12013-11-06 18:51:19 -0800680 // send invitation
Yingdi Yu42f66462013-10-31 17:38:22 -0700681 chatDialog->sendInvitation(inviteeItem, isIntroducer);
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700682
683 chatDialog->show();
Yingdi Yu100267f2013-10-21 15:01:40 -0700684}
685
Yingdi Yu42f66462013-10-31 17:38:22 -0700686// For Invitee
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700687void
Yingdi Yu42f66462013-10-31 17:38:22 -0700688ContactPanel::startChatroom2(const ChronosInvitation& invitation,
689 const security::IdentityCertificate& identityCertificate)
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700690{
Yingdi Yu6a5b9f62013-11-06 23:00:21 -0800691 Ptr<ContactItem> inviterItem = m_contactManager->getContact(invitation.getInviterNameSpace());
692
Yingdi Yu42f66462013-10-31 17:38:22 -0700693 Name chatroomName("/ndn/broadcast/chronos");
694 chatroomName.append(invitation.getChatroom());
Yingdi Yu6a5b9f62013-11-06 23:00:21 -0800695
Yingdi Yuc90deb12013-11-06 18:51:19 -0800696 ChatDialog* chatDialog = new ChatDialog(m_contactManager, chatroomName, m_localPrefix, m_defaultIdentity, m_nickName, true);
Yingdi Yua0594092013-11-06 22:07:38 -0800697
Yingdi Yu42372442013-11-06 18:43:31 -0800698 connect(chatDialog, SIGNAL(closeChatDialog(const ndn::Name&)),
699 this, SLOT(removeChatDialog(const ndn::Name&)));
Yingdi Yub29f78c2013-11-09 20:12:31 -0800700 connect(chatDialog, SIGNAL(noNdnConnection(const QString&)),
701 this, SLOT(showError(const QString&)));
Yingdi Yu3e87bd82013-11-10 10:47:44 -0800702 connect(chatDialog, SIGNAL(inivationRejection(const QString&)),
703 this, SLOT(showWarning(const QString&)));
Yingdi Yu42f66462013-10-31 17:38:22 -0700704
Yingdi Yuc90deb12013-11-06 18:51:19 -0800705 chatDialog->addChatDataRule(invitation.getInviterPrefix(), identityCertificate, true);
Yingdi Yua0594092013-11-06 22:07:38 -0800706 chatDialog->publishIntroCert(identityCertificate, true);
Yingdi Yu42f66462013-10-31 17:38:22 -0700707
Yingdi Yu42f66462013-10-31 17:38:22 -0700708 chatDialog->addTrustAnchor(inviterItem->getSelfEndorseCertificate());
709
710 m_chatDialogs.insert(pair <Name, ChatDialog*> (chatroomName, chatDialog));
711
712 chatDialog->show();
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700713}
714
715void
Yingdi Yu42f66462013-10-31 17:38:22 -0700716ContactPanel::acceptInvitation(const ChronosInvitation& invitation,
717 const security::IdentityCertificate& identityCertificate)
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700718{
719 string prefix = m_localPrefix.toUri();
Yingdi Yu42f66462013-10-31 17:38:22 -0700720 m_handler->publishDataByIdentity (invitation.getInterestName(), prefix);
Yingdi Yu42f66462013-10-31 17:38:22 -0700721 startChatroom2(invitation, identityCertificate);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700722}
723
724void
Yingdi Yu42f66462013-10-31 17:38:22 -0700725ContactPanel::rejectInvitation(const ChronosInvitation& invitation)
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700726{
Yingdi Yu97936352013-11-08 14:13:42 -0800727 string empty("nack");
Yingdi Yu42f66462013-10-31 17:38:22 -0700728 m_handler->publishDataByIdentity (invitation.getInterestName(), empty);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700729}
730
Yingdi Yua50c3252013-11-03 15:05:26 -0800731void
732ContactPanel::isIntroducerChanged(int state)
733{
734 if(state == Qt::Checked)
735 {
736 ui->addScope->setEnabled(true);
737 ui->deleteScope->setEnabled(true);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800738 ui->trustScopeList->setEnabled(true);
739
740 string filter("contact_namespace = '");
741 filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'");
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800742
743 m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
744 m_trustScopeModel->setTable("TrustScope");
745 m_trustScopeModel->setFilter(filter.c_str());
746 m_trustScopeModel->select();
747 m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
748 m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact"));
749 m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope"));
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800750
751 ui->trustScopeList->setModel(m_trustScopeModel);
752 ui->trustScopeList->setColumnHidden(0, true);
753 ui->trustScopeList->setColumnHidden(1, true);
754 ui->trustScopeList->show();
755
756 m_currentSelectedContact->setIsIntroducer(true);
Yingdi Yua50c3252013-11-03 15:05:26 -0800757 }
758 else
759 {
Yingdi Yua50c3252013-11-03 15:05:26 -0800760 ui->addScope->setEnabled(false);
761 ui->deleteScope->setEnabled(false);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800762
763 string filter("contact_namespace = '");
764 filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'");
765
766 m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
767 m_trustScopeModel->setTable("TrustScope");
768 m_trustScopeModel->setFilter(filter.c_str());
769 m_trustScopeModel->select();
770 m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
771 m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact"));
772 m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope"));
773
774 ui->trustScopeList->setModel(m_trustScopeModel);
775 ui->trustScopeList->setColumnHidden(0, true);
776 ui->trustScopeList->setColumnHidden(1, true);
777 ui->trustScopeList->show();
778
779 ui->trustScopeList->setEnabled(false);
780
781 m_currentSelectedContact->setIsIntroducer(false);
Yingdi Yua50c3252013-11-03 15:05:26 -0800782 }
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800783 m_contactManager->getContactStorage()->updateIsIntroducer(m_currentSelectedContact->getNameSpace(), m_currentSelectedContact->isIntroducer());
784}
785
786void
787ContactPanel::addScopeClicked()
788{
789 int rowCount = m_trustScopeModel->rowCount();
790 QSqlRecord record;
791 QSqlField identityField("contact_namespace", QVariant::String);
792 record.append(identityField);
793 record.setValue("contact_namespace", QString(m_currentSelectedContact->getNameSpace().toUri().c_str()));
794 m_trustScopeModel->insertRow(rowCount);
795 m_trustScopeModel->setRecord(rowCount, record);
796}
797
798void
799ContactPanel::deleteScopeClicked()
800{
801 QItemSelectionModel* selectionModel = ui->trustScopeList->selectionModel();
802 QModelIndexList indexList = selectionModel->selectedIndexes();
803
804 int i = indexList.size() - 1;
805 for(; i >= 0; i--)
806 m_trustScopeModel->removeRow(indexList[i].row());
807
808 m_trustScopeModel->submitAll();
809}
810
811void
812ContactPanel::saveScopeClicked()
Yingdi Yua0594092013-11-06 22:07:38 -0800813{ m_trustScopeModel->submitAll(); }
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800814
815void
816ContactPanel::endorseButtonClicked()
817{
818 m_endorseDataModel->submitAll();
819 m_contactManager->updateEndorseCertificate(m_currentSelectedContact->getNameSpace(), m_defaultIdentity);
Yingdi Yua50c3252013-11-03 15:05:26 -0800820}
Yingdi Yu100267f2013-10-21 15:01:40 -0700821
Yingdi Yu42372442013-11-06 18:43:31 -0800822void
823ContactPanel::removeChatDialog(const ndn::Name& chatroomName)
824{
825 map<Name, ChatDialog*>::iterator it = m_chatDialogs.find(chatroomName);
Yingdi Yua0594092013-11-06 22:07:38 -0800826
827 ChatDialog* deletedChat = NULL;
Yingdi Yu42372442013-11-06 18:43:31 -0800828 if(it != m_chatDialogs.end())
829 {
Yingdi Yu42372442013-11-06 18:43:31 -0800830 deletedChat = it->second;
831 m_chatDialogs.erase(it);
832 }
Yingdi Yua0594092013-11-06 22:07:38 -0800833 if (deletedChat != NULL)
834 delete deletedChat;
Yingdi Yu42372442013-11-06 18:43:31 -0800835}
836
Yingdi Yu9e0dc292013-10-10 11:39:45 -0700837#if WAF
838#include "contactpanel.moc"
839#include "contactpanel.cpp.moc"
840#endif