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 | |
| 23 | #include <ndn-cxx/face.hpp> |
| 24 | #include <ndn-cxx/interest.hpp> |
| 25 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 26 | #ifdef OSX_BUILD |
Alexander Afanasyev | 0621cec | 2016-03-20 23:18:27 -0700 | [diff] [blame] | 27 | #define CONNECT_ICON ":/res/icon-connected-black.png" |
| 28 | #define DISCONNECT_ICON ":/res/icon-disconnected-black.png" |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 29 | |
| 30 | #include <Security/Authorization.h> |
| 31 | #include <Security/AuthorizationTags.h> |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 32 | #else |
Alexander Afanasyev | 0621cec | 2016-03-20 23:18:27 -0700 | [diff] [blame] | 33 | #define CONNECT_ICON ":/res/icon-connected-white.png" |
| 34 | #define DISCONNECT_ICON ":/res/icon-disconnected-white.png" |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 35 | #endif // OSX_BUILD |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 36 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 37 | namespace ndn { |
Alexander Afanasyev | fda42a8 | 2017-02-01 18:03:39 -0800 | [diff] [blame^] | 38 | namespace ncc { |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 39 | |
Alexander Afanasyev | 81509f3 | 2016-03-21 17:02:38 -0700 | [diff] [blame] | 40 | TrayMenu::TrayMenu(QQmlContext* context, Face& face) |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 41 | : m_context(context) |
| 42 | , m_isNfdRunning(false) |
Yingdi Yu | 53c11c1 | 2016-03-20 12:56:49 -0700 | [diff] [blame] | 43 | , m_menu(new QMenu(this)) |
| 44 | , m_entryPref(new QAction("Preferences...", m_menu)) |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 45 | , m_entrySec(new QAction("Security...", m_menu)) |
Alexander Afanasyev | fda42a8 | 2017-02-01 18:03:39 -0800 | [diff] [blame^] | 46 | , m_acProc(new QProcess()) |
| 47 | , m_settings(new QSettings()) |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 48 | #ifdef OSX_BUILD |
| 49 | , m_entryEnableCli(new QAction("Enable Command Terminal Usage...", m_menu)) |
Alexander Afanasyev | fda42a8 | 2017-02-01 18:03:39 -0800 | [diff] [blame^] | 50 | , m_checkForUpdates(new QAction("Check for updates", m_menu)) |
| 51 | , m_sparkle("https://irl.cs.ucla.edu/~cawka/ndn-control-center.xml") |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 52 | #endif |
Yingdi Yu | 53c11c1 | 2016-03-20 12:56:49 -0700 | [diff] [blame] | 53 | , m_entryQuit(new QAction("Quit", m_menu)) |
Yingdi Yu | 1f82464 | 2016-03-20 17:07:22 -0700 | [diff] [blame] | 54 | , m_keyViewerDialog(new ncc::KeyViewerDialog) |
Alexander Afanasyev | 81509f3 | 2016-03-21 17:02:38 -0700 | [diff] [blame] | 55 | , m_face(face) |
Yingdi Yu | 53c11c1 | 2016-03-20 12:56:49 -0700 | [diff] [blame] | 56 | { |
| 57 | connect(m_entryPref, SIGNAL(triggered()), this, SIGNAL(showApp())); |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 58 | connect(this, SIGNAL(showApp()), this, SLOT(showPref())); |
Yingdi Yu | 1f82464 | 2016-03-20 17:07:22 -0700 | [diff] [blame] | 59 | connect(m_entrySec, SIGNAL(triggered()), m_keyViewerDialog, SLOT(present())); |
Yingdi Yu | 53c11c1 | 2016-03-20 12:56:49 -0700 | [diff] [blame] | 60 | connect(m_entryQuit, SIGNAL(triggered()), this, SLOT(quitApp())); |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 61 | |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 62 | connect(this, SIGNAL(nfdActivityUpdate(bool)), this, SLOT(updateNfdActivityIcon(bool)), |
| 63 | Qt::QueuedConnection); |
| 64 | |
| 65 | m_context->setContextProperty("startStopButtonText", QVariant::fromValue(QString("Start NFD"))); |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 66 | m_context->setContextProperty("acText", QVariant::fromValue(QString(""))); |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 67 | |
Yingdi Yu | 53c11c1 | 2016-03-20 12:56:49 -0700 | [diff] [blame] | 68 | m_menu->addAction(m_entryPref); |
| 69 | m_menu->addAction(m_entrySec); |
susmit | 5060791 | 2016-03-21 12:00:15 -0700 | [diff] [blame] | 70 | #ifdef OSX_BUILD |
Alexander Afanasyev | fda42a8 | 2017-02-01 18:03:39 -0800 | [diff] [blame^] | 71 | connect(m_entryEnableCli, SIGNAL(triggered()), this, SLOT(enableCli())); |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 72 | m_menu->addAction(m_entryEnableCli); |
Alexander Afanasyev | fda42a8 | 2017-02-01 18:03:39 -0800 | [diff] [blame^] | 73 | |
| 74 | connect(m_checkForUpdates, SIGNAL(triggered()), this, SLOT(checkForUpdates())); |
| 75 | m_menu->addAction(m_checkForUpdates); |
susmit | 5060791 | 2016-03-21 12:00:15 -0700 | [diff] [blame] | 76 | #endif |
Yingdi Yu | 53c11c1 | 2016-03-20 12:56:49 -0700 | [diff] [blame] | 77 | m_menu->addAction(m_entryQuit); |
| 78 | m_tray = new QSystemTrayIcon(this); |
| 79 | m_tray->setContextMenu(m_menu); |
| 80 | connect(m_tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 81 | this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason))); |
Yingdi Yu | 53c11c1 | 2016-03-20 12:56:49 -0700 | [diff] [blame] | 82 | m_tray->setIcon(QIcon(DISCONNECT_ICON)); |
| 83 | m_tray->show(); |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 84 | if (isAutoConfigEnabled()) { |
| 85 | stopAutoConfig(); // Make sure no more than one auto-config process exist |
| 86 | QTimer* mTimer = new QTimer(this); |
| 87 | mTimer->setSingleShot(true); |
| 88 | connect(mTimer, SIGNAL(timeout()), SLOT(startAutoConfig())); |
| 89 | mTimer->start(2000); |
| 90 | } |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | TrayMenu::~TrayMenu() |
| 94 | { |
| 95 | } |
| 96 | |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 97 | void |
| 98 | TrayMenu::appendMsg(QString &target, QString source) |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 99 | { |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 100 | int maxLine = 100; // Max line that will show in auto-config status tab view |
| 101 | if (target.count(QString("\n")) > maxLine) { // Only when target QString has more line than maxLine, it needs remove line |
| 102 | int end = target.indexOf(QString("\n")); |
| 103 | target.remove(0, end + 1); // Remove the first line of target |
| 104 | } |
| 105 | target.append(source); |
| 106 | } |
| 107 | |
| 108 | void |
| 109 | TrayMenu::showPref() |
| 110 | { |
| 111 | m_context->setContextProperty("acText", QVariant::fromValue(m_autoConfigMsg)); // Update auto-config status tab view |
| 112 | } |
| 113 | |
| 114 | void |
| 115 | TrayMenu::processOutput() |
| 116 | { |
| 117 | std::string msg = m_acProc->readAllStandardOutput().toStdString(); |
| 118 | if (msg != "") { |
| 119 | appendMsg(m_autoConfigMsg, QString::fromStdString(msg)); |
| 120 | } |
| 121 | msg = m_acProc->readAllStandardError().toStdString(); |
| 122 | if (msg != "") { |
| 123 | appendMsg(m_autoConfigMsg, QString::fromStdString(msg)); |
| 124 | } |
| 125 | m_context->setContextProperty("acText", QVariant::fromValue(m_autoConfigMsg)); |
| 126 | } |
| 127 | |
| 128 | Q_INVOKABLE bool |
| 129 | TrayMenu::isAutoConfigEnabled() |
| 130 | { |
| 131 | bool sAutoConfig = m_settings.value("main/auto-config", QVariant(false)).toBool(); |
| 132 | return sAutoConfig; |
| 133 | } |
| 134 | |
| 135 | void |
| 136 | TrayMenu::startAutoConfig() |
| 137 | { |
| 138 | if (m_isNfdRunning) { |
| 139 | appendMsg(m_autoConfigMsg, QString("NDN auto configuration will start...\n")); |
| 140 | connect(m_acProc, SIGNAL(readyReadStandardOutput()), this, SLOT(processOutput())); |
| 141 | connect(m_acProc, SIGNAL(readyReadStandardError()), this, SLOT(processOutput())); |
| 142 | m_acProc->start((QCoreApplication::applicationDirPath().toStdString() + "/../Platform/ndn-autoconfig").c_str(), |
| 143 | QStringList() |
| 144 | << "--daemon"); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | void |
| 149 | TrayMenu::stopAutoConfig() |
| 150 | { |
| 151 | #ifdef OSX_BUILD |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 152 | QProcess* proc = new QProcess(); |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 153 | connect(proc, SIGNAL(finished(int)), proc, SLOT(deleteLater())); |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 154 | proc->startDetached("killall", QStringList() << "ndn-autoconfig"); |
| 155 | #endif |
| 156 | } |
| 157 | |
| 158 | Q_INVOKABLE void |
| 159 | TrayMenu::startStopAutoConfig(bool autoConfig) |
| 160 | { |
| 161 | if (m_isNfdRunning) { |
| 162 | if (autoConfig) { |
| 163 | stopAutoConfig(); // Make sure no more than one auto-config process exist |
| 164 | QTimer* mTimer = new QTimer(this); |
| 165 | mTimer->setSingleShot(true); |
| 166 | connect(mTimer, SIGNAL(timeout()), SLOT(startAutoConfig())); |
| 167 | mTimer->start(2000); |
| 168 | m_context->setContextProperty("acText", QVariant::fromValue(m_autoConfigMsg)); |
| 169 | m_settings.setValue("main/auto-config", true); |
| 170 | } |
| 171 | else { |
| 172 | stopAutoConfig(); |
| 173 | appendMsg(m_autoConfigMsg, QString("NDN auto configuration will be stopped!\n")); |
| 174 | m_context->setContextProperty("acText", QVariant::fromValue(m_autoConfigMsg)); |
| 175 | m_settings.setValue("main/auto-config", false); |
| 176 | } |
| 177 | } |
| 178 | else { // No need to start or stop auto-config when NFD is not running, but it needs to update settings |
| 179 | if (autoConfig) { |
| 180 | m_settings.setValue("main/auto-config", true); |
| 181 | } |
| 182 | else { |
| 183 | m_settings.setValue("main/auto-config", false); |
| 184 | } |
| 185 | } |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | void |
| 189 | TrayMenu::quitApp() |
| 190 | { |
| 191 | QCoreApplication::exit(0); |
| 192 | } |
| 193 | |
| 194 | void |
| 195 | TrayMenu::iconActivated(QSystemTrayIcon::ActivationReason reason) |
| 196 | { |
| 197 | switch (reason) { |
| 198 | // case QSystemTrayIcon::Trigger: |
| 199 | // emit showApp(); |
| 200 | // break; |
| 201 | case QSystemTrayIcon::Context: |
| 202 | break; |
| 203 | default: |
| 204 | break; |
| 205 | } |
| 206 | } |
| 207 | |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 208 | Q_INVOKABLE void |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 209 | TrayMenu::startStopNfd(bool autoConfig) |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 210 | { |
| 211 | if (!m_isNfdRunning) { |
| 212 | startNfd(); |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 213 | if (autoConfig) { |
| 214 | stopAutoConfig(); // Make sure no more than one auto-config process exist |
| 215 | QTimer* mTimer = new QTimer(this); |
| 216 | mTimer->setSingleShot(true); |
| 217 | connect(mTimer, SIGNAL(timeout()), SLOT(startAutoConfig())); |
| 218 | mTimer->start(2000); |
| 219 | m_context->setContextProperty("acText", QVariant::fromValue(m_autoConfigMsg)); |
| 220 | } |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 221 | } |
| 222 | else { |
| 223 | stopNfd(); |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 224 | stopAutoConfig(); |
| 225 | appendMsg(m_autoConfigMsg, QString("NDN auto configuration will be stopped!\n")); |
| 226 | m_context->setContextProperty("acText", QVariant::fromValue(m_autoConfigMsg)); |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 230 | void |
| 231 | TrayMenu::startNfd() |
| 232 | { |
Alexander Afanasyev | 8e986f8 | 2016-03-21 14:19:15 -0700 | [diff] [blame] | 233 | #ifdef OSX_BUILD |
| 234 | QProcess* proc = new QProcess(); |
| 235 | connect(proc, SIGNAL(finished(int)), proc, SLOT(deleteLater())); |
| 236 | proc->startDetached((QCoreApplication::applicationDirPath().toStdString() + "/../Platform/nfd").c_str(), |
| 237 | QStringList() |
| 238 | << "--config" |
Alexander Afanasyev | 964feb9 | 2016-03-22 13:03:11 -0700 | [diff] [blame] | 239 | << (QCoreApplication::applicationDirPath().toStdString() + "/../etc/ndn/nfd.conf").c_str()); |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 240 | |
| 241 | |
| 242 | // #endif |
| 243 | // QProcess * proc = new QProcess(); |
| 244 | // connect(proc, SIGNAL(finished(int)), proc, SLOT(deleteLater())); |
| 245 | // #ifdef __linux__ |
| 246 | // proc->start("gksudo", QStringList() << NFD_START_COMMAND); |
| 247 | // #else |
| 248 | // proc->start("osascript", QStringList() |
| 249 | // << "-e" |
| 250 | // << "do shell script \"" NFD_START_COMMAND "\" with administrator privileges"); |
Alexander Afanasyev | 8e986f8 | 2016-03-21 14:19:15 -0700 | [diff] [blame] | 251 | #endif |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | void |
| 255 | TrayMenu::stopNfd() |
| 256 | { |
Alexander Afanasyev | 8e986f8 | 2016-03-21 14:19:15 -0700 | [diff] [blame] | 257 | #ifdef OSX_BUILD |
| 258 | QProcess* proc = new QProcess(); |
| 259 | connect(proc, SIGNAL(finished(int)), proc, SLOT(deleteLater())); |
| 260 | proc->startDetached("killall", QStringList() << "nfd"); |
| 261 | #endif |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 262 | } |
| 263 | |
susmit | 4fe3cb9 | 2016-03-20 17:08:41 -0700 | [diff] [blame] | 264 | Q_INVOKABLE void |
| 265 | TrayMenu::addDeleteRoute() |
| 266 | { |
| 267 | addRoute(); |
| 268 | } |
| 269 | |
| 270 | Q_INVOKABLE void |
| 271 | TrayMenu::addRoute() |
| 272 | { |
| 273 | std::cout << "Adding route" << std::endl; |
| 274 | QString cmd = "nfdc register /test tcp4://localhost"; |
| 275 | QProcess *addNewRoute = new QProcess(); |
| 276 | connect(addNewRoute,SIGNAL(finished(int)), addNewRoute, SLOT(deleteLater())); |
| 277 | addNewRoute->start("bash", QStringList() << "-c" << cmd); |
| 278 | std::cout << "Done" << std::endl; |
susmit | 4fe3cb9 | 2016-03-20 17:08:41 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | void |
| 282 | TrayMenu::deleteRoute() |
| 283 | { |
| 284 | std::cout << "Deleting route" << std::endl; |
| 285 | QString cmd = "nfdc unregister /test tcp4://localhost"; |
| 286 | QProcess *addNewRoute = new QProcess(); |
| 287 | connect(addNewRoute,SIGNAL(finished(int)), addNewRoute, SLOT(deleteLater())); |
| 288 | addNewRoute->start("bash", QStringList() << "-c" << cmd); |
| 289 | std::cout << "Done" << std::endl; |
susmit | 4fe3cb9 | 2016-03-20 17:08:41 -0700 | [diff] [blame] | 290 | } |
| 291 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 292 | void |
| 293 | TrayMenu::updateNfdActivityIcon(bool isActive) |
| 294 | { |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 295 | m_isNfdRunning = isActive; |
| 296 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 297 | if (isActive) { |
Yingdi Yu | 53c11c1 | 2016-03-20 12:56:49 -0700 | [diff] [blame] | 298 | m_tray->setIcon(QIcon(CONNECT_ICON)); |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 299 | m_context->setContextProperty("startStopButtonText", QVariant::fromValue(QString("Stop NFD"))); |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 300 | } |
| 301 | else { |
Yingdi Yu | 53c11c1 | 2016-03-20 12:56:49 -0700 | [diff] [blame] | 302 | m_tray->setIcon(QIcon(DISCONNECT_ICON)); |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 303 | m_context->setContextProperty("startStopButtonText", QVariant::fromValue(QString("Start NFD"))); |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 304 | } |
| 305 | } |
| 306 | |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 307 | void |
| 308 | TrayMenu::enableCli() |
| 309 | { |
| 310 | #ifdef OSX_BUILD |
| 311 | AuthorizationRef authorizationRef; |
| 312 | OSStatus status = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, |
| 313 | kAuthorizationFlagDefaults, &authorizationRef); |
| 314 | if (status != errAuthorizationSuccess) |
| 315 | return; |
| 316 | |
| 317 | AuthorizationItem item = { kAuthorizationRightExecute, 0, 0, 0 }; |
| 318 | AuthorizationRights rights = { 1, &item }; |
| 319 | const AuthorizationFlags flags = kAuthorizationFlagDefaults | kAuthorizationFlagInteractionAllowed |
| 320 | | kAuthorizationFlagPreAuthorize | kAuthorizationFlagExtendRights; |
| 321 | |
| 322 | status = AuthorizationCopyRights(authorizationRef, &rights, kAuthorizationEmptyEnvironment, |
| 323 | flags, 0); |
| 324 | if (status != errAuthorizationSuccess) |
| 325 | return; |
| 326 | |
| 327 | char const* mkdir_arg[] = { "-p", "/usr/local/bin", nullptr }; |
| 328 | char const* mkdir = "/bin/mkdir"; |
| 329 | AuthorizationExecuteWithPrivileges(authorizationRef, |
| 330 | mkdir, |
| 331 | kAuthorizationFlagDefaults, (char**)mkdir_arg, nullptr); |
| 332 | |
Alexander Afanasyev | 964feb9 | 2016-03-22 13:03:11 -0700 | [diff] [blame] | 333 | std::vector<std::string> arguments = { "-f", "-s", |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 334 | QCoreApplication::applicationDirPath().toStdString() + "/../Resources/ndn", |
| 335 | "/usr/local/bin/ndn" }; |
| 336 | std::vector<const char*> args; |
| 337 | for (const auto& i : arguments) { |
| 338 | args.push_back(i.c_str()); |
| 339 | } |
| 340 | args.push_back(nullptr); |
| 341 | |
Qi Zhao | 0e043e5 | 2016-12-05 18:27:09 -0800 | [diff] [blame] | 342 | char const* helperTool = "/bin/ln"; |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 343 | AuthorizationExecuteWithPrivileges(authorizationRef, |
| 344 | helperTool, |
| 345 | kAuthorizationFlagDefaults, |
| 346 | (char**)args.data(), NULL); |
| 347 | |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 348 | AuthorizationFree(authorizationRef, kAuthorizationFlagDestroyRights); |
| 349 | #endif |
| 350 | } |
| 351 | |
Alexander Afanasyev | fda42a8 | 2017-02-01 18:03:39 -0800 | [diff] [blame^] | 352 | #ifdef OSX_BUILD |
| 353 | void |
| 354 | TrayMenu::checkForUpdates() |
| 355 | { |
| 356 | m_sparkle.checkForUpdates(); |
| 357 | } |
| 358 | #endif // OSX_BUILD |
| 359 | |
| 360 | } // namespace ncc |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 361 | } // namespace ndn |