taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 3766775 | 2017-02-02 13:52:12 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2017, Regents of the University of California, |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of NFD Control Center. See AUTHORS.md for complete list of NFD |
| 6 | * authors and contributors. |
| 7 | * |
| 8 | * NFD Control Center is free software: you can redistribute it and/or modify it under the |
| 9 | * terms of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * NFD Control Center is distributed in the hope that it will be useful, but WITHOUT ANY |
| 13 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 14 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
Qi Zhao | 0e043e5 | 2016-12-05 18:27:09 -0800 | [diff] [blame] | 16 | * You should have received a copy of the GNU General Public License along with NFD |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 17 | * Control Center, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 20 | #include "tray-menu.hpp" |
Alexander Afanasyev | 3766775 | 2017-02-02 13:52:12 -0800 | [diff] [blame] | 21 | #include "tray-menu.moc" |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 22 | |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame^] | 23 | #include <chrono> |
| 24 | #include <functional> |
| 25 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 26 | #include <ndn-cxx/face.hpp> |
| 27 | #include <ndn-cxx/interest.hpp> |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame^] | 28 | #include <boost/algorithm/string/replace.hpp> |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 29 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 30 | #ifdef OSX_BUILD |
Alexander Afanasyev | 0621cec | 2016-03-20 23:18:27 -0700 | [diff] [blame] | 31 | #define CONNECT_ICON ":/res/icon-connected-black.png" |
| 32 | #define DISCONNECT_ICON ":/res/icon-disconnected-black.png" |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 33 | |
| 34 | #include <Security/Authorization.h> |
| 35 | #include <Security/AuthorizationTags.h> |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 36 | #else |
Alexander Afanasyev | 0621cec | 2016-03-20 23:18:27 -0700 | [diff] [blame] | 37 | #define CONNECT_ICON ":/res/icon-connected-white.png" |
| 38 | #define DISCONNECT_ICON ":/res/icon-disconnected-white.png" |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 39 | #endif // OSX_BUILD |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 40 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 41 | namespace ndn { |
Alexander Afanasyev | fda42a8 | 2017-02-01 18:03:39 -0800 | [diff] [blame] | 42 | namespace ncc { |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 43 | |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame^] | 44 | /** |
| 45 | * @brief Maximum number of lines that can show up in auto-config status tab view |
| 46 | */ |
| 47 | const int MAX_LINES_IN_AUTOCONF_STATUS = 100; |
| 48 | |
| 49 | #ifdef OSX_BUILD |
| 50 | const QString AUTO_START_SUFFIX = "Library/LaunchAgents/net.named-data.control-center.plist"; |
| 51 | #endif // OSX_BUILD |
| 52 | |
Alexander Afanasyev | 81509f3 | 2016-03-21 17:02:38 -0700 | [diff] [blame] | 53 | TrayMenu::TrayMenu(QQmlContext* context, Face& face) |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 54 | : m_context(context) |
| 55 | , m_isNfdRunning(false) |
Yingdi Yu | 53c11c1 | 2016-03-20 12:56:49 -0700 | [diff] [blame] | 56 | , m_menu(new QMenu(this)) |
| 57 | , m_entryPref(new QAction("Preferences...", m_menu)) |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 58 | , m_entrySec(new QAction("Security...", m_menu)) |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame^] | 59 | , m_acProc(nullptr) |
Alexander Afanasyev | fda42a8 | 2017-02-01 18:03:39 -0800 | [diff] [blame] | 60 | , m_settings(new QSettings()) |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 61 | #ifdef OSX_BUILD |
| 62 | , m_entryEnableCli(new QAction("Enable Command Terminal Usage...", m_menu)) |
Alexander Afanasyev | fda42a8 | 2017-02-01 18:03:39 -0800 | [diff] [blame] | 63 | , m_checkForUpdates(new QAction("Check for updates", m_menu)) |
| 64 | , m_sparkle("https://irl.cs.ucla.edu/~cawka/ndn-control-center.xml") |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 65 | #endif |
Yingdi Yu | 53c11c1 | 2016-03-20 12:56:49 -0700 | [diff] [blame] | 66 | , m_entryQuit(new QAction("Quit", m_menu)) |
Yingdi Yu | 1f82464 | 2016-03-20 17:07:22 -0700 | [diff] [blame] | 67 | , m_keyViewerDialog(new ncc::KeyViewerDialog) |
Alexander Afanasyev | 81509f3 | 2016-03-21 17:02:38 -0700 | [diff] [blame] | 68 | , m_face(face) |
Yingdi Yu | 53c11c1 | 2016-03-20 12:56:49 -0700 | [diff] [blame] | 69 | { |
| 70 | connect(m_entryPref, SIGNAL(triggered()), this, SIGNAL(showApp())); |
Yingdi Yu | 1f82464 | 2016-03-20 17:07:22 -0700 | [diff] [blame] | 71 | connect(m_entrySec, SIGNAL(triggered()), m_keyViewerDialog, SLOT(present())); |
Yingdi Yu | 53c11c1 | 2016-03-20 12:56:49 -0700 | [diff] [blame] | 72 | connect(m_entryQuit, SIGNAL(triggered()), this, SLOT(quitApp())); |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 73 | |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 74 | connect(this, SIGNAL(nfdActivityUpdate(bool)), this, SLOT(updateNfdActivityIcon(bool)), |
| 75 | Qt::QueuedConnection); |
| 76 | |
Yingdi Yu | 53c11c1 | 2016-03-20 12:56:49 -0700 | [diff] [blame] | 77 | m_menu->addAction(m_entryPref); |
| 78 | m_menu->addAction(m_entrySec); |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame^] | 79 | |
susmit | 5060791 | 2016-03-21 12:00:15 -0700 | [diff] [blame] | 80 | #ifdef OSX_BUILD |
Alexander Afanasyev | fda42a8 | 2017-02-01 18:03:39 -0800 | [diff] [blame] | 81 | connect(m_entryEnableCli, SIGNAL(triggered()), this, SLOT(enableCli())); |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 82 | m_menu->addAction(m_entryEnableCli); |
Alexander Afanasyev | fda42a8 | 2017-02-01 18:03:39 -0800 | [diff] [blame] | 83 | |
| 84 | connect(m_checkForUpdates, SIGNAL(triggered()), this, SLOT(checkForUpdates())); |
| 85 | m_menu->addAction(m_checkForUpdates); |
susmit | 5060791 | 2016-03-21 12:00:15 -0700 | [diff] [blame] | 86 | #endif |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame^] | 87 | |
Yingdi Yu | 53c11c1 | 2016-03-20 12:56:49 -0700 | [diff] [blame] | 88 | m_menu->addAction(m_entryQuit); |
| 89 | m_tray = new QSystemTrayIcon(this); |
| 90 | m_tray->setContextMenu(m_menu); |
Yingdi Yu | 53c11c1 | 2016-03-20 12:56:49 -0700 | [diff] [blame] | 91 | m_tray->setIcon(QIcon(DISCONNECT_ICON)); |
| 92 | m_tray->show(); |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame^] | 93 | |
| 94 | // delaying for the case when NFD is already started (to avoid starting / to avoid starting autoconfig |
| 95 | if (isNfdAutoStartEnabled()) { |
| 96 | scheduleDelayedTask(std::chrono::seconds(5), [this] { |
| 97 | if (!m_isNfdRunning) { |
| 98 | startNfd(); |
| 99 | } |
| 100 | }); |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 101 | } |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | TrayMenu::~TrayMenu() |
| 105 | { |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame^] | 106 | // delete for all new's |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame^] | 109 | //////////////////////////////////////////////////////////////////////////////// |
| 110 | // NFD Control Center start on login |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 111 | |
| 112 | Q_INVOKABLE bool |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame^] | 113 | TrayMenu::isNccAutoStartEnabled() const |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 114 | { |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame^] | 115 | QFileInfo file(QDir::home().path() + "/" + AUTO_START_SUFFIX); |
| 116 | return file.exists() && file.isFile(); |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | Q_INVOKABLE void |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame^] | 120 | TrayMenu::enableDisableNccAutoStart(bool isEnabled) |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 121 | { |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame^] | 122 | if (isEnabled) { |
| 123 | QFile file(QDir::home().path() + "/" + AUTO_START_SUFFIX); |
| 124 | file.open(QIODevice::WriteOnly); |
| 125 | |
| 126 | std::string plist = R"PLIST(<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
| 127 | <?xml version="1.0" encoding="UTF-8"?> |
| 128 | <plist version="1.0"> |
| 129 | <dict> |
| 130 | <key>Label</key> |
| 131 | <string>net.named-data.control-center</string> |
| 132 | <key>ProgramArguments</key> |
| 133 | <array> |
| 134 | <string>%%PATH%%</string> |
| 135 | </array> |
| 136 | <key>RunAtLoad</key> |
| 137 | <true/> |
| 138 | <key>KeepAlive</key> |
| 139 | <false/> |
| 140 | </dict> |
| 141 | </plist> |
| 142 | )PLIST"; //" |
| 143 | boost::replace_all(plist, "%%PATH%%", QCoreApplication::applicationFilePath().toStdString()); |
| 144 | file.write(plist.data(), plist.size()); |
| 145 | file.close(); |
| 146 | } else { |
| 147 | QFile::remove(QDir::home().path() + "/" + AUTO_START_SUFFIX); |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 148 | } |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame^] | 151 | //////////////////////////////////////////////////////////////////////////////// |
| 152 | // NFD start on launch |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 153 | |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame^] | 154 | Q_INVOKABLE bool |
| 155 | TrayMenu::isNfdAutoStartEnabled() const |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 156 | { |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame^] | 157 | return m_settings->value("ENABLE_AUTO_START", false).toBool(); |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 160 | Q_INVOKABLE void |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame^] | 161 | TrayMenu::enableDisableNfdAutoStart(bool isEnabled) |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 162 | { |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame^] | 163 | m_settings->setValue("ENABLE_AUTO_START", isEnabled); |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 164 | if (!m_isNfdRunning) { |
| 165 | startNfd(); |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 166 | } |
| 167 | } |
| 168 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 169 | void |
| 170 | TrayMenu::startNfd() |
| 171 | { |
Alexander Afanasyev | 8e986f8 | 2016-03-21 14:19:15 -0700 | [diff] [blame] | 172 | #ifdef OSX_BUILD |
| 173 | QProcess* proc = new QProcess(); |
| 174 | connect(proc, SIGNAL(finished(int)), proc, SLOT(deleteLater())); |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame^] | 175 | proc->startDetached((QCoreApplication::applicationDirPath() + "/../Platform/nfd"), |
Alexander Afanasyev | 8e986f8 | 2016-03-21 14:19:15 -0700 | [diff] [blame] | 176 | QStringList() |
| 177 | << "--config" |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame^] | 178 | << (QCoreApplication::applicationDirPath() + "/../etc/ndn/nfd.conf")); |
Alexander Afanasyev | 8e986f8 | 2016-03-21 14:19:15 -0700 | [diff] [blame] | 179 | #endif |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | void |
| 183 | TrayMenu::stopNfd() |
| 184 | { |
Alexander Afanasyev | 8e986f8 | 2016-03-21 14:19:15 -0700 | [diff] [blame] | 185 | #ifdef OSX_BUILD |
| 186 | QProcess* proc = new QProcess(); |
| 187 | connect(proc, SIGNAL(finished(int)), proc, SLOT(deleteLater())); |
| 188 | proc->startDetached("killall", QStringList() << "nfd"); |
| 189 | #endif |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame^] | 192 | //////////////////////////////////////////////////////////////////////////////// |
| 193 | // NDN Autoconfig |
| 194 | |
| 195 | Q_INVOKABLE bool |
| 196 | TrayMenu::isNdnAutoConfigEnabled() const |
| 197 | { |
| 198 | return m_settings->value("ENABLE_NDN_AUTO_CONFIG", false).toBool(); |
| 199 | } |
| 200 | |
| 201 | Q_INVOKABLE void |
| 202 | TrayMenu::enableDisableNdnAutoConfig(bool isEnabled) |
| 203 | { |
| 204 | m_settings->setValue("ENABLE_NDN_AUTO_CONFIG", isEnabled); |
| 205 | |
| 206 | if (isEnabled) { |
| 207 | startNdnAutoConfig(); |
| 208 | } |
| 209 | else { |
| 210 | stopNdnAutoConfig(); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | void |
| 215 | TrayMenu::startNdnAutoConfig() |
| 216 | { |
| 217 | if (m_acProc != nullptr) { |
| 218 | return; |
| 219 | } |
| 220 | |
| 221 | stopNdnAutoConfig(false); // Make sure no more than one auto-config process exist |
| 222 | |
| 223 | if (!m_isNfdRunning) { |
| 224 | return; |
| 225 | } |
| 226 | |
| 227 | m_acProc = new QProcess(); |
| 228 | |
| 229 | scheduleDelayedTask(std::chrono::seconds(2), [this] { |
| 230 | appendNdnAutoConfigStatus("NDN auto configuration starting...\n"); |
| 231 | m_acProc->start(QCoreApplication::applicationDirPath() + "/../Platform/ndn-autoconfig", |
| 232 | QStringList() << "--daemon"); |
| 233 | connect(m_acProc, SIGNAL(readyReadStandardOutput()), this, SLOT(processOutput())); |
| 234 | connect(m_acProc, SIGNAL(readyReadStandardError()), this, SLOT(processOutput())); |
| 235 | }); |
| 236 | } |
| 237 | |
| 238 | void |
| 239 | TrayMenu::stopNdnAutoConfig(bool appendStatus) |
| 240 | { |
| 241 | m_acProc = nullptr; |
| 242 | QProcess* proc = new QProcess(); |
| 243 | connect(proc, SIGNAL(finished(int)), proc, SLOT(deleteLater())); |
| 244 | proc->startDetached("killall", QStringList() << "ndn-autoconfig"); |
| 245 | if (appendStatus) { |
| 246 | appendNdnAutoConfigStatus("NDN auto configuration stopped\n"); |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | void |
| 251 | TrayMenu::appendNdnAutoConfigStatus(const QString& message) |
| 252 | { |
| 253 | if (message == "") { |
| 254 | return; |
| 255 | } |
| 256 | if (m_ndnAutoConfigMsg.count("\n") > MAX_LINES_IN_AUTOCONF_STATUS) { |
| 257 | int end = m_ndnAutoConfigMsg.indexOf("\n"); |
| 258 | m_ndnAutoConfigMsg.remove(0, end + 1); |
| 259 | } |
| 260 | m_ndnAutoConfigMsg.append(message); |
| 261 | |
| 262 | m_context->setContextProperty("ndnAutoConfigText", m_ndnAutoConfigMsg); |
| 263 | } |
| 264 | |
| 265 | void |
| 266 | TrayMenu::processOutput() |
| 267 | { |
| 268 | if (m_acProc == nullptr) { |
| 269 | return; |
| 270 | } |
| 271 | appendNdnAutoConfigStatus(m_acProc->readAllStandardOutput()); |
| 272 | appendNdnAutoConfigStatus(m_acProc->readAllStandardError()); |
| 273 | } |
| 274 | |
| 275 | //////////////////////////////////////////////////////////////////////////////// |
| 276 | // NFD stop on shutdown |
| 277 | |
| 278 | Q_INVOKABLE bool |
| 279 | TrayMenu::isNfdStopOnExitEnabled() const |
| 280 | { |
| 281 | return m_settings->value("ENABLE_SHUTDOWN", false).toBool(); |
| 282 | } |
| 283 | |
| 284 | Q_INVOKABLE void |
| 285 | TrayMenu::enableDisableNfdStopOnExit(bool isEnabled) |
| 286 | { |
| 287 | m_settings->setValue("ENABLE_SHUTDOWN", isEnabled); |
| 288 | } |
| 289 | |
| 290 | //////////////////////////////////////////////////////////////////////////////// |
| 291 | // Misc |
| 292 | |
| 293 | void |
| 294 | TrayMenu::quitApp() |
| 295 | { |
| 296 | if (isNfdStopOnExitEnabled()) { |
| 297 | stopNdnAutoConfig(); |
| 298 | stopNfd(); |
| 299 | } |
| 300 | QCoreApplication::exit(0); |
| 301 | } |
| 302 | |
susmit | 4fe3cb9 | 2016-03-20 17:08:41 -0700 | [diff] [blame] | 303 | Q_INVOKABLE void |
| 304 | TrayMenu::addDeleteRoute() |
| 305 | { |
| 306 | addRoute(); |
| 307 | } |
| 308 | |
| 309 | Q_INVOKABLE void |
| 310 | TrayMenu::addRoute() |
| 311 | { |
| 312 | std::cout << "Adding route" << std::endl; |
| 313 | QString cmd = "nfdc register /test tcp4://localhost"; |
| 314 | QProcess *addNewRoute = new QProcess(); |
| 315 | connect(addNewRoute,SIGNAL(finished(int)), addNewRoute, SLOT(deleteLater())); |
| 316 | addNewRoute->start("bash", QStringList() << "-c" << cmd); |
| 317 | std::cout << "Done" << std::endl; |
susmit | 4fe3cb9 | 2016-03-20 17:08:41 -0700 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | void |
| 321 | TrayMenu::deleteRoute() |
| 322 | { |
| 323 | std::cout << "Deleting route" << std::endl; |
| 324 | QString cmd = "nfdc unregister /test tcp4://localhost"; |
| 325 | QProcess *addNewRoute = new QProcess(); |
| 326 | connect(addNewRoute,SIGNAL(finished(int)), addNewRoute, SLOT(deleteLater())); |
| 327 | addNewRoute->start("bash", QStringList() << "-c" << cmd); |
| 328 | std::cout << "Done" << std::endl; |
susmit | 4fe3cb9 | 2016-03-20 17:08:41 -0700 | [diff] [blame] | 329 | } |
| 330 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 331 | void |
| 332 | TrayMenu::updateNfdActivityIcon(bool isActive) |
| 333 | { |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 334 | m_isNfdRunning = isActive; |
| 335 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 336 | if (isActive) { |
Yingdi Yu | 53c11c1 | 2016-03-20 12:56:49 -0700 | [diff] [blame] | 337 | m_tray->setIcon(QIcon(CONNECT_ICON)); |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame^] | 338 | if (isNdnAutoConfigEnabled()) { |
| 339 | startNdnAutoConfig(); |
| 340 | } |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 341 | } |
| 342 | else { |
Yingdi Yu | 53c11c1 | 2016-03-20 12:56:49 -0700 | [diff] [blame] | 343 | m_tray->setIcon(QIcon(DISCONNECT_ICON)); |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 344 | } |
| 345 | } |
| 346 | |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 347 | void |
| 348 | TrayMenu::enableCli() |
| 349 | { |
| 350 | #ifdef OSX_BUILD |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame^] | 351 | QProcess* proc = new QProcess(); |
| 352 | connect(proc, SIGNAL(finished(int)), proc, SLOT(deleteLater())); |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 353 | |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame^] | 354 | proc->start("osascript", QStringList() |
| 355 | << "-e" |
| 356 | << "do shell script \"" |
| 357 | "/bin/mkdir -vp /usr/local/bin; " |
| 358 | "/bin/ln -s -f '" + QCoreApplication::applicationDirPath() + |
| 359 | "/../Resources/ndn" + "' /usr/local/bin/ndn;" |
| 360 | "\" with administrator privileges"); |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 361 | #endif |
| 362 | } |
| 363 | |
Alexander Afanasyev | fda42a8 | 2017-02-01 18:03:39 -0800 | [diff] [blame] | 364 | #ifdef OSX_BUILD |
| 365 | void |
| 366 | TrayMenu::checkForUpdates() |
| 367 | { |
| 368 | m_sparkle.checkForUpdates(); |
| 369 | } |
| 370 | #endif // OSX_BUILD |
| 371 | |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame^] | 372 | void |
| 373 | TrayMenu::scheduleDelayedTask(std::chrono::milliseconds delays, const std::function<void()>& task) |
| 374 | { |
| 375 | auto timer = new QTimer(); |
| 376 | timer->setSingleShot(true); |
| 377 | timer->setInterval(delays); |
| 378 | connect(timer, &QTimer::timeout, |
| 379 | [task, timer] { |
| 380 | task(); |
| 381 | timer->deleteLater(); |
| 382 | }); |
| 383 | timer->start(); |
| 384 | } |
| 385 | |
Alexander Afanasyev | fda42a8 | 2017-02-01 18:03:39 -0800 | [diff] [blame] | 386 | } // namespace ncc |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 387 | } // namespace ndn |