Stellarium 0.12.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 "Pulsar.hpp"
26 #include <QFont>
27 #include <QVariantMap>
28 #include <QDateTime>
29 #include <QList>
30 #include <QSharedPointer>
31 
32 class QNetworkAccessManager;
33 class QNetworkReply;
34 class QProgressBar;
35 class QSettings;
36 class QTimer;
37 class QPixmap;
38 class StelButton;
39 class PulsarsDialog;
40 
41 
42 typedef QSharedPointer<Pulsar> PulsarP;
43 
45 class Pulsars : public StelObjectModule
46 {
47  Q_OBJECT
48 public:
51  enum UpdateState {
57  };
58 
59  Pulsars();
60  virtual ~Pulsars();
61 
63  // Methods defined in the StelModule class
64  virtual void init();
65  virtual void deinit();
66  virtual void update(double) {;}
67  virtual void draw(StelCore* core, class StelRenderer* renderer);
68  virtual void drawPointer(StelCore* core, class StelRenderer* renderer, StelProjectorP projector);
69  virtual double getCallOrder(StelModuleActionName actionName) const;
70 
72  // Methods defined in StelObjectManager class
78  virtual QList<StelObjectP> searchAround(const Vec3d& v, double limitFov, const StelCore* core) const;
79 
82  virtual StelObjectP searchByNameI18n(const QString& nameI18n) const;
83 
86  virtual StelObjectP searchByName(const QString& name) const;
87 
92  virtual QStringList listMatchingObjectsI18n(const QString& objPrefix, int maxNbItem=5) const;
97  virtual QStringList listMatchingObjects(const QString& objPrefix, int maxNbItem=5) const;
98  virtual QStringList listAllObjects(bool inEnglish) const;
99  virtual QString getName() const { return "Pulsars"; }
100 
102  PulsarP getByID(const QString& id);
103 
106  virtual bool configureGui(bool show=true);
107 
111  void restoreDefaults(void);
112 
115  void readSettingsFromConfig(void);
116 
118  void saveSettingsToConfig(void);
119 
122  bool getUpdatesEnabled(void) {return updatesEnabled;}
125  void setUpdatesEnabled(bool b) {updatesEnabled=b;}
126 
127  bool getDisplayMode(void) {return distributionEnabled;}
128  void setDisplayMode(bool b) {distributionEnabled=b;}
129 
130  void setEnableAtStartup(bool b) { enableAtStartup=b; }
131  bool getEnableAtStartup(void) { return enableAtStartup; }
132 
134  QDateTime getLastUpdate(void) {return lastUpdate;}
135 
137  int getUpdateFrequencyDays(void) {return updateFrequencyDays;}
138  void setUpdateFrequencyDays(int days) {updateFrequencyDays = days;}
139 
141  int getSecondsToUpdate(void);
142 
144  UpdateState getUpdateState(void) {return updateState;}
145 
146 signals:
149 
151  void jsonUpdateComplete(void);
152 
153 public slots:
156  void updateJSON(void);
157 
158  void setFlagShowPulsars(bool b) { flagShowPulsars=b; }
159  bool getFlagShowPulsars(void) { return flagShowPulsars; }
160 
162  void displayMessage(const QString& message, const QString hexColor="#999999");
163  void messageTimeout(void);
164 
166  void setFlagShowPulsarsButton(bool b);
167  bool getFlagShowPulsarsButton(void) { return flagShowPulsarsButton; }
168 
169 
170 private:
171  // Font used for displaying our text
172  QFont font;
173 
174  // if existing, delete Satellites section in main config.ini, then create with default values
175  void restoreDefaultConfigIni(void);
176 
177  // Upgrade config.ini: rename old key settings to new
178  void upgradeConfigIni(void);
179 
181  void restoreDefaultJsonFile(void);
182 
184  void readJsonFile(void);
185 
189  bool backupJsonFile(bool deleteOriginal=false);
190 
193  int getJsonFileFormatVersion(void);
194 
196  QVariantMap loadPSRMap(QString path=QString());
197 
199  void setPSRMap(const QVariantMap& map);
200 
201  QString jsonCatalogPath;
202 
203  class StelTextureNew* texPointer;
204  class StelTextureNew* markerTexture;
205  QList<PulsarP> psr;
206 
207  // variables and functions for the updater
208  UpdateState updateState;
209  QNetworkAccessManager* downloadMgr;
210  QString updateUrl;
211  QTimer* updateTimer;
212  QTimer* messageTimer;
213  QList<int> messageIDs;
214  bool updatesEnabled;
215  QDateTime lastUpdate;
216  int updateFrequencyDays;
217  bool distributionEnabled;
218  bool enableAtStartup;
219 
220  QSettings* conf;
221 
222  // GUI
223  PulsarsDialog* configDialog;
224  bool flagShowPulsars;
225  bool flagShowPulsarsButton;
226  QPixmap* OnIcon;
227  QPixmap* OffIcon;
228  QPixmap* GlowIcon;
229  StelButton* toolbarButton;
230  QProgressBar* progressBar;
231 
232 
233 private slots:
237  void checkForUpdate(void);
238  void updateDownloadComplete(QNetworkReply* reply);
239 
240 };
241 
242 
243 #include "fixx11h.h"
244 #include <QObject>
245 #include "StelPluginInterface.hpp"
246 
248 class PulsarsStelPluginInterface : public QObject, public StelPluginInterface
249 {
250  Q_OBJECT
251  Q_INTERFACES(StelPluginInterface)
252 public:
253  virtual StelModule* getStelModule() const;
254  virtual StelPluginInfo getPluginInfo() const;
255 };
256 
257 #endif /*_PULSARS_HPP_*/