Stellarium 0.15.2
Supernovae.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 _SUPERNOVAE_HPP_
20 #define _SUPERNOVAE_HPP_
21 
22 #include "StelObjectModule.hpp"
23 #include "StelObject.hpp"
24 #include "StelFader.hpp"
25 #include "StelTextureTypes.hpp"
26 #include "Supernova.hpp"
27 #include <QFont>
28 #include <QVariantMap>
29 #include <QDateTime>
30 #include <QList>
31 #include <QSharedPointer>
32 #include <QHash>
33 
34 class QNetworkAccessManager;
35 class QNetworkReply;
36 class QSettings;
37 class QTimer;
38 class SupernovaeDialog;
39 
40 class StelPainter;
41 
61 typedef QSharedPointer<Supernova> SupernovaP;
63 
69 {
70  Q_OBJECT
71 public:
74  enum UpdateState {
80  };
81 
82  Supernovae();
83  virtual ~Supernovae();
84 
86  // Methods defined in the StelModule class
87  virtual void init();
88  virtual void deinit();
89  virtual void update(double) {;}
90  virtual void draw(StelCore* core);
91  virtual void drawPointer(StelCore* core, StelPainter& painter);
92  virtual double getCallOrder(StelModuleActionName actionName) const;
93 
95  // Methods defined in StelObjectManager class
101  virtual QList<StelObjectP> searchAround(const Vec3d& v, double limitFov, const StelCore* core) const;
102 
105  virtual StelObjectP searchByNameI18n(const QString& nameI18n) const;
106 
109  virtual StelObjectP searchByName(const QString& name) const;
110 
111  virtual QStringList listAllObjects(bool inEnglish) const;
112 
113  virtual QString getName() const { return "Historical Supernovae"; }
114 
116  SupernovaP getByID(const QString& id);
117 
120  virtual bool configureGui(bool show=true);
121 
125  void restoreDefaults(void);
126 
129  void readSettingsFromConfig(void);
130 
132  void saveSettingsToConfig(void);
133 
136  bool getUpdatesEnabled(void) {return updatesEnabled;}
139  void setUpdatesEnabled(bool b) {updatesEnabled=b;}
140 
142  QDateTime getLastUpdate(void) {return lastUpdate;}
143 
145  int getUpdateFrequencyDays(void) {return updateFrequencyDays;}
146  void setUpdateFrequencyDays(int days) {updateFrequencyDays = days;}
147 
149  int getSecondsToUpdate(void);
150 
152  UpdateState getUpdateState(void) {return updateState;}
153 
155  QString getSupernovaeList();
156 
158  float getLowerLimitBrightness();
159 
161  int getCountSupernovae(void) {return SNCount;}
162 
163 signals:
166 
168  void jsonUpdateComplete(void);
169 
170 public slots:
171  // FIXME: Add functions for scripting support
172 
175  void updateJSON(void);
176 
178  void displayMessage(const QString& message, const QString hexColor="#999999");
179  void messageTimeout(void);
180 
181  void reloadCatalog(void);
182 
183 private:
184  // Font used for displaying our text
185  QFont font;
186 
187  // if existing, delete Satellites section in main config.ini, then create with default values
188  void restoreDefaultConfigIni(void);
189 
191  void restoreDefaultJsonFile(void);
192 
194  void readJsonFile(void);
195 
199  bool backupJsonFile(bool deleteOriginal=false);
200 
203  int getJsonFileVersion(void);
204 
207  bool checkJsonFileFormat(void);
208 
210  QVariantMap loadSNeMap(QString path=QString());
211 
213  void setSNeMap(const QVariantMap& map);
214 
215  QString sneJsonPath;
216 
217  int SNCount;
218 
219  StelTextureSP texPointer;
220  QList<SupernovaP> snstar;
221  QHash<QString, double> snlist;
222 
223  // variables and functions for the updater
224  UpdateState updateState;
225  QNetworkAccessManager* downloadMgr;
226  QString updateUrl;
227  class StelProgressController* progressBar;
228  QTimer* updateTimer;
229  QTimer* messageTimer;
230  QList<int> messageIDs;
231  bool updatesEnabled;
232  QDateTime lastUpdate;
233  int updateFrequencyDays;
234 
235  QSettings* conf;
236 
237  // GUI
238  SupernovaeDialog* configDialog;
239 
240 private slots:
244  void checkForUpdate(void);
245  void updateDownloadComplete(QNetworkReply* reply);
246 
247 };
248 
249 
250 
251 #include <QObject>
252 #include "StelPluginInterface.hpp"
253 
256 {
257  Q_OBJECT
258  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
259  Q_INTERFACES(StelPluginInterface)
260 public:
261  virtual StelModule* getStelModule() const;
262  virtual StelPluginInfo getPluginInfo() const;
263 };
264 
265 #endif /*_SUPERNOVAE_HPP_*/
Update completed, there we no updates.
Definition: Supernovae.hpp:76
Define the interface to implement when creating a plugin.
void displayMessage(const QString &message, const QString hexColor="#999999")
Display a message. This is used for plugin-specific warnings and such.
int getUpdateFrequencyDays(void)
Get the update frequency in days.
Definition: Supernovae.hpp:145
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.
Define the StelTextureSP type.
void setUpdatesEnabled(bool b)
Set whether or not the plugin will try to update catalog data from the internet.
Definition: Supernovae.hpp:139
SupernovaP getByID(const QString &id)
get a supernova object by identifier
Update completed, there were updates.
Definition: Supernovae.hpp:77
Main class for Stellarium core processing.
Definition: StelCore.hpp:48
Specialization of StelModule which manages a collection of StelObject.
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 void init()
Initialize itself.
Error during download phase.
Definition: Supernovae.hpp:78
float getLowerLimitBrightness()
Get lower limit of brightness for displayed supernovae.
Provides functions for performing openGL drawing operations.
Definition: StelPainter.hpp:40
Main class of the Historical Supernovae plugin.
Definition: Supernovae.hpp:68
int getCountSupernovae(void)
Get count of supernovae from catalog.
Definition: Supernovae.hpp:161
bool getUpdatesEnabled(void)
Get whether or not the plugin will try to update catalog data from the internet.
Definition: Supernovae.hpp:136
virtual StelObjectP searchByName(const QString &name) const
Return the matching satellite if exists or NULL.
This class is used by Qt to manage a plug-in interface.
Definition: Supernovae.hpp:255
void readSettingsFromConfig(void)
Read (or re-read) settings from the main config file.
StelModuleActionName
Define the possible action for which an order is defined.
Definition: StelModule.hpp:121
void updateJSON(void)
Download JSON from web recources described in the module section of the module.ini file and update th...
UpdateState
Used for keeping for track of the download/update status.
Definition: Supernovae.hpp:74
virtual void draw(StelCore *core)
Execute all the drawing functions for this module.
Maintain the state of a progress bar.
virtual bool configureGui(bool show=true)
Implement this to tell the main Stellarium GUI that there is a GUI element to configure this plugin...
QDateTime getLastUpdate(void)
Get the date and time the supernovae were updated.
Definition: Supernovae.hpp:142
virtual void update(double)
Update the module with respect to the time.
Definition: Supernovae.hpp:89
QSharedPointer< StelTexture > StelTextureSP
Use shared pointer to simplify memory managment.
void updateStateChanged(Supernovae::UpdateState state)
Update in progress.
Definition: Supernovae.hpp:75
virtual void deinit()
Called before the module will be delete, and before the openGL context is suppressed.
void saveSettingsToConfig(void)
Save the settings to the main configuration file.
int getSecondsToUpdate(void)
Get the number of seconds till the next update.
This is the common base class for all the main components of stellarium.
Definition: StelModule.hpp:49
void restoreDefaults(void)
Set up the plugin with default values.
Contains information about a Stellarium plugin.
QString getSupernovaeList()
Get list of supernovae.
UpdateState getUpdateState(void)
Get the current updateState.
Definition: Supernovae.hpp:152
virtual QStringList listAllObjects(bool inEnglish) const
List all StelObjects.
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.