blob: e95f251ba036e5168c20ce2a5ca114a07cd7d6c0 [file] [log] [blame]
taylorchuc27dd482014-05-17 20:06:49 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev37667752017-02-02 13:52:12 -08003 * Copyright (c) 2013-2017, Regents of the University of California,
taylorchuc27dd482014-05-17 20:06:49 -07004 *
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 Zhao0e043e52016-12-05 18:27:09 -080016 * You should have received a copy of the GNU General Public License along with NFD
taylorchuc27dd482014-05-17 20:06:49 -070017 * Control Center, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
taylorchuc27dd482014-05-17 20:06:49 -070020#include "tray-menu.hpp"
Alexander Afanasyev37667752017-02-02 13:52:12 -080021#include "tray-menu.moc"
taylorchuc27dd482014-05-17 20:06:49 -070022
Qi Zhaoae9c4312017-02-02 11:36:12 -080023#include <chrono>
24#include <functional>
25
taylorchuc27dd482014-05-17 20:06:49 -070026#include <ndn-cxx/face.hpp>
27#include <ndn-cxx/interest.hpp>
Qi Zhaoae9c4312017-02-02 11:36:12 -080028#include <boost/algorithm/string/replace.hpp>
taylorchuc27dd482014-05-17 20:06:49 -070029
taylorchuc27dd482014-05-17 20:06:49 -070030#ifdef OSX_BUILD
Alexander Afanasyev0621cec2016-03-20 23:18:27 -070031#define CONNECT_ICON ":/res/icon-connected-black.png"
32#define DISCONNECT_ICON ":/res/icon-disconnected-black.png"
Qi Zhaodec77d92017-02-15 15:49:04 -080033#define CONNECT_STATUS_ICON ":/res/icon-connected-status-black.png"
Qi Zhao3ec33312017-02-12 02:51:05 -080034#define CONNECT_ADHOC_ICON ":/res/icon-connected-adhoc-black.png"
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -070035
36#include <Security/Authorization.h>
37#include <Security/AuthorizationTags.h>
Qi Zhao3615a102017-02-02 20:38:34 -080038
39#include "build/NFD/build/core/version.hpp"
40#include "build/ndn-tools/build/core/version.cpp"
41
taylorchuc27dd482014-05-17 20:06:49 -070042#else
Alexander Afanasyev0621cec2016-03-20 23:18:27 -070043#define CONNECT_ICON ":/res/icon-connected-white.png"
44#define DISCONNECT_ICON ":/res/icon-disconnected-white.png"
Qi Zhao3615a102017-02-02 20:38:34 -080045
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -070046#endif // OSX_BUILD
taylorchuc27dd482014-05-17 20:06:49 -070047
Qi Zhao3615a102017-02-02 20:38:34 -080048#include <ndn-cxx/version.hpp>
49
taylorchuc27dd482014-05-17 20:06:49 -070050namespace ndn {
Alexander Afanasyevfda42a82017-02-01 18:03:39 -080051namespace ncc {
taylorchuc27dd482014-05-17 20:06:49 -070052
Qi Zhaoae9c4312017-02-02 11:36:12 -080053/**
54 * @brief Maximum number of lines that can show up in auto-config status tab view
55 */
56const int MAX_LINES_IN_AUTOCONF_STATUS = 100;
57
58#ifdef OSX_BUILD
59const QString AUTO_START_SUFFIX = "Library/LaunchAgents/net.named-data.control-center.plist";
60#endif // OSX_BUILD
61
Qi Zhao7e524492017-03-02 15:05:45 -080062TrayMenu::TrayMenu(QQmlContext* context, Face& face, KeyChain& keyChain)
Alexander Afanasyev4086d512014-07-11 15:56:33 -070063 : m_context(context)
64 , m_isNfdRunning(false)
Qi Zhaodec77d92017-02-15 15:49:04 -080065 , m_isConnectedToHub(false)
Qi Zhao3ec33312017-02-12 02:51:05 -080066 , m_isConnectedToAdhoc(false)
Yingdi Yu53c11c12016-03-20 12:56:49 -070067 , m_menu(new QMenu(this))
68 , m_entryPref(new QAction("Preferences...", m_menu))
Qi Zhao7e524492017-03-02 15:05:45 -080069 , m_entryStatus(new QAction("Status...", m_menu))
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -070070 , m_entrySec(new QAction("Security...", m_menu))
Qi Zhaoae9c4312017-02-02 11:36:12 -080071 , m_acProc(nullptr)
Alexander Afanasyevfda42a82017-02-01 18:03:39 -080072 , m_settings(new QSettings())
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -070073#ifdef OSX_BUILD
Alexander Afanasyevb0beef52017-03-17 15:26:03 -070074 , m_entryEnableCli(new QAction("Install command-line tools...", m_menu))
Qi Zhao3ec33312017-02-12 02:51:05 -080075 , m_entryAdhoc(new QAction("Enable ad hoc Wi-Fi...", m_menu))
Alexander Afanasyevfda42a82017-02-01 18:03:39 -080076 , m_checkForUpdates(new QAction("Check for updates", m_menu))
Alexander Afanasyeve095ed12017-02-04 23:09:55 -080077 , m_sparkle(NCC_APPCAST)
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -070078#endif
Yingdi Yu53c11c12016-03-20 12:56:49 -070079 , m_entryQuit(new QAction("Quit", m_menu))
Yingdi Yu1f824642016-03-20 17:07:22 -070080 , m_keyViewerDialog(new ncc::KeyViewerDialog)
Alexander Afanasyev81509f32016-03-21 17:02:38 -070081 , m_face(face)
Qi Zhao7e524492017-03-02 15:05:45 -080082 , m_keyChain(keyChain)
Qi Zhao3ec33312017-02-12 02:51:05 -080083 , m_adhoc(m_face, m_keyChain)
Qi Zhao7e524492017-03-02 15:05:45 -080084 , m_statusViewer(new StatusViewer(m_face, m_keyChain))
Yingdi Yu53c11c12016-03-20 12:56:49 -070085{
86 connect(m_entryPref, SIGNAL(triggered()), this, SIGNAL(showApp()));
Qi Zhao7e524492017-03-02 15:05:45 -080087 connect(m_entryStatus, SIGNAL(triggered()), m_statusViewer, SLOT(present()));
Yingdi Yu1f824642016-03-20 17:07:22 -070088 connect(m_entrySec, SIGNAL(triggered()), m_keyViewerDialog, SLOT(present()));
Yingdi Yu53c11c12016-03-20 12:56:49 -070089 connect(m_entryQuit, SIGNAL(triggered()), this, SLOT(quitApp()));
taylorchuc27dd482014-05-17 20:06:49 -070090
Qi Zhao3ec33312017-02-12 02:51:05 -080091 connect(this, SIGNAL(nfdActivityUpdate(bool)), this, SLOT(updateNfdActivityIcon(bool)), Qt::QueuedConnection);
92 connect(this, SIGNAL(connectivityUpdate(bool)), this, SLOT(updateConnectivity(bool)), Qt::QueuedConnection);
93 connect(this, SIGNAL(adhocUpdate(bool)), this, SLOT(updateAdhoc(bool)), Qt::QueuedConnection);
Alexander Afanasyev4086d512014-07-11 15:56:33 -070094
Qi Zhao3615a102017-02-02 20:38:34 -080095 QString nccVersion = QString(NCC_VERSION) + " (ndn-cxx: " + NDN_CXX_VERSION_BUILD_STRING +
96 ", NFD: " + NFD_VERSION_BUILD_STRING +
97 ", ndn-tools: " + ::ndn::tools::VERSION +
98 ")";
99
100 m_context->setContextProperty("nccVersion", nccVersion);
101
Qi Zhao7e524492017-03-02 15:05:45 -0800102 m_menu->addAction(m_entryStatus);
Yingdi Yu53c11c12016-03-20 12:56:49 -0700103 m_menu->addAction(m_entrySec);
Qi Zhaoae9c4312017-02-02 11:36:12 -0800104
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -0800105 m_menu->addSeparator();
106 m_menu->addAction(m_entryPref);
107
susmit50607912016-03-21 12:00:15 -0700108#ifdef OSX_BUILD
Qi Zhao3ec33312017-02-12 02:51:05 -0800109 m_entryAdhoc->setChecked(false);
110 m_entryAdhoc->setCheckable(true);
111 connect(m_entryAdhoc, SIGNAL(triggered()), this, SLOT(onAdhocChange()));
112 m_menu->addAction(m_entryAdhoc);
113
Alexander Afanasyevfda42a82017-02-01 18:03:39 -0800114 connect(m_entryEnableCli, SIGNAL(triggered()), this, SLOT(enableCli()));
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -0700115 m_menu->addAction(m_entryEnableCli);
Alexander Afanasyevfda42a82017-02-01 18:03:39 -0800116
117 connect(m_checkForUpdates, SIGNAL(triggered()), this, SLOT(checkForUpdates()));
118 m_menu->addAction(m_checkForUpdates);
susmit50607912016-03-21 12:00:15 -0700119#endif
Qi Zhaoae9c4312017-02-02 11:36:12 -0800120
Alexander Afanasyev8d1a3a02017-03-11 13:00:24 -0800121 m_menu->addSeparator();
Yingdi Yu53c11c12016-03-20 12:56:49 -0700122 m_menu->addAction(m_entryQuit);
123 m_tray = new QSystemTrayIcon(this);
124 m_tray->setContextMenu(m_menu);
Yingdi Yu53c11c12016-03-20 12:56:49 -0700125 m_tray->setIcon(QIcon(DISCONNECT_ICON));
126 m_tray->show();
Qi Zhaoae9c4312017-02-02 11:36:12 -0800127
128 // delaying for the case when NFD is already started (to avoid starting / to avoid starting autoconfig
129 if (isNfdAutoStartEnabled()) {
130 scheduleDelayedTask(std::chrono::seconds(5), [this] {
131 if (!m_isNfdRunning) {
132 startNfd();
133 }
134 });
Qi Zhao86f2b212016-12-06 12:44:16 -0800135 }
taylorchuc27dd482014-05-17 20:06:49 -0700136}
137
138TrayMenu::~TrayMenu()
139{
Qi Zhaoae9c4312017-02-02 11:36:12 -0800140 // delete for all new's
taylorchuc27dd482014-05-17 20:06:49 -0700141}
142
Qi Zhaoae9c4312017-02-02 11:36:12 -0800143////////////////////////////////////////////////////////////////////////////////
144// NFD Control Center start on login
Qi Zhao86f2b212016-12-06 12:44:16 -0800145
146Q_INVOKABLE bool
Qi Zhaoae9c4312017-02-02 11:36:12 -0800147TrayMenu::isNccAutoStartEnabled() const
Qi Zhao86f2b212016-12-06 12:44:16 -0800148{
Qi Zhaoae9c4312017-02-02 11:36:12 -0800149 QFileInfo file(QDir::home().path() + "/" + AUTO_START_SUFFIX);
150 return file.exists() && file.isFile();
Qi Zhao86f2b212016-12-06 12:44:16 -0800151}
152
153Q_INVOKABLE void
Qi Zhaoae9c4312017-02-02 11:36:12 -0800154TrayMenu::enableDisableNccAutoStart(bool isEnabled)
Qi Zhao86f2b212016-12-06 12:44:16 -0800155{
Qi Zhaoae9c4312017-02-02 11:36:12 -0800156 if (isEnabled) {
157 QFile file(QDir::home().path() + "/" + AUTO_START_SUFFIX);
158 file.open(QIODevice::WriteOnly);
159
160 std::string plist = R"PLIST(<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
161<?xml version="1.0" encoding="UTF-8"?>
162<plist version="1.0">
163 <dict>
164 <key>Label</key>
165 <string>net.named-data.control-center</string>
166 <key>ProgramArguments</key>
167 <array>
168 <string>%%PATH%%</string>
169 </array>
170 <key>RunAtLoad</key>
171 <true/>
172 <key>KeepAlive</key>
173 <false/>
174 </dict>
175</plist>
176)PLIST"; //"
177 boost::replace_all(plist, "%%PATH%%", QCoreApplication::applicationFilePath().toStdString());
178 file.write(plist.data(), plist.size());
179 file.close();
Qi Zhao7e524492017-03-02 15:05:45 -0800180 }
181 else {
Qi Zhaoae9c4312017-02-02 11:36:12 -0800182 QFile::remove(QDir::home().path() + "/" + AUTO_START_SUFFIX);
Qi Zhao86f2b212016-12-06 12:44:16 -0800183 }
taylorchuc27dd482014-05-17 20:06:49 -0700184}
185
Qi Zhaoae9c4312017-02-02 11:36:12 -0800186////////////////////////////////////////////////////////////////////////////////
187// NFD start on launch
taylorchuc27dd482014-05-17 20:06:49 -0700188
Qi Zhaoae9c4312017-02-02 11:36:12 -0800189Q_INVOKABLE bool
190TrayMenu::isNfdAutoStartEnabled() const
taylorchuc27dd482014-05-17 20:06:49 -0700191{
Qi Zhaoae9c4312017-02-02 11:36:12 -0800192 return m_settings->value("ENABLE_AUTO_START", false).toBool();
taylorchuc27dd482014-05-17 20:06:49 -0700193}
194
Alexander Afanasyev4086d512014-07-11 15:56:33 -0700195Q_INVOKABLE void
Qi Zhaoae9c4312017-02-02 11:36:12 -0800196TrayMenu::enableDisableNfdAutoStart(bool isEnabled)
Alexander Afanasyev4086d512014-07-11 15:56:33 -0700197{
Qi Zhaoae9c4312017-02-02 11:36:12 -0800198 m_settings->setValue("ENABLE_AUTO_START", isEnabled);
Alexander Afanasyev4086d512014-07-11 15:56:33 -0700199 if (!m_isNfdRunning) {
200 startNfd();
Alexander Afanasyev4086d512014-07-11 15:56:33 -0700201 }
202}
203
taylorchuc27dd482014-05-17 20:06:49 -0700204void
205TrayMenu::startNfd()
206{
Alexander Afanasyev8e986f82016-03-21 14:19:15 -0700207#ifdef OSX_BUILD
208 QProcess* proc = new QProcess();
209 connect(proc, SIGNAL(finished(int)), proc, SLOT(deleteLater()));
Alexander Afanasyev9c45c642017-03-18 15:29:42 -0700210 proc->startDetached((QCoreApplication::applicationDirPath() + "/../Helpers/nfd"),
Alexander Afanasyev8e986f82016-03-21 14:19:15 -0700211 QStringList()
212 << "--config"
Qi Zhaoae9c4312017-02-02 11:36:12 -0800213 << (QCoreApplication::applicationDirPath() + "/../etc/ndn/nfd.conf"));
Alexander Afanasyev8e986f82016-03-21 14:19:15 -0700214#endif
taylorchuc27dd482014-05-17 20:06:49 -0700215}
216
217void
218TrayMenu::stopNfd()
219{
Alexander Afanasyev8e986f82016-03-21 14:19:15 -0700220#ifdef OSX_BUILD
221 QProcess* proc = new QProcess();
222 connect(proc, SIGNAL(finished(int)), proc, SLOT(deleteLater()));
223 proc->startDetached("killall", QStringList() << "nfd");
224#endif
taylorchuc27dd482014-05-17 20:06:49 -0700225}
226
Qi Zhaoae9c4312017-02-02 11:36:12 -0800227////////////////////////////////////////////////////////////////////////////////
228// NDN Autoconfig
229
230Q_INVOKABLE bool
231TrayMenu::isNdnAutoConfigEnabled() const
232{
233 return m_settings->value("ENABLE_NDN_AUTO_CONFIG", false).toBool();
234}
235
236Q_INVOKABLE void
237TrayMenu::enableDisableNdnAutoConfig(bool isEnabled)
238{
239 m_settings->setValue("ENABLE_NDN_AUTO_CONFIG", isEnabled);
240
241 if (isEnabled) {
242 startNdnAutoConfig();
243 }
244 else {
245 stopNdnAutoConfig();
246 }
247}
248
249void
250TrayMenu::startNdnAutoConfig()
251{
252 if (m_acProc != nullptr) {
253 return;
254 }
255
256 stopNdnAutoConfig(false); // Make sure no more than one auto-config process exist
257
258 if (!m_isNfdRunning) {
259 return;
260 }
261
262 m_acProc = new QProcess();
263
264 scheduleDelayedTask(std::chrono::seconds(2), [this] {
265 appendNdnAutoConfigStatus("NDN auto configuration starting...\n");
Alexander Afanasyev9c45c642017-03-18 15:29:42 -0700266 m_acProc->start(QCoreApplication::applicationDirPath() + "/../Helpers/ndn-autoconfig",
Qi Zhaoae9c4312017-02-02 11:36:12 -0800267 QStringList() << "--daemon");
268 connect(m_acProc, SIGNAL(readyReadStandardOutput()), this, SLOT(processOutput()));
269 connect(m_acProc, SIGNAL(readyReadStandardError()), this, SLOT(processOutput()));
270 });
271}
272
273void
274TrayMenu::stopNdnAutoConfig(bool appendStatus)
275{
276 m_acProc = nullptr;
277 QProcess* proc = new QProcess();
278 connect(proc, SIGNAL(finished(int)), proc, SLOT(deleteLater()));
279 proc->startDetached("killall", QStringList() << "ndn-autoconfig");
280 if (appendStatus) {
281 appendNdnAutoConfigStatus("NDN auto configuration stopped\n");
282 }
283}
284
285void
286TrayMenu::appendNdnAutoConfigStatus(const QString& message)
287{
288 if (message == "") {
289 return;
290 }
291 if (m_ndnAutoConfigMsg.count("\n") > MAX_LINES_IN_AUTOCONF_STATUS) {
292 int end = m_ndnAutoConfigMsg.indexOf("\n");
293 m_ndnAutoConfigMsg.remove(0, end + 1);
294 }
295 m_ndnAutoConfigMsg.append(message);
296
297 m_context->setContextProperty("ndnAutoConfigText", m_ndnAutoConfigMsg);
298}
299
300void
301TrayMenu::processOutput()
302{
303 if (m_acProc == nullptr) {
304 return;
305 }
306 appendNdnAutoConfigStatus(m_acProc->readAllStandardOutput());
307 appendNdnAutoConfigStatus(m_acProc->readAllStandardError());
308}
309
310////////////////////////////////////////////////////////////////////////////////
311// NFD stop on shutdown
312
313Q_INVOKABLE bool
314TrayMenu::isNfdStopOnExitEnabled() const
315{
316 return m_settings->value("ENABLE_SHUTDOWN", false).toBool();
317}
318
319Q_INVOKABLE void
320TrayMenu::enableDisableNfdStopOnExit(bool isEnabled)
321{
322 m_settings->setValue("ENABLE_SHUTDOWN", isEnabled);
323}
324
Qi Zhao3ec33312017-02-12 02:51:05 -0800325///////////////////////////////////////////////////////////////////////////////
326// Ad hoc WiFi communication
327
328void
329TrayMenu::onAdhocChange()
330{
331#ifdef ADHOC_SUPPORTED
332 if (m_entryAdhoc->isChecked()) {
333 QMessageBox* msgBox = new QMessageBox();
334 msgBox->setText("WARNING: Wi-Fi will be disconnected!");
335 msgBox->setIcon(QMessageBox::Warning);
336 msgBox->setInformativeText(
337 "Are you sure that you are OK with that?");
338 msgBox->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
339 msgBox->setDefaultButton(QMessageBox::No);
340 int ret = msgBox->exec();
341
342 if (ret == QMessageBox::No) {
343 m_entryAdhoc->setChecked(false);
344 }
345 else {
346 stopNdnAutoConfig();
347 m_entryAdhoc->setText("Adhoc Wi-Fi is enabled");
348 m_adhoc.createAdhoc();
349 std::cerr << "ad hoc is on!" << std::endl;
350 }
351 }
352 else {
353 m_entryAdhoc->setText("Enable Adhoc Wi-Fi...");
354 m_adhoc.destroyAdhoc();
355 std::cerr << "ad hos is off!" << std::endl;
356 // a trick in DestroyAdhoc ensures that WiFi will be reconnected to a default WiFi
357 if (isNdnAutoConfigEnabled()) {
358 startNdnAutoConfig();
359 }
360 }
361#endif
362}
363
Qi Zhaoae9c4312017-02-02 11:36:12 -0800364////////////////////////////////////////////////////////////////////////////////
365// Misc
366
367void
368TrayMenu::quitApp()
369{
370 if (isNfdStopOnExitEnabled()) {
371 stopNdnAutoConfig();
372 stopNfd();
373 }
374 QCoreApplication::exit(0);
375}
376
susmit4fe3cb92016-03-20 17:08:41 -0700377Q_INVOKABLE void
378TrayMenu::addDeleteRoute()
379{
380 addRoute();
381}
382
383Q_INVOKABLE void
384TrayMenu::addRoute()
385{
386 std::cout << "Adding route" << std::endl;
387 QString cmd = "nfdc register /test tcp4://localhost";
388 QProcess *addNewRoute = new QProcess();
389 connect(addNewRoute,SIGNAL(finished(int)), addNewRoute, SLOT(deleteLater()));
390 addNewRoute->start("bash", QStringList() << "-c" << cmd);
391 std::cout << "Done" << std::endl;
susmit4fe3cb92016-03-20 17:08:41 -0700392}
393
394void
395TrayMenu::deleteRoute()
396{
397 std::cout << "Deleting route" << std::endl;
398 QString cmd = "nfdc unregister /test tcp4://localhost";
399 QProcess *addNewRoute = new QProcess();
400 connect(addNewRoute,SIGNAL(finished(int)), addNewRoute, SLOT(deleteLater()));
401 addNewRoute->start("bash", QStringList() << "-c" << cmd);
402 std::cout << "Done" << std::endl;
susmit4fe3cb92016-03-20 17:08:41 -0700403}
404
taylorchuc27dd482014-05-17 20:06:49 -0700405void
406TrayMenu::updateNfdActivityIcon(bool isActive)
407{
Alexander Afanasyev4086d512014-07-11 15:56:33 -0700408 m_isNfdRunning = isActive;
409
taylorchuc27dd482014-05-17 20:06:49 -0700410 if (isActive) {
Qi Zhao3ec33312017-02-12 02:51:05 -0800411 if (m_isConnectedToHub) {
Qi Zhaodec77d92017-02-15 15:49:04 -0800412 m_tray->setIcon(QIcon(CONNECT_STATUS_ICON));
413 }
Qi Zhao3ec33312017-02-12 02:51:05 -0800414 else if (m_isConnectedToAdhoc) {
415 m_tray->setIcon(QIcon(CONNECT_ADHOC_ICON));
416 }
Qi Zhaodec77d92017-02-15 15:49:04 -0800417 else {
418 m_tray->setIcon(QIcon(CONNECT_ICON));
419 }
Qi Zhao3ec33312017-02-12 02:51:05 -0800420 if (!m_entryAdhoc->isChecked() && isNdnAutoConfigEnabled()) {
Qi Zhaoae9c4312017-02-02 11:36:12 -0800421 startNdnAutoConfig();
422 }
taylorchuc27dd482014-05-17 20:06:49 -0700423 }
424 else {
Yingdi Yu53c11c12016-03-20 12:56:49 -0700425 m_tray->setIcon(QIcon(DISCONNECT_ICON));
taylorchuc27dd482014-05-17 20:06:49 -0700426 }
427}
428
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -0700429void
Qi Zhaodec77d92017-02-15 15:49:04 -0800430TrayMenu::updateConnectivity(bool isConnectedToHub)
431{
432 m_isConnectedToHub = isConnectedToHub;
433}
434
435void
Qi Zhao3ec33312017-02-12 02:51:05 -0800436TrayMenu::updateAdhoc(bool isConnectedToAdhoc)
437{
438 m_isConnectedToAdhoc = isConnectedToAdhoc;
439}
440
441void
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -0700442TrayMenu::enableCli()
443{
444#ifdef OSX_BUILD
Qi Zhaoae9c4312017-02-02 11:36:12 -0800445 QProcess* proc = new QProcess();
446 connect(proc, SIGNAL(finished(int)), proc, SLOT(deleteLater()));
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -0700447
Qi Zhaoae9c4312017-02-02 11:36:12 -0800448 proc->start("osascript", QStringList()
449 << "-e"
450 << "do shell script \""
451 "/bin/mkdir -vp /usr/local/bin; "
452 "/bin/ln -s -f '" + QCoreApplication::applicationDirPath() +
Qi Zhao9d6442e2017-03-22 00:40:11 -0500453 "/../Resources/ndn" + "' /usr/local/bin/ndn;"
Qi Zhaoae9c4312017-02-02 11:36:12 -0800454 "\" with administrator privileges");
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -0700455#endif
456}
457
Alexander Afanasyevfda42a82017-02-01 18:03:39 -0800458#ifdef OSX_BUILD
459void
460TrayMenu::checkForUpdates()
461{
462 m_sparkle.checkForUpdates();
463}
464#endif // OSX_BUILD
465
Qi Zhaoae9c4312017-02-02 11:36:12 -0800466void
467TrayMenu::scheduleDelayedTask(std::chrono::milliseconds delays, const std::function<void()>& task)
468{
469 auto timer = new QTimer();
470 timer->setSingleShot(true);
471 timer->setInterval(delays);
472 connect(timer, &QTimer::timeout,
473 [task, timer] {
474 task();
475 timer->deleteLater();
476 });
477 timer->start();
478}
479
Alexander Afanasyevfda42a82017-02-01 18:03:39 -0800480} // namespace ncc
taylorchuc27dd482014-05-17 20:06:49 -0700481} // namespace ndn