Stellarium 0.15.2
Novae.hpp
1 /*
2  * Copyright (C) 2013 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 _NOVAE_HPP_
20 #define _NOVAE_HPP_
21 
22 #include "StelObjectModule.hpp"
23 #include "StelObject.hpp"
24 #include "StelFader.hpp"
25 #include "Nova.hpp"
26 #include "StelTextureTypes.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 NovaeDialog;
39 class StelPainter;
40 
60 typedef QSharedPointer<Nova> NovaP;
62 
67 class Novae : public StelObjectModule
68 {
69  Q_OBJECT
70 public:
73  enum UpdateState {
79  };
80 
81  Novae();
82  virtual ~Novae();
83 
85  // Methods defined in the StelModule class
86  virtual void init();
87  virtual void update(double) {;}
88  virtual void draw(StelCore* core);
89  virtual void drawPointer(StelCore* core, StelPainter& painter);
90  virtual double getCallOrder(StelModuleActionName actionName) const;
91 
93  // Methods defined in StelObjectManager class
99  virtual QList<StelObjectP> searchAround(const Vec3d& v, double limitFov, const StelCore* core) const;
100 
103  virtual StelObjectP searchByNameI18n(const QString& nameI18n) const;
104 
107  virtual StelObjectP searchByName(const QString& name) const;
108 
114  virtual QStringList listMatchingObjects(const QString& objPrefix, int maxNbItem=5, bool useStartOfWords=false, bool inEnglish=false) const;
115  virtual QStringList listAllObjects(bool inEnglish) const;
116  virtual QString getName() const { return "Bright Novae"; }
117 
119  NovaP getByID(const QString& id);
120 
123  virtual bool configureGui(bool show=true);
124 
128  void restoreDefaults(void);
129 
132  void readSettingsFromConfig(void);
133 
135  void saveSettingsToConfig(void);
136 
139  bool getUpdatesEnabled(void) {return updatesEnabled;}
142  void setUpdatesEnabled(bool b) {updatesEnabled=b;}
143 
145  QDateTime getLastUpdate(void) {return lastUpdate;}
146 
148  int getUpdateFrequencyDays(void) {return updateFrequencyDays;}
149  void setUpdateFrequencyDays(int days) {updateFrequencyDays = days;}
150 
152  int getSecondsToUpdate(void);
153 
155  UpdateState getUpdateState(void) {return updateState;}
156 
158  QString getNovaeList();
159 
161  float getLowerLimitBrightness();
162 
164  int getCountNovae(void) {return NovaCnt;}
165 
166 signals:
169 
171  void jsonUpdateComplete(void);
172 
173 public slots:
174  // FIXME: Add functions for scripting support
175 
178  void updateJSON(void);
179 
181  void displayMessage(const QString& message, const QString hexColor="#999999");
182  void messageTimeout(void);
183 
184  void reloadCatalog(void);
185 
186 private:
187  // Font used for displaying our text
188  QFont font;
189 
190  // if existing, delete Novae section in main config.ini, then create with default values
191  void restoreDefaultConfigIni(void);
192 
194  void restoreDefaultJsonFile(void);
195 
197  void readJsonFile(void);
198 
202  bool backupJsonFile(bool deleteOriginal=false);
203 
206  int getJsonFileVersion(void);
207 
210  bool checkJsonFileFormat(void);
211 
213  QVariantMap loadNovaeMap(QString path=QString());
214 
216  void setNovaeMap(const QVariantMap& map);
217 
218  QString novaeJsonPath;
219 
220  int NovaCnt;
221 
222  StelTextureSP texPointer;
223  QList<NovaP> nova;
224  QHash<QString, double> novalist;
225 
226  // variables and functions for the updater
227  UpdateState updateState;
228  QNetworkAccessManager* downloadMgr;
229  QString updateUrl;
230  class StelProgressController* progressBar;
231  QTimer* updateTimer;
232  QTimer* messageTimer;
233  QList<int> messageIDs;
234  bool updatesEnabled;
235  QDateTime lastUpdate;
236  int updateFrequencyDays;
237 
238  QSettings* conf;
239 
240  // GUI
241  NovaeDialog* configDialog;
242 
243 private slots:
247  void checkForUpdate(void);
248  void updateDownloadComplete(QNetworkReply* reply);
249 
250 };
251 
252 
253 #include <QObject>
254 #include "StelPluginInterface.hpp"
255 
257 class NovaeStelPluginInterface : public QObject, public StelPluginInterface
258 {
259  Q_OBJECT
260  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
261  Q_INTERFACES(StelPluginInterface)
262 public:
263  virtual StelModule* getStelModule() const;
264  virtual StelPluginInfo getPluginInfo() const;
265 };
266 
267 #endif /*_NOVAE_HPP_*/
virtual void draw(StelCore *core)
Execute all the drawing functions for this module.
Update in progress.
Definition: Novae.hpp:74
void setUpdatesEnabled(bool b)
Set whether or not the plugin will try to update catalog data from the internet.
Definition: Novae.hpp:142
Define the interface to implement when creating a plugin.
Update completed, there were updates.
Definition: Novae.hpp:76
QString getNovaeList()
Get list of novae.
void restoreDefaults(void)
Set up the plugin with default values.
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.
void jsonUpdateComplete(void)
Emitted after a JSON update has run.
QDateTime getLastUpdate(void)
Get the date and time the novae were updated.
Definition: Novae.hpp:145
Define the StelTextureSP type.
Main class of the Bright Novae plugin.
Definition: Novae.hpp:67
void displayMessage(const QString &message, const QString hexColor="#999999")
Display a message. This is used for plugin-specific warnings and such.
UpdateState getUpdateState(void)
Get the current updateState.
Definition: Novae.hpp:155
float getLowerLimitBrightness()
Get lower limit of brightness for displayed novae.
NovaP getByID(const QString &id)
get a nova object by identifier
Main class for Stellarium core processing.
Definition: StelCore.hpp:48
int getCountNovae(void)
Get count of novae from catalog.
Definition: Novae.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.
virtual StelObjectP searchByName(const QString &name) const
Return the matching satellite if exists or NULL.
void updateJSON(void)
Download JSON from web recources described in the module section of the module.ini file and update th...
void updateStateChanged(Novae::UpdateState state)
void saveSettingsToConfig(void)
Save the settings to the main configuration file.
virtual StelObjectP searchByNameI18n(const QString &nameI18n) const
Return the matching satellite object&#39;s pointer if exists or NULL.
Specialization of StelModule which manages a collection of StelObject.
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 QStringList listAllObjects(bool inEnglish) const
List all StelObjects.
int getSecondsToUpdate(void)
Get the number of seconds till the next update.
Other error.
Definition: Novae.hpp:78
Error during download phase.
Definition: Novae.hpp:77
Provides functions for performing openGL drawing operations.
Definition: StelPainter.hpp:40
virtual void update(double)
Update the module with respect to the time.
Definition: Novae.hpp:87
void readSettingsFromConfig(void)
Read (or re-read) settings from the main config file.
This class is used by Qt to manage a plug-in interface.
Definition: Novae.hpp:257
StelModuleActionName
Define the possible action for which an order is defined.
Definition: StelModule.hpp:121
bool getUpdatesEnabled(void)
Get whether or not the plugin will try to update catalog data from the internet.
Definition: Novae.hpp:139
Maintain the state of a progress bar.
int getUpdateFrequencyDays(void)
Get the update frequency in days.
Definition: Novae.hpp:148
UpdateState
Used for keeping for track of the download/update status.
Definition: Novae.hpp:73
Update completed, there we no updates.
Definition: Novae.hpp:75
QSharedPointer< StelTexture > StelTextureSP
Use shared pointer to simplify memory managment.
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...
This is the common base class for all the main components of stellarium.
Definition: StelModule.hpp:49
virtual void init()
Initialize itself.
Contains information about a Stellarium plugin.