Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [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 | * |
| 8 | * Author: Yingdi Yu <yingdi@cs.ucla.edu> |
| 9 | */ |
| 10 | |
| 11 | #include <QApplication> |
| 12 | #include <QMessageBox> |
| 13 | #include <QDir> |
| 14 | #include <QTimer> |
| 15 | #include "controller.h" |
| 16 | |
| 17 | #ifndef Q_MOC_RUN |
| 18 | #include <boost/filesystem.hpp> |
| 19 | #include <boost/lexical_cast.hpp> |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 20 | #include <ndn-cxx/util/random.hpp> |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 21 | #include <cryptopp/sha.h> |
| 22 | #include <cryptopp/hex.h> |
| 23 | #include <cryptopp/files.h> |
| 24 | #include <cryptopp/filters.h> |
| 25 | #include "config.pb.h" |
| 26 | #include "endorse-info.pb.h" |
| 27 | #include "logging.h" |
| 28 | #endif |
| 29 | |
| 30 | INIT_LOGGER("chronos.Controller"); |
| 31 | |
| 32 | using namespace ndn; |
| 33 | |
| 34 | Q_DECLARE_METATYPE(ndn::Name) |
| 35 | Q_DECLARE_METATYPE(ndn::IdentityCertificate) |
| 36 | Q_DECLARE_METATYPE(chronos::EndorseInfo) |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 37 | Q_DECLARE_METATYPE(ndn::Interest) |
| 38 | Q_DECLARE_METATYPE(size_t) |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 39 | |
| 40 | namespace chronos { |
| 41 | |
Yingdi Yu | 17032f8 | 2014-03-25 15:48:23 -0700 | [diff] [blame] | 42 | using ndn::shared_ptr; |
| 43 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 44 | static const uint8_t ROUTING_PREFIX_SEPARATOR[2] = {0xF0, 0x2E}; |
| 45 | |
| 46 | // constructor & destructor |
| 47 | Controller::Controller(shared_ptr<Face> face, |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 48 | QWidget* parent) |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 49 | : QDialog(parent) |
| 50 | , m_face(face) |
| 51 | , m_invitationListenerId(0) |
| 52 | , m_contactManager(m_face) |
| 53 | , m_settingDialog(new SettingDialog) |
| 54 | , m_startChatDialog(new StartChatDialog) |
| 55 | , m_profileEditor(new ProfileEditor) |
| 56 | , m_invitationDialog(new InvitationDialog) |
| 57 | , m_contactPanel(new ContactPanel) |
| 58 | , m_browseContactDialog(new BrowseContactDialog) |
| 59 | , m_addContactPanel(new AddContactPanel) |
| 60 | { |
| 61 | qRegisterMetaType<ndn::Name>("ndn.Name"); |
| 62 | qRegisterMetaType<ndn::IdentityCertificate>("ndn.IdentityCertificate"); |
| 63 | qRegisterMetaType<chronos::EndorseInfo>("chronos.EndorseInfo"); |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 64 | qRegisterMetaType<ndn::Interest>("ndn.Interest"); |
| 65 | qRegisterMetaType<size_t>("size_t"); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 66 | |
| 67 | connect(this, SIGNAL(localPrefixUpdated(const QString&)), |
| 68 | this, SLOT(onLocalPrefixUpdated(const QString&))); |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 69 | connect(this, SIGNAL(invitationInterest(const ndn::Name&, const ndn::Interest&, size_t)), |
| 70 | this, SLOT(onInvitationInterest(const ndn::Name&, const ndn::Interest&, size_t))); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 71 | |
| 72 | // Connection to ContactManager |
| 73 | connect(this, SIGNAL(identityUpdated(const QString&)), |
| 74 | &m_contactManager, SLOT(onIdentityUpdated(const QString&))); |
| 75 | connect(&m_contactManager, SIGNAL(warning(const QString&)), |
| 76 | this, SLOT(onWarning(const QString&))); |
| 77 | connect(this, SIGNAL(refreshBrowseContact()), |
| 78 | &m_contactManager, SLOT(onRefreshBrowseContact())); |
| 79 | connect(&m_contactManager, SIGNAL(contactInfoFetchFailed(const QString&)), |
| 80 | this, SLOT(onWarning(const QString&))); |
| 81 | connect(&m_contactManager, SIGNAL(contactIdListReady(const QStringList&)), |
| 82 | this, SLOT(onContactIdListReady(const QStringList&))); |
| 83 | |
| 84 | // Connection to SettingDialog |
| 85 | connect(this, SIGNAL(identityUpdated(const QString&)), |
| 86 | m_settingDialog, SLOT(onIdentityUpdated(const QString&))); |
| 87 | connect(m_settingDialog, SIGNAL(identityUpdated(const QString&)), |
| 88 | this, SLOT(onIdentityUpdated(const QString&))); |
| 89 | connect(m_settingDialog, SIGNAL(nickUpdated(const QString&)), |
| 90 | this, SLOT(onNickUpdated(const QString&))); |
| 91 | |
| 92 | // Connection to ProfileEditor |
| 93 | connect(this, SIGNAL(closeDBModule()), |
| 94 | m_profileEditor, SLOT(onCloseDBModule())); |
| 95 | connect(this, SIGNAL(identityUpdated(const QString&)), |
| 96 | m_profileEditor, SLOT(onIdentityUpdated(const QString&))); |
| 97 | connect(m_profileEditor, SIGNAL(updateProfile()), |
| 98 | &m_contactManager, SLOT(onUpdateProfile())); |
| 99 | |
| 100 | // Connection to StartChatDialog |
| 101 | connect(m_startChatDialog, SIGNAL(startChatroom(const QString&, bool)), |
| 102 | this, SLOT(onStartChatroom(const QString&, bool))); |
| 103 | |
| 104 | // Connection to InvitationDialog |
| 105 | connect(m_invitationDialog, SIGNAL(invitationResponded(const ndn::Name&, bool)), |
| 106 | this, SLOT(onInvitationResponded(const ndn::Name&, bool))); |
| 107 | |
| 108 | // Connection to AddContactPanel |
| 109 | connect(m_addContactPanel, SIGNAL(fetchInfo(const QString&)), |
| 110 | &m_contactManager, SLOT(onFetchContactInfo(const QString&))); |
| 111 | connect(m_addContactPanel, SIGNAL(addContact(const QString&)), |
| 112 | &m_contactManager, SLOT(onAddFetchedContact(const QString&))); |
| 113 | connect(&m_contactManager, SIGNAL(contactEndorseInfoReady(const chronos::EndorseInfo&)), |
| 114 | m_addContactPanel, SLOT(onContactEndorseInfoReady(const chronos::EndorseInfo&))); |
| 115 | |
| 116 | |
| 117 | // Connection to BrowseContactDialog |
| 118 | connect(m_browseContactDialog, SIGNAL(directAddClicked()), |
| 119 | this, SLOT(onDirectAdd())); |
| 120 | connect(m_browseContactDialog, SIGNAL(fetchIdCert(const QString&)), |
| 121 | &m_contactManager, SLOT(onFetchIdCert(const QString&))); |
| 122 | connect(m_browseContactDialog, SIGNAL(addContact(const QString&)), |
| 123 | &m_contactManager, SLOT(onAddFetchedContactIdCert(const QString&))); |
| 124 | connect(&m_contactManager, SIGNAL(idCertNameListReady(const QStringList&)), |
| 125 | m_browseContactDialog, SLOT(onIdCertNameListReady(const QStringList&))); |
| 126 | connect(&m_contactManager, SIGNAL(nameListReady(const QStringList&)), |
| 127 | m_browseContactDialog, SLOT(onNameListReady(const QStringList&))); |
| 128 | connect(&m_contactManager, SIGNAL(idCertReady(const ndn::IdentityCertificate&)), |
| 129 | m_browseContactDialog, SLOT(onIdCertReady(const ndn::IdentityCertificate&))); |
| 130 | |
| 131 | // Connection to ContactPanel |
| 132 | connect(m_contactPanel, SIGNAL(waitForContactList()), |
| 133 | &m_contactManager, SLOT(onWaitForContactList())); |
| 134 | connect(m_contactPanel, SIGNAL(waitForContactInfo(const QString&)), |
| 135 | &m_contactManager, SLOT(onWaitForContactInfo(const QString&))); |
| 136 | connect(m_contactPanel, SIGNAL(removeContact(const QString&)), |
| 137 | &m_contactManager, SLOT(onRemoveContact(const QString&))); |
| 138 | connect(m_contactPanel, SIGNAL(updateAlias(const QString&, const QString&)), |
| 139 | &m_contactManager, SLOT(onUpdateAlias(const QString&, const QString&))); |
| 140 | connect(m_contactPanel, SIGNAL(updateIsIntroducer(const QString&, bool)), |
| 141 | &m_contactManager, SLOT(onUpdateIsIntroducer(const QString&, bool))); |
| 142 | connect(m_contactPanel, SIGNAL(updateEndorseCertificate(const QString&)), |
| 143 | &m_contactManager, SLOT(onUpdateEndorseCertificate(const QString&))); |
| 144 | connect(m_contactPanel, SIGNAL(warning(const QString&)), |
| 145 | this, SLOT(onWarning(const QString&))); |
| 146 | connect(this, SIGNAL(closeDBModule()), |
| 147 | m_contactPanel, SLOT(onCloseDBModule())); |
| 148 | connect(this, SIGNAL(identityUpdated(const QString&)), |
| 149 | m_contactPanel, SLOT(onIdentityUpdated(const QString&))); |
| 150 | connect(&m_contactManager, SIGNAL(contactAliasListReady(const QStringList&)), |
| 151 | m_contactPanel, SLOT(onContactAliasListReady(const QStringList&))); |
| 152 | connect(&m_contactManager, SIGNAL(contactIdListReady(const QStringList&)), |
| 153 | m_contactPanel, SLOT(onContactIdListReady(const QStringList&))); |
| 154 | connect(&m_contactManager, SIGNAL(contactInfoReady(const QString&, const QString&, const QString&, bool)), |
| 155 | m_contactPanel, SLOT(onContactInfoReady(const QString&, const QString&, const QString&, bool))); |
| 156 | |
| 157 | initialize(); |
| 158 | |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 159 | createTrayIcon(); |
| 160 | |
| 161 | onUpdateLocalPrefixAction(); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 162 | } |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 163 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 164 | Controller::~Controller() |
| 165 | { |
| 166 | saveConf(); |
| 167 | } |
| 168 | |
| 169 | // public methods |
| 170 | |
| 171 | |
| 172 | // private methods |
| 173 | std::string |
| 174 | Controller::getDBName() |
| 175 | { |
| 176 | std::string dbName("chronos-"); |
| 177 | |
| 178 | std::stringstream ss; |
| 179 | { |
| 180 | using namespace CryptoPP; |
| 181 | |
| 182 | SHA256 hash; |
| 183 | StringSource(m_identity.wireEncode().wire(), m_identity.wireEncode().size(), true, |
| 184 | new HashFilter(hash, new HexEncoder(new FileSink(ss), false))); |
| 185 | } |
| 186 | dbName.append(ss.str()).append(".db"); |
| 187 | |
| 188 | return dbName; |
| 189 | } |
| 190 | |
| 191 | void |
| 192 | Controller::openDB() |
| 193 | { |
| 194 | m_db = QSqlDatabase::addDatabase("QSQLITE"); |
| 195 | QString path = (QDir::home().path()); |
| 196 | path.append(QDir::separator()).append(".chronos").append(QDir::separator()).append(getDBName().c_str()); |
| 197 | m_db.setDatabaseName(path); |
| 198 | bool ok = m_db.open(); |
| 199 | |
| 200 | _LOG_DEBUG("DB opened: " << std::boolalpha << ok ); |
| 201 | } |
| 202 | |
| 203 | void |
| 204 | Controller::initialize() |
| 205 | { |
| 206 | loadConf(); |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 207 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 208 | m_keyChain.createIdentity(m_identity); |
| 209 | |
| 210 | openDB(); |
| 211 | |
| 212 | emit identityUpdated(QString(m_identity.toUri().c_str())); |
| 213 | |
| 214 | setInvitationListener(); |
| 215 | } |
| 216 | |
| 217 | void |
| 218 | Controller::setInvitationListener() |
| 219 | { |
| 220 | if(m_invitationListenerId != 0) |
| 221 | m_face->unsetInterestFilter(m_invitationListenerId); |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 222 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 223 | Name invitationPrefix; |
| 224 | Name routingPrefix = getInvitationRoutingPrefix(); |
| 225 | size_t offset = 0; |
| 226 | if(!routingPrefix.isPrefixOf(m_identity)) |
| 227 | { |
| 228 | invitationPrefix.append(routingPrefix).append(ROUTING_PREFIX_SEPARATOR, 2); |
| 229 | offset = routingPrefix.size() + 1; |
| 230 | } |
| 231 | invitationPrefix.append(m_identity).append("CHRONOCHAT-INVITATION"); |
| 232 | |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 233 | m_invitationListenerId = m_face->setInterestFilter(invitationPrefix, |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 234 | bind(&Controller::onInvitationInterestWrapper, this, _1, _2, offset), |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 235 | bind(&Controller::onInvitationRegisterFailed, this, _1, _2)); |
| 236 | } |
| 237 | |
| 238 | void |
| 239 | Controller::loadConf() |
| 240 | { |
| 241 | namespace fs = boost::filesystem; |
| 242 | |
| 243 | fs::path chronosDir = fs::path(getenv("HOME")) / ".chronos"; |
| 244 | fs::create_directories (chronosDir); |
| 245 | |
| 246 | std::ifstream is((chronosDir / "config").c_str ()); |
| 247 | ChronoChat::Conf conf; |
| 248 | if(conf.ParseFromIstream(&is)) |
| 249 | { |
| 250 | m_identity.clear(); |
| 251 | m_identity.append(conf.identity()); |
| 252 | if(conf.has_nick()) |
| 253 | m_nick = conf.nick(); |
| 254 | else |
| 255 | m_nick = m_identity.get(-1).toUri(); |
| 256 | } |
| 257 | else |
| 258 | { |
| 259 | m_identity.clear(); |
| 260 | // TODO: change below to system default; |
| 261 | m_identity.append("chronochat-tmp-identity") |
Yingdi Yu | a787672 | 2014-03-25 14:46:55 -0700 | [diff] [blame] | 262 | .append(getRandomString()); |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 263 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 264 | m_nick = m_identity.get(-1).toUri(); |
| 265 | } |
| 266 | } |
| 267 | |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 268 | void |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 269 | Controller::saveConf() |
| 270 | { |
| 271 | namespace fs = boost::filesystem; |
| 272 | |
| 273 | fs::path chronosDir = fs::path(getenv("HOME")) / ".chronos"; |
| 274 | fs::create_directories (chronosDir); |
| 275 | |
| 276 | std::ofstream os((chronosDir / "config").c_str ()); |
| 277 | ChronoChat::Conf conf; |
| 278 | conf.set_identity(m_identity.toUri()); |
| 279 | if(!m_nick.empty()) |
| 280 | conf.set_nick(m_nick); |
| 281 | conf.SerializeToOstream(&os); |
| 282 | |
| 283 | os.close(); |
| 284 | } |
| 285 | |
| 286 | void |
| 287 | Controller::createActions() |
| 288 | { |
| 289 | m_startChatroom = new QAction(tr("Start new chat"), this); |
| 290 | connect(m_startChatroom, SIGNAL(triggered()), this, SLOT(onStartChatAction())); |
| 291 | |
| 292 | m_settingsAction = new QAction(tr("Settings"), this); |
| 293 | connect(m_settingsAction, SIGNAL(triggered()), this, SLOT(onSettingsAction())); |
| 294 | |
| 295 | m_editProfileAction = new QAction(tr("Edit profile"), this); |
| 296 | connect(m_editProfileAction, SIGNAL(triggered()), this, SLOT(onProfileEditorAction())); |
| 297 | |
| 298 | m_contactListAction = new QAction(tr("Contact List"), this); |
| 299 | connect(m_contactListAction, SIGNAL(triggered()), this, SLOT(onContactListAction())); |
| 300 | |
| 301 | m_addContactAction = new QAction(tr("Add contact"), this); |
| 302 | connect(m_addContactAction, SIGNAL(triggered()), this, SLOT(onAddContactAction())); |
| 303 | |
| 304 | m_updateLocalPrefixAction = new QAction(tr("Update local prefix"), this); |
| 305 | connect(m_updateLocalPrefixAction, SIGNAL(triggered()), this, SLOT(onUpdateLocalPrefixAction())); |
| 306 | |
| 307 | m_minimizeAction = new QAction(tr("Mi&nimize"), this); |
| 308 | connect(m_minimizeAction, SIGNAL(triggered()), this, SLOT(onMinimizeAction())); |
| 309 | |
| 310 | m_quitAction = new QAction(tr("Quit"), this); |
| 311 | connect(m_quitAction, SIGNAL(triggered()), this, SLOT(onQuitAction())); |
| 312 | } |
| 313 | |
| 314 | void |
| 315 | Controller::createTrayIcon() |
| 316 | { |
| 317 | createActions(); |
| 318 | |
| 319 | m_trayIconMenu = new QMenu(this); |
| 320 | m_trayIconMenu->addAction(m_startChatroom); |
| 321 | m_trayIconMenu->addSeparator(); |
| 322 | m_trayIconMenu->addAction(m_settingsAction); |
| 323 | m_trayIconMenu->addAction(m_editProfileAction); |
| 324 | m_trayIconMenu->addSeparator(); |
| 325 | m_trayIconMenu->addAction(m_contactListAction); |
| 326 | m_trayIconMenu->addAction(m_addContactAction); |
| 327 | m_trayIconMenu->addSeparator(); |
| 328 | m_trayIconMenu->addAction(m_updateLocalPrefixAction); |
| 329 | m_trayIconMenu->addSeparator(); |
| 330 | m_trayIconMenu->addAction(m_minimizeAction); |
| 331 | m_closeMenu = m_trayIconMenu->addMenu("Close chatroom"); |
| 332 | m_closeMenu->setEnabled(false); |
| 333 | m_trayIconMenu->addSeparator(); |
| 334 | m_trayIconMenu->addAction(m_quitAction); |
| 335 | |
| 336 | m_trayIcon = new QSystemTrayIcon(this); |
| 337 | m_trayIcon->setContextMenu(m_trayIconMenu); |
| 338 | |
| 339 | m_trayIcon->setIcon(QIcon(":/images/icon_small.png")); |
| 340 | m_trayIcon->setToolTip("ChronoChat System Tray Icon"); |
| 341 | m_trayIcon->setVisible(true); |
| 342 | } |
| 343 | |
| 344 | void |
| 345 | Controller::updateMenu() |
| 346 | { |
| 347 | QMenu* menu = new QMenu(this); |
| 348 | QMenu* closeMenu = 0; |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 349 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 350 | menu->addAction(m_startChatroom); |
| 351 | menu->addSeparator(); |
| 352 | menu->addAction(m_settingsAction); |
| 353 | menu->addAction(m_editProfileAction); |
| 354 | menu->addSeparator(); |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 355 | menu->addAction(m_contactListAction); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 356 | menu->addAction(m_addContactAction); |
| 357 | menu->addSeparator(); |
| 358 | { |
| 359 | ChatActionList::const_iterator it = m_chatActionList.begin(); |
| 360 | ChatActionList::const_iterator end = m_chatActionList.end(); |
| 361 | if(it != end) |
| 362 | { |
| 363 | for(; it != end; it++) |
| 364 | menu->addAction(it->second); |
| 365 | menu->addSeparator(); |
| 366 | } |
| 367 | } |
| 368 | menu->addAction(m_updateLocalPrefixAction); |
| 369 | menu->addSeparator(); |
| 370 | menu->addAction(m_minimizeAction); |
| 371 | closeMenu = menu->addMenu("Close chatroom"); |
| 372 | { |
| 373 | ChatActionList::const_iterator it = m_closeActionList.begin(); |
| 374 | ChatActionList::const_iterator end = m_closeActionList.end(); |
| 375 | if(it == end) |
| 376 | { |
| 377 | closeMenu->setEnabled(false); |
| 378 | } |
| 379 | else |
| 380 | { |
| 381 | for(; it != end; it++) |
| 382 | closeMenu->addAction(it->second); |
| 383 | } |
| 384 | } |
| 385 | menu->addSeparator(); |
| 386 | menu->addAction(m_quitAction); |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 387 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 388 | m_trayIcon->setContextMenu(menu); |
| 389 | delete m_trayIconMenu; |
| 390 | m_trayIconMenu = menu; |
| 391 | m_closeMenu = closeMenu; |
| 392 | } |
| 393 | |
| 394 | void |
| 395 | Controller::onLocalPrefix(const Interest& interest, Data& data) |
| 396 | { |
| 397 | QString localPrefixStr = QString::fromUtf8 |
| 398 | (reinterpret_cast<const char*>(data.getContent().value()), data.getContent().value_size()) |
| 399 | .trimmed(); |
| 400 | |
| 401 | Name localPrefix(localPrefixStr.toStdString()); |
| 402 | if(m_localPrefix.empty() || m_localPrefix != localPrefix) |
| 403 | emit localPrefixUpdated(localPrefixStr); |
| 404 | } |
| 405 | |
| 406 | void |
| 407 | Controller::onLocalPrefixTimeout(const Interest& interest) |
| 408 | { |
| 409 | QString localPrefixStr("/private/local"); |
| 410 | |
| 411 | Name localPrefix(localPrefixStr.toStdString()); |
| 412 | if(m_localPrefix.empty() || m_localPrefix != localPrefix) |
| 413 | emit localPrefixUpdated(localPrefixStr); |
| 414 | } |
| 415 | |
| 416 | void |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 417 | Controller::onInvitationInterestWrapper(const Name& prefix, const Interest& interest, size_t routingPrefixOffset) |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 418 | { |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 419 | emit invitationInterest(prefix, interest, routingPrefixOffset); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | void |
| 423 | Controller::onInvitationRegisterFailed(const Name& prefix, const std::string& failInfo) |
| 424 | { |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 425 | _LOG_DEBUG("Controller::onInvitationRegisterFailed: " << failInfo); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | void |
| 429 | Controller::onInvitationValidated(const shared_ptr<const Interest>& interest) |
| 430 | { |
| 431 | Invitation invitation(interest->getName()); |
| 432 | std::string alias = invitation.getInviterCertificate().getPublicKeyName().getPrefix(-1).toUri(); // Should be obtained via a method of ContactManager. |
| 433 | |
| 434 | m_invitationDialog->setInvitation(alias, invitation.getChatroom(), interest->getName()); |
| 435 | m_invitationDialog->show(); |
| 436 | } |
| 437 | |
| 438 | void |
| 439 | Controller::onInvitationValidationFailed(const shared_ptr<const Interest>& interest, std::string failureInfo) |
| 440 | { |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 441 | _LOG_DEBUG("Invitation: " << interest->getName() << " cannot not be validated due to: " << failureInfo); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | std::string |
| 445 | Controller::getRandomString() |
| 446 | { |
| 447 | uint32_t r = random::generateWord32(); |
| 448 | std::stringstream ss; |
| 449 | { |
| 450 | using namespace CryptoPP; |
| 451 | StringSource(reinterpret_cast<uint8_t*>(&r), 4, true, |
| 452 | new HexEncoder(new FileSink(ss), false)); |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 453 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 454 | } |
| 455 | // for(int i = 0; i < 8; i++) |
| 456 | // { |
| 457 | // uint32_t t = r & mask; |
| 458 | // if(t < 10) |
| 459 | // ss << static_cast<char>(t + 0x30); |
| 460 | // else |
| 461 | // ss << static_cast<char>(t + 0x57); |
| 462 | // r = r >> 4; |
| 463 | // } |
| 464 | |
| 465 | return ss.str(); |
| 466 | } |
| 467 | |
| 468 | ndn::Name |
| 469 | Controller::getInvitationRoutingPrefix() |
| 470 | { |
| 471 | return Name("/ndn/broadcast"); |
| 472 | } |
| 473 | |
| 474 | void |
| 475 | Controller::addChatDialog(const QString& chatroomName, ChatDialog* chatDialog) |
| 476 | { |
| 477 | m_chatDialogList[chatroomName.toStdString()] = chatDialog; |
| 478 | connect(chatDialog, SIGNAL(closeChatDialog(const QString&)), |
| 479 | this, SLOT(onRemoveChatDialog(const QString&))); |
| 480 | connect(chatDialog, SIGNAL(showChatMessage(const QString&, const QString&, const QString&)), |
| 481 | this, SLOT(onShowChatMessage(const QString&, const QString&, const QString&))); |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 482 | connect(chatDialog, SIGNAL(resetIcon()), |
| 483 | this, SLOT(onResetIcon())); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 484 | connect(this, SIGNAL(localPrefixUpdated(const QString&)), |
| 485 | chatDialog, SLOT(onLocalPrefixUpdated(const QString&))); |
| 486 | |
| 487 | QAction* chatAction = new QAction(chatroomName, this); |
| 488 | m_chatActionList[chatroomName.toStdString()] = chatAction; |
Yingdi Yu | 46ebfc4 | 2014-03-10 15:50:27 -0700 | [diff] [blame] | 489 | connect(chatAction, SIGNAL(triggered()), chatDialog, SLOT(raise())); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 490 | |
| 491 | QAction* closeAction = new QAction(chatroomName, this); |
| 492 | m_closeActionList[chatroomName.toStdString()] = closeAction; |
| 493 | connect(closeAction, SIGNAL(triggered()), chatDialog, SLOT(onClose())); |
| 494 | |
| 495 | updateMenu(); |
| 496 | } |
| 497 | |
| 498 | // private slots: |
| 499 | void |
| 500 | Controller::onIdentityUpdated(const QString& identity) |
| 501 | { |
| 502 | Name identityName(identity.toStdString()); |
| 503 | |
| 504 | while(!m_chatDialogList.empty()) |
| 505 | { |
| 506 | ChatDialogList::const_iterator it = m_chatDialogList.begin(); |
| 507 | onRemoveChatDialog(QString::fromStdString(it->first)); |
| 508 | } |
| 509 | |
| 510 | m_identity = identityName; |
| 511 | m_keyChain.createIdentity(m_identity); |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 512 | setInvitationListener(); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 513 | |
| 514 | emit closeDBModule(); |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 515 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 516 | QTimer::singleShot(500, this, SLOT(onIdentityUpdatedContinued())); |
| 517 | |
| 518 | } |
| 519 | |
| 520 | void |
| 521 | Controller::onIdentityUpdatedContinued() |
| 522 | { |
| 523 | QString connection = m_db.connectionName(); |
| 524 | // _LOG_DEBUG("connection name: " << connection.toStdString()); |
| 525 | QSqlDatabase::removeDatabase(connection); |
| 526 | m_db.close(); |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 527 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 528 | openDB(); |
| 529 | |
| 530 | emit identityUpdated(QString(m_identity.toUri().c_str())); |
| 531 | } |
| 532 | |
| 533 | void |
| 534 | Controller::onContactIdListReady(const QStringList& list) |
| 535 | { |
| 536 | ContactList contactList; |
| 537 | |
| 538 | m_contactManager.getContactList(contactList); |
| 539 | m_validator.cleanTrustAnchor(); |
| 540 | |
| 541 | ContactList::const_iterator it = contactList.begin(); |
| 542 | ContactList::const_iterator end = contactList.end(); |
| 543 | |
| 544 | for(; it != end; it++) |
| 545 | m_validator.addTrustAnchor((*it)->getPublicKeyName(), (*it)->getPublicKey()); |
| 546 | |
| 547 | } |
| 548 | |
| 549 | void |
| 550 | Controller::onNickUpdated(const QString& nick) |
| 551 | { |
| 552 | m_nick = nick.toStdString(); |
| 553 | } |
| 554 | |
| 555 | void |
| 556 | Controller::onLocalPrefixUpdated(const QString& localPrefix) |
| 557 | { |
| 558 | m_localPrefix = Name(localPrefix.toStdString()); |
| 559 | } |
| 560 | |
| 561 | void |
| 562 | Controller::onStartChatAction() |
| 563 | { |
| 564 | std::string chatroom = "chatroom-" + getRandomString(); |
| 565 | |
| 566 | m_startChatDialog->setChatroom(chatroom); |
| 567 | m_startChatDialog->show(); |
| 568 | m_startChatDialog->raise(); |
| 569 | } |
| 570 | |
| 571 | void |
| 572 | Controller::onSettingsAction() |
| 573 | { |
| 574 | m_settingDialog->setNick(QString(m_nick.c_str())); |
| 575 | m_settingDialog->show(); |
| 576 | m_settingDialog->raise(); |
| 577 | } |
| 578 | |
| 579 | void |
| 580 | Controller::onProfileEditorAction() |
| 581 | { |
| 582 | m_profileEditor->show(); |
| 583 | m_profileEditor->raise(); |
| 584 | } |
| 585 | |
| 586 | void |
| 587 | Controller::onAddContactAction() |
| 588 | { |
| 589 | emit refreshBrowseContact(); |
| 590 | m_browseContactDialog->show(); |
| 591 | m_browseContactDialog->raise(); |
| 592 | } |
| 593 | |
| 594 | void |
| 595 | Controller::onContactListAction() |
| 596 | { |
| 597 | m_contactPanel->show(); |
| 598 | m_contactPanel->raise(); |
| 599 | } |
| 600 | |
| 601 | void |
| 602 | Controller::onDirectAdd() |
| 603 | { |
| 604 | m_addContactPanel->show(); |
| 605 | m_addContactPanel->raise(); |
| 606 | } |
| 607 | |
| 608 | void |
| 609 | Controller::onUpdateLocalPrefixAction() |
| 610 | { |
| 611 | // Name interestName(); |
| 612 | Interest interest("/local/ndn/prefix"); |
Yingdi Yu | a787672 | 2014-03-25 14:46:55 -0700 | [diff] [blame] | 613 | interest.setInterestLifetime(time::milliseconds(1000)); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 614 | interest.setMustBeFresh(true); |
| 615 | |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 616 | m_face->expressInterest(interest, |
| 617 | bind(&Controller::onLocalPrefix, this, _1, _2), |
| 618 | bind(&Controller::onLocalPrefixTimeout, this, _1)); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | void |
| 622 | Controller::onMinimizeAction() |
| 623 | { |
| 624 | m_settingDialog->hide(); |
| 625 | m_startChatDialog->hide(); |
| 626 | m_profileEditor->hide(); |
| 627 | m_invitationDialog->hide(); |
| 628 | m_addContactPanel->hide(); |
| 629 | |
| 630 | ChatDialogList::iterator it = m_chatDialogList.begin(); |
| 631 | ChatDialogList::iterator end = m_chatDialogList.end(); |
| 632 | for(; it != end; it++) |
| 633 | it->second->hide(); |
| 634 | } |
| 635 | |
| 636 | void |
| 637 | Controller::onQuitAction() |
| 638 | { |
| 639 | while(!m_chatDialogList.empty()) |
| 640 | { |
| 641 | ChatDialogList::const_iterator it = m_chatDialogList.begin(); |
| 642 | onRemoveChatDialog(QString::fromStdString(it->first)); |
| 643 | } |
| 644 | |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 645 | if(m_invitationListenerId != 0) |
| 646 | m_face->unsetInterestFilter(m_invitationListenerId); |
| 647 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 648 | delete m_settingDialog; |
| 649 | delete m_startChatDialog; |
| 650 | delete m_profileEditor; |
| 651 | delete m_invitationDialog; |
Yingdi Yu | f4aaa8b | 2014-03-10 11:24:31 -0700 | [diff] [blame] | 652 | delete m_browseContactDialog; |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 653 | delete m_addContactPanel; |
Yingdi Yu | f4aaa8b | 2014-03-10 11:24:31 -0700 | [diff] [blame] | 654 | |
Yingdi Yu | a787672 | 2014-03-25 14:46:55 -0700 | [diff] [blame] | 655 | m_face->ioService()->stop(); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 656 | |
| 657 | QApplication::quit(); |
| 658 | } |
| 659 | |
| 660 | void |
| 661 | Controller::onStartChatroom(const QString& chatroomName, bool secured) |
| 662 | { |
| 663 | Name chatroomPrefix; |
| 664 | chatroomPrefix.append("ndn") |
| 665 | .append("broadcast") |
| 666 | .append("ChronoChat") |
| 667 | .append(chatroomName.toStdString()); |
| 668 | |
| 669 | // check if the chatroom exists |
| 670 | if(m_chatDialogList.find(chatroomName.toStdString()) != m_chatDialogList.end()) |
| 671 | { |
| 672 | QMessageBox::information(this, tr("ChronoChat"), |
| 673 | tr("You are creating an existing chatroom." |
| 674 | "You can check it in the context memu.")); |
| 675 | return; |
| 676 | } |
| 677 | |
| 678 | // TODO: We should create a chatroom specific key/cert (which should be created in the first half of this method, but let's use the default one for now. |
| 679 | shared_ptr<IdentityCertificate> idCert = m_keyChain.getCertificate(m_keyChain.getDefaultCertificateNameForIdentity(m_identity)); |
| 680 | ChatDialog* chatDialog = new ChatDialog(&m_contactManager, m_face, *idCert, chatroomPrefix, m_localPrefix, m_nick, secured); |
| 681 | |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 682 | addChatDialog(chatroomName, chatDialog); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 683 | chatDialog->show(); |
| 684 | } |
| 685 | |
| 686 | void |
| 687 | Controller::onInvitationResponded(const Name& invitationName, bool accepted) |
| 688 | { |
| 689 | Data response; |
| 690 | shared_ptr<IdentityCertificate> chatroomCert; |
| 691 | |
| 692 | // generate reply; |
| 693 | if(accepted) |
| 694 | { |
| 695 | Name responseName = invitationName; |
| 696 | responseName.append(m_localPrefix.wireEncode()); |
| 697 | |
| 698 | response.setName(responseName); |
| 699 | |
| 700 | // We should create a particular certificate for this chatroom, but let's use default one for now. |
| 701 | chatroomCert = m_keyChain.getCertificate(m_keyChain.getDefaultCertificateNameForIdentity(m_identity)); |
| 702 | |
| 703 | response.setContent(chatroomCert->wireEncode()); |
Yingdi Yu | a787672 | 2014-03-25 14:46:55 -0700 | [diff] [blame] | 704 | response.setFreshnessPeriod(time::milliseconds(1000)); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 705 | } |
| 706 | else |
| 707 | { |
| 708 | response.setName(invitationName); |
Yingdi Yu | a787672 | 2014-03-25 14:46:55 -0700 | [diff] [blame] | 709 | response.setFreshnessPeriod(time::milliseconds(1000)); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 710 | } |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 711 | m_keyChain.signByIdentity(response, m_identity); |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 712 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 713 | // Check if we need a wrapper |
| 714 | Name invitationRoutingPrefix = getInvitationRoutingPrefix(); |
| 715 | if(invitationRoutingPrefix.isPrefixOf(m_identity)) |
| 716 | { |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 717 | m_face->put(response); |
| 718 | } |
| 719 | else |
| 720 | { |
| 721 | Name wrappedName; |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 722 | wrappedName.append(invitationRoutingPrefix) |
| 723 | .append(ROUTING_PREFIX_SEPARATOR, 2) |
| 724 | .append(response.getName()); |
| 725 | |
| 726 | _LOG_DEBUG("onInvitationResponded: prepare reply " << wrappedName); |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 727 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 728 | Data wrappedData(wrappedName); |
| 729 | wrappedData.setContent(response.wireEncode()); |
Yingdi Yu | a787672 | 2014-03-25 14:46:55 -0700 | [diff] [blame] | 730 | wrappedData.setFreshnessPeriod(time::milliseconds(1000)); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 731 | |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 732 | m_keyChain.signByIdentity(wrappedData, m_identity); |
| 733 | m_face->put(wrappedData); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | // create chatroom |
| 737 | if(accepted) |
| 738 | { |
| 739 | Invitation invitation(invitationName); |
| 740 | Name chatroomPrefix; |
| 741 | chatroomPrefix.append("ndn") |
| 742 | .append("broadcast") |
| 743 | .append("ChronoChat") |
| 744 | .append(invitation.getChatroom()); |
| 745 | |
| 746 | //We should create a chatroom specific key/cert (which should be created in the first half of this method, but let's use the default one for now. |
| 747 | shared_ptr<IdentityCertificate> idCert = m_keyChain.getCertificate(m_keyChain.getDefaultCertificateNameForIdentity(m_identity)); |
| 748 | ChatDialog* chatDialog = new ChatDialog(&m_contactManager, m_face, *idCert, chatroomPrefix, m_localPrefix, m_nick, true); |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 749 | chatDialog->addSyncAnchor(invitation); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 750 | |
| 751 | addChatDialog(QString::fromStdString(invitation.getChatroom()), chatDialog); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 752 | chatDialog->show(); |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | void |
| 757 | Controller::onShowChatMessage(const QString& chatroomName, const QString& from, const QString& data) |
| 758 | { |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 759 | m_trayIcon->showMessage(QString("Chatroom %1 has a new message").arg(chatroomName), |
| 760 | QString("<%1>: %2").arg(from).arg(data), |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 761 | QSystemTrayIcon::Information, 20000); |
| 762 | m_trayIcon->setIcon(QIcon(":/images/note.png")); |
| 763 | } |
| 764 | |
| 765 | void |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 766 | Controller::onResetIcon() |
| 767 | { |
| 768 | m_trayIcon->setIcon(QIcon(":/images/icon_small.png")); |
| 769 | } |
| 770 | |
| 771 | void |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 772 | Controller::onRemoveChatDialog(const QString& chatroomName) |
| 773 | { |
| 774 | ChatDialogList::iterator it = m_chatDialogList.find(chatroomName.toStdString()); |
| 775 | |
| 776 | if(it != m_chatDialogList.end()) |
| 777 | { |
| 778 | ChatDialog* deletedChat = it->second; |
| 779 | if(deletedChat) |
| 780 | delete deletedChat; |
| 781 | m_chatDialogList.erase(it); |
| 782 | |
| 783 | QAction* chatAction = m_chatActionList[chatroomName.toStdString()]; |
| 784 | QAction* closeAction = m_closeActionList[chatroomName.toStdString()]; |
| 785 | if(chatAction) |
| 786 | delete chatAction; |
| 787 | if(closeAction) |
| 788 | delete closeAction; |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 789 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 790 | m_chatActionList.erase(chatroomName.toStdString()); |
| 791 | m_closeActionList.erase(chatroomName.toStdString()); |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 792 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 793 | updateMenu(); |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | void |
| 798 | Controller::onWarning(const QString& msg) |
| 799 | { |
| 800 | QMessageBox::information(this, tr("ChronoChat"), msg); |
| 801 | } |
| 802 | |
| 803 | void |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 804 | Controller::onError(const QString& msg) |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 805 | { |
| 806 | QMessageBox::critical(this, tr("ChronoChat"), msg, QMessageBox::Ok); |
| 807 | exit(1); |
| 808 | } |
| 809 | |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 810 | void |
| 811 | Controller::onInvitationInterest(const Name& prefix, const Interest& interest, size_t routingPrefixOffset) |
| 812 | { |
| 813 | _LOG_DEBUG("onInvitationInterest: " << interest.getName()); |
| 814 | shared_ptr<Interest> invitationInterest = make_shared<Interest>(boost::cref(interest.getName().getSubName(routingPrefixOffset))); |
| 815 | |
| 816 | // check if the chatroom already exists; |
| 817 | try |
| 818 | { |
| 819 | Invitation invitation(invitationInterest->getName()); |
| 820 | if(m_chatDialogList.find(invitation.getChatroom()) != m_chatDialogList.end()) |
| 821 | return; |
| 822 | } |
| 823 | catch(Invitation::Error& e) |
| 824 | { |
| 825 | // Cannot parse the invitation; |
| 826 | return; |
| 827 | } |
| 828 | |
| 829 | OnInterestValidated onValidated = bind(&Controller::onInvitationValidated, this, _1); |
| 830 | OnInterestValidationFailed onValidationFailed = bind(&Controller::onInvitationValidationFailed, this, _1, _2); |
| 831 | m_validator.validate(*invitationInterest, onValidated, onValidationFailed); |
| 832 | } |
| 833 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 834 | } // namespace chronos |
| 835 | |
| 836 | #if WAF |
| 837 | #include "controller.moc" |
| 838 | #include "controller.cpp.moc" |
| 839 | #endif |