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" |
| 40 | |
Alexander Afanasyev | fda42a8 | 2017-02-01 18:03:39 -0800 | [diff] [blame] | 41 | #ifdef OSX_BUILD |
| 42 | #include "osx-auto-update-sparkle.hpp" |
| 43 | #endif // OSX_BUILD |
| 44 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 45 | namespace ndn { |
| 46 | |
Alexander Afanasyev | 81509f3 | 2016-03-21 17:02:38 -0700 | [diff] [blame] | 47 | class Face; |
| 48 | |
Alexander Afanasyev | fda42a8 | 2017-02-01 18:03:39 -0800 | [diff] [blame] | 49 | namespace ncc { |
| 50 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 51 | class TrayMenu : public QWidget |
| 52 | { |
| 53 | Q_OBJECT |
| 54 | |
| 55 | signals: |
| 56 | void |
| 57 | showApp(); |
| 58 | |
| 59 | void |
| 60 | nfdActivityUpdate(bool isActive); |
| 61 | |
Qi Zhao | dec77d9 | 2017-02-15 15:49:04 -0800 | [diff] [blame] | 62 | void |
| 63 | connectivityUpdate(bool isConnectedToHub); |
| 64 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 65 | public: |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 66 | explicit |
Alexander Afanasyev | 81509f3 | 2016-03-21 17:02:38 -0700 | [diff] [blame] | 67 | TrayMenu(QQmlContext* context, Face& face); |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 68 | |
| 69 | ~TrayMenu(); |
| 70 | |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 71 | Q_INVOKABLE bool |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame] | 72 | isNccAutoStartEnabled() const; |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 73 | |
| 74 | Q_INVOKABLE void |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame] | 75 | enableDisableNccAutoStart(bool isEnabled); |
| 76 | |
| 77 | Q_INVOKABLE bool |
| 78 | isNfdAutoStartEnabled() const; |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 79 | |
| 80 | Q_INVOKABLE void |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame] | 81 | enableDisableNfdAutoStart(bool isEnabled); |
| 82 | |
| 83 | Q_INVOKABLE bool |
| 84 | isNdnAutoConfigEnabled() const; |
| 85 | |
| 86 | Q_INVOKABLE void |
| 87 | enableDisableNdnAutoConfig(bool isEnabled); |
| 88 | |
| 89 | Q_INVOKABLE bool |
| 90 | isNfdStopOnExitEnabled() const; |
| 91 | |
| 92 | Q_INVOKABLE void |
| 93 | enableDisableNfdStopOnExit(bool isEnabled); |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 94 | |
susmit | 4fe3cb9 | 2016-03-20 17:08:41 -0700 | [diff] [blame] | 95 | Q_INVOKABLE void |
| 96 | addDeleteRoute(); |
| 97 | |
| 98 | Q_INVOKABLE void |
| 99 | addRoute(); |
| 100 | |
| 101 | Q_INVOKABLE void |
| 102 | deleteRoute(); |
| 103 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 104 | private slots: |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame] | 105 | void |
| 106 | startNdnAutoConfig(); |
| 107 | |
| 108 | void |
| 109 | stopNdnAutoConfig(bool appendStatus = true); |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 110 | |
| 111 | void |
| 112 | quitApp(); |
| 113 | |
| 114 | void |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 115 | startNfd(); |
| 116 | |
| 117 | void |
| 118 | stopNfd(); |
| 119 | |
| 120 | void |
| 121 | updateNfdActivityIcon(bool isActive); |
| 122 | |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 123 | void |
Qi Zhao | dec77d9 | 2017-02-15 15:49:04 -0800 | [diff] [blame] | 124 | updateConnectivity(bool isConnectedToHub); |
| 125 | |
| 126 | void |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 127 | enableCli(); |
| 128 | |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 129 | void |
| 130 | processOutput(); |
| 131 | |
| 132 | void |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame] | 133 | appendNdnAutoConfigStatus(const QString& message); |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 134 | |
Alexander Afanasyev | fda42a8 | 2017-02-01 18:03:39 -0800 | [diff] [blame] | 135 | #ifdef OSX_BUILD |
| 136 | void |
| 137 | checkForUpdates(); |
| 138 | #endif // OSX_BUILD |
| 139 | |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame] | 140 | void |
| 141 | scheduleDelayedTask(std::chrono::milliseconds delays, const std::function<void()>& task); |
| 142 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 143 | private: |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 144 | QQmlContext* m_context; |
| 145 | bool m_isNfdRunning; |
Qi Zhao | dec77d9 | 2017-02-15 15:49:04 -0800 | [diff] [blame] | 146 | bool m_isConnectedToHub; |
Yingdi Yu | 53c11c1 | 2016-03-20 12:56:49 -0700 | [diff] [blame] | 147 | QSystemTrayIcon* m_tray; |
| 148 | QMenu* m_menu; |
| 149 | QAction* m_entryPref; |
| 150 | QAction* m_entrySec; |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 151 | QProcess* m_acProc; |
Qi Zhao | ae9c431 | 2017-02-02 11:36:12 -0800 | [diff] [blame] | 152 | QSettings* m_settings; |
| 153 | QString m_ndnAutoConfigMsg; |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 154 | #ifdef OSX_BUILD |
| 155 | QAction* m_entryEnableCli; |
Alexander Afanasyev | fda42a8 | 2017-02-01 18:03:39 -0800 | [diff] [blame] | 156 | QAction* m_checkForUpdates; |
| 157 | OsxAutoUpdateSparkle m_sparkle; |
| 158 | #endif // OSX_BUILD |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 159 | |
Yingdi Yu | 53c11c1 | 2016-03-20 12:56:49 -0700 | [diff] [blame] | 160 | QAction* m_entryQuit; |
Yingdi Yu | 1f82464 | 2016-03-20 17:07:22 -0700 | [diff] [blame] | 161 | |
| 162 | ncc::KeyViewerDialog* m_keyViewerDialog; |
Alexander Afanasyev | 81509f3 | 2016-03-21 17:02:38 -0700 | [diff] [blame] | 163 | Face& m_face; |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 164 | }; |
| 165 | |
Alexander Afanasyev | fda42a8 | 2017-02-01 18:03:39 -0800 | [diff] [blame] | 166 | } // namespace ncc |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 167 | } // namespace ndn |
| 168 | |
| 169 | #endif // NCC_TRAY_MENU_HPP |