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