blob: 1159a1d4847b77846b2f4cb1eea6179bac6c4216 [file] [log] [blame]
taylorchuc27dd482014-05-17 20:06:49 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Qi Zhao86f2b212016-12-06 12:44:16 -08003 * Copyright (c) 2013-2017, Regents of the University of California,
taylorchuc27dd482014-05-17 20:06:49 -07004 *
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 Afanasyev11ae34d2016-03-21 11:55:16 -070023#include "config.hpp"
24
Qi Zhaoae9c4312017-02-02 11:36:12 -080025#include <QtCore/QDir>
taylorchuc27dd482014-05-17 20:06:49 -070026#include <QtCore/QObject>
27#include <QtCore/QProcess>
28#include <QtCore/QCoreApplication>
Qi Zhao86f2b212016-12-06 12:44:16 -080029#include <QtCore/QSettings>
Qi Zhaoae9c4312017-02-02 11:36:12 -080030#include <QtCore/QXmlStreamWriter>
taylorchuc27dd482014-05-17 20:06:49 -070031
Qi Zhao86f2b212016-12-06 12:44:16 -080032#include <QtWidgets/QWidget>
taylorchuc27dd482014-05-17 20:06:49 -070033#include <QtWidgets/QSystemTrayIcon>
34#include <QtWidgets/QAction>
35#include <QtWidgets/QMenu>
36
Alexander Afanasyev4086d512014-07-11 15:56:33 -070037#include <QtQml/QQmlContext>
38
Yingdi Yu1f824642016-03-20 17:07:22 -070039#include "key-viewer-dialog.hpp"
Qi Zhao7e524492017-03-02 15:05:45 -080040#include "status-viewer.hpp"
Yingdi Yu1f824642016-03-20 17:07:22 -070041
Alexander Afanasyevfda42a82017-02-01 18:03:39 -080042#ifdef OSX_BUILD
43#include "osx-auto-update-sparkle.hpp"
44#endif // OSX_BUILD
45
taylorchuc27dd482014-05-17 20:06:49 -070046namespace ndn {
47
Alexander Afanasyev81509f32016-03-21 17:02:38 -070048class Face;
49
Alexander Afanasyevfda42a82017-02-01 18:03:39 -080050namespace ncc {
51
taylorchuc27dd482014-05-17 20:06:49 -070052class TrayMenu : public QWidget
53{
54 Q_OBJECT
55
56signals:
57 void
58 showApp();
59
60 void
61 nfdActivityUpdate(bool isActive);
62
Qi Zhaodec77d92017-02-15 15:49:04 -080063 void
64 connectivityUpdate(bool isConnectedToHub);
65
taylorchuc27dd482014-05-17 20:06:49 -070066public:
Alexander Afanasyev4086d512014-07-11 15:56:33 -070067 explicit
Qi Zhao7e524492017-03-02 15:05:45 -080068 TrayMenu(QQmlContext* context, Face& face, KeyChain& keyChain);
taylorchuc27dd482014-05-17 20:06:49 -070069
70 ~TrayMenu();
71
Qi Zhao86f2b212016-12-06 12:44:16 -080072 Q_INVOKABLE bool
Qi Zhaoae9c4312017-02-02 11:36:12 -080073 isNccAutoStartEnabled() const;
taylorchuc27dd482014-05-17 20:06:49 -070074
75 Q_INVOKABLE void
Qi Zhaoae9c4312017-02-02 11:36:12 -080076 enableDisableNccAutoStart(bool isEnabled);
77
78 Q_INVOKABLE bool
79 isNfdAutoStartEnabled() const;
Qi Zhao86f2b212016-12-06 12:44:16 -080080
81 Q_INVOKABLE void
Qi Zhaoae9c4312017-02-02 11:36:12 -080082 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);
taylorchuc27dd482014-05-17 20:06:49 -070095
susmit4fe3cb92016-03-20 17:08:41 -070096 Q_INVOKABLE void
97 addDeleteRoute();
98
99 Q_INVOKABLE void
100 addRoute();
101
102 Q_INVOKABLE void
103 deleteRoute();
104
taylorchuc27dd482014-05-17 20:06:49 -0700105private slots:
Qi Zhaoae9c4312017-02-02 11:36:12 -0800106 void
107 startNdnAutoConfig();
108
109 void
110 stopNdnAutoConfig(bool appendStatus = true);
taylorchuc27dd482014-05-17 20:06:49 -0700111
112 void
113 quitApp();
114
115 void
taylorchuc27dd482014-05-17 20:06:49 -0700116 startNfd();
117
118 void
119 stopNfd();
120
121 void
122 updateNfdActivityIcon(bool isActive);
123
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -0700124 void
Qi Zhaodec77d92017-02-15 15:49:04 -0800125 updateConnectivity(bool isConnectedToHub);
126
127 void
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -0700128 enableCli();
129
Qi Zhao86f2b212016-12-06 12:44:16 -0800130 void
131 processOutput();
132
133 void
Qi Zhaoae9c4312017-02-02 11:36:12 -0800134 appendNdnAutoConfigStatus(const QString& message);
Qi Zhao86f2b212016-12-06 12:44:16 -0800135
Alexander Afanasyevfda42a82017-02-01 18:03:39 -0800136#ifdef OSX_BUILD
137 void
138 checkForUpdates();
139#endif // OSX_BUILD
140
Qi Zhaoae9c4312017-02-02 11:36:12 -0800141 void
142 scheduleDelayedTask(std::chrono::milliseconds delays, const std::function<void()>& task);
143
taylorchuc27dd482014-05-17 20:06:49 -0700144private:
Alexander Afanasyev4086d512014-07-11 15:56:33 -0700145 QQmlContext* m_context;
146 bool m_isNfdRunning;
Qi Zhaodec77d92017-02-15 15:49:04 -0800147 bool m_isConnectedToHub;
Yingdi Yu53c11c12016-03-20 12:56:49 -0700148 QSystemTrayIcon* m_tray;
149 QMenu* m_menu;
150 QAction* m_entryPref;
Qi Zhao7e524492017-03-02 15:05:45 -0800151 QAction* m_entryStatus;
Yingdi Yu53c11c12016-03-20 12:56:49 -0700152 QAction* m_entrySec;
Qi Zhao86f2b212016-12-06 12:44:16 -0800153 QProcess* m_acProc;
Qi Zhaoae9c4312017-02-02 11:36:12 -0800154 QSettings* m_settings;
155 QString m_ndnAutoConfigMsg;
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -0700156#ifdef OSX_BUILD
157 QAction* m_entryEnableCli;
Alexander Afanasyevfda42a82017-02-01 18:03:39 -0800158 QAction* m_checkForUpdates;
159 OsxAutoUpdateSparkle m_sparkle;
160#endif // OSX_BUILD
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -0700161
Yingdi Yu53c11c12016-03-20 12:56:49 -0700162 QAction* m_entryQuit;
Yingdi Yu1f824642016-03-20 17:07:22 -0700163
164 ncc::KeyViewerDialog* m_keyViewerDialog;
Alexander Afanasyev81509f32016-03-21 17:02:38 -0700165 Face& m_face;
Qi Zhao7e524492017-03-02 15:05:45 -0800166 KeyChain& m_keyChain;
167 StatusViewer* m_statusViewer;
taylorchuc27dd482014-05-17 20:06:49 -0700168};
169
Alexander Afanasyevfda42a82017-02-01 18:03:39 -0800170} // namespace ncc
taylorchuc27dd482014-05-17 20:06:49 -0700171} // namespace ndn
172
173#endif // NCC_TRAY_MENU_HPP