Stellarium  0.90.0
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 
117  virtual StelObjectP searchByID(const QString &id) const
118  {
119  return qSharedPointerCast<StelObject>(getByID(id));
120  }
121 
127  virtual QStringList listMatchingObjects(const QString& objPrefix, int maxNbItem=5, bool useStartOfWords=false, bool inEnglish=false) const;
128 
129  virtual QStringList listAllObjects(bool inEnglish) const;
130 
131  virtual QString getName() const { return "Quasars"; }
132 
133  virtual QString getStelObjectType() const { return Quasar::QUASAR_TYPE; }
134 
136  QuasarP getByID(const QString& id) const;
137 
140  virtual bool configureGui(bool show=true);
141 
145  void restoreDefaults(void);
146 
149  void readSettingsFromConfig(void);
150 
152  void saveSettingsToConfig(void);
153 
156  bool getUpdatesEnabled(void) {return updatesEnabled;}
159  void setUpdatesEnabled(bool b) {updatesEnabled=b;}
160 
161  void setEnableAtStartup(bool b) { enableAtStartup=b; }
162  bool getEnableAtStartup(void) { return enableAtStartup; }
163 
165  QDateTime getLastUpdate(void) {return lastUpdate;}
166 
168  int getUpdateFrequencyDays(void) {return updateFrequencyDays;}
169  void setUpdateFrequencyDays(int days) {updateFrequencyDays = days;}
170 
172  int getSecondsToUpdate(void);
173 
175  UpdateState getUpdateState(void) {return updateState;}
176 
177 signals:
180 
182  void jsonUpdateComplete(void);
183 
184  void flagQuasarsVisibilityChanged(bool b);
185 
186 public slots:
189  void updateJSON(void);
190 
193  void setFlagShowQuasars(bool b);
196  bool getFlagShowQuasars(void) { return flagShowQuasars; }
197 
199  void setFlagShowQuasarsButton(bool b);
200  bool getFlagShowQuasarsButton(void) { return flagShowQuasarsButton; }
201 
204  int getCountQuasars(void) {return QsrCount;}
205 
208  bool getDisplayMode(void);
211  void setDisplayMode(bool b);
212 
215  Vec3f getMarkerColor(void);
222  void setMarkerColor(const Vec3f& c);
223 
224 private:
225  // Font used for displaying our text
226  QFont font;
227 
228  // if existing, delete Satellites section in main config.ini, then create with default values
229  void restoreDefaultConfigIni(void);
230 
231  // Upgrade config.ini: rename old key settings to new
232  void upgradeConfigIni(void);
233 
235  void restoreDefaultJsonFile(void);
236 
238  void readJsonFile(void);
239 
243  bool backupJsonFile(bool deleteOriginal=false);
244 
247  int getJsonFileFormatVersion(void);
248 
251  bool checkJsonFileFormat(void);
252 
254  QVariantMap loadQSOMap(QString path=QString());
255 
257  void setQSOMap(const QVariantMap& map);
258 
259  QString catalogJsonPath;
260 
261  int QsrCount;
262 
263  StelTextureSP texPointer;
264  QList<QuasarP> QSO;
265 
266  // variables and functions for the updater
267  UpdateState updateState;
268  QNetworkAccessManager* downloadMgr;
269  QString updateUrl;
270  QTimer* updateTimer;
271  QTimer* messageTimer;
272  QList<int> messageIDs;
273  bool updatesEnabled;
274  QDateTime lastUpdate;
275  int updateFrequencyDays;
276  bool enableAtStartup;
277 
278  QSettings* conf;
279 
280  // GUI
281  QuasarsDialog* configDialog;
282  bool flagShowQuasars;
283  bool flagShowQuasarsButton;
284  QPixmap* OnIcon;
285  QPixmap* OffIcon;
286  QPixmap* GlowIcon;
287  StelButton* toolbarButton;
288  class StelProgressController* progressBar;
289 
290 private slots:
294  void checkForUpdate(void);
295  void updateDownloadComplete(QNetworkReply* reply);
296 
298  void displayMessage(const QString& message, const QString hexColor="#999999");
299  void messageTimeout(void);
300 
301  void reloadCatalog(void);
302 };
303 
304 
305 
306 #include <QObject>
307 #include "StelPluginInterface.hpp"
308 
310 class QuasarsStelPluginInterface : public QObject, public StelPluginInterface
311 {
312  Q_OBJECT
313  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
314  Q_INTERFACES(StelPluginInterface)
315 public:
316  virtual StelModule* getStelModule() const;
317  virtual StelPluginInfo getPluginInfo() const;
318  virtual QObjectList getExtensionList() const { return QObjectList(); }
319 };
320 
321 #endif /*_QUASARS_HPP_*/
void readSettingsFromConfig(void)
Read (or re-read) settings from the main config file.
Vec3f getMarkerColor(void)
Get color for quasars markers.
QuasarP getByID(const QString &id) const
get a Quasar object by identifier
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.
int getCountQuasars(void)
Get count of quasars from catalog.
Definition: Quasars.hpp:204
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 Q_NULLPTR.
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:159
virtual StelObjectP searchByName(const QString &name) const
Return the matching satellite if exists or Q_NULLPTR.
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
virtual StelObjectP searchByID(const QString &id) const
Return the StelObject with the given ID if exists or the empty StelObject if not found.
Definition: Quasars.hpp:117
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:196
virtual QString getName() const
Gets a user-displayable name of the object category.
Definition: Quasars.hpp:131
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:156
UpdateState getUpdateState(void)
Get the current updateState.
Definition: Quasars.hpp:175
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...
virtual QObjectList getExtensionList() const
A mechanism to provide abitrary QObjects to the StelModuleMgr.
Definition: Quasars.hpp:318
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.
virtual QString getStelObjectType() const
Returns the name that will be returned by StelObject::getType() for the objects this module manages...
Definition: Quasars.hpp:133
This class is used by Qt to manage a plug-in interface.
Definition: Quasars.hpp:310
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:165
void setMarkerColor(const Vec3f &c)
Set color for quasars markers.
int getUpdateFrequencyDays(void)
get the update frequency in days
Definition: Quasars.hpp:168
Contains information about a Stellarium plugin.
Update in progress.
Definition: Quasars.hpp:81