Stellarium  0.90.0
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 "VecMath.hpp"
27 #include "StelModule.hpp"
28 #include "StelFader.hpp"
29 #include "StelCore.hpp"
30 
31 class QTimer;
32 class QPixmap;
33 class StelButton;
35 class HttpListener;
36 class RequestHandler;
37 
43 class RemoteControl : public StelModule
44 {
45  Q_OBJECT
47  Q_PROPERTY(bool enabled
48  READ getFlagEnabled
49  WRITE setFlagEnabled
50  NOTIFY flagEnabledChanged)
52  Q_PROPERTY(bool autoStart
53  READ getFlagAutoStart
54  WRITE setFlagAutoStart
55  NOTIFY flagAutoStartChanged)
58  Q_PROPERTY(bool usePassword
59  READ getFlagUsePassword
60  WRITE setFlagUsePassword
61  NOTIFY flagUsePasswordChanged)
62 public:
63  RemoteControl();
64  virtual ~RemoteControl();
65 
67  // Methods defined in the StelModule class
68  virtual void init();
69  virtual void update(double deltaTime);
70  virtual void draw(StelCore* core);
71  virtual double getCallOrder(StelModuleActionName actionName) const;
72  virtual void handleKeys(QKeyEvent* event){event->setAccepted(false);}
73 
74  //virtual void handleMouseClicks(class QMouseEvent* event);
75  //virtual bool handleMouseMoves(int x, int y, Qt::MouseButtons b);
76  virtual bool configureGui(bool show=true);
78  // Property getters
79  bool getFlagEnabled() const {return enabled;}
80  bool getFlagAutoStart() const { return autoStart; }
81  bool getFlagUsePassword() const { return usePassword; }
82 
83  QString getPassword() const { return password; }
84  int getPort() const {return port; }
85 
86 public slots:
87  //property setters
89  void setFlagEnabled(bool b);
91  void setFlagAutoStart(bool b);
93  void setFlagUsePassword(bool b);
94 
98  void setPassword(const QString& password);
101  void setPort(const int port);
102 
108  void loadSettings();
109 
112  void saveSettings();
113 
118  void restoreDefaultSettings();
119 
123  void startServer();
125  void stopServer();
126 
127 signals:
128  //property notifiers
129  void flagEnabledChanged(bool val);
130  void flagAutoStartChanged(bool val);
131  void flagUsePasswordChanged(bool val);
132 
133  void portChanged(int val);
134  void passwordChanged(const QString& val);
135 
136 
137 private:
138 
139  //the http server
140  HttpListener* httpListener;
141  //the main request handler
142  RequestHandler* requestHandler;
143 
144  bool enabled;
145  bool autoStart;
146  bool usePassword;
147  QString password;
148 
149  int port;
150  int minThreads;
151  int maxThreads;
152 
153  StelButton* toolbarButton;
154 
155  QSettings* conf;
156 
157  // GUI
158  RemoteControlDialog* configDialog;
159 };
160 
161 
162 
163 #include <QObject>
164 #include "StelPluginInterface.hpp"
165 
169 {
170  Q_OBJECT
171  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
172  Q_INTERFACES(StelPluginInterface)
173 public:
174  virtual StelModule* getStelModule() const;
175  virtual StelPluginInfo getPluginInfo() const;
176  virtual QObjectList getExtensionList() const { return QObjectList(); }
177 };
178 
179 #endif /*REMOTECONTROL_HPP_*/
180 
virtual void init()
Initialize itself.
void setFlagUsePassword(bool b)
If true, the password from setPassword() is required for all web requests.
void setPort(const int port)
Sets the port where the server listens.
Define the interface to implement when creating a plugin.
void setFlagEnabled(bool b)
Starts/stops the web server.
Main class for Stellarium core processing.
Definition: StelCore.hpp:48
void restoreDefaultSettings()
Restore the plug-in&#39;s settings to the default state.
bool usePassword
If true, the password set with setPassword() is required for all requests.
Main class of the RemoteControl plug-in, implementing the StelModule interface.
void stopServer()
Stops the HTTP server gracefully.
virtual double getCallOrder(StelModuleActionName actionName) const
Return the value defining the order of call for the given action For example if stars.callOrder[ActionDraw] == 10 and constellation.callOrder[ActionDraw] == 11, the stars module will be drawn before the constellations.
void saveSettings()
Save the plug-in&#39;s settings to the configuration file.
This is the main request handler for the remote control plugin, receiving and dispatching the HTTP re...
virtual void update(double deltaTime)
Update the module with respect to the time.
A Button Graphicsitem for use in Stellarium&#39;s graphic widgets.
virtual void draw(StelCore *core)
Execute all the drawing functions for this module.
virtual QObjectList getExtensionList() const
A mechanism to provide abitrary QObjects to the StelModuleMgr.
bool autoStart
If true, the server is automatically started when init() is called.
void setPassword(const QString &password)
Sets the password that is optionally enabled with setFlagUsePassword().
void startServer()
Starts the HTTP server using the current settings and begins handling requests.
void loadSettings()
Load the plug-in&#39;s settings from the configuration file.
StelModuleActionName
Define the possible action for which an order is defined.
Definition: StelModule.hpp:121
virtual void handleKeys(QKeyEvent *event)
Handle key events.
Listens for incoming TCP connections and and passes all incoming HTTP requests to your implementation...
Definition: httplistener.h:57
This class defines the plugin interface with the main Stellarium program.
virtual bool configureGui(bool show=true)
Detect or show the configuration GUI elements for the module.
Main window of the Angle Measure plug-in.
void setFlagAutoStart(bool b)
If true, the server is automatically started when init() is called.
bool enabled
Determines if the web server is running, and can be used to start/stop the server.
This is the common base class for all the main components of stellarium.
Definition: StelModule.hpp:49
Contains information about a Stellarium plugin.