Stellarium 0.15.2
Quasars.hpp
1 /*
2  * Copyright (C) 2011 Alexander Wolf
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
17  */
18 
19 #ifndef _QUASARS_HPP_
20 #define _QUASARS_HPP_
21 
22 #include "StelObjectModule.hpp"
23 #include "StelObject.hpp"
24 #include "StelTextureTypes.hpp"
25 #include "Quasar.hpp"
26 #include <QFont>
27 #include <QVariantMap>
28 #include <QDateTime>
29 #include <QList>
30 #include <QSharedPointer>
31 
32 class StelPainter;
33 
34 class QNetworkAccessManager;
35 class QNetworkReply;
36 class QSettings;
37 class QTimer;
38 class QPixmap;
39 class StelButton;
40 class QuasarsDialog;
41 
62 typedef QSharedPointer<Quasar> QuasarP;
64 
69 class Quasars : public StelObjectModule
70 {
71  Q_OBJECT
72  Q_PROPERTY(bool quasarsVisible
74  WRITE setFlagShowQuasars
75  NOTIFY flagQuasarsVisibilityChanged
76  )
77 public:
80  enum UpdateState {
86  };
87 
88  Quasars();
89  virtual ~Quasars();
90 
92  // Methods defined in the StelModule class
93  virtual void init();
94  virtual void deinit();
95  virtual void update(double) {;}
96  virtual void draw(StelCore* core);
97  virtual void drawPointer(StelCore* core, StelPainter& painter);
98  virtual double getCallOrder(StelModuleActionName actionName) const;
99 
101  // Methods defined in StelObjectManager class
107  virtual QList<StelObjectP> searchAround(const Vec3d& v, double limitFov, const StelCore* core) const;
108 
111  virtual StelObjectP searchByNameI18n(const QString& nameI18n) const;
112 
115  virtual StelObjectP searchByName(const QString& name) const;
116 
122  virtual QStringList listMatchingObjects(const QString& objPrefix, int maxNbItem=5, bool useStartOfWords=false, bool inEnglish=false) const;
123 
124  virtual QStringList listAllObjects(bool inEnglish) const;
125 
126  virtual QString getName() const { return "Quasars"; }
127 
129  QuasarP getByID(const QString& id);
130 
133  virtual bool configureGui(bool show=true);
134 
138  void restoreDefaults(void);
139 
142  void readSettingsFromConfig(void);
143 
145  void saveSettingsToConfig(void);
146 
149  bool getUpdatesEnabled(void) {return updatesEnabled;}
152  void setUpdatesEnabled(bool b) {updatesEnabled=b;}
153 
154  void setEnableAtStartup(bool b) { enableAtStartup=b; }
155  bool getEnableAtStartup(void) { return enableAtStartup; }
156 
158  QDateTime getLastUpdate(void) {return lastUpdate;}
159 
161  int getUpdateFrequencyDays(void) {return updateFrequencyDays;}
162  void setUpdateFrequencyDays(int days) {updateFrequencyDays = days;}
163 
165  int getSecondsToUpdate(void);
166 
168  UpdateState getUpdateState(void) {return updateState;}
169 
170 signals:
173 
175  void jsonUpdateComplete(void);
176 
177  void flagQuasarsVisibilityChanged(bool b);
178 
179 public slots:
182  void updateJSON(void);
183 
186  void setFlagShowQuasars(bool b);
189  bool getFlagShowQuasars(void) { return flagShowQuasars; }
190 
192  void setFlagShowQuasarsButton(bool b);
193  bool getFlagShowQuasarsButton(void) { return flagShowQuasarsButton; }
194 
197  int getCountQuasars(void) {return QsrCount;}
198 
201  bool getDisplayMode(void);
204  void setDisplayMode(bool b);
205 
208  Vec3f getMarkerColor(void);
215  void setMarkerColor(const Vec3f& c);
216 
217 private:
218  // Font used for displaying our text
219  QFont font;
220 
221  // if existing, delete Satellites section in main config.ini, then create with default values
222  void restoreDefaultConfigIni(void);
223 
224  // Upgrade config.ini: rename old key settings to new
225  void upgradeConfigIni(void);
226 
228  void restoreDefaultJsonFile(void);
229 
231  void readJsonFile(void);
232 
236  bool backupJsonFile(bool deleteOriginal=false);
237 
240  int getJsonFileFormatVersion(void);
241 
244  bool checkJsonFileFormat(void);
245 
247  QVariantMap loadQSOMap(QString path=QString());
248 
250  void setQSOMap(const QVariantMap& map);
251 
252  QString catalogJsonPath;
253 
254  int QsrCount;
255 
256  StelTextureSP texPointer;
257  QList<QuasarP> QSO;
258 
259  // variables and functions for the updater
260  UpdateState updateState;
261  QNetworkAccessManager* downloadMgr;
262  QString updateUrl;
263  QTimer* updateTimer;
264  QTimer* messageTimer;
265  QList<int> messageIDs;
266  bool updatesEnabled;
267  QDateTime lastUpdate;
268  int updateFrequencyDays;
269  bool enableAtStartup;
270 
271  QSettings* conf;
272 
273  // GUI
274  QuasarsDialog* configDialog;
275  bool flagShowQuasars;
276  bool flagShowQuasarsButton;
277  QPixmap* OnIcon;
278  QPixmap* OffIcon;
279  QPixmap* GlowIcon;
280  StelButton* toolbarButton;
281  class StelProgressController* progressBar;
282 
283 private slots:
287  void checkForUpdate(void);
288  void updateDownloadComplete(QNetworkReply* reply);
289 
291  void displayMessage(const QString& message, const QString hexColor="#999999");
292  void messageTimeout(void);
293 
294  void reloadCatalog(void);
295 };
296 
297 
298 
299 #include <QObject>
300 #include "StelPluginInterface.hpp"
301 
303 class QuasarsStelPluginInterface : public QObject, public StelPluginInterface
304 {
305  Q_OBJECT
306  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
307  Q_INTERFACES(StelPluginInterface)
308 public:
309  virtual StelModule* getStelModule() const;
310  virtual StelPluginInfo getPluginInfo() const;
311 };
312 
313 #endif /*_QUASARS_HPP_*/
void readSettingsFromConfig(void)
Read (or re-read) settings from the main config file.
Vec3f getMarkerColor(void)
Get color for quasars markers.
UpdateState
Used for keeping for track of the download/update status.
Definition: Quasars.hpp:80
void setFlagShowQuasarsButton(bool b)
Define whether the button toggling quasars should be visible.
virtual void draw(StelCore *core)
Execute all the drawing functions for this module.
QuasarP getByID(const QString &id)
get a Quasar object by identifier
int getCountQuasars(void)
Get count of quasars from catalog.
Definition: Quasars.hpp:197
Define the interface to implement when creating a plugin.
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.
virtual bool configureGui(bool show=true)
Implement this to tell the main Stellarium GUI that there is a GUI element to configure this plugin...
void jsonUpdateComplete(void)
emitted after a JSON update has run.
virtual StelObjectP searchByNameI18n(const QString &nameI18n) const
Return the matching satellite object&#39;s pointer if exists or NULL.
virtual QStringList listMatchingObjects(const QString &objPrefix, int maxNbItem=5, bool useStartOfWords=false, bool inEnglish=false) const
Find and return the list of at most maxNbItem objects auto-completing the passed object name...
void setUpdatesEnabled(bool b)
set whether or not the plugin will try to update catalog data from the internet
Definition: Quasars.hpp:152
virtual StelObjectP searchByName(const QString &name) const
Return the matching satellite if exists or NULL.
Update completed, there we no updates.
Definition: Quasars.hpp:82
Define the StelTextureSP type.
int getSecondsToUpdate(void)
get the number of seconds till the next update
Main class for Stellarium core processing.
Definition: StelCore.hpp:48
void saveSettingsToConfig(void)
Save the settings to the main configuration file.
Specialization of StelModule which manages a collection of StelObject.
virtual QList< StelObjectP > searchAround(const Vec3d &v, double limitFov, const StelCore *core) const
Used to get a list of objects which are near to some position.
Other error.
Definition: Quasars.hpp:85
void restoreDefaults(void)
Set up the plugin with default values.
bool getDisplayMode(void)
Get status to display of distribution of pulsars.
Update completed, there were updates.
Definition: Quasars.hpp:83
virtual QStringList listAllObjects(bool inEnglish) const
List all StelObjects.
bool getFlagShowQuasars(void)
Get status to display of markers of quasars.
Definition: Quasars.hpp:189
Provides functions for performing openGL drawing operations.
Definition: StelPainter.hpp:40
void updateStateChanged(Quasars::UpdateState state)
Main class of the Quasars plugin.
Definition: Quasars.hpp:69
virtual void update(double)
Update the module with respect to the time.
Definition: Quasars.hpp:95
A Button Graphicsitem for use in Stellarium&#39;s graphic widgets.
bool getUpdatesEnabled(void)
get whether or not the plugin will try to update catalog data from the internet
Definition: Quasars.hpp:149
UpdateState getUpdateState(void)
Get the current updateState.
Definition: Quasars.hpp:168
virtual void init()
Initialize itself.
void setFlagShowQuasars(bool b)
Enable/disable display of markers of quasars.
StelModuleActionName
Define the possible action for which an order is defined.
Definition: StelModule.hpp:121
Maintain the state of a progress bar.
virtual void deinit()
Called before the module will be delete, and before the openGL context is suppressed.
void updateJSON(void)
Download JSON from web recources described in the module section of the module.ini file and update th...
QSharedPointer< StelTexture > StelTextureSP
Use shared pointer to simplify memory managment.
Error during download phase.
Definition: Quasars.hpp:84
void setDisplayMode(bool b)
Enable/disable display of distribution of pulsars.
This class is used by Qt to manage a plug-in interface.
Definition: Quasars.hpp:303
This is the common base class for all the main components of stellarium.
Definition: StelModule.hpp:49
QDateTime getLastUpdate(void)
get the date and time the TLE elements were updated
Definition: Quasars.hpp:158
void setMarkerColor(const Vec3f &c)
Set color for quasars markers.
int getUpdateFrequencyDays(void)
get the update frequency in days
Definition: Quasars.hpp:161
Contains information about a Stellarium plugin.
Update in progress.
Definition: Quasars.hpp:81