blob: 878c0a6c51c607c0090e27d698c42783c1910bd6 [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"
40
Alexander Afanasyevfda42a82017-02-01 18:03:39 -080041#ifdef OSX_BUILD
42#include "osx-auto-update-sparkle.hpp"
43#endif // OSX_BUILD
44
taylorchuc27dd482014-05-17 20:06:49 -070045namespace ndn {
46
Alexander Afanasyev81509f32016-03-21 17:02:38 -070047class Face;
48
Alexander Afanasyevfda42a82017-02-01 18:03:39 -080049namespace ncc {
50
taylorchuc27dd482014-05-17 20:06:49 -070051class TrayMenu : public QWidget
52{
53 Q_OBJECT
54
55signals:
56 void
57 showApp();
58
59 void
60 nfdActivityUpdate(bool isActive);
61
Qi Zhaodec77d92017-02-15 15:49:04 -080062 void
63 connectivityUpdate(bool isConnectedToHub);
64
taylorchuc27dd482014-05-17 20:06:49 -070065public:
Alexander Afanasyev4086d512014-07-11 15:56:33 -070066 explicit
Alexander Afanasyev81509f32016-03-21 17:02:38 -070067 TrayMenu(QQmlContext* context, Face& face);
taylorchuc27dd482014-05-17 20:06:49 -070068
69 ~TrayMenu();
70
Qi Zhao86f2b212016-12-06 12:44:16 -080071 Q_INVOKABLE bool
Qi Zhaoae9c4312017-02-02 11:36:12 -080072 isNccAutoStartEnabled() const;
taylorchuc27dd482014-05-17 20:06:49 -070073
74 Q_INVOKABLE void
Qi Zhaoae9c4312017-02-02 11:36:12 -080075 enableDisableNccAutoStart(bool isEnabled);
76
77 Q_INVOKABLE bool
78 isNfdAutoStartEnabled() const;
Qi Zhao86f2b212016-12-06 12:44:16 -080079
80 Q_INVOKABLE void
Qi Zhaoae9c4312017-02-02 11:36:12 -080081 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);
taylorchuc27dd482014-05-17 20:06:49 -070094
susmit4fe3cb92016-03-20 17:08:41 -070095 Q_INVOKABLE void
96 addDeleteRoute();
97
98 Q_INVOKABLE void
99 addRoute();
100
101 Q_INVOKABLE void
102 deleteRoute();
103
taylorchuc27dd482014-05-17 20:06:49 -0700104private slots:
Qi Zhaoae9c4312017-02-02 11:36:12 -0800105 void
106 startNdnAutoConfig();
107
108 void
109 stopNdnAutoConfig(bool appendStatus = true);
taylorchuc27dd482014-05-17 20:06:49 -0700110
111 void
112 quitApp();
113
114 void
taylorchuc27dd482014-05-17 20:06:49 -0700115 startNfd();
116
117 void
118 stopNfd();
119
120 void
121 updateNfdActivityIcon(bool isActive);
122
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -0700123 void
Qi Zhaodec77d92017-02-15 15:49:04 -0800124 updateConnectivity(bool isConnectedToHub);
125
126 void
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -0700127 enableCli();
128
Qi Zhao86f2b212016-12-06 12:44:16 -0800129 void
130 processOutput();
131
132 void
Qi Zhaoae9c4312017-02-02 11:36:12 -0800133 appendNdnAutoConfigStatus(const QString& message);
Qi Zhao86f2b212016-12-06 12:44:16 -0800134
Alexander Afanasyevfda42a82017-02-01 18:03:39 -0800135#ifdef OSX_BUILD
136 void
137 checkForUpdates();
138#endif // OSX_BUILD
139
Qi Zhaoae9c4312017-02-02 11:36:12 -0800140 void
141 scheduleDelayedTask(std::chrono::milliseconds delays, const std::function<void()>& task);
142
taylorchuc27dd482014-05-17 20:06:49 -0700143private:
Alexander Afanasyev4086d512014-07-11 15:56:33 -0700144 QQmlContext* m_context;
145 bool m_isNfdRunning;
Qi Zhaodec77d92017-02-15 15:49:04 -0800146 bool m_isConnectedToHub;
Yingdi Yu53c11c12016-03-20 12:56:49 -0700147 QSystemTrayIcon* m_tray;
148 QMenu* m_menu;
149 QAction* m_entryPref;
150 QAction* m_entrySec;
Qi Zhao86f2b212016-12-06 12:44:16 -0800151 QProcess* m_acProc;
Qi Zhaoae9c4312017-02-02 11:36:12 -0800152 QSettings* m_settings;
153 QString m_ndnAutoConfigMsg;
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -0700154#ifdef OSX_BUILD
155 QAction* m_entryEnableCli;
Alexander Afanasyevfda42a82017-02-01 18:03:39 -0800156 QAction* m_checkForUpdates;
157 OsxAutoUpdateSparkle m_sparkle;
158#endif // OSX_BUILD
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -0700159
Yingdi Yu53c11c12016-03-20 12:56:49 -0700160 QAction* m_entryQuit;
Yingdi Yu1f824642016-03-20 17:07:22 -0700161
162 ncc::KeyViewerDialog* m_keyViewerDialog;
Alexander Afanasyev81509f32016-03-21 17:02:38 -0700163 Face& m_face;
taylorchuc27dd482014-05-17 20:06:49 -0700164};
165
Alexander Afanasyevfda42a82017-02-01 18:03:39 -0800166} // namespace ncc
taylorchuc27dd482014-05-17 20:06:49 -0700167} // namespace ndn
168
169#endif // NCC_TRAY_MENU_HPP