• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Stellarium / stellarium / 6345643563

29 Sep 2023 12:15AM UTC coverage: 11.865% (-0.002%) from 11.867%
6345643563

Pull #3433

github

gzotti
Allow window size change via RemoteControl API
- also follow Qt recommendations w.r.t. nullptr and override.
Pull Request #3433: Remote control command to change window size

52 of 52 new or added lines in 18 files covered. (100.0%)

14841 of 125077 relevant lines covered (11.87%)

27788.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/plugins/RemoteControl/src/RemoteControl.hpp
1
/*
2
 * Stellarium Remote Control plugin
3
 * Copyright (C) 2015 Florian Schaukowitsch
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
18
 */
19

20
#ifndef REMOTECONTROL_HPP
21
#define REMOTECONTROL_HPP
22

23
#include <QFont>
24
#include <QKeyEvent>
25

26
#include "StelModule.hpp"
27
#include "StelCore.hpp"
28

29
class QTimer;
30
class QPixmap;
31
class StelButton;
32
class RemoteControlDialog;
33
class HttpListener;
34
class RequestHandler;
35

36
//! @ingroup remoteControl
37
//! Main class of the %RemoteControl plug-in, implementing the StelModule interface.
38
//! Manages the settings and the starting/stopping of the <a href="http://stefanfrings.de/qtwebapp/index-en.html">QtWebApp</a> web server.
39
//! The RequestHandler class is used for request processing.
40
//! @author Florian Schaukowitsch
41
class RemoteControl : public StelModule
42
{
43
        Q_OBJECT
44
        //! Determines if the web server is running, and can be used to start/stop the server
45
        Q_PROPERTY(bool enabled
46
                   READ getFlagEnabled
47
                   WRITE setFlagEnabled
48
                   NOTIFY flagEnabledChanged)
49
        //! If true, the server is automatically started when init() is called
50
        Q_PROPERTY(bool autoStart
51
                   READ getFlagAutoStart
52
                   WRITE setFlagAutoStart
53
                   NOTIFY flagAutoStartChanged)
54
        //! If true, the password set with setPassword() is required for all requests.
55
        //! The password is passed on to the RequestHandler.
56
        Q_PROPERTY(bool usePassword
57
                   READ getFlagUsePassword
58
                   WRITE setFlagUsePassword
59
                   NOTIFY flagUsePasswordChanged)
60
        Q_PROPERTY(bool enableCors
61
                   READ getFlagEnableCors
62
                   WRITE setFlagEnableCors
63
                   NOTIFY flagEnableCorsChanged)
64
public:
65
        RemoteControl();
66
        ~RemoteControl() override;
67

68
        ///////////////////////////////////////////////////////////////////////////
69
        // Methods defined in the StelModule class
70
        void init() override;
71
        void update(double deltaTime) override;
72
        void draw(StelCore* core) override;
73
        double getCallOrder(StelModuleActionName actionName) const override;
74
        void handleKeys(QKeyEvent* event) override {event->setAccepted(false);}
×
75

76
        //virtual void handleMouseClicks(class QMouseEvent* event);
77
        //virtual bool handleMouseMoves(int x, int y, Qt::MouseButtons b);
78
        bool configureGui(bool show=true) override;
79
        ///////////////////////////////////////////////////////////////////////////
80
        // Property getters
81
        bool getFlagEnabled() const {return enabled;}
×
82
        bool getFlagAutoStart() const { return autoStart; }
×
83
        bool getFlagUsePassword() const { return usePassword; }
×
84
        bool getFlagEnableCors() const { return enableCors; }
×
85

86
        QString getPassword() const { return password; }
×
87
        QString getCorsOrigin() const { return corsOrigin; }
×
88
        int getPort() const {return port; }
×
89

90
public slots:
91
        //property setters
92
        //! Starts/stops the web server
93
        void setFlagEnabled(bool b);
94
        //! If true, the server is automatically started when init() is called
95
        void setFlagAutoStart(bool b);
96
        //! If true, the password from setPassword() is required for all web requests
97
        void setFlagUsePassword(bool b);
98

99
        //! Sets the password that is optionally enabled with setFlagUsePassword().
100
        //! The password is required by RequestHandler for all HTTP requests.
101
        //! Basic HTTP auth is used, without a user name.
102
        void setPassword(const QString& password);
103

104
        //! If true, Access-Control-Allow-Origin header will be appended to responses.
105
        void setFlagEnableCors(bool b);
106

107
        //! Sets the CORS origin that is optionally enabled with setFlagEnableCors().
108
        void setCorsOrigin(const QString& corsOrigin);
109

110

111
        //! Sets the port where the server listens. Must be done before startServer() is called,
112
        //! or restart the server to use the new setting.
113
        void setPort(const int port);
114

115
        //! Load the plug-in's settings from the configuration file.
116
        //! Settings are kept in the "RemoteControl" section in Stellarium's
117
        //! configuration file. If no such section exists, it will load default
118
        //! values.
119
        //! @see saveSettings(), restoreDefaultSettings()
120
        void loadSettings();
121

122
        //! Save the plug-in's settings to the configuration file.
123
        //! @see loadSettings(), restoreDefaultSettings()
124
        void saveSettings();
125

126
        //! Restore the plug-in's settings to the default state.
127
        //! Replace the plug-in's settings in Stellarium's configuration file
128
        //! with the default values and re-load them.
129
        //! Uses internally loadSettings() and saveSettings().
130
        void restoreDefaultSettings();
131

132
        //! Starts the HTTP server using the current settings and begins handling requests.
133
        //! Uses the RequestHandler class for processing.
134
        //! @see RequestHandler
135
        void startServer();
136
        //! Stops the HTTP server gracefully
137
        void stopServer();
138

139
signals:
140
        //property notifiers
141
        void flagEnabledChanged(bool val);
142
        void flagAutoStartChanged(bool val);
143
        void flagUsePasswordChanged(bool val);
144
        void flagEnableCorsChanged(bool val);
145

146
        void portChanged(int val);
147
        void passwordChanged(const QString& val);
148
        void corsOriginChanged(const QString& val);
149

150

151
private:
152
        //the http server
153
        HttpListener* httpListener;
154
        //the main request handler
155
        RequestHandler* requestHandler;
156

157
        bool enabled;
158
        bool autoStart;
159
        bool usePassword;
160
        QString password;
161
        bool enableCors;
162
        QString corsOrigin;
163

164
        int port;
165
        int minThreads;
166
        int maxThreads;
167

168
        StelButton* toolbarButton;
169

170
        QSettings* conf;
171

172
        // GUI
173
        RemoteControlDialog* configDialog;
174
};
175

176

177

178
#include <QObject>
179
#include "StelPluginInterface.hpp"
180

181
//! @ingroup remoteControl
182
//! This class defines the plugin interface with the main Stellarium program
183
class RemoteControlStelPluginInterface : public QObject, public StelPluginInterface
184
{
185
        Q_OBJECT
186
        Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
187
        Q_INTERFACES(StelPluginInterface)
188
public:
189
        StelModule* getStelModule() const override;
190
        StelPluginInfo getPluginInfo() const override;
191
        //QObjectList getExtensionList() const override { return QObjectList(); }
192
};
193

194
#endif /*REMOTECONTROL_HPP*/
195

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc