Stellarium 0.14.3
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 listMatchingObjectsI18n(const QString& objPrefix, int maxNbItem=5, bool useStartOfWords=false) const;
120  virtual QStringList listMatchingObjects(const QString& objPrefix, int maxNbItem=5, bool useStartOfWords=false) const;
121  virtual QStringList listAllObjects(bool inEnglish) const;
122  virtual QStringList listAllObjectsByType(const QString& objType, bool inEnglish) const { Q_UNUSED(objType) Q_UNUSED(inEnglish) return QStringList(); }
123  virtual QString getName() const { return "Bright Novae"; }
124 
126  NovaP getByID(const QString& id);
127 
130  virtual bool configureGui(bool show=true);
131 
135  void restoreDefaults(void);
136 
139  void readSettingsFromConfig(void);
140 
142  void saveSettingsToConfig(void);
143 
146  bool getUpdatesEnabled(void) {return updatesEnabled;}
149  void setUpdatesEnabled(bool b) {updatesEnabled=b;}
150 
152  QDateTime getLastUpdate(void) {return lastUpdate;}
153 
155  int getUpdateFrequencyDays(void) {return updateFrequencyDays;}
156  void setUpdateFrequencyDays(int days) {updateFrequencyDays = days;}
157 
159  int getSecondsToUpdate(void);
160 
162  UpdateState getUpdateState(void) {return updateState;}
163 
165  QString getNovaeList();
166 
168  float getLowerLimitBrightness();
169 
171  int getCountNovae(void) {return NovaCnt;}
172 
173 signals:
176 
178  void jsonUpdateComplete(void);
179 
180 public slots:
181  // FIXME: Add functions for scripting support
182 
185  void updateJSON(void);
186 
188  void displayMessage(const QString& message, const QString hexColor="#999999");
189  void messageTimeout(void);
190 
191 private:
192  // Font used for displaying our text
193  QFont font;
194 
195  // if existing, delete Novae section in main config.ini, then create with default values
196  void restoreDefaultConfigIni(void);
197 
199  void restoreDefaultJsonFile(void);
200 
202  void readJsonFile(void);
203 
207  bool backupJsonFile(bool deleteOriginal=false);
208 
211  int getJsonFileVersion(void);
212 
215  bool checkJsonFileFormat(void);
216 
218  QVariantMap loadNovaeMap(QString path=QString());
219 
221  void setNovaeMap(const QVariantMap& map);
222 
223  QString novaeJsonPath;
224 
225  int NovaCnt;
226 
227  StelTextureSP texPointer;
228  QList<NovaP> nova;
229  QHash<QString, double> novalist;
230 
231  // variables and functions for the updater
232  UpdateState updateState;
233  QNetworkAccessManager* downloadMgr;
234  QString updateUrl;
235  class StelProgressController* progressBar;
236  QTimer* updateTimer;
237  QTimer* messageTimer;
238  QList<int> messageIDs;
239  bool updatesEnabled;
240  QDateTime lastUpdate;
241  int updateFrequencyDays;
242 
243  QSettings* conf;
244 
245  // GUI
246  NovaeDialog* configDialog;
247 
248 private slots:
252  void checkForUpdate(void);
253  void updateDownloadComplete(QNetworkReply* reply);
254 
255 };
256 
257 
258 #include <QObject>
259 #include "StelPluginInterface.hpp"
260 
262 class NovaeStelPluginInterface : public QObject, public StelPluginInterface
263 {
264  Q_OBJECT
265  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
266  Q_INTERFACES(StelPluginInterface)
267 public:
268  virtual StelModule* getStelModule() const;
269  virtual StelPluginInfo getPluginInfo() const;
270 };
271 
272 #endif /*_NOVAE_HPP_*/
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:149
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...
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.
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:152
Main class of the Bright Novae plugin.
Definition: Novae.hpp:67
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 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:162
float getLowerLimitBrightness()
Get lower limit of brightness for displayed novae.
NovaP getByID(const QString &id)
get a nova object by identifier
int getCountNovae(void)
Get count of novae from catalog.
Definition: Novae.hpp:171
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's pointer if exists or NULL.
virtual bool configureGui(bool show=true)
Implement this to tell the main Stellarium GUI that there is a GUI element to configure this plugin...
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
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:262
bool getUpdatesEnabled(void)
Get whether or not the plugin will try to update catalog data from the internet.
Definition: Novae.hpp:146
int getUpdateFrequencyDays(void)
Get the update frequency in days.
Definition: Novae.hpp:155
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