taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -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 | * |
| 16 | * You should have received a copy of the GNU General Public License along with NFD |
| 17 | * Control Center, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #ifndef NCC_TRAY_MENU_HPP |
| 21 | #define NCC_TRAY_MENU_HPP |
| 22 | |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 23 | #include "config.hpp" |
| 24 | |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame] | 25 | #include <QtCore/QDir> |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 26 | #include <QtCore/QObject> |
| 27 | #include <QtCore/QProcess> |
| 28 | #include <QtCore/QCoreApplication> |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 29 | #include <QtCore/QSettings> |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame] | 30 | #include <QtCore/QXmlStreamWriter> |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 31 | |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 32 | #include <QtWidgets/QWidget> |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 33 | #include <QtWidgets/QSystemTrayIcon> |
| 34 | #include <QtWidgets/QAction> |
| 35 | #include <QtWidgets/QMenu> |
| 36 | |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 37 | #include <QtQml/QQmlContext> |
| 38 | |
Yingdi Yu | 1f82464 | 2016-03-20 17:07:22 -0700 | [diff] [blame] | 39 | #include "key-viewer-dialog.hpp" |
Qi Zhao | 7e52449 | 2017-03-02 15:05:45 -0800 | [diff] [blame] | 40 | #include "status-viewer.hpp" |
Yingdi Yu | 1f82464 | 2016-03-20 17:07:22 -0700 | [diff] [blame] | 41 | |
Alexander Afanasyev | fda42a8 | 2017-02-01 18:03:39 -0800 | [diff] [blame] | 42 | #ifdef OSX_BUILD |
| 43 | #include "osx-auto-update-sparkle.hpp" |
| 44 | #endif // OSX_BUILD |
| 45 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 46 | namespace ndn { |
| 47 | |
Alexander Afanasyev | 81509f3 | 2016-03-21 17:02:38 -0700 | [diff] [blame] | 48 | class Face; |
| 49 | |
Alexander Afanasyev | fda42a8 | 2017-02-01 18:03:39 -0800 | [diff] [blame] | 50 | namespace ncc { |
| 51 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 52 | class TrayMenu : public QWidget |
| 53 | { |
| 54 | Q_OBJECT |
| 55 | |
| 56 | signals: |
| 57 | void |
| 58 | showApp(); |
| 59 | |
| 60 | void |
| 61 | nfdActivityUpdate(bool isActive); |
| 62 | |
Qi Zhao | dec77d9 | 2017-02-15 15:49:04 -0800 | [diff] [blame] | 63 | void |
| 64 | connectivityUpdate(bool isConnectedToHub); |
| 65 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 66 | public: |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 67 | explicit |
Qi Zhao | 7e52449 | 2017-03-02 15:05:45 -0800 | [diff] [blame] | 68 | TrayMenu(QQmlContext* context, Face& face, KeyChain& keyChain); |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 69 | |
| 70 | ~TrayMenu(); |
| 71 | |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 72 | Q_INVOKABLE bool |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame] | 73 | isNccAutoStartEnabled() const; |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 74 | |
| 75 | Q_INVOKABLE void |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame] | 76 | enableDisableNccAutoStart(bool isEnabled); |
| 77 | |
| 78 | Q_INVOKABLE bool |
| 79 | isNfdAutoStartEnabled() const; |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 80 | |
| 81 | Q_INVOKABLE void |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame] | 82 | enableDisableNfdAutoStart(bool isEnabled); |
| 83 | |
| 84 | Q_INVOKABLE bool |
| 85 | isNdnAutoConfigEnabled() const; |
| 86 | |
| 87 | Q_INVOKABLE void |
| 88 | enableDisableNdnAutoConfig(bool isEnabled); |
| 89 | |
| 90 | Q_INVOKABLE bool |
| 91 | isNfdStopOnExitEnabled() const; |
| 92 | |
| 93 | Q_INVOKABLE void |
| 94 | enableDisableNfdStopOnExit(bool isEnabled); |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 95 | |
susmit | 4fe3cb9 | 2016-03-20 17:08:41 -0700 | [diff] [blame] | 96 | Q_INVOKABLE void |
| 97 | addDeleteRoute(); |
| 98 | |
| 99 | Q_INVOKABLE void |
| 100 | addRoute(); |
| 101 | |
| 102 | Q_INVOKABLE void |
| 103 | deleteRoute(); |
| 104 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 105 | private slots: |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame] | 106 | void |
| 107 | startNdnAutoConfig(); |
| 108 | |
| 109 | void |
| 110 | stopNdnAutoConfig(bool appendStatus = true); |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 111 | |
| 112 | void |
| 113 | quitApp(); |
| 114 | |
| 115 | void |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 116 | startNfd(); |
| 117 | |
| 118 | void |
| 119 | stopNfd(); |
| 120 | |
| 121 | void |
| 122 | updateNfdActivityIcon(bool isActive); |
| 123 | |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 124 | void |
Qi Zhao | dec77d9 | 2017-02-15 15:49:04 -0800 | [diff] [blame] | 125 | updateConnectivity(bool isConnectedToHub); |
| 126 | |
| 127 | void |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 128 | enableCli(); |
| 129 | |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 130 | void |
| 131 | processOutput(); |
| 132 | |
| 133 | void |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame] | 134 | appendNdnAutoConfigStatus(const QString& message); |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 135 | |
Alexander Afanasyev | fda42a8 | 2017-02-01 18:03:39 -0800 | [diff] [blame] | 136 | #ifdef OSX_BUILD |
| 137 | void |
| 138 | checkForUpdates(); |
| 139 | #endif // OSX_BUILD |
| 140 | |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame] | 141 | void |
| 142 | scheduleDelayedTask(std::chrono::milliseconds delays, const std::function<void()>& task); |
| 143 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 144 | private: |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 145 | QQmlContext* m_context; |
| 146 | bool m_isNfdRunning; |
Qi Zhao | dec77d9 | 2017-02-15 15:49:04 -0800 | [diff] [blame] | 147 | bool m_isConnectedToHub; |
Yingdi Yu | 53c11c1 | 2016-03-20 12:56:49 -0700 | [diff] [blame] | 148 | QSystemTrayIcon* m_tray; |
| 149 | QMenu* m_menu; |
| 150 | QAction* m_entryPref; |
Qi Zhao | 7e52449 | 2017-03-02 15:05:45 -0800 | [diff] [blame] | 151 | QAction* m_entryStatus; |
Yingdi Yu | 53c11c1 | 2016-03-20 12:56:49 -0700 | [diff] [blame] | 152 | QAction* m_entrySec; |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 153 | QProcess* m_acProc; |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame] | 154 | QSettings* m_settings; |
| 155 | QString m_ndnAutoConfigMsg; |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 156 | #ifdef OSX_BUILD |
| 157 | QAction* m_entryEnableCli; |
Alexander Afanasyev | fda42a8 | 2017-02-01 18:03:39 -0800 | [diff] [blame] | 158 | QAction* m_checkForUpdates; |
| 159 | OsxAutoUpdateSparkle m_sparkle; |
| 160 | #endif // OSX_BUILD |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 161 | |
Yingdi Yu | 53c11c1 | 2016-03-20 12:56:49 -0700 | [diff] [blame] | 162 | QAction* m_entryQuit; |
Yingdi Yu | 1f82464 | 2016-03-20 17:07:22 -0700 | [diff] [blame] | 163 | |
| 164 | ncc::KeyViewerDialog* m_keyViewerDialog; |
Alexander Afanasyev | 81509f3 | 2016-03-21 17:02:38 -0700 | [diff] [blame] | 165 | Face& m_face; |
Qi Zhao | 7e52449 | 2017-03-02 15:05:45 -0800 | [diff] [blame] | 166 | KeyChain& m_keyChain; |
| 167 | StatusViewer* m_statusViewer; |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 168 | }; |
| 169 | |
Alexander Afanasyev | fda42a8 | 2017-02-01 18:03:39 -0800 | [diff] [blame] | 170 | } // namespace ncc |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 171 | } // namespace ndn |
| 172 | |
| 173 | #endif // NCC_TRAY_MENU_HPP |