blob: d71804b669d7af374b89c47c613acd200fac0b15 [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>
Qi Zhao3ec33312017-02-12 02:51:05 -080036#include <QtWidgets/QMessageBox>
taylorchuc27dd482014-05-17 20:06:49 -070037
Alexander Afanasyev4086d512014-07-11 15:56:33 -070038#include <QtQml/QQmlContext>
39
Yingdi Yu1f824642016-03-20 17:07:22 -070040#include "key-viewer-dialog.hpp"
Qi Zhao7e524492017-03-02 15:05:45 -080041#include "status-viewer.hpp"
Yingdi Yu1f824642016-03-20 17:07:22 -070042
Alexander Afanasyevfda42a82017-02-01 18:03:39 -080043#ifdef OSX_BUILD
44#include "osx-auto-update-sparkle.hpp"
Qi Zhao3ec33312017-02-12 02:51:05 -080045#include "osx-adhoc.hpp"
Alexander Afanasyevfda42a82017-02-01 18:03:39 -080046#endif // OSX_BUILD
47
Qi Zhao3ec33312017-02-12 02:51:05 -080048#include <thread>
49
taylorchuc27dd482014-05-17 20:06:49 -070050namespace ndn {
51
Alexander Afanasyev81509f32016-03-21 17:02:38 -070052class Face;
53
Alexander Afanasyevfda42a82017-02-01 18:03:39 -080054namespace ncc {
55
taylorchuc27dd482014-05-17 20:06:49 -070056class TrayMenu : public QWidget
57{
58 Q_OBJECT
59
60signals:
61 void
62 showApp();
63
64 void
65 nfdActivityUpdate(bool isActive);
66
Qi Zhaodec77d92017-02-15 15:49:04 -080067 void
68 connectivityUpdate(bool isConnectedToHub);
69
Qi Zhao3ec33312017-02-12 02:51:05 -080070 void
71 adhocUpdate(bool isConnectedToAdhoc);
72
taylorchuc27dd482014-05-17 20:06:49 -070073public:
Alexander Afanasyev4086d512014-07-11 15:56:33 -070074 explicit
Qi Zhao7e524492017-03-02 15:05:45 -080075 TrayMenu(QQmlContext* context, Face& face, KeyChain& keyChain);
taylorchuc27dd482014-05-17 20:06:49 -070076
77 ~TrayMenu();
78
Qi Zhao86f2b212016-12-06 12:44:16 -080079 Q_INVOKABLE bool
Qi Zhaoae9c4312017-02-02 11:36:12 -080080 isNccAutoStartEnabled() const;
taylorchuc27dd482014-05-17 20:06:49 -070081
82 Q_INVOKABLE void
Qi Zhaoae9c4312017-02-02 11:36:12 -080083 enableDisableNccAutoStart(bool isEnabled);
84
85 Q_INVOKABLE bool
86 isNfdAutoStartEnabled() const;
Qi Zhao86f2b212016-12-06 12:44:16 -080087
88 Q_INVOKABLE void
Qi Zhaoae9c4312017-02-02 11:36:12 -080089 enableDisableNfdAutoStart(bool isEnabled);
90
91 Q_INVOKABLE bool
92 isNdnAutoConfigEnabled() const;
93
94 Q_INVOKABLE void
95 enableDisableNdnAutoConfig(bool isEnabled);
96
97 Q_INVOKABLE bool
98 isNfdStopOnExitEnabled() const;
99
100 Q_INVOKABLE void
101 enableDisableNfdStopOnExit(bool isEnabled);
taylorchuc27dd482014-05-17 20:06:49 -0700102
susmit4fe3cb92016-03-20 17:08:41 -0700103 Q_INVOKABLE void
104 addDeleteRoute();
105
106 Q_INVOKABLE void
107 addRoute();
108
109 Q_INVOKABLE void
110 deleteRoute();
111
taylorchuc27dd482014-05-17 20:06:49 -0700112private slots:
Qi Zhaoae9c4312017-02-02 11:36:12 -0800113 void
114 startNdnAutoConfig();
115
116 void
117 stopNdnAutoConfig(bool appendStatus = true);
taylorchuc27dd482014-05-17 20:06:49 -0700118
119 void
120 quitApp();
121
122 void
taylorchuc27dd482014-05-17 20:06:49 -0700123 startNfd();
124
125 void
126 stopNfd();
127
128 void
129 updateNfdActivityIcon(bool isActive);
130
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -0700131 void
Qi Zhaodec77d92017-02-15 15:49:04 -0800132 updateConnectivity(bool isConnectedToHub);
133
134 void
Qi Zhao3ec33312017-02-12 02:51:05 -0800135 updateAdhoc(bool isConnectedToAdhoc);
136
137 void
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -0700138 enableCli();
139
Qi Zhao86f2b212016-12-06 12:44:16 -0800140 void
141 processOutput();
142
143 void
Qi Zhaoae9c4312017-02-02 11:36:12 -0800144 appendNdnAutoConfigStatus(const QString& message);
Qi Zhao86f2b212016-12-06 12:44:16 -0800145
Alexander Afanasyevfda42a82017-02-01 18:03:39 -0800146#ifdef OSX_BUILD
147 void
Qi Zhao3ec33312017-02-12 02:51:05 -0800148 onAdhocChange();
149
150 void
Alexander Afanasyevfda42a82017-02-01 18:03:39 -0800151 checkForUpdates();
152#endif // OSX_BUILD
153
Qi Zhaoae9c4312017-02-02 11:36:12 -0800154 void
155 scheduleDelayedTask(std::chrono::milliseconds delays, const std::function<void()>& task);
156
taylorchuc27dd482014-05-17 20:06:49 -0700157private:
Alexander Afanasyev4086d512014-07-11 15:56:33 -0700158 QQmlContext* m_context;
159 bool m_isNfdRunning;
Qi Zhaodec77d92017-02-15 15:49:04 -0800160 bool m_isConnectedToHub;
Qi Zhao3ec33312017-02-12 02:51:05 -0800161 bool m_isConnectedToAdhoc;
Yingdi Yu53c11c12016-03-20 12:56:49 -0700162 QSystemTrayIcon* m_tray;
163 QMenu* m_menu;
164 QAction* m_entryPref;
Qi Zhao7e524492017-03-02 15:05:45 -0800165 QAction* m_entryStatus;
Yingdi Yu53c11c12016-03-20 12:56:49 -0700166 QAction* m_entrySec;
Qi Zhao86f2b212016-12-06 12:44:16 -0800167 QProcess* m_acProc;
Qi Zhaoae9c4312017-02-02 11:36:12 -0800168 QSettings* m_settings;
169 QString m_ndnAutoConfigMsg;
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -0700170#ifdef OSX_BUILD
171 QAction* m_entryEnableCli;
Qi Zhao3ec33312017-02-12 02:51:05 -0800172 QAction* m_entryAdhoc;
Alexander Afanasyevfda42a82017-02-01 18:03:39 -0800173 QAction* m_checkForUpdates;
174 OsxAutoUpdateSparkle m_sparkle;
175#endif // OSX_BUILD
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -0700176
Yingdi Yu53c11c12016-03-20 12:56:49 -0700177 QAction* m_entryQuit;
Yingdi Yu1f824642016-03-20 17:07:22 -0700178
179 ncc::KeyViewerDialog* m_keyViewerDialog;
Alexander Afanasyev81509f32016-03-21 17:02:38 -0700180 Face& m_face;
Qi Zhao7e524492017-03-02 15:05:45 -0800181 KeyChain& m_keyChain;
Qi Zhao3ec33312017-02-12 02:51:05 -0800182 Adhoc m_adhoc;
Qi Zhao7e524492017-03-02 15:05:45 -0800183 StatusViewer* m_statusViewer;
taylorchuc27dd482014-05-17 20:06:49 -0700184};
185
Alexander Afanasyevfda42a82017-02-01 18:03:39 -0800186} // namespace ncc
taylorchuc27dd482014-05-17 20:06:49 -0700187} // namespace ndn
188
189#endif // NCC_TRAY_MENU_HPP