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 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 25 | #include <QtCore/QObject> |
| 26 | #include <QtCore/QProcess> |
| 27 | #include <QtCore/QCoreApplication> |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 28 | #include <QtCore/QSettings> |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 29 | |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 30 | #include <QtWidgets/QWidget> |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 31 | #include <QtWidgets/QSystemTrayIcon> |
| 32 | #include <QtWidgets/QAction> |
| 33 | #include <QtWidgets/QMenu> |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 34 | #include <QtWidgets/QVBoxLayout> |
| 35 | #include <QtWidgets/QPlainTextEdit> |
| 36 | #include <QtWidgets/QPushButton> |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 37 | |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 38 | #include <QtQml/QQmlContext> |
| 39 | |
Yingdi Yu | 1f82464 | 2016-03-20 17:07:22 -0700 | [diff] [blame] | 40 | #include "key-viewer-dialog.hpp" |
| 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 | |
| 63 | public: |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 64 | explicit |
Alexander Afanasyev | 81509f3 | 2016-03-21 17:02:38 -0700 | [diff] [blame] | 65 | TrayMenu(QQmlContext* context, Face& face); |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 66 | |
| 67 | ~TrayMenu(); |
| 68 | |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 69 | Q_INVOKABLE bool |
| 70 | isAutoConfigEnabled(); |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 71 | |
| 72 | Q_INVOKABLE void |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 73 | startStopAutoConfig(bool autoConfig); |
| 74 | |
| 75 | Q_INVOKABLE void |
| 76 | startStopNfd(bool autoConfig); |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 77 | |
susmit | 4fe3cb9 | 2016-03-20 17:08:41 -0700 | [diff] [blame] | 78 | Q_INVOKABLE void |
| 79 | addDeleteRoute(); |
| 80 | |
| 81 | Q_INVOKABLE void |
| 82 | addRoute(); |
| 83 | |
| 84 | Q_INVOKABLE void |
| 85 | deleteRoute(); |
| 86 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 87 | private slots: |
| 88 | |
| 89 | void |
| 90 | quitApp(); |
| 91 | |
| 92 | void |
| 93 | iconActivated(QSystemTrayIcon::ActivationReason reason); |
| 94 | |
| 95 | void |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 96 | startAutoConfig(); |
| 97 | |
| 98 | void |
| 99 | stopAutoConfig(); |
| 100 | |
| 101 | void |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 102 | startNfd(); |
| 103 | |
| 104 | void |
| 105 | stopNfd(); |
| 106 | |
| 107 | void |
| 108 | updateNfdActivityIcon(bool isActive); |
| 109 | |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 110 | void |
| 111 | enableCli(); |
| 112 | |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 113 | void |
| 114 | processOutput(); |
| 115 | |
| 116 | void |
| 117 | showPref(); |
| 118 | |
| 119 | static void |
| 120 | appendMsg(QString &target, QString source); |
| 121 | |
Alexander Afanasyev | fda42a8 | 2017-02-01 18:03:39 -0800 | [diff] [blame] | 122 | #ifdef OSX_BUILD |
| 123 | void |
| 124 | checkForUpdates(); |
| 125 | #endif // OSX_BUILD |
| 126 | |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 127 | private: |
Alexander Afanasyev | 4086d51 | 2014-07-11 15:56:33 -0700 | [diff] [blame] | 128 | QQmlContext* m_context; |
| 129 | bool m_isNfdRunning; |
Yingdi Yu | 53c11c1 | 2016-03-20 12:56:49 -0700 | [diff] [blame] | 130 | QSystemTrayIcon* m_tray; |
| 131 | QMenu* m_menu; |
| 132 | QAction* m_entryPref; |
| 133 | QAction* m_entrySec; |
Qi Zhao | 86f2b21 | 2016-12-06 12:44:16 -0800 | [diff] [blame] | 134 | QProcess* m_acProc; |
| 135 | QString m_autoConfigMsg; |
| 136 | QSettings m_settings; |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 137 | #ifdef OSX_BUILD |
| 138 | QAction* m_entryEnableCli; |
Alexander Afanasyev | fda42a8 | 2017-02-01 18:03:39 -0800 | [diff] [blame] | 139 | QAction* m_checkForUpdates; |
| 140 | OsxAutoUpdateSparkle m_sparkle; |
| 141 | #endif // OSX_BUILD |
Alexander Afanasyev | 11ae34d | 2016-03-21 11:55:16 -0700 | [diff] [blame] | 142 | |
Yingdi Yu | 53c11c1 | 2016-03-20 12:56:49 -0700 | [diff] [blame] | 143 | QAction* m_entryQuit; |
Yingdi Yu | 1f82464 | 2016-03-20 17:07:22 -0700 | [diff] [blame] | 144 | |
| 145 | ncc::KeyViewerDialog* m_keyViewerDialog; |
Alexander Afanasyev | 81509f3 | 2016-03-21 17:02:38 -0700 | [diff] [blame] | 146 | Face& m_face; |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 147 | }; |
| 148 | |
Alexander Afanasyev | fda42a8 | 2017-02-01 18:03:39 -0800 | [diff] [blame] | 149 | } // namespace ncc |
taylorchu | c27dd48 | 2014-05-17 20:06:49 -0700 | [diff] [blame] | 150 | } // namespace ndn |
| 151 | |
| 152 | #endif // NCC_TRAY_MENU_HPP |