Stellarium 0.14.3
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 
116  virtual QStringList listMatchingObjectsI18n(const QString& objPrefix, int maxNbItem=5, bool useStartOfWords=false) const;
122  virtual QStringList listMatchingObjects(const QString& objPrefix, int maxNbItem=5, bool useStartOfWords=false) const;
123  virtual QStringList listAllObjects(bool inEnglish) const;
124  virtual QStringList listAllObjectsByType(const QString& objType, bool inEnglish) const { Q_UNUSED(objType) Q_UNUSED(inEnglish) return QStringList(); }
125  virtual QString getName() const { return "Historical Supernovae"; }
126 
128  SupernovaP getByID(const QString& id);
129 
132  virtual bool configureGui(bool show=true);
133 
137  void restoreDefaults(void);
138 
141  void readSettingsFromConfig(void);
142 
144  void saveSettingsToConfig(void);
145 
148  bool getUpdatesEnabled(void) {return updatesEnabled;}
151  void setUpdatesEnabled(bool b) {updatesEnabled=b;}
152 
154  QDateTime getLastUpdate(void) {return lastUpdate;}
155 
157  int getUpdateFrequencyDays(void) {return updateFrequencyDays;}
158  void setUpdateFrequencyDays(int days) {updateFrequencyDays = days;}
159 
161  int getSecondsToUpdate(void);
162 
164  UpdateState getUpdateState(void) {return updateState;}
165 
167  QString getSupernovaeList();
168 
170  float getLowerLimitBrightness();
171 
173  int getCountSupernovae(void) {return SNCount;}
174 
175 signals:
178 
180  void jsonUpdateComplete(void);
181 
182 public slots:
183  // FIXME: Add functions for scripting support
184 
187  void updateJSON(void);
188 
190  void displayMessage(const QString& message, const QString hexColor="#999999");
191  void messageTimeout(void);
192 
193 private:
194  // Font used for displaying our text
195  QFont font;
196 
197  // if existing, delete Satellites section in main config.ini, then create with default values
198  void restoreDefaultConfigIni(void);
199 
201  void restoreDefaultJsonFile(void);
202 
204  void readJsonFile(void);
205 
209  bool backupJsonFile(bool deleteOriginal=false);
210 
213  int getJsonFileVersion(void);
214 
217  bool checkJsonFileFormat(void);
218 
220  QVariantMap loadSNeMap(QString path=QString());
221 
223  void setSNeMap(const QVariantMap& map);
224 
225  QString sneJsonPath;
226 
227  int SNCount;
228 
229  StelTextureSP texPointer;
230  QList<SupernovaP> snstar;
231  QHash<QString, double> snlist;
232 
233  // variables and functions for the updater
234  UpdateState updateState;
235  QNetworkAccessManager* downloadMgr;
236  QString updateUrl;
237  class StelProgressController* progressBar;
238  QTimer* updateTimer;
239  QTimer* messageTimer;
240  QList<int> messageIDs;
241  bool updatesEnabled;
242  QDateTime lastUpdate;
243  int updateFrequencyDays;
244 
245  QSettings* conf;
246 
247  // GUI
248  SupernovaeDialog* configDialog;
249 
250 private slots:
254  void checkForUpdate(void);
255  void updateDownloadComplete(QNetworkReply* reply);
256 
257 };
258 
259 
260 
261 #include <QObject>
262 #include "StelPluginInterface.hpp"
263 
266 {
267  Q_OBJECT
268  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
269  Q_INTERFACES(StelPluginInterface)
270 public:
271  virtual StelModule* getStelModule() const;
272  virtual StelPluginInfo getPluginInfo() const;
273 };
274 
275 #endif /*_SUPERNOVAE_HPP_*/
Update completed, there we no updates.
Definition: Supernovae.hpp:76
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:157
virtual QStringList listMatchingObjectsI18n(const QString &objPrefix, int maxNbItem=5, bool useStartOfWords=false) const
Find and return the list of at most maxNbItem objects auto-completing the passed object I18n name...
void setUpdatesEnabled(bool b)
Set whether or not the plugin will try to update catalog data from the internet.
Definition: Supernovae.hpp:151
SupernovaP getByID(const QString &id)
get a supernova object by identifier
Update completed, there were updates.
Definition: Supernovae.hpp:77
virtual QStringList listMatchingObjects(const QString &objPrefix, int maxNbItem=5, bool useStartOfWords=false) const
Find and return the list of at most maxNbItem objects auto-completing the passed object English name...
void jsonUpdateComplete(void)
Emitted after a JSON update has run.
virtual StelObjectP searchByNameI18n(const QString &nameI18n) const
Return the matching satellite object's pointer if exists or NULL.
Error during download phase.
Definition: Supernovae.hpp:78
float getLowerLimitBrightness()
Get lower limit of brightness for displayed supernovae.
Main class of the Historical Supernovae plugin.
Definition: Supernovae.hpp:68
int getCountSupernovae(void)
Get count of supernovae from catalog.
Definition: Supernovae.hpp:173
bool getUpdatesEnabled(void)
Get whether or not the plugin will try to update catalog data from the internet.
Definition: Supernovae.hpp:148
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:265
void readSettingsFromConfig(void)
Read (or re-read) settings from the main config file.
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 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:154
QSharedPointer< StelTexture > StelTextureSP
void updateStateChanged(Supernovae::UpdateState state)
Update in progress.
Definition: Supernovae.hpp:75
void saveSettingsToConfig(void)
Save the settings to the main configuration file.
int getSecondsToUpdate(void)
Get the number of seconds till the next update.
void restoreDefaults(void)
Set up the plugin with default values.
QString getSupernovaeList()
Get list of supernovae.
UpdateState getUpdateState(void)
Get the current updateState.
Definition: Supernovae.hpp:164
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.