Stellarium 0.12.3
Quasars.hpp
1 /*
2  * Copyright (C) 2011 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 _QUASARS_HPP_
20 #define _QUASARS_HPP_
21 
22 #include "StelObjectModule.hpp"
23 #include "StelObject.hpp"
24 #include "Quasar.hpp"
25 #include <QFont>
26 #include <QVariantMap>
27 #include <QDateTime>
28 #include <QList>
29 #include <QSharedPointer>
30 
31 
32 class QNetworkAccessManager;
33 class QNetworkReply;
34 class QProgressBar;
35 class QSettings;
36 class QTimer;
37 class QPixmap;
38 class StelButton;
39 class QuasarsDialog;
40 
41 typedef QSharedPointer<Quasar> QuasarP;
42 
44 class Quasars : public StelObjectModule
45 {
46  Q_OBJECT
47 public:
50  enum UpdateState {
56  };
57 
58  Quasars();
59  virtual ~Quasars();
60 
62  // Methods defined in the StelModule class
63  virtual void init();
64  virtual void deinit();
65  virtual void update(double) {;}
66  virtual void draw(StelCore* core, class StelRenderer* renderer);
67  virtual void drawPointer(StelCore* core, class StelRenderer* renderer, StelProjectorP projector);
68  virtual double getCallOrder(StelModuleActionName actionName) const;
69 
71  // Methods defined in StelObjectManager class
77  virtual QList<StelObjectP> searchAround(const Vec3d& v, double limitFov, const StelCore* core) const;
78 
81  virtual StelObjectP searchByNameI18n(const QString& nameI18n) const;
82 
85  virtual StelObjectP searchByName(const QString& name) const;
86 
91  virtual QStringList listMatchingObjectsI18n(const QString& objPrefix, int maxNbItem=5) const;
92 
97  virtual QStringList listMatchingObjects(const QString& objPrefix, int maxNbItem=5) const;
98 
99  virtual QStringList listAllObjects(bool inEnglish) const;
100  virtual QString getName() const { return "Quasars"; }
101 
103  QuasarP getByID(const QString& id);
104 
107  virtual bool configureGui(bool show=true);
108 
112  void restoreDefaults(void);
113 
116  void readSettingsFromConfig(void);
117 
119  void saveSettingsToConfig(void);
120 
123  bool getUpdatesEnabled(void) {return updatesEnabled;}
126  void setUpdatesEnabled(bool b) {updatesEnabled=b;}
127 
128  bool getDisplayMode(void) {return distributionEnabled;}
129  void setDisplayMode(bool b) {distributionEnabled=b;}
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 setFlagShowQuasars(bool b) { flagShowQuasars=b; }
159  bool getFlagShowQuasars(void) { return flagShowQuasars; }
160 
162  void setFlagShowQuasarsButton(bool b);
163  bool getFlagShowQuasarsButton(void) { return flagShowQuasarsButton; }
164 
166  void displayMessage(const QString& message, const QString hexColor="#999999");
167  void messageTimeout(void);
168 
169 private:
170  // Font used for displaying our text
171  QFont font;
172 
173  // if existing, delete Satellites section in main config.ini, then create with default values
174  void restoreDefaultConfigIni(void);
175 
176  // Upgrade config.ini: rename old key settings to new
177  void upgradeConfigIni(void);
178 
180  void restoreDefaultJsonFile(void);
181 
183  void readJsonFile(void);
184 
188  bool backupJsonFile(bool deleteOriginal=false);
189 
192  int getJsonFileFormatVersion(void);
193 
195  QVariantMap loadQSOMap(QString path=QString());
196 
198  void setQSOMap(const QVariantMap& map);
199 
200  QString catalogJsonPath;
201 
202  class StelTextureNew* texPointer;
203  class StelTextureNew* markerTexture;
204  QList<QuasarP> QSO;
205 
206  // variables and functions for the updater
207  UpdateState updateState;
208  QNetworkAccessManager* downloadMgr;
209  QString updateUrl;
210  QTimer* updateTimer;
211  QTimer* messageTimer;
212  QList<int> messageIDs;
213  bool updatesEnabled;
214  QDateTime lastUpdate;
215  int updateFrequencyDays;
216  bool distributionEnabled;
217  bool enableAtStartup;
218 
219  QSettings* conf;
220 
221  // GUI
222  QuasarsDialog* configDialog;
223  bool flagShowQuasars;
224  bool flagShowQuasarsButton;
225  QPixmap* OnIcon;
226  QPixmap* OffIcon;
227  QPixmap* GlowIcon;
228  StelButton* toolbarButton;
229  QProgressBar* progressBar;
230 
231 private slots:
235  void checkForUpdate(void);
236  void updateDownloadComplete(QNetworkReply* reply);
237 
238 };
239 
240 
241 #include "fixx11h.h"
242 #include <QObject>
243 #include "StelPluginInterface.hpp"
244 
246 class QuasarsStelPluginInterface : public QObject, public StelPluginInterface
247 {
248  Q_OBJECT
249  Q_INTERFACES(StelPluginInterface)
250 public:
251  virtual StelModule* getStelModule() const;
252  virtual StelPluginInfo getPluginInfo() const;
253 };
254 
255 #endif /*_QUASARS_HPP_*/