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