blob: 6015fe546807d154fbbd6fabc34a412ca9c13b05 [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
62public:
Alexander Afanasyev4086d512014-07-11 15:56:33 -070063 explicit
Alexander Afanasyev81509f32016-03-21 17:02:38 -070064 TrayMenu(QQmlContext* context, Face& face);
taylorchuc27dd482014-05-17 20:06:49 -070065
66 ~TrayMenu();
67
Qi Zhao86f2b212016-12-06 12:44:16 -080068 Q_INVOKABLE bool
Qi Zhaoae9c4312017-02-02 11:36:12 -080069 isNccAutoStartEnabled() const;
taylorchuc27dd482014-05-17 20:06:49 -070070
71 Q_INVOKABLE void
Qi Zhaoae9c4312017-02-02 11:36:12 -080072 enableDisableNccAutoStart(bool isEnabled);
73
74 Q_INVOKABLE bool
75 isNfdAutoStartEnabled() const;
Qi Zhao86f2b212016-12-06 12:44:16 -080076
77 Q_INVOKABLE void
Qi Zhaoae9c4312017-02-02 11:36:12 -080078 enableDisableNfdAutoStart(bool isEnabled);
79
80 Q_INVOKABLE bool
81 isNdnAutoConfigEnabled() const;
82
83 Q_INVOKABLE void
84 enableDisableNdnAutoConfig(bool isEnabled);
85
86 Q_INVOKABLE bool
87 isNfdStopOnExitEnabled() const;
88
89 Q_INVOKABLE void
90 enableDisableNfdStopOnExit(bool isEnabled);
taylorchuc27dd482014-05-17 20:06:49 -070091
susmit4fe3cb92016-03-20 17:08:41 -070092 Q_INVOKABLE void
93 addDeleteRoute();
94
95 Q_INVOKABLE void
96 addRoute();
97
98 Q_INVOKABLE void
99 deleteRoute();
100
taylorchuc27dd482014-05-17 20:06:49 -0700101private slots:
Qi Zhaoae9c4312017-02-02 11:36:12 -0800102 void
103 startNdnAutoConfig();
104
105 void
106 stopNdnAutoConfig(bool appendStatus = true);
taylorchuc27dd482014-05-17 20:06:49 -0700107
108 void
109 quitApp();
110
111 void
taylorchuc27dd482014-05-17 20:06:49 -0700112 startNfd();
113
114 void
115 stopNfd();
116
117 void
118 updateNfdActivityIcon(bool isActive);
119
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -0700120 void
121 enableCli();
122
Qi Zhao86f2b212016-12-06 12:44:16 -0800123 void
124 processOutput();
125
126 void
Qi Zhaoae9c4312017-02-02 11:36:12 -0800127 appendNdnAutoConfigStatus(const QString& message);
Qi Zhao86f2b212016-12-06 12:44:16 -0800128
Alexander Afanasyevfda42a82017-02-01 18:03:39 -0800129#ifdef OSX_BUILD
130 void
131 checkForUpdates();
132#endif // OSX_BUILD
133
Qi Zhaoae9c4312017-02-02 11:36:12 -0800134 void
135 scheduleDelayedTask(std::chrono::milliseconds delays, const std::function<void()>& task);
136
taylorchuc27dd482014-05-17 20:06:49 -0700137private:
Alexander Afanasyev4086d512014-07-11 15:56:33 -0700138 QQmlContext* m_context;
139 bool m_isNfdRunning;
Yingdi Yu53c11c12016-03-20 12:56:49 -0700140 QSystemTrayIcon* m_tray;
141 QMenu* m_menu;
142 QAction* m_entryPref;
143 QAction* m_entrySec;
Qi Zhao86f2b212016-12-06 12:44:16 -0800144 QProcess* m_acProc;
Qi Zhaoae9c4312017-02-02 11:36:12 -0800145 QSettings* m_settings;
146 QString m_ndnAutoConfigMsg;
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -0700147#ifdef OSX_BUILD
148 QAction* m_entryEnableCli;
Alexander Afanasyevfda42a82017-02-01 18:03:39 -0800149 QAction* m_checkForUpdates;
150 OsxAutoUpdateSparkle m_sparkle;
151#endif // OSX_BUILD
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -0700152
Yingdi Yu53c11c12016-03-20 12:56:49 -0700153 QAction* m_entryQuit;
Yingdi Yu1f824642016-03-20 17:07:22 -0700154
155 ncc::KeyViewerDialog* m_keyViewerDialog;
Alexander Afanasyev81509f32016-03-21 17:02:38 -0700156 Face& m_face;
taylorchuc27dd482014-05-17 20:06:49 -0700157};
158
Alexander Afanasyevfda42a82017-02-01 18:03:39 -0800159} // namespace ncc
taylorchuc27dd482014-05-17 20:06:49 -0700160} // namespace ndn
161
162#endif // NCC_TRAY_MENU_HPP