Yingdi Yu | 0484223 | 2013-10-23 14:03:09 -0700 | [diff] [blame] | 1 | /* -*- 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 | * |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 8 | * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| 9 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 10 | * Yingdi Yu <yingdi@cs.ucla.edu> |
Yingdi Yu | 0484223 | 2013-10-23 14:03:09 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include "chatdialog.h" |
| 14 | #include "ui_chatdialog.h" |
| 15 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 16 | #include <QScrollBar> |
Yingdi Yu | 07b5b09 | 2013-11-07 17:00:54 -0800 | [diff] [blame] | 17 | #include <QMessageBox> |
| 18 | #include <QCloseEvent> |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 19 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 20 | #ifndef Q_MOC_RUN |
| 21 | #include <ndn.cxx/security/identity/identity-manager.h> |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 22 | #include <ndn.cxx/security/policy/no-verify-policy-manager.h> |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 23 | #include <ndn.cxx/security/encryption/basic-encryption-manager.h> |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 24 | #include <sync-intro-certificate.h> |
| 25 | #include <boost/random/random_device.hpp> |
| 26 | #include <boost/random/uniform_int_distribution.hpp> |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 27 | #include "logging.h" |
| 28 | #endif |
| 29 | |
Yingdi Yu | 0484223 | 2013-10-23 14:03:09 -0700 | [diff] [blame] | 30 | using namespace std; |
Yingdi Yu | 0484223 | 2013-10-23 14:03:09 -0700 | [diff] [blame] | 31 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 32 | INIT_LOGGER("ChatDialog"); |
| 33 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 34 | static const int HELLO_INTERVAL = FRESHNESS * 3 / 4; |
| 35 | |
| 36 | Q_DECLARE_METATYPE(std::vector<Sync::MissingDataInfo> ) |
| 37 | Q_DECLARE_METATYPE(size_t) |
| 38 | |
| 39 | ChatDialog::ChatDialog(ndn::Ptr<ContactManager> contactManager, |
| 40 | const ndn::Name& chatroomPrefix, |
| 41 | const ndn::Name& localPrefix, |
| 42 | const ndn::Name& defaultIdentity, |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 43 | const std::string& nick, |
| 44 | bool trial, |
Yingdi Yu | 0484223 | 2013-10-23 14:03:09 -0700 | [diff] [blame] | 45 | QWidget *parent) |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 46 | : QDialog(parent) |
| 47 | , ui(new Ui::ChatDialog) |
| 48 | , m_contactManager(contactManager) |
| 49 | , m_chatroomPrefix(chatroomPrefix) |
| 50 | , m_localPrefix(localPrefix) |
| 51 | , m_defaultIdentity(defaultIdentity) |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 52 | , m_invitationPolicyManager(ndn::Ptr<InvitationPolicyManager>(new InvitationPolicyManager(m_chatroomPrefix.get(-1).toUri(), m_defaultIdentity))) |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 53 | , m_nick(nick) |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 54 | , m_sock(NULL) |
| 55 | , m_lastMsgTime(0) |
| 56 | // , m_historyInitialized(false) |
| 57 | , m_joined(false) |
| 58 | , m_inviteListDialog(new InviteListDialog(m_contactManager)) |
Yingdi Yu | 0484223 | 2013-10-23 14:03:09 -0700 | [diff] [blame] | 59 | { |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 60 | qRegisterMetaType<std::vector<Sync::MissingDataInfo> >("std::vector<Sync::MissingDataInfo>"); |
| 61 | qRegisterMetaType<size_t>("size_t"); |
| 62 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 63 | ui->setupUi(this); |
| 64 | |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 65 | QString randString = getRandomString(); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 66 | m_localChatPrefix = m_localPrefix; |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 67 | m_localChatPrefix.append("%F0.").append(m_defaultIdentity); |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 68 | m_localChatPrefix.append("chronos").append(m_chatroomPrefix.get(-1)).append(randString.toStdString()); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 69 | |
| 70 | m_session = time(NULL); |
| 71 | m_scene = new DigestTreeScene(this); |
| 72 | |
| 73 | initializeSetting(); |
| 74 | updateLabels(); |
| 75 | |
| 76 | ui->treeViewer->setScene(m_scene); |
| 77 | ui->treeViewer->hide(); |
| 78 | m_scene->plot("Empty"); |
| 79 | QRectF rect = m_scene->itemsBoundingRect(); |
| 80 | m_scene->setSceneRect(rect); |
| 81 | |
| 82 | m_rosterModel = new QStringListModel(this); |
| 83 | ui->listView->setModel(m_rosterModel); |
| 84 | |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 85 | createActions(); |
| 86 | createTrayIcon(); |
| 87 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 88 | m_timer = new QTimer(this); |
| 89 | |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 90 | setWrapper(trial); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 91 | |
| 92 | connect(ui->inviteButton, SIGNAL(clicked()), |
| 93 | this, SLOT(openInviteListDialog())); |
| 94 | connect(m_inviteListDialog, SIGNAL(invitionDetermined(QString, bool)), |
| 95 | this, SLOT(sendInvitationWrapper(QString, bool))); |
| 96 | connect(ui->lineEdit, SIGNAL(returnPressed()), |
| 97 | this, SLOT(returnPressed())); |
| 98 | connect(ui->treeButton, SIGNAL(pressed()), |
| 99 | this, SLOT(treeButtonPressed())); |
| 100 | connect(this, SIGNAL(dataReceived(QString, const char *, size_t, bool, bool)), |
| 101 | this, SLOT(processData(QString, const char *, size_t, bool, bool))); |
| 102 | connect(this, SIGNAL(treeUpdated(const std::vector<Sync::MissingDataInfo>)), |
| 103 | this, SLOT(processTreeUpdate(const std::vector<Sync::MissingDataInfo>))); |
| 104 | connect(m_timer, SIGNAL(timeout()), |
| 105 | this, SLOT(replot())); |
| 106 | connect(m_scene, SIGNAL(replot()), |
| 107 | this, SLOT(replot())); |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 108 | connect(trayIcon, SIGNAL(messageClicked()), |
| 109 | this, SLOT(showNormal())); |
| 110 | connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), |
| 111 | this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason))); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 112 | connect(m_scene, SIGNAL(rosterChanged(QStringList)), |
| 113 | this, SLOT(updateRosterList(QStringList))); |
| 114 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 115 | |
| 116 | initializeSync(); |
Yingdi Yu | 0484223 | 2013-10-23 14:03:09 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 119 | |
Yingdi Yu | 0484223 | 2013-10-23 14:03:09 -0700 | [diff] [blame] | 120 | ChatDialog::~ChatDialog() |
| 121 | { |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 122 | if(m_sock != NULL) |
| 123 | { |
| 124 | sendLeave(); |
| 125 | delete m_sock; |
| 126 | m_sock = NULL; |
| 127 | } |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 128 | m_handler->shutdown(); |
Yingdi Yu | 0484223 | 2013-10-23 14:03:09 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | void |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 132 | ChatDialog::setWrapper(bool trial) |
Yingdi Yu | 0484223 | 2013-10-23 14:03:09 -0700 | [diff] [blame] | 133 | { |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 134 | m_identityManager = ndn::Ptr<ndn::security::IdentityManager>::Create(); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 135 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 136 | ndn::Name certificateName = m_identityManager->getDefaultCertificateNameByIdentity(m_defaultIdentity); |
| 137 | m_syncPolicyManager = ndn::Ptr<SyncPolicyManager>(new SyncPolicyManager(m_defaultIdentity, certificateName, m_chatroomPrefix)); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 138 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 139 | m_keychain = ndn::Ptr<ndn::security::Keychain>(new ndn::security::Keychain(m_identityManager, m_invitationPolicyManager, NULL)); |
| 140 | |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 141 | ndn::Ptr<ndn::security::Keychain> noVerifyKeychain = ndn::Ptr<ndn::security::Keychain>(new ndn::security::Keychain(m_identityManager, |
| 142 | ndn::Ptr<ndn::security::NoVerifyPolicyManager>::Create(), NULL)); |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 143 | try{ |
| 144 | m_handler = ndn::Ptr<ndn::Wrapper>(new ndn::Wrapper(m_keychain)); |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 145 | m_localPrefixHandler = ndn::Ptr<ndn::Wrapper>(new ndn::Wrapper(noVerifyKeychain)); |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 146 | }catch(ndn::Error::ndnOperation& e){ |
| 147 | emit noNdnConnection(QString::fromStdString("Cannot conect to ndnd!\n Have you started your ndnd?")); |
| 148 | } |
Yingdi Yu | 0484223 | 2013-10-23 14:03:09 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 151 | void |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 152 | ChatDialog::initializeSetting() |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 153 | { |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 154 | m_user.setNick(QString::fromStdString(m_nick)); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 155 | m_user.setChatroom(QString::fromStdString(m_chatroomPrefix.get(-1).toUri())); |
| 156 | m_user.setOriginPrefix(QString::fromStdString(m_localPrefix.toUri())); |
| 157 | m_user.setPrefix(QString::fromStdString(m_localChatPrefix.toUri())); |
| 158 | m_scene->setCurrentPrefix(QString::fromStdString(m_localChatPrefix.toUri())); |
| 159 | } |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 160 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 161 | void |
| 162 | ChatDialog::updateLabels() |
| 163 | { |
| 164 | QString settingDisp = QString("Chatroom: %1").arg(m_user.getChatroom()); |
| 165 | ui->infoLabel->setStyleSheet("QLabel {color: #630; font-size: 16px; font: bold \"Verdana\";}"); |
| 166 | ui->infoLabel->setText(settingDisp); |
| 167 | QString prefixDisp; |
| 168 | if (m_user.getPrefix().startsWith("/private/local")) |
| 169 | { |
| 170 | prefixDisp = QString("<Warning: no connection to hub or hub does not support prefix autoconfig.>\n <Prefix = %1>").arg(m_user.getPrefix()); |
| 171 | ui->prefixLabel->setStyleSheet("QLabel {color: red; font-size: 12px; font: bold \"Verdana\";}"); |
| 172 | } |
| 173 | else |
| 174 | { |
| 175 | prefixDisp = QString("<Prefix = %1>").arg(m_user.getPrefix()); |
| 176 | ui->prefixLabel->setStyleSheet("QLabel {color: Green; font-size: 12px; font: bold \"Verdana\";}"); |
| 177 | } |
| 178 | ui->prefixLabel->setText(prefixDisp); |
| 179 | } |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 180 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 181 | void |
| 182 | ChatDialog::sendInvitation(ndn::Ptr<ContactItem> contact, bool isIntroducer) |
| 183 | { |
| 184 | m_invitationPolicyManager->addTrustAnchor(contact->getSelfEndorseCertificate()); |
| 185 | |
| 186 | ndn::Name certificateName = m_identityManager->getDefaultCertificateNameByIdentity(m_defaultIdentity); |
| 187 | |
| 188 | ndn::Name interestName("/ndn/broadcast/chronos/invitation"); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 189 | interestName.append(contact->getNameSpace()); |
| 190 | interestName.append("chatroom"); |
| 191 | interestName.append(m_chatroomPrefix.get(-1)); |
| 192 | interestName.append("inviter-prefix"); |
| 193 | interestName.append(m_localPrefix); |
| 194 | interestName.append("inviter"); |
| 195 | interestName.append(certificateName); |
| 196 | |
| 197 | string signedUri = interestName.toUri(); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 198 | ndn::Blob signedBlob(signedUri.c_str(), signedUri.size()); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 199 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 200 | ndn::Ptr<const ndn::signature::Sha256WithRsa> sha256sig = ndn::DynamicCast<const ndn::signature::Sha256WithRsa>(m_identityManager->signByCertificate(signedBlob, certificateName)); |
| 201 | const ndn::Blob& sigBits = sha256sig->getSignatureBits(); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 202 | |
| 203 | interestName.append(sigBits.buf(), sigBits.size()); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 204 | interestName.appendVersion(); |
| 205 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 206 | ndn::Ptr<ndn::Interest> interest = ndn::Ptr<ndn::Interest>(new ndn::Interest(interestName)); |
| 207 | ndn::Ptr<ndn::Closure> closure = ndn::Ptr<ndn::Closure>(new ndn::Closure(boost::bind(&ChatDialog::onInviteReplyVerified, |
| 208 | this, |
| 209 | _1, |
| 210 | contact->getNameSpace(), |
| 211 | isIntroducer), |
| 212 | boost::bind(&ChatDialog::onInviteTimeout, |
| 213 | this, |
| 214 | _1, |
| 215 | _2, |
| 216 | contact->getNameSpace(), |
| 217 | 7), |
| 218 | boost::bind(&ChatDialog::onUnverified, |
| 219 | this, |
| 220 | _1))); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 221 | |
| 222 | m_handler->sendInterest(interest, closure); |
| 223 | } |
| 224 | |
| 225 | void |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 226 | ChatDialog::addTrustAnchor(const EndorseCertificate& selfEndorseCertificate) |
| 227 | { m_invitationPolicyManager->addTrustAnchor(selfEndorseCertificate); } |
| 228 | |
| 229 | void |
| 230 | ChatDialog::addChatDataRule(const ndn::Name& prefix, |
| 231 | const ndn::security::IdentityCertificate& identityCertificate, |
| 232 | bool isIntroducer) |
| 233 | { m_syncPolicyManager->addChatDataRule(prefix, identityCertificate, isIntroducer); } |
| 234 | |
| 235 | void |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 236 | ChatDialog::publishIntroCert(const ndn::security::IdentityCertificate& dskCertificate, bool isIntroducer) |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 237 | { |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 238 | SyncIntroCertificate syncIntroCertificate(m_chatroomPrefix, |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 239 | dskCertificate.getPublicKeyName(), |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 240 | m_identityManager->getDefaultKeyNameForIdentity(m_defaultIdentity), |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 241 | dskCertificate.getNotBefore(), |
| 242 | dskCertificate.getNotAfter(), |
| 243 | dskCertificate.getPublicKeyInfo(), |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 244 | (isIntroducer ? SyncIntroCertificate::INTRODUCER : SyncIntroCertificate::PRODUCER)); |
| 245 | ndn::Name certName = m_identityManager->getDefaultCertificateNameByIdentity(m_defaultIdentity); |
Yingdi Yu | 6a5b9f6 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 246 | _LOG_DEBUG("Publish Intro Certificate: " << syncIntroCertificate.getName()); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 247 | m_identityManager->signByCertificate(syncIntroCertificate, certName); |
| 248 | m_handler->putToNdnd(*syncIntroCertificate.encodeToWire()); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | void |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 252 | ChatDialog::invitationRejected(const ndn::Name& identity) |
| 253 | { |
Yingdi Yu | 6a5b9f6 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 254 | _LOG_DEBUG(" " << identity.toUri() << " Rejected your invitation!"); |
Yingdi Yu | 3e87bd8 | 2013-11-10 10:47:44 -0800 | [diff] [blame^] | 255 | QString msg = QString::fromStdString(identity.toUri()) + " Rejected your invitation!"; |
| 256 | emit inivationRejection(msg); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | void |
| 260 | ChatDialog::invitationAccepted(const ndn::Name& identity, ndn::Ptr<ndn::Data> data, const string& inviteePrefix, bool isIntroducer) |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 261 | { |
Yingdi Yu | 6a5b9f6 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 262 | _LOG_DEBUG(" " << identity.toUri() << " Accepted your invitation!"); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 263 | ndn::Ptr<const ndn::signature::Sha256WithRsa> sha256sig = boost::dynamic_pointer_cast<const ndn::signature::Sha256WithRsa> (data->getSignature()); |
| 264 | const ndn::Name & keyLocatorName = sha256sig->getKeyLocator().getKeyName(); |
| 265 | ndn::Ptr<ndn::security::IdentityCertificate> dskCertificate = m_invitationPolicyManager->getValidatedDskCertificate(keyLocatorName); |
Yingdi Yu | c90deb1 | 2013-11-06 18:51:19 -0800 | [diff] [blame] | 266 | m_syncPolicyManager->addChatDataRule(inviteePrefix, *dskCertificate, isIntroducer); |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 267 | publishIntroCert(*dskCertificate, isIntroducer); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | void |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 271 | ChatDialog::onInviteReplyVerified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity, bool isIntroducer) |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 272 | { |
| 273 | string content(data->content().buf(), data->content().size()); |
Yingdi Yu | 9793635 | 2013-11-08 14:13:42 -0800 | [diff] [blame] | 274 | if(content == string("nack")) |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 275 | invitationRejected(identity); |
| 276 | else |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 277 | invitationAccepted(identity, data, content, isIntroducer); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | void |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 281 | ChatDialog::onInviteTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry) |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 282 | { |
| 283 | if(retry > 0) |
| 284 | { |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 285 | ndn::Ptr<ndn::Closure> newClosure = ndn::Ptr<ndn::Closure>(new ndn::Closure(closure->m_dataCallback, |
| 286 | boost::bind(&ChatDialog::onInviteTimeout, |
| 287 | this, |
| 288 | _1, |
| 289 | _2, |
| 290 | identity, |
| 291 | retry - 1), |
| 292 | closure->m_unverifiedCallback, |
| 293 | closure->m_stepCount) |
| 294 | ); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 295 | m_handler->sendInterest(interest, newClosure); |
| 296 | } |
| 297 | else |
| 298 | invitationRejected(identity); |
| 299 | } |
| 300 | |
| 301 | void |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 302 | ChatDialog::onUnverified(ndn::Ptr<ndn::Data> data) |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 303 | {} |
| 304 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 305 | void |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 306 | ChatDialog::onTimeout(ndn::Ptr<ndn::Closure> closure, |
| 307 | ndn::Ptr<ndn::Interest> interest) |
| 308 | {} |
| 309 | |
| 310 | void |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 311 | ChatDialog::initializeSync() |
| 312 | { |
| 313 | |
| 314 | m_sock = new Sync::SyncSocket(m_chatroomPrefix.toUri(), |
| 315 | m_syncPolicyManager, |
| 316 | bind(&ChatDialog::processTreeUpdateWrapper, this, _1, _2), |
| 317 | bind(&ChatDialog::processRemoveWrapper, this, _1)); |
| 318 | |
| 319 | usleep(100000); |
| 320 | |
| 321 | QTimer::singleShot(600, this, SLOT(sendJoin())); |
| 322 | m_timer->start(FRESHNESS * 1000); |
| 323 | disableTreeDisplay(); |
| 324 | QTimer::singleShot(2200, this, SLOT(enableTreeDisplay())); |
| 325 | // Sync::CcnxWrapperPtr handle = boost::make_shared<Sync::CcnxWrapper> (); |
| 326 | // handle->setInterestFilter(m_user.getPrefix().toStdString(), bind(&ChatDialog::respondHistoryRequest, this, _1)); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | void |
| 330 | ChatDialog::returnPressed() |
| 331 | { |
| 332 | QString text = ui->lineEdit->text(); |
| 333 | if (text.isEmpty()) |
| 334 | return; |
| 335 | |
| 336 | ui->lineEdit->clear(); |
| 337 | |
| 338 | if (text.startsWith("boruoboluomi")) |
| 339 | { |
| 340 | summonReaper (); |
| 341 | // reapButton->show(); |
| 342 | fitView(); |
| 343 | return; |
| 344 | } |
| 345 | |
| 346 | if (text.startsWith("minimanihong")) |
| 347 | { |
| 348 | // reapButton->hide(); |
| 349 | fitView(); |
| 350 | return; |
| 351 | } |
| 352 | |
| 353 | SyncDemo::ChatMessage msg; |
| 354 | formChatMessage(text, msg); |
| 355 | |
| 356 | appendMessage(msg); |
| 357 | |
| 358 | sendMsg(msg); |
| 359 | |
| 360 | fitView(); |
| 361 | } |
| 362 | |
| 363 | void |
| 364 | ChatDialog::treeButtonPressed() |
| 365 | { |
| 366 | if (ui->treeViewer->isVisible()) |
| 367 | { |
| 368 | ui->treeViewer->hide(); |
| 369 | ui->treeButton->setText("Show ChronoSync Tree"); |
| 370 | } |
| 371 | else |
| 372 | { |
| 373 | ui->treeViewer->show(); |
| 374 | ui->treeButton->setText("Hide ChronoSync Tree"); |
| 375 | } |
| 376 | |
| 377 | fitView(); |
| 378 | } |
| 379 | |
| 380 | void ChatDialog::disableTreeDisplay() |
| 381 | { |
| 382 | ui->treeButton->setEnabled(false); |
| 383 | ui->treeViewer->hide(); |
| 384 | fitView(); |
| 385 | } |
| 386 | |
| 387 | void ChatDialog::enableTreeDisplay() |
| 388 | { |
| 389 | ui->treeButton->setEnabled(true); |
| 390 | // treeViewer->show(); |
| 391 | // fitView(); |
| 392 | } |
| 393 | |
| 394 | void |
| 395 | ChatDialog::processTreeUpdateWrapper(const std::vector<Sync::MissingDataInfo> v, Sync::SyncSocket *sock) |
| 396 | { |
| 397 | emit treeUpdated(v); |
| 398 | _LOG_DEBUG("<<< Tree update signal emitted"); |
| 399 | } |
| 400 | |
| 401 | void |
| 402 | ChatDialog::processRemoveWrapper(std::string prefix) |
| 403 | { |
| 404 | _LOG_DEBUG("Sync REMOVE signal received for prefix: " << prefix); |
| 405 | } |
| 406 | |
| 407 | void |
| 408 | ChatDialog::processTreeUpdate(const std::vector<Sync::MissingDataInfo> v) |
| 409 | { |
| 410 | _LOG_DEBUG("<<< processing Tree Update"); |
| 411 | |
| 412 | if (v.empty()) |
| 413 | { |
| 414 | return; |
| 415 | } |
| 416 | |
| 417 | // reflect the changes on digest tree |
| 418 | { |
| 419 | boost::recursive_mutex::scoped_lock lock(m_sceneMutex); |
| 420 | m_scene->processUpdate(v, m_sock->getRootDigest().c_str()); |
| 421 | } |
| 422 | |
| 423 | int n = v.size(); |
| 424 | int totalMissingPackets = 0; |
| 425 | for (int i = 0; i < n; i++) |
| 426 | { |
| 427 | totalMissingPackets += v[i].high.getSeq() - v[i].low.getSeq() + 1; |
| 428 | } |
| 429 | |
| 430 | for (int i = 0; i < n; i++) |
| 431 | { |
| 432 | if (totalMissingPackets < 4) |
| 433 | { |
| 434 | for (Sync::SeqNo seq = v[i].low; seq <= v[i].high; ++seq) |
| 435 | { |
| 436 | m_sock->fetchData(v[i].prefix, seq, bind(&ChatDialog::processDataWrapper, this, _1), 2); |
| 437 | _LOG_DEBUG("<<< Fetching " << v[i].prefix << "/" <<seq.getSession() <<"/" << seq.getSeq()); |
| 438 | } |
| 439 | } |
| 440 | else |
| 441 | { |
| 442 | m_sock->fetchData(v[i].prefix, v[i].high, bind(&ChatDialog::processDataNoShowWrapper, this, _1), 2); |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | // adjust the view |
| 447 | fitView(); |
| 448 | |
| 449 | } |
| 450 | |
| 451 | void |
| 452 | ChatDialog::processDataWrapper(ndn::Ptr<ndn::Data> data) |
| 453 | { |
| 454 | string name = data->getName().toUri(); |
| 455 | const char* buf = data->content().buf(); |
| 456 | size_t len = data->content().size(); |
| 457 | |
| 458 | char *tempBuf = new char[len]; |
| 459 | memcpy(tempBuf, buf, len); |
| 460 | emit dataReceived(name.c_str(), tempBuf, len, true, false); |
| 461 | _LOG_DEBUG("<<< " << name << " fetched"); |
| 462 | } |
| 463 | |
| 464 | void |
| 465 | ChatDialog::processDataNoShowWrapper(ndn::Ptr<ndn::Data> data) |
| 466 | { |
| 467 | string name = data->getName().toUri(); |
| 468 | const char* buf = data->content().buf(); |
| 469 | size_t len = data->content().size(); |
| 470 | |
| 471 | char *tempBuf = new char[len]; |
| 472 | memcpy(tempBuf, buf, len); |
| 473 | emit dataReceived(name.c_str(), tempBuf, len, false, false); |
| 474 | |
| 475 | // if (!m_historyInitialized) |
| 476 | // { |
| 477 | // fetchHistory(name); |
| 478 | // m_historyInitialized = true; |
| 479 | // } |
| 480 | } |
| 481 | |
| 482 | // void |
| 483 | // ChatDialog::fetchHistory(std::string name) |
| 484 | // { |
| 485 | |
| 486 | // /****************************/ |
| 487 | // /* TODO: fix following part */ |
| 488 | // /****************************/ |
| 489 | // string nameWithoutSeq = name.substr(0, name.find_last_of('/')); |
| 490 | // string prefix = nameWithoutSeq.substr(0, nameWithoutSeq.find_last_of('/')); |
| 491 | // prefix += "/history"; |
| 492 | // // Ptr<Wrapper>CcnxWrapperPtr handle = boost::make_shared<Sync::CcnxWrapper> (); |
| 493 | // // QString randomString = getRandomString(); |
| 494 | // // for (int i = 0; i < MAX_HISTORY_ENTRY; i++) |
| 495 | // // { |
| 496 | // // QString interest = QString("%1/%2/%3").arg(prefix.c_str()).arg(randomString).arg(i); |
| 497 | // // handle->sendInterest(interest.toStdString(), bind(&ChatDialog::processDataHistoryWrapper, this, _1, _2, _3)); |
| 498 | // // } |
| 499 | // } |
| 500 | |
| 501 | void |
| 502 | ChatDialog::processData(QString name, const char *buf, size_t len, bool show, bool isHistory) |
| 503 | { |
| 504 | SyncDemo::ChatMessage msg; |
| 505 | bool corrupted = false; |
| 506 | if (!msg.ParseFromArray(buf, len)) |
| 507 | { |
| 508 | _LOG_DEBUG("Errrrr.. Can not parse msg with name: " << name.toStdString() << ". what is happening?"); |
| 509 | // nasty stuff: as a remedy, we'll form some standard msg for inparsable msgs |
| 510 | msg.set_from("inconnu"); |
| 511 | msg.set_type(SyncDemo::ChatMessage::OTHER); |
| 512 | corrupted = true; |
| 513 | } |
| 514 | |
| 515 | delete [] buf; |
| 516 | buf = NULL; |
| 517 | |
| 518 | // display msg received from network |
| 519 | // we have to do so; this function is called by ccnd thread |
| 520 | // so if we call appendMsg directly |
| 521 | // Qt crash as "QObject: Cannot create children for a parent that is in a different thread" |
| 522 | // the "cannonical" way to is use signal-slot |
| 523 | if (show && !corrupted) |
| 524 | { |
| 525 | appendMessage(msg, isHistory); |
| 526 | } |
| 527 | |
| 528 | if (!isHistory) |
| 529 | { |
| 530 | // update the tree view |
| 531 | std::string stdStrName = name.toStdString(); |
| 532 | std::string stdStrNameWithoutSeq = stdStrName.substr(0, stdStrName.find_last_of('/')); |
| 533 | std::string prefix = stdStrNameWithoutSeq.substr(0, stdStrNameWithoutSeq.find_last_of('/')); |
| 534 | _LOG_DEBUG("<<< updating scene for" << prefix << ": " << msg.from()); |
| 535 | if (msg.type() == SyncDemo::ChatMessage::LEAVE) |
| 536 | { |
| 537 | processRemove(prefix.c_str()); |
| 538 | } |
| 539 | else |
| 540 | { |
| 541 | boost::recursive_mutex::scoped_lock lock(m_sceneMutex); |
| 542 | m_scene->msgReceived(prefix.c_str(), msg.from().c_str()); |
| 543 | } |
| 544 | } |
| 545 | fitView(); |
| 546 | } |
| 547 | |
| 548 | void |
| 549 | ChatDialog::processRemove(QString prefix) |
| 550 | { |
| 551 | _LOG_DEBUG("<<< remove node for prefix" << prefix.toStdString()); |
| 552 | |
| 553 | bool removed = m_scene->removeNode(prefix); |
| 554 | if (removed) |
| 555 | { |
| 556 | boost::recursive_mutex::scoped_lock lock(m_sceneMutex); |
| 557 | m_scene->plot(m_sock->getRootDigest().c_str()); |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | void |
| 562 | ChatDialog::sendJoin() |
| 563 | { |
| 564 | m_joined = true; |
| 565 | SyncDemo::ChatMessage msg; |
| 566 | formControlMessage(msg, SyncDemo::ChatMessage::JOIN); |
| 567 | sendMsg(msg); |
| 568 | boost::random::random_device rng; |
| 569 | boost::random::uniform_int_distribution<> uniform(1, FRESHNESS / 5 * 1000); |
| 570 | m_randomizedInterval = HELLO_INTERVAL * 1000 + uniform(rng); |
| 571 | QTimer::singleShot(m_randomizedInterval, this, SLOT(sendHello())); |
| 572 | } |
| 573 | |
| 574 | void |
| 575 | ChatDialog::sendHello() |
| 576 | { |
| 577 | time_t now = time(NULL); |
| 578 | int elapsed = now - m_lastMsgTime; |
| 579 | if (elapsed >= m_randomizedInterval / 1000) |
| 580 | { |
| 581 | SyncDemo::ChatMessage msg; |
| 582 | formControlMessage(msg, SyncDemo::ChatMessage::HELLO); |
| 583 | sendMsg(msg); |
| 584 | boost::random::random_device rng; |
| 585 | boost::random::uniform_int_distribution<> uniform(1, FRESHNESS / 5 * 1000); |
| 586 | m_randomizedInterval = HELLO_INTERVAL * 1000 + uniform(rng); |
| 587 | QTimer::singleShot(m_randomizedInterval, this, SLOT(sendHello())); |
| 588 | } |
| 589 | else |
| 590 | { |
| 591 | QTimer::singleShot((m_randomizedInterval - elapsed * 1000), this, SLOT(sendHello())); |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | void |
| 596 | ChatDialog::sendLeave() |
| 597 | { |
| 598 | SyncDemo::ChatMessage msg; |
| 599 | formControlMessage(msg, SyncDemo::ChatMessage::LEAVE); |
| 600 | sendMsg(msg); |
| 601 | usleep(500000); |
| 602 | m_sock->remove(m_user.getPrefix().toStdString()); |
| 603 | usleep(5000); |
| 604 | m_joined = false; |
| 605 | _LOG_DEBUG("Sync REMOVE signal sent"); |
| 606 | } |
| 607 | |
| 608 | void |
| 609 | ChatDialog::replot() |
| 610 | { |
| 611 | boost::recursive_mutex::scoped_lock lock(m_sceneMutex); |
| 612 | m_scene->plot(m_sock->getRootDigest().c_str()); |
| 613 | fitView(); |
| 614 | } |
| 615 | |
| 616 | void |
| 617 | ChatDialog::summonReaper() |
| 618 | { |
| 619 | Sync::SyncLogic &logic = m_sock->getLogic (); |
| 620 | map<string, bool> branches = logic.getBranchPrefixes(); |
| 621 | QMap<QString, DisplayUserPtr> roster = m_scene->getRosterFull(); |
| 622 | |
| 623 | m_zombieList.clear(); |
| 624 | |
| 625 | QMapIterator<QString, DisplayUserPtr> it(roster); |
| 626 | map<string, bool>::iterator mapIt; |
| 627 | while(it.hasNext()) |
| 628 | { |
| 629 | it.next(); |
| 630 | DisplayUserPtr p = it.value(); |
| 631 | if (p != DisplayUserNullPtr) |
| 632 | { |
| 633 | mapIt = branches.find(p->getPrefix().toStdString()); |
| 634 | if (mapIt != branches.end()) |
| 635 | { |
| 636 | mapIt->second = true; |
| 637 | } |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | for (mapIt = branches.begin(); mapIt != branches.end(); ++mapIt) |
| 642 | { |
| 643 | // this is zombie. all active users should have been marked true |
| 644 | if (! mapIt->second) |
| 645 | { |
| 646 | m_zombieList.append(mapIt->first.c_str()); |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | m_zombieIndex = 0; |
| 651 | |
| 652 | // start reaping |
| 653 | reap(); |
| 654 | } |
| 655 | |
| 656 | void |
| 657 | ChatDialog::reap() |
| 658 | { |
| 659 | if (m_zombieIndex < m_zombieList.size()) |
| 660 | { |
| 661 | string prefix = m_zombieList.at(m_zombieIndex).toStdString(); |
| 662 | m_sock->remove(prefix); |
| 663 | _LOG_DEBUG("Reaped: prefix = " << prefix); |
| 664 | m_zombieIndex++; |
| 665 | // reap again in 10 seconds |
| 666 | QTimer::singleShot(10000, this, SLOT(reap())); |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | void |
| 671 | ChatDialog::updateRosterList(QStringList staleUserList) |
| 672 | { |
| 673 | boost::recursive_mutex::scoped_lock lock(m_sceneMutex); |
| 674 | QStringList rosterList = m_scene->getRosterList(); |
| 675 | m_rosterModel->setStringList(rosterList); |
| 676 | QString user; |
| 677 | QStringListIterator it(staleUserList); |
| 678 | while(it.hasNext()) |
| 679 | { |
| 680 | std::string nick = it.next().toStdString(); |
| 681 | if (nick.empty()) |
| 682 | continue; |
| 683 | |
| 684 | SyncDemo::ChatMessage msg; |
| 685 | formControlMessage(msg, SyncDemo::ChatMessage::LEAVE); |
| 686 | msg.set_from(nick); |
| 687 | appendMessage(msg); |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | void |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 692 | ChatDialog::settingUpdated(QString nick, QString chatroom, QString originPrefix) |
| 693 | { |
| 694 | QString randString = getRandomString(); |
| 695 | bool needWrite = false; |
| 696 | bool needFresh = false; |
| 697 | |
| 698 | QString oldPrefix = m_user.getPrefix(); |
| 699 | if (!originPrefix.isEmpty() && originPrefix != m_user.getOriginPrefix()) { |
| 700 | m_user.setOriginPrefix(originPrefix); |
| 701 | |
| 702 | m_localPrefix = ndn::Name(originPrefix.toStdString()); |
| 703 | m_localChatPrefix = m_localPrefix; |
| 704 | m_localChatPrefix.append("%F0.").append(m_defaultIdentity); |
| 705 | m_localChatPrefix.append("chronos").append(m_chatroomPrefix.get(-1)).append(randString.toStdString()); |
| 706 | m_user.setPrefix(QString::fromStdString(m_localChatPrefix.toUri())); |
| 707 | m_scene->setCurrentPrefix(QString::fromStdString(m_localChatPrefix.toUri())); |
| 708 | needWrite = true; |
| 709 | needFresh = true; |
| 710 | } |
| 711 | |
| 712 | if (needWrite) { |
| 713 | updateLabels(); |
| 714 | } |
| 715 | |
| 716 | if (needFresh && m_sock != NULL) |
| 717 | { |
| 718 | |
| 719 | { |
| 720 | boost::recursive_mutex::scoped_lock lock(m_sceneMutex); |
| 721 | m_scene->clearAll(); |
| 722 | m_scene->plot("Empty"); |
| 723 | } |
| 724 | |
Yingdi Yu | 0a953c3 | 2013-11-10 10:32:18 -0800 | [diff] [blame] | 725 | ui->textEdit->clear(); |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 726 | |
| 727 | // keep the new prefix |
| 728 | QString newPrefix = m_user.getPrefix(); |
| 729 | // send leave for the old |
| 730 | m_user.setPrefix(oldPrefix); |
| 731 | // there is no point to send leave if we haven't joined yet |
| 732 | if (m_joined) |
| 733 | { |
| 734 | sendLeave(); |
| 735 | } |
| 736 | // resume new prefix |
| 737 | m_user.setPrefix(newPrefix); |
| 738 | // Sync::CcnxWrapperPtr handle = Sync::CcnxWrapper::Create(); |
| 739 | // handle->clearInterestFilter(oldPrefix.toStdString()); |
| 740 | delete m_sock; |
| 741 | m_sock = NULL; |
| 742 | |
| 743 | try |
| 744 | { |
| 745 | usleep(100000); |
| 746 | m_sock = new Sync::SyncSocket(m_chatroomPrefix.toUri(), |
| 747 | m_syncPolicyManager, |
| 748 | bind(&ChatDialog::processTreeUpdateWrapper, this, _1, _2), |
| 749 | bind(&ChatDialog::processRemoveWrapper, this, _1)); |
| 750 | usleep(100000); |
| 751 | // Sync::CcnxWrapperPtr handle = boost::make_shared<Sync::CcnxWrapper> (); |
| 752 | // handle->setInterestFilter(m_user.getPrefix().toStdString(), bind(&ChatDialog::respondHistoryRequest, this, _1)); |
Yingdi Yu | 0a953c3 | 2013-11-10 10:32:18 -0800 | [diff] [blame] | 753 | QTimer::singleShot(600, this, SLOT(sendJoin())); |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 754 | m_timer->start(FRESHNESS * 1000); |
| 755 | disableTreeDisplay(); |
Yingdi Yu | 0a953c3 | 2013-11-10 10:32:18 -0800 | [diff] [blame] | 756 | QTimer::singleShot(2200, this, SLOT(enableTreeDisplay())); |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 757 | }catch(ndn::Error::ndnOperation& e){ |
| 758 | emit noNdnConnection(QString::fromStdString("Cannot conect to ndnd!\n Have you started your ndnd?")); |
| 759 | } |
| 760 | } |
| 761 | else if (needFresh && m_sock == NULL) |
| 762 | { |
| 763 | initializeSync(); |
| 764 | } |
| 765 | else if (m_sock == NULL) |
| 766 | { |
| 767 | initializeSync(); |
| 768 | } |
| 769 | else |
| 770 | { |
| 771 | // #ifdef __DEBUG |
| 772 | // std::cout << "Just changing nicks, we're good. " << std::endl; |
| 773 | // #endif |
| 774 | } |
| 775 | |
| 776 | fitView(); |
| 777 | } |
| 778 | |
| 779 | void |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 780 | ChatDialog::iconActivated(QSystemTrayIcon::ActivationReason reason) |
| 781 | { |
| 782 | switch (reason) |
| 783 | { |
| 784 | case QSystemTrayIcon::Trigger: |
| 785 | case QSystemTrayIcon::DoubleClick: |
| 786 | break; |
| 787 | case QSystemTrayIcon::MiddleClick: |
| 788 | // showMessage(); |
| 789 | break; |
| 790 | default:; |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | |
| 795 | void |
| 796 | ChatDialog::messageClicked() |
| 797 | { |
| 798 | this->showMaximized(); |
| 799 | } |
| 800 | |
| 801 | |
| 802 | void |
| 803 | ChatDialog::createActions() |
| 804 | { |
Yingdi Yu | 07b5b09 | 2013-11-07 17:00:54 -0800 | [diff] [blame] | 805 | minimizeAction = new QAction(tr("Mi&nimize"), this); |
| 806 | connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide())); |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 807 | |
Yingdi Yu | 07b5b09 | 2013-11-07 17:00:54 -0800 | [diff] [blame] | 808 | maximizeAction = new QAction(tr("Ma&ximize"), this); |
| 809 | connect(maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized())); |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 810 | |
Yingdi Yu | 07b5b09 | 2013-11-07 17:00:54 -0800 | [diff] [blame] | 811 | restoreAction = new QAction(tr("&Restore"), this); |
| 812 | connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal())); |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 813 | |
| 814 | // settingsAction = new QAction(tr("Settings"), this); |
| 815 | // connect (settingsAction, SIGNAL(triggered()), this, SLOT(buttonPressed())); |
| 816 | |
| 817 | // settingsAction->setMenuRole (QAction::PreferencesRole); |
| 818 | |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 819 | updateLocalPrefixAction = new QAction(tr("Update local prefix"), this); |
| 820 | connect (updateLocalPrefixAction, SIGNAL(triggered()), this, SLOT(updateLocalPrefix())); |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 821 | |
Yingdi Yu | 07b5b09 | 2013-11-07 17:00:54 -0800 | [diff] [blame] | 822 | quitAction = new QAction(tr("Quit"), this); |
| 823 | connect(quitAction, SIGNAL(triggered()), this, SLOT(quit())); |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | void |
| 827 | ChatDialog::createTrayIcon() |
| 828 | { |
Yingdi Yu | 07b5b09 | 2013-11-07 17:00:54 -0800 | [diff] [blame] | 829 | trayIconMenu = new QMenu(this); |
| 830 | trayIconMenu->addAction(minimizeAction); |
| 831 | trayIconMenu->addAction(maximizeAction); |
| 832 | trayIconMenu->addAction(restoreAction); |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 833 | // trayIconMenu->addSeparator(); |
| 834 | // trayIconMenu->addAction(settingsAction); |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 835 | trayIconMenu->addSeparator(); |
| 836 | trayIconMenu->addAction(updateLocalPrefixAction); |
Yingdi Yu | 07b5b09 | 2013-11-07 17:00:54 -0800 | [diff] [blame] | 837 | trayIconMenu->addSeparator(); |
| 838 | trayIconMenu->addAction(quitAction); |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 839 | |
| 840 | trayIcon = new QSystemTrayIcon(this); |
Yingdi Yu | 07b5b09 | 2013-11-07 17:00:54 -0800 | [diff] [blame] | 841 | trayIcon->setContextMenu(trayIconMenu); |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 842 | |
| 843 | QIcon icon(":/images/icon_small.png"); |
| 844 | trayIcon->setIcon(icon); |
| 845 | setWindowIcon(icon); |
| 846 | trayIcon->setToolTip("ChronoChat System Tray Icon"); |
| 847 | trayIcon->setVisible(true); |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | |
| 851 | void |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 852 | ChatDialog::resizeEvent(QResizeEvent *e) |
| 853 | { |
| 854 | fitView(); |
| 855 | } |
| 856 | |
| 857 | void |
| 858 | ChatDialog::showEvent(QShowEvent *e) |
| 859 | { |
| 860 | fitView(); |
| 861 | } |
| 862 | |
| 863 | void |
| 864 | ChatDialog::fitView() |
| 865 | { |
| 866 | boost::recursive_mutex::scoped_lock lock(m_sceneMutex); |
| 867 | QRectF rect = m_scene->itemsBoundingRect(); |
| 868 | m_scene->setSceneRect(rect); |
| 869 | ui->treeViewer->fitInView(m_scene->itemsBoundingRect(), Qt::KeepAspectRatio); |
| 870 | } |
| 871 | |
| 872 | void |
| 873 | ChatDialog::formChatMessage(const QString &text, SyncDemo::ChatMessage &msg) { |
| 874 | msg.set_from(m_user.getNick().toStdString()); |
| 875 | msg.set_to(m_user.getChatroom().toStdString()); |
| 876 | msg.set_data(text.toUtf8().constData()); |
| 877 | time_t seconds = time(NULL); |
| 878 | msg.set_timestamp(seconds); |
| 879 | msg.set_type(SyncDemo::ChatMessage::CHAT); |
| 880 | } |
| 881 | |
| 882 | void |
| 883 | ChatDialog::formControlMessage(SyncDemo::ChatMessage &msg, SyncDemo::ChatMessage::ChatMessageType type) |
| 884 | { |
| 885 | msg.set_from(m_user.getNick().toStdString()); |
| 886 | msg.set_to(m_user.getChatroom().toStdString()); |
| 887 | time_t seconds = time(NULL); |
| 888 | msg.set_timestamp(seconds); |
| 889 | msg.set_type(type); |
| 890 | } |
| 891 | |
| 892 | void |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 893 | ChatDialog::updateLocalPrefix() |
| 894 | { |
Yingdi Yu | 0a953c3 | 2013-11-10 10:32:18 -0800 | [diff] [blame] | 895 | m_newLocalPrefixReady = false; |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 896 | ndn::Ptr<ndn::Interest> interest = ndn::Ptr<ndn::Interest>(new ndn::Interest(ndn::Name("/local/ndn/prefix"))); |
| 897 | interest->setChildSelector(ndn::Interest::CHILD_RIGHT); |
Yingdi Yu | 0a953c3 | 2013-11-10 10:32:18 -0800 | [diff] [blame] | 898 | interest->setInterestLifetime(1); |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 899 | |
Yingdi Yu | 0a953c3 | 2013-11-10 10:32:18 -0800 | [diff] [blame] | 900 | ndn::Ptr<ndn::Closure> closure = ndn::Ptr<ndn::Closure>(new ndn::Closure(boost::bind(&ChatDialog::onLocalPrefix, |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 901 | this, |
| 902 | _1), |
Yingdi Yu | 0a953c3 | 2013-11-10 10:32:18 -0800 | [diff] [blame] | 903 | boost::bind(&ChatDialog::onLocalPrefixTimeout, |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 904 | this, |
| 905 | _1, |
| 906 | _2), |
Yingdi Yu | 0a953c3 | 2013-11-10 10:32:18 -0800 | [diff] [blame] | 907 | boost::bind(&ChatDialog::onLocalPrefix, |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 908 | this, |
| 909 | _1))); |
| 910 | |
| 911 | m_localPrefixHandler->sendInterest(interest, closure); |
Yingdi Yu | 0a953c3 | 2013-11-10 10:32:18 -0800 | [diff] [blame] | 912 | while(m_newLocalPrefixReady == false) |
| 913 | { |
| 914 | #if BOOST_VERSION >= 1050000 |
| 915 | boost::this_thread::sleep_for(boost::chrono::milliseconds(100)); |
| 916 | #else |
| 917 | boost::this_thread::sleep(boost::posix_time::milliseconds(100)); |
| 918 | #endif |
| 919 | } |
| 920 | _LOG_DEBUG("now the prefix is " << m_localPrefix.toUri()); |
| 921 | QString originPrefix = QString::fromStdString(m_newLocalPrefix.toUri()); |
| 922 | |
| 923 | if (originPrefix != "" && m_user.getOriginPrefix () != originPrefix) |
| 924 | emit settingUpdated(m_user.getNick (), m_user.getChatroom (), originPrefix); |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | static std::string chars2("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789"); |
| 928 | |
| 929 | QString |
| 930 | ChatDialog::getRandomString() |
| 931 | { |
| 932 | std::string randStr; |
| 933 | boost::random::random_device rng; |
| 934 | boost::random::uniform_int_distribution<> index_dist(0, chars2.size() - 1); |
| 935 | for (int i = 0; i < 10; i ++) |
| 936 | { |
| 937 | randStr += chars2[index_dist(rng)]; |
| 938 | } |
| 939 | return randStr.c_str(); |
| 940 | } |
| 941 | |
| 942 | void |
Yingdi Yu | 0a953c3 | 2013-11-10 10:32:18 -0800 | [diff] [blame] | 943 | ChatDialog::onLocalPrefix(ndn::Ptr<ndn::Data> data) |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 944 | { |
| 945 | string dataString(data->content().buf(), data->content().size()); |
| 946 | QString originPrefix = QString::fromStdString (dataString).trimmed (); |
Yingdi Yu | 0a953c3 | 2013-11-10 10:32:18 -0800 | [diff] [blame] | 947 | string trimmedString = originPrefix.toStdString(); |
| 948 | m_newLocalPrefix = ndn::Name(trimmedString); |
| 949 | m_newLocalPrefixReady = true; |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | void |
Yingdi Yu | 0a953c3 | 2013-11-10 10:32:18 -0800 | [diff] [blame] | 953 | ChatDialog::onLocalPrefixTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest) |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 954 | { |
Yingdi Yu | 0a953c3 | 2013-11-10 10:32:18 -0800 | [diff] [blame] | 955 | m_newLocalPrefix = m_localPrefix; |
| 956 | m_newLocalPrefixReady = true; |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | void |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 960 | ChatDialog::changeEvent(QEvent *e) |
| 961 | { |
| 962 | switch(e->type()) |
| 963 | { |
| 964 | case QEvent::ActivationChange: |
| 965 | if (isActiveWindow()) |
| 966 | { |
| 967 | trayIcon->setIcon(QIcon(":/images/icon_small.png")); |
| 968 | } |
| 969 | break; |
| 970 | default: |
| 971 | break; |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | void |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 976 | ChatDialog::appendMessage(const SyncDemo::ChatMessage msg, bool isHistory) |
| 977 | { |
| 978 | boost::recursive_mutex::scoped_lock lock(m_msgMutex); |
| 979 | |
| 980 | if (msg.type() == SyncDemo::ChatMessage::CHAT) |
| 981 | { |
| 982 | |
| 983 | if (!msg.has_data()) |
| 984 | { |
| 985 | return; |
| 986 | } |
| 987 | |
| 988 | if (msg.from().empty() || msg.data().empty()) |
| 989 | { |
| 990 | return; |
| 991 | } |
| 992 | |
| 993 | if (!msg.has_timestamp()) |
| 994 | { |
| 995 | return; |
| 996 | } |
| 997 | |
| 998 | // if (m_history.size() == MAX_HISTORY_ENTRY) |
| 999 | // { |
| 1000 | // m_history.dequeue(); |
| 1001 | // } |
| 1002 | |
| 1003 | // m_history.enqueue(msg); |
| 1004 | |
| 1005 | QTextCharFormat nickFormat; |
| 1006 | nickFormat.setForeground(Qt::darkGreen); |
| 1007 | nickFormat.setFontWeight(QFont::Bold); |
| 1008 | nickFormat.setFontUnderline(true); |
| 1009 | nickFormat.setUnderlineColor(Qt::gray); |
| 1010 | |
| 1011 | QTextCursor cursor(ui->textEdit->textCursor()); |
| 1012 | cursor.movePosition(QTextCursor::End); |
| 1013 | QTextTableFormat tableFormat; |
| 1014 | tableFormat.setBorder(0); |
| 1015 | QTextTable *table = cursor.insertTable(1, 2, tableFormat); |
| 1016 | QString from = QString("%1 ").arg(msg.from().c_str()); |
| 1017 | QTextTableCell fromCell = table->cellAt(0, 0); |
| 1018 | fromCell.setFormat(nickFormat); |
| 1019 | fromCell.firstCursorPosition().insertText(from); |
| 1020 | |
| 1021 | time_t timestamp = msg.timestamp(); |
| 1022 | printTimeInCell(table, timestamp); |
| 1023 | |
| 1024 | QTextCursor nextCursor(ui->textEdit->textCursor()); |
| 1025 | nextCursor.movePosition(QTextCursor::End); |
| 1026 | table = nextCursor.insertTable(1, 1, tableFormat); |
| 1027 | table->cellAt(0, 0).firstCursorPosition().insertText(QString::fromUtf8(msg.data().c_str())); |
| 1028 | if (!isHistory) |
| 1029 | { |
| 1030 | showMessage(from, QString::fromUtf8(msg.data().c_str())); |
| 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | if (msg.type() == SyncDemo::ChatMessage::JOIN || msg.type() == SyncDemo::ChatMessage::LEAVE) |
| 1035 | { |
| 1036 | QTextCharFormat nickFormat; |
| 1037 | nickFormat.setForeground(Qt::gray); |
| 1038 | nickFormat.setFontWeight(QFont::Bold); |
| 1039 | nickFormat.setFontUnderline(true); |
| 1040 | nickFormat.setUnderlineColor(Qt::gray); |
| 1041 | |
| 1042 | QTextCursor cursor(ui->textEdit->textCursor()); |
| 1043 | cursor.movePosition(QTextCursor::End); |
| 1044 | QTextTableFormat tableFormat; |
| 1045 | tableFormat.setBorder(0); |
| 1046 | QTextTable *table = cursor.insertTable(1, 2, tableFormat); |
| 1047 | QString action; |
| 1048 | if (msg.type() == SyncDemo::ChatMessage::JOIN) |
| 1049 | { |
| 1050 | action = "enters room"; |
| 1051 | } |
| 1052 | else |
| 1053 | { |
| 1054 | action = "leaves room"; |
| 1055 | } |
| 1056 | |
| 1057 | QString from = QString("%1 %2 ").arg(msg.from().c_str()).arg(action); |
| 1058 | QTextTableCell fromCell = table->cellAt(0, 0); |
| 1059 | fromCell.setFormat(nickFormat); |
| 1060 | fromCell.firstCursorPosition().insertText(from); |
| 1061 | |
| 1062 | time_t timestamp = msg.timestamp(); |
| 1063 | printTimeInCell(table, timestamp); |
| 1064 | } |
| 1065 | |
| 1066 | QScrollBar *bar = ui->textEdit->verticalScrollBar(); |
| 1067 | bar->setValue(bar->maximum()); |
| 1068 | } |
| 1069 | |
| 1070 | QString |
| 1071 | ChatDialog::formatTime(time_t timestamp) |
| 1072 | { |
| 1073 | struct tm *tm_time = localtime(×tamp); |
| 1074 | int hour = tm_time->tm_hour; |
| 1075 | QString amOrPM; |
| 1076 | if (hour > 12) |
| 1077 | { |
| 1078 | hour -= 12; |
| 1079 | amOrPM = "PM"; |
| 1080 | } |
| 1081 | else |
| 1082 | { |
| 1083 | amOrPM = "AM"; |
| 1084 | if (hour == 0) |
| 1085 | { |
| 1086 | hour = 12; |
| 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | char textTime[12]; |
| 1091 | sprintf(textTime, "%d:%02d:%02d %s", hour, tm_time->tm_min, tm_time->tm_sec, amOrPM.toStdString().c_str()); |
| 1092 | return QString(textTime); |
| 1093 | } |
| 1094 | |
| 1095 | void |
| 1096 | ChatDialog::printTimeInCell(QTextTable *table, time_t timestamp) |
| 1097 | { |
| 1098 | QTextCharFormat timeFormat; |
| 1099 | timeFormat.setForeground(Qt::gray); |
| 1100 | timeFormat.setFontUnderline(true); |
| 1101 | timeFormat.setUnderlineColor(Qt::gray); |
| 1102 | QTextTableCell timeCell = table->cellAt(0, 1); |
| 1103 | timeCell.setFormat(timeFormat); |
| 1104 | timeCell.firstCursorPosition().insertText(formatTime(timestamp)); |
| 1105 | } |
| 1106 | |
| 1107 | void |
| 1108 | ChatDialog::showMessage(QString from, QString data) |
| 1109 | { |
| 1110 | if (!isActiveWindow()) |
| 1111 | { |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 1112 | trayIcon->showMessage(QString("Chatroom %1 has a new message").arg(m_user.getChatroom()), QString("<%1>: %2").arg(from).arg(data), QSystemTrayIcon::Information, 20000); |
| 1113 | trayIcon->setIcon(QIcon(":/images/note.png")); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 1114 | } |
| 1115 | } |
| 1116 | |
| 1117 | void |
| 1118 | ChatDialog::sendMsg(SyncDemo::ChatMessage &msg) |
| 1119 | { |
| 1120 | // send msg |
| 1121 | size_t size = msg.ByteSize(); |
| 1122 | char *buf = new char[size]; |
| 1123 | msg.SerializeToArray(buf, size); |
| 1124 | if (!msg.IsInitialized()) |
| 1125 | { |
| 1126 | _LOG_DEBUG("Errrrr.. msg was not probally initialized "<<__FILE__ <<":"<<__LINE__<<". what is happening?"); |
| 1127 | abort(); |
| 1128 | } |
| 1129 | m_sock->publishData(m_user.getPrefix().toStdString(), m_session, buf, size, FRESHNESS); |
| 1130 | |
| 1131 | delete buf; |
| 1132 | |
| 1133 | m_lastMsgTime = time(NULL); |
| 1134 | |
| 1135 | int nextSequence = m_sock->getNextSeq(m_user.getPrefix().toStdString(), m_session); |
| 1136 | Sync::MissingDataInfo mdi = {m_user.getPrefix().toStdString(), Sync::SeqNo(0), Sync::SeqNo(nextSequence - 1)}; |
| 1137 | std::vector<Sync::MissingDataInfo> v; |
| 1138 | v.push_back(mdi); |
| 1139 | { |
| 1140 | boost::recursive_mutex::scoped_lock lock(m_sceneMutex); |
| 1141 | m_scene->processUpdate(v, m_sock->getRootDigest().c_str()); |
| 1142 | m_scene->msgReceived(m_user.getPrefix(), m_user.getNick()); |
| 1143 | } |
| 1144 | } |
| 1145 | |
| 1146 | void |
| 1147 | ChatDialog::openInviteListDialog() |
| 1148 | { |
| 1149 | m_inviteListDialog->setInviteLabel(m_chatroomPrefix.toUri()); |
| 1150 | m_inviteListDialog->show(); |
| 1151 | } |
| 1152 | |
| 1153 | void |
| 1154 | ChatDialog::sendInvitationWrapper(QString invitee, bool isIntroducer) |
| 1155 | { |
| 1156 | ndn::Name inviteeNamespace(invitee.toUtf8().constData()); |
| 1157 | ndn::Ptr<ContactItem> inviteeItem = m_contactManager->getContact(inviteeNamespace); |
| 1158 | sendInvitation(inviteeItem, isIntroducer); |
| 1159 | } |
| 1160 | |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 1161 | void |
| 1162 | ChatDialog::closeEvent(QCloseEvent *e) |
| 1163 | { |
Yingdi Yu | 07b5b09 | 2013-11-07 17:00:54 -0800 | [diff] [blame] | 1164 | if (trayIcon->isVisible()) |
| 1165 | { |
| 1166 | QMessageBox::information(this, tr("Chronos"), |
| 1167 | tr("The program will keep running in the " |
| 1168 | "system tray. To terminate the program" |
| 1169 | "choose <b>Quit</b> in the context memu" |
| 1170 | "of the system tray entry.")); |
| 1171 | hide(); |
| 1172 | e->ignore(); |
| 1173 | } |
| 1174 | } |
| 1175 | |
| 1176 | void |
| 1177 | ChatDialog::quit() |
| 1178 | { |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 1179 | hide(); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 1180 | emit closeChatDialog(m_chatroomPrefix); |
| 1181 | } |
| 1182 | |
| 1183 | |
| 1184 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 1185 | |
Yingdi Yu | 0484223 | 2013-10-23 14:03:09 -0700 | [diff] [blame] | 1186 | #if WAF |
| 1187 | #include "chatdialog.moc" |
| 1188 | #include "chatdialog.cpp.moc" |
| 1189 | #endif |