Stellarium 0.14.3
Pulsars.hpp
1 /*
2  * Copyright (C) 2012 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 _PULSARS_HPP_
20 #define _PULSARS_HPP_
21 
22 #include "StelObjectModule.hpp"
23 #include "StelObject.hpp"
24 #include "StelFader.hpp"
25 #include "StelTextureTypes.hpp"
26 #include "Pulsar.hpp"
27 #include <QFont>
28 #include <QVariantMap>
29 #include <QDateTime>
30 #include <QList>
31 #include <QSharedPointer>
32 
33 class QNetworkAccessManager;
34 class QNetworkReply;
35 class QSettings;
36 class QTimer;
37 class QPixmap;
38 class StelButton;
39 class PulsarsDialog;
40 
41 class StelPainter;
42 
66 typedef QSharedPointer<Pulsar> PulsarP;
68 
73 class Pulsars : public StelObjectModule
74 {
75  Q_OBJECT
76  Q_PROPERTY(bool pulsarsVisible READ getFlagShowPulsars WRITE setFlagShowPulsars)
77 public:
80  enum UpdateState {
86  };
87 
88  Pulsars();
89  virtual ~Pulsars();
90 
92  // Methods defined in the StelModule class
93  virtual void init();
94  virtual void deinit();
95  virtual void update(double) {;}
96  virtual void draw(StelCore* core);
97  virtual void drawPointer(StelCore* core, StelPainter& painter);
98  virtual double getCallOrder(StelModuleActionName actionName) const;
99 
101  // Methods defined in StelObjectManager class
107  virtual QList<StelObjectP> searchAround(const Vec3d& v, double limitFov, const StelCore* core) const;
108 
111  virtual StelObjectP searchByNameI18n(const QString& nameI18n) const;
112 
115  virtual StelObjectP searchByName(const QString& name) const;
116 
122  virtual QStringList listMatchingObjectsI18n(const QString& objPrefix, int maxNbItem=5, bool useStartOfWords=false) const;
128  virtual QStringList listMatchingObjects(const QString& objPrefix, int maxNbItem=5, bool useStartOfWords=false) const;
129  virtual QStringList listAllObjects(bool inEnglish) const;
130  virtual QStringList listAllObjectsByType(const QString& objType, bool inEnglish) const { Q_UNUSED(objType) Q_UNUSED(inEnglish) return QStringList(); }
131  virtual QString getName() const { return "Pulsars"; }
132 
134  PulsarP getByID(const QString& id);
135 
138  virtual bool configureGui(bool show=true);
139 
143  void restoreDefaults(void);
144 
147  void readSettingsFromConfig(void);
148 
150  void saveSettingsToConfig(void);
151 
154  bool getUpdatesEnabled(void) {return updatesEnabled;}
157  void setUpdatesEnabled(bool b) {updatesEnabled=b;}
158 
159  bool getDisplayMode(void);
160  void setDisplayMode(bool b);
161 
162  bool getGlitchFlag(void);
163  void setGlitchFlag(bool b);
164 
165  QString getMarkerColor(bool mtype = true);
166  void setMarkerColor(QString c, bool mtype = true);
167 
168  void setEnableAtStartup(bool b) { enableAtStartup=b; }
169  bool getEnableAtStartup(void) { return enableAtStartup; }
170 
172  QDateTime getLastUpdate(void) {return lastUpdate;}
173 
175  int getUpdateFrequencyDays(void) {return updateFrequencyDays;}
176  void setUpdateFrequencyDays(int days) {updateFrequencyDays = days;}
177 
179  int getSecondsToUpdate(void);
180 
182  UpdateState getUpdateState(void) {return updateState;}
183 
185  int getCountPulsars(void) {return PsrCount;}
186 
187 signals:
190 
192  void jsonUpdateComplete(void);
193 
194 public slots:
197  void updateJSON(void);
198 
199  void setFlagShowPulsars(bool b) { flagShowPulsars=b; }
200  bool getFlagShowPulsars(void) { return flagShowPulsars; }
201 
203  void displayMessage(const QString& message, const QString hexColor="#999999");
204  void messageTimeout(void);
205 
207  void setFlagShowPulsarsButton(bool b);
208  bool getFlagShowPulsarsButton(void) { return flagShowPulsarsButton; }
209 
210 
211 private:
212  // Font used for displaying our text
213  QFont font;
214 
215  // if existing, delete Satellites section in main config.ini, then create with default values
216  void restoreDefaultConfigIni(void);
217 
218  // Upgrade config.ini: rename old key settings to new
219  void upgradeConfigIni(void);
220 
222  void restoreDefaultJsonFile(void);
223 
225  void readJsonFile(void);
226 
230  bool backupJsonFile(bool deleteOriginal=false);
231 
234  int getJsonFileFormatVersion(void);
235 
238  bool checkJsonFileFormat(void);
239 
241  QVariantMap loadPSRMap(QString path=QString());
242 
244  void setPSRMap(const QVariantMap& map);
245 
246  QString jsonCatalogPath;
247 
248  StelTextureSP texPointer;
249  QList<PulsarP> psr;
250 
251  int PsrCount;
252 
253  // variables and functions for the updater
254  UpdateState updateState;
255  QNetworkAccessManager* downloadMgr;
256  QString updateUrl;
257  QTimer* updateTimer;
258  QTimer* messageTimer;
259  QList<int> messageIDs;
260  bool updatesEnabled;
261  QDateTime lastUpdate;
262  int updateFrequencyDays;
263  bool enableAtStartup;
264 
265  QSettings* conf;
266 
267  // GUI
268  PulsarsDialog* configDialog;
269  bool flagShowPulsars;
270  bool flagShowPulsarsButton;
271  QPixmap* OnIcon;
272  QPixmap* OffIcon;
273  QPixmap* GlowIcon;
274  StelButton* toolbarButton;
275  class StelProgressController* progressBar;
276 
277 
278 private slots:
282  void checkForUpdate(void);
283  void updateDownloadComplete(QNetworkReply* reply);
284 
285 };
286 
287 
288 
289 #include <QObject>
290 #include "StelPluginInterface.hpp"
291 
293 class PulsarsStelPluginInterface : public QObject, public StelPluginInterface
294 {
295  Q_OBJECT
296  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
297  Q_INTERFACES(StelPluginInterface)
298 public:
299  virtual StelModule* getStelModule() const;
300  virtual StelPluginInfo getPluginInfo() const;
301 };
302 
303 #endif /*_PULSARS_HPP_*/
void displayMessage(const QString &message, const QString hexColor="#999999")
Display a message. This is used for plugin-specific warnings and such.
virtual StelObjectP searchByName(const QString &name) const
Return the matching satellite if exists or NULL.
void setFlagShowPulsarsButton(bool b)
Define whether the button toggling pulsars should be visible.
void jsonUpdateComplete(void)
emitted after a JSON update has run.
Error during download phase.
Definition: Pulsars.hpp:84
void updateStateChanged(Pulsars::UpdateState state)
void restoreDefaults(void)
Set up the plugin with default values.
void setUpdatesEnabled(bool b)
set whether or not the plugin will try to update catalog data from the internet
Definition: Pulsars.hpp:157
Main class of the Pulsars plugin.
Definition: Pulsars.hpp:73
virtual bool configureGui(bool show=true)
Implement this to tell the main Stellarium GUI that there is a GUI element to configure this plugin...
PulsarP getByID(const QString &id)
get a Pulsar object by identifier
void saveSettingsToConfig(void)
Save the settings to the main configuration file.
UpdateState
Used for keeping for track of the download/update status.
Definition: Pulsars.hpp:80
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.
void updateJSON(void)
Download JSON from web recources described in the module section of the module.ini file and update th...
int getCountPulsars(void)
Get count of pulsars from catalog.
Definition: Pulsars.hpp:185
Other error.
Definition: Pulsars.hpp:85
bool getUpdatesEnabled(void)
get whether or not the plugin will try to update catalog data from the internet
Definition: Pulsars.hpp:154
Update completed, there were updates.
Definition: Pulsars.hpp:83
int getSecondsToUpdate(void)
get the number of seconds till the next update
virtual StelObjectP searchByNameI18n(const QString &nameI18n) const
Return the matching satellite object's pointer if exists or NULL.
void readSettingsFromConfig(void)
Read (or re-read) settings from the main config file.
int getUpdateFrequencyDays(void)
get the update frequency in days
Definition: Pulsars.hpp:175
This class is used by Qt to manage a plug-in interface.
Definition: Pulsars.hpp:293
Update completed, there we no updates.
Definition: Pulsars.hpp:82
QDateTime getLastUpdate(void)
get the date and time the pulsars were updated
Definition: Pulsars.hpp:172
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...
QSharedPointer< StelTexture > StelTextureSP
UpdateState getUpdateState(void)
Get the current updateState.
Definition: Pulsars.hpp:182
Update in progress.
Definition: Pulsars.hpp:81
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...