blob: 841f068c74f8c8871c1c83f95671e1703ba080a6 [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
taylorchuc27dd482014-05-17 20:06:49 -070025#include <QtCore/QObject>
26#include <QtCore/QProcess>
27#include <QtCore/QCoreApplication>
Qi Zhao86f2b212016-12-06 12:44:16 -080028#include <QtCore/QSettings>
taylorchuc27dd482014-05-17 20:06:49 -070029
Qi Zhao86f2b212016-12-06 12:44:16 -080030#include <QtWidgets/QWidget>
taylorchuc27dd482014-05-17 20:06:49 -070031#include <QtWidgets/QSystemTrayIcon>
32#include <QtWidgets/QAction>
33#include <QtWidgets/QMenu>
Qi Zhao86f2b212016-12-06 12:44:16 -080034#include <QtWidgets/QVBoxLayout>
35#include <QtWidgets/QPlainTextEdit>
36#include <QtWidgets/QPushButton>
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"
41
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
63public:
Alexander Afanasyev4086d512014-07-11 15:56:33 -070064 explicit
Alexander Afanasyev81509f32016-03-21 17:02:38 -070065 TrayMenu(QQmlContext* context, Face& face);
taylorchuc27dd482014-05-17 20:06:49 -070066
67 ~TrayMenu();
68
Qi Zhao86f2b212016-12-06 12:44:16 -080069 Q_INVOKABLE bool
70 isAutoConfigEnabled();
taylorchuc27dd482014-05-17 20:06:49 -070071
72 Q_INVOKABLE void
Qi Zhao86f2b212016-12-06 12:44:16 -080073 startStopAutoConfig(bool autoConfig);
74
75 Q_INVOKABLE void
76 startStopNfd(bool autoConfig);
taylorchuc27dd482014-05-17 20:06:49 -070077
susmit4fe3cb92016-03-20 17:08:41 -070078 Q_INVOKABLE void
79 addDeleteRoute();
80
81 Q_INVOKABLE void
82 addRoute();
83
84 Q_INVOKABLE void
85 deleteRoute();
86
taylorchuc27dd482014-05-17 20:06:49 -070087private slots:
88
89 void
90 quitApp();
91
92 void
93 iconActivated(QSystemTrayIcon::ActivationReason reason);
94
95 void
Qi Zhao86f2b212016-12-06 12:44:16 -080096 startAutoConfig();
97
98 void
99 stopAutoConfig();
100
101 void
taylorchuc27dd482014-05-17 20:06:49 -0700102 startNfd();
103
104 void
105 stopNfd();
106
107 void
108 updateNfdActivityIcon(bool isActive);
109
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -0700110 void
111 enableCli();
112
Qi Zhao86f2b212016-12-06 12:44:16 -0800113 void
114 processOutput();
115
116 void
117 showPref();
118
119 static void
120 appendMsg(QString &target, QString source);
121
Alexander Afanasyevfda42a82017-02-01 18:03:39 -0800122#ifdef OSX_BUILD
123 void
124 checkForUpdates();
125#endif // OSX_BUILD
126
taylorchuc27dd482014-05-17 20:06:49 -0700127private:
Alexander Afanasyev4086d512014-07-11 15:56:33 -0700128 QQmlContext* m_context;
129 bool m_isNfdRunning;
Yingdi Yu53c11c12016-03-20 12:56:49 -0700130 QSystemTrayIcon* m_tray;
131 QMenu* m_menu;
132 QAction* m_entryPref;
133 QAction* m_entrySec;
Qi Zhao86f2b212016-12-06 12:44:16 -0800134 QProcess* m_acProc;
135 QString m_autoConfigMsg;
136 QSettings m_settings;
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -0700137#ifdef OSX_BUILD
138 QAction* m_entryEnableCli;
Alexander Afanasyevfda42a82017-02-01 18:03:39 -0800139 QAction* m_checkForUpdates;
140 OsxAutoUpdateSparkle m_sparkle;
141#endif // OSX_BUILD
Alexander Afanasyev11ae34d2016-03-21 11:55:16 -0700142
Yingdi Yu53c11c12016-03-20 12:56:49 -0700143 QAction* m_entryQuit;
Yingdi Yu1f824642016-03-20 17:07:22 -0700144
145 ncc::KeyViewerDialog* m_keyViewerDialog;
Alexander Afanasyev81509f32016-03-21 17:02:38 -0700146 Face& m_face;
taylorchuc27dd482014-05-17 20:06:49 -0700147};
148
Alexander Afanasyevfda42a82017-02-01 18:03:39 -0800149} // namespace ncc
taylorchuc27dd482014-05-17 20:06:49 -0700150} // namespace ndn
151
152#endif // NCC_TRAY_MENU_HPP