Stellarium  0.90.0
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 
109  virtual StelObjectP searchByID(const QString &id) const
110  {
111  return qSharedPointerCast<StelObject>(getByID(id));
112  }
113 
119  virtual QStringList listMatchingObjects(const QString& objPrefix, int maxNbItem=5, bool useStartOfWords=false, bool inEnglish=false) const;
120  virtual QStringList listAllObjects(bool inEnglish) const;
121  virtual QString getName() const { return "Bright Novae"; }
122  virtual QString getStelObjectType() const { return Nova::NOVA_TYPE; }
123 
125  NovaP getByID(const QString& id) const;
126 
129  virtual bool configureGui(bool show=true);
130 
134  void restoreDefaults(void);
135 
138  void readSettingsFromConfig(void);
139 
141  void saveSettingsToConfig(void);
142 
145  bool getUpdatesEnabled(void) {return updatesEnabled;}
148  void setUpdatesEnabled(bool b) {updatesEnabled=b;}
149 
151  QDateTime getLastUpdate(void) const {return lastUpdate;}
152 
154  int getUpdateFrequencyDays(void) const {return updateFrequencyDays;}
155  void setUpdateFrequencyDays(int days) {updateFrequencyDays = days;}
156 
158  int getSecondsToUpdate(void);
159 
161  UpdateState getUpdateState(void) const {return updateState;}
162 
164  QString getNovaeList();
165 
167  float getLowerLimitBrightness();
168 
170  int getCountNovae(void) const {return NovaCnt;}
171 
172 signals:
175 
177  void jsonUpdateComplete(void);
178 
179 public slots:
180  // FIXME: Add functions for scripting support
181 
184  void updateJSON(void);
185 
187  void displayMessage(const QString& message, const QString hexColor="#999999");
188  void messageTimeout(void) const;
189 
190  void reloadCatalog(void);
191 
192 private:
193  // Font used for displaying our text
194  QFont font;
195 
196  // if existing, delete Novae section in main config.ini, then create with default values
197  void restoreDefaultConfigIni(void);
198 
200  void restoreDefaultJsonFile(void);
201 
203  void readJsonFile(void);
204 
208  bool backupJsonFile(bool deleteOriginal=false);
209 
212  int getJsonFileVersion(void) const;
213 
216  bool checkJsonFileFormat(void) const;
217 
219  QVariantMap loadNovaeMap(QString path=QString());
220 
222  void setNovaeMap(const QVariantMap& map);
223 
224  QString novaeJsonPath;
225 
226  int NovaCnt;
227 
228  StelTextureSP texPointer;
229  QList<NovaP> nova;
230  QHash<QString, double> novalist;
231 
232  // variables and functions for the updater
233  UpdateState updateState;
234  QNetworkAccessManager* downloadMgr;
235  QString updateUrl;
236  class StelProgressController* progressBar;
237  QTimer* updateTimer;
238  QTimer* messageTimer;
239  QList<int> messageIDs;
240  bool updatesEnabled;
241  QDateTime lastUpdate;
242  int updateFrequencyDays;
243 
244  QSettings* conf;
245 
246  // GUI
247  NovaeDialog* configDialog;
248 
249 private slots:
253  void checkForUpdate(void);
254  void updateDownloadComplete(QNetworkReply* reply);
255 
256 };
257 
258 
259 #include <QObject>
260 #include "StelPluginInterface.hpp"
261 
263 class NovaeStelPluginInterface : public QObject, public StelPluginInterface
264 {
265  Q_OBJECT
266  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
267  Q_INTERFACES(StelPluginInterface)
268 public:
269  virtual StelModule* getStelModule() const;
270  virtual StelPluginInfo getPluginInfo() const;
271  virtual QObjectList getExtensionList() const { return QObjectList(); }
272 };
273 
274 #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:148
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.
Define the StelTextureSP type.
Main class of the Bright Novae plugin.
Definition: Novae.hpp:67
virtual QObjectList getExtensionList() const
A mechanism to provide abitrary QObjects to the StelModuleMgr.
Definition: Novae.hpp:271
void displayMessage(const QString &message, const QString hexColor="#999999")
Display a message. This is used for plugin-specific warnings and such.
int getCountNovae(void) const
Get count of novae from catalog.
Definition: Novae.hpp:170
float getLowerLimitBrightness()
Get lower limit of brightness for displayed novae.
Main class for Stellarium core processing.
Definition: StelCore.hpp:48
QDateTime getLastUpdate(void) const
Get the date and time the novae were updated.
Definition: Novae.hpp:151
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 Q_NULLPTR.
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 Q_NULLPTR.
Specialization of StelModule which manages a collection of StelObject.
virtual QString getName() const
Gets a user-displayable name of the object category.
Definition: Novae.hpp:121
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 QString getStelObjectType() const
Returns the name that will be returned by StelObject::getType() for the objects this module manages...
Definition: Novae.hpp:122
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:263
virtual StelObjectP searchByID(const QString &id) const
Return the StelObject with the given ID if exists or the empty StelObject if not found.
Definition: Novae.hpp:109
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:145
Maintain the state of a progress bar.
NovaP getByID(const QString &id) const
get a nova object by identifier
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.
int getUpdateFrequencyDays(void) const
Get the update frequency in days.
Definition: Novae.hpp:154
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
UpdateState getUpdateState(void) const
Get the current updateState.
Definition: Novae.hpp:161
virtual void init()
Initialize itself.
Contains information about a Stellarium plugin.