Stellarium  0.16.1
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 StelObjectP searchByID(const QString &id) const
112  {
113  return qSharedPointerCast<StelObject>(getByID(id));
114  }
115 
116  virtual QStringList listAllObjects(bool inEnglish) const;
117 
118  virtual QString getName() const { return "Historical Supernovae"; }
119  virtual QString getStelObjectType() const { return Supernova::SUPERNOVA_TYPE; }
120 
122  SupernovaP getByID(const QString& id) const;
123 
126  virtual bool configureGui(bool show=true);
127 
131  void restoreDefaults(void);
132 
135  void readSettingsFromConfig(void);
136 
138  void saveSettingsToConfig(void);
139 
142  bool getUpdatesEnabled(void) {return updatesEnabled;}
145  void setUpdatesEnabled(bool b) {updatesEnabled=b;}
146 
148  QDateTime getLastUpdate(void) {return lastUpdate;}
149 
151  int getUpdateFrequencyDays(void) {return updateFrequencyDays;}
152  void setUpdateFrequencyDays(int days) {updateFrequencyDays = days;}
153 
155  int getSecondsToUpdate(void);
156 
158  UpdateState getUpdateState(void) {return updateState;}
159 
161  QString getSupernovaeList() const;
162 
164  float getLowerLimitBrightness() const;
165 
167  int getCountSupernovae(void) const {return SNCount;}
168 
169 signals:
172 
174  void jsonUpdateComplete(void);
175 
176 public slots:
177  // FIXME: Add functions for scripting support
178 
181  void updateJSON(void);
182 
184  void displayMessage(const QString& message, const QString hexColor="#999999");
185  void messageTimeout(void);
186 
187  void reloadCatalog(void);
188 
189 private:
190  // Font used for displaying our text
191  QFont font;
192 
193  // if existing, delete Satellites section in main config.ini, then create with default values
194  void restoreDefaultConfigIni(void);
195 
197  void restoreDefaultJsonFile(void);
198 
200  void readJsonFile(void);
201 
205  bool backupJsonFile(bool deleteOriginal=false);
206 
209  int getJsonFileVersion(void) const;
210 
213  bool checkJsonFileFormat(void) const;
214 
216  QVariantMap loadSNeMap(QString path=QString());
217 
219  void setSNeMap(const QVariantMap& map);
220 
221  QString sneJsonPath;
222 
223  int SNCount;
224 
225  StelTextureSP texPointer;
226  QList<SupernovaP> snstar;
227  QHash<QString, double> snlist;
228 
229  // variables and functions for the updater
230  UpdateState updateState;
231  QNetworkAccessManager* downloadMgr;
232  QString updateUrl;
233  class StelProgressController* progressBar;
234  QTimer* updateTimer;
235  QTimer* messageTimer;
236  QList<int> messageIDs;
237  bool updatesEnabled;
238  QDateTime lastUpdate;
239  int updateFrequencyDays;
240 
241  QSettings* conf;
242 
243  // GUI
244  SupernovaeDialog* configDialog;
245 
246 private slots:
250  void checkForUpdate(void);
251  void updateDownloadComplete(QNetworkReply* reply);
252 
253 };
254 
255 
256 
257 #include <QObject>
258 #include "StelPluginInterface.hpp"
259 
262 {
263  Q_OBJECT
264  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
265  Q_INTERFACES(StelPluginInterface)
266 public:
267  virtual StelModule* getStelModule() const;
268  virtual StelPluginInfo getPluginInfo() const;
269  virtual QObjectList getExtensionList() const { return QObjectList(); }
270 };
271 
272 #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:151
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 QString getName() const
Gets a user-displayable name of the object category.
Definition: Supernovae.hpp:118
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:145
Update completed, there were updates.
Definition: Supernovae.hpp:77
virtual QString getStelObjectType() const
Returns the name that will be returned by StelObject::getType() for the objects this module manages...
Definition: Supernovae.hpp:119
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 Q_NULLPTR.
virtual void init()
Initialize itself.
virtual StelObjectP searchByID(const QString &id) const
Return the StelObject with the given ID if exists or the empty StelObject if not found.
Definition: Supernovae.hpp:111
Error during download phase.
Definition: Supernovae.hpp:78
Provides functions for performing openGL drawing operations.
Definition: StelPainter.hpp:40
Main class of the Historical Supernovae plugin.
Definition: Supernovae.hpp:68
bool getUpdatesEnabled(void)
Get whether or not the plugin will try to update catalog data from the internet.
Definition: Supernovae.hpp:142
virtual StelObjectP searchByName(const QString &name) const
Return the matching satellite if exists or Q_NULLPTR.
This class is used by Qt to manage a plug-in interface.
Definition: Supernovae.hpp:261
void readSettingsFromConfig(void)
Read (or re-read) settings from the main config file.
QString getSupernovaeList() const
Get list of supernovae.
StelModuleActionName
Define the possible action for which an order is defined.
Definition: StelModule.hpp:121
SupernovaP getByID(const QString &id) const
get a supernova object by identifier
float getLowerLimitBrightness() const
Get lower limit of brightness for displayed supernovae.
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...
virtual QObjectList getExtensionList() const
A mechanism to provide abitrary QObjects to the StelModuleMgr.
Definition: Supernovae.hpp:269
QDateTime getLastUpdate(void)
Get the date and time the supernovae were updated.
Definition: Supernovae.hpp:148
virtual void update(double)
Update the module with respect to the time.
Definition: Supernovae.hpp:89
int getCountSupernovae(void) const
Get count of supernovae from catalog.
Definition: Supernovae.hpp:167
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.
UpdateState getUpdateState(void)
Get the current updateState.
Definition: Supernovae.hpp:158
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.