Stellarium 0.15.2
RemoteSync.hpp
1 /*
2  * Stellarium Remote Sync 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 REMOTESYNC_HPP_
21 #define REMOTESYNC_HPP_
22 
23 #include <QFont>
24 #include <QKeyEvent>
25 
26 #include "StelModule.hpp"
27 
28 class RemoteSyncDialog;
29 class SyncServer;
30 class SyncClient;
31 
35 class RemoteSync : public StelModule
36 {
37  Q_OBJECT
38  Q_ENUMS(SyncState)
39 
40 public:
41  enum SyncState
42  {
43  IDLE, //Plugin is disabled
44  SERVER, //Plugin is running as server
45  CLIENT, //Plugin is connected as a client to a server
46  CLIENT_CONNECTING //Plugin is currently trying to connect to a server
47  };
48 
49  RemoteSync();
50  virtual ~RemoteSync();
51 
53  // Methods defined in the StelModule class
54  virtual void init() Q_DECL_OVERRIDE;
55  virtual void update(double deltaTime) Q_DECL_OVERRIDE;
56 
57  virtual double getCallOrder(StelModuleActionName actionName) const Q_DECL_OVERRIDE;
58 
59  virtual bool configureGui(bool show=true) Q_DECL_OVERRIDE;
61 
62  QString getClientServerHost() const { return clientServerHost; }
63  int getClientServerPort() const { return clientServerPort; }
64  int getServerPort() const { return serverPort; }
65  SyncState getState() const { return state; }
66 
67 public slots:
68  void setClientServerHost(const QString& clientServerHost);
69  void setClientServerPort(const int port);
70  void setServerPort(const int port);
71 
74  void startServer();
75 
78  void stopServer();
79 
82  void connectToServer();
83 
86  void disconnectFromServer();
87 
93  void loadSettings();
94 
97  void saveSettings();
98 
103  void restoreDefaultSettings();
104 
105 signals:
106  void errorOccurred(const QString errorString);
107  void clientServerHostChanged(const QString clientServerHost);
108  void clientServerPortChanged(const int port);
109  void serverPortChanged(const int port);
110  void stateChanged(RemoteSync::SyncState state);
111 
112 private slots:
113  void clientDisconnected();
114  void clientConnected();
115  void clientConnectionFailed();
116 private:
117  void setState(RemoteSync::SyncState state);
118  void setError(const QString& errorString);
119 
120  //The host string/IP addr to connect to
121  QString clientServerHost;
122  //The host port to connect to
123  int clientServerPort;
124  //the port used in server mode
125  int serverPort;
126  SyncState state;
127 
128  SyncServer* server;
129  SyncClient* client;
130 
131  // the last error that occurred
132  QString errorString;
133 
134  QSettings* conf;
135 
136  // GUI
137  RemoteSyncDialog* configDialog;
138 };
139 
140 Q_DECLARE_METATYPE(RemoteSync::SyncState)
141 
142 QDebug operator<<(QDebug, RemoteSync::SyncState);
144 
145 #include "StelPluginInterface.hpp"
146 
149 {
150  Q_OBJECT
151  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
152  Q_INTERFACES(StelPluginInterface)
153 public:
154  virtual StelModule* getStelModule() const;
155  virtual StelPluginInfo getPluginInfo() const;
156 };
157 
158 #endif /*REMOTESYNC_HPP_*/
159 
virtual double getCallOrder(StelModuleActionName actionName) const Q_DECL_OVERRIDE
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.
A client which can connect to a SyncServer to receive state changes, and apply them.
Definition: SyncClient.hpp:30
Define the interface to implement when creating a plugin.
virtual void update(double deltaTime) Q_DECL_OVERRIDE
Update the module with respect to the time.
void restoreDefaultSettings()
Restore the plug-in&#39;s settings to the default state.
virtual bool configureGui(bool show=true) Q_DECL_OVERRIDE
Detect or show the configuration GUI elements for the module.
virtual void init() Q_DECL_OVERRIDE
Initialize itself.
Main class of the RemoteSync plug-in.
Definition: RemoteSync.hpp:35
This class is used by Qt to manage a plug-in interface.
Definition: RemoteSync.hpp:148
void loadSettings()
Load the plug-in&#39;s settings from the configuration file.
void startServer()
Starts the plugin in server mode, on the port specified by the serverPort property.
QDataStream & operator<<(QDataStream &out, const SphericalRegionP &region)
Serialize the passed SphericalRegionP into a binary blob.
void stopServer()
Tries to disconnect all current clients and stops the server, returning to the IDLE state...
void disconnectFromServer()
Disconnects from the server and returns to the IDLE state.
StelModuleActionName
Define the possible action for which an order is defined.
Definition: StelModule.hpp:121
This is the common base class for all the main components of stellarium.
Definition: StelModule.hpp:49
void connectToServer()
Connects the plugin to the server specified by the clientServerHost and clientServerPort properties...
Contains information about a Stellarium plugin.
Implements a server to which SyncClients can connect and receive state changes.
Definition: SyncServer.hpp:33
void saveSettings()
Save the plug-in&#39;s settings to the configuration file.