Stellarium 0.14.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 "StelTextureTypes.hpp"
25 #include "Quasar.hpp"
26 #include <QFont>
27 #include <QVariantMap>
28 #include <QDateTime>
29 #include <QList>
30 #include <QSharedPointer>
31 
32 class StelPainter;
33 
34 class QNetworkAccessManager;
35 class QNetworkReply;
36 class QSettings;
37 class QTimer;
38 class QPixmap;
39 class StelButton;
40 class QuasarsDialog;
41 
62 typedef QSharedPointer<Quasar> QuasarP;
64 
69 class Quasars : public StelObjectModule
70 {
71  Q_OBJECT
72  Q_PROPERTY(bool quasarsVisible READ getFlagShowQuasars WRITE setFlagShowQuasars)
73 public:
76  enum UpdateState {
82  };
83 
84  Quasars();
85  virtual ~Quasars();
86 
88  // Methods defined in the StelModule class
89  virtual void init();
90  virtual void deinit();
91  virtual void update(double) {;}
92  virtual void draw(StelCore* core);
93  virtual void drawPointer(StelCore* core, StelPainter& painter);
94  virtual double getCallOrder(StelModuleActionName actionName) const;
95 
97  // Methods defined in StelObjectManager class
103  virtual QList<StelObjectP> searchAround(const Vec3d& v, double limitFov, const StelCore* core) const;
104 
107  virtual StelObjectP searchByNameI18n(const QString& nameI18n) const;
108 
111  virtual StelObjectP searchByName(const QString& name) const;
112 
118  virtual QStringList listMatchingObjectsI18n(const QString& objPrefix, int maxNbItem=5, bool useStartOfWords=false) const;
119 
125  virtual QStringList listMatchingObjects(const QString& objPrefix, int maxNbItem=5, bool useStartOfWords=false) const;
126 
127  virtual QStringList listAllObjects(bool inEnglish) const;
128  virtual QStringList listAllObjectsByType(const QString& objType, bool inEnglish) const { Q_UNUSED(objType) Q_UNUSED(inEnglish) return QStringList(); }
129 
130  virtual QString getName() const { return "Quasars"; }
131 
133  QuasarP getByID(const QString& id);
134 
137  virtual bool configureGui(bool show=true);
138 
142  void restoreDefaults(void);
143 
146  void readSettingsFromConfig(void);
147 
149  void saveSettingsToConfig(void);
150 
153  bool getUpdatesEnabled(void) {return updatesEnabled;}
156  void setUpdatesEnabled(bool b) {updatesEnabled=b;}
157 
158  bool getDisplayMode(void);
159  void setDisplayMode(bool b);
160  QString getMarkerColor(void);
161  void setMarkerColor(QString c);
162  void setEnableAtStartup(bool b) { enableAtStartup=b; }
163  bool getEnableAtStartup(void) { return enableAtStartup; }
164 
166  QDateTime getLastUpdate(void) {return lastUpdate;}
167 
169  int getUpdateFrequencyDays(void) {return updateFrequencyDays;}
170  void setUpdateFrequencyDays(int days) {updateFrequencyDays = days;}
171 
173  int getSecondsToUpdate(void);
174 
176  UpdateState getUpdateState(void) {return updateState;}
177 
179  int getCountQuasars(void) {return QsrCount;}
180 
181 signals:
184 
186  void jsonUpdateComplete(void);
187 
188 public slots:
191  void updateJSON(void);
192 
193  void setFlagShowQuasars(bool b) { flagShowQuasars=b; }
194  bool getFlagShowQuasars(void) { return flagShowQuasars; }
195 
197  void setFlagShowQuasarsButton(bool b);
198  bool getFlagShowQuasarsButton(void) { return flagShowQuasarsButton; }
199 
201  void displayMessage(const QString& message, const QString hexColor="#999999");
202  void messageTimeout(void);
203 
204 private:
205  // Font used for displaying our text
206  QFont font;
207 
208  // if existing, delete Satellites section in main config.ini, then create with default values
209  void restoreDefaultConfigIni(void);
210 
211  // Upgrade config.ini: rename old key settings to new
212  void upgradeConfigIni(void);
213 
215  void restoreDefaultJsonFile(void);
216 
218  void readJsonFile(void);
219 
223  bool backupJsonFile(bool deleteOriginal=false);
224 
227  int getJsonFileFormatVersion(void);
228 
231  bool checkJsonFileFormat(void);
232 
234  QVariantMap loadQSOMap(QString path=QString());
235 
237  void setQSOMap(const QVariantMap& map);
238 
239  QString catalogJsonPath;
240 
241  int QsrCount;
242 
243  StelTextureSP texPointer;
244  QList<QuasarP> QSO;
245 
246  // variables and functions for the updater
247  UpdateState updateState;
248  QNetworkAccessManager* downloadMgr;
249  QString updateUrl;
250  QTimer* updateTimer;
251  QTimer* messageTimer;
252  QList<int> messageIDs;
253  bool updatesEnabled;
254  QDateTime lastUpdate;
255  int updateFrequencyDays;
256  bool enableAtStartup;
257 
258  QSettings* conf;
259 
260  // GUI
261  QuasarsDialog* configDialog;
262  bool flagShowQuasars;
263  bool flagShowQuasarsButton;
264  QPixmap* OnIcon;
265  QPixmap* OffIcon;
266  QPixmap* GlowIcon;
267  StelButton* toolbarButton;
268  class StelProgressController* progressBar;
269 
270 private slots:
274  void checkForUpdate(void);
275  void updateDownloadComplete(QNetworkReply* reply);
276 
277 };
278 
279 
280 
281 #include <QObject>
282 #include "StelPluginInterface.hpp"
283 
285 class QuasarsStelPluginInterface : public QObject, public StelPluginInterface
286 {
287  Q_OBJECT
288  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
289  Q_INTERFACES(StelPluginInterface)
290 public:
291  virtual StelModule* getStelModule() const;
292  virtual StelPluginInfo getPluginInfo() const;
293 };
294 
295 #endif /*_QUASARS_HPP_*/
void readSettingsFromConfig(void)
Read (or re-read) settings from the main config file.
UpdateState
Used for keeping for track of the download/update status.
Definition: Quasars.hpp:76
void setFlagShowQuasarsButton(bool b)
Define whether the button toggling quasars should be visible.
QuasarP getByID(const QString &id)
get a Quasar object by identifier
int getCountQuasars(void)
Get count of quasars from catalog.
Definition: Quasars.hpp:179
virtual bool configureGui(bool show=true)
Implement this to tell the main Stellarium GUI that there is a GUI element to configure this plugin...
void jsonUpdateComplete(void)
emitted after a JSON update has run.
virtual StelObjectP searchByNameI18n(const QString &nameI18n) const
Return the matching satellite object's pointer if exists or NULL.
void setUpdatesEnabled(bool b)
set whether or not the plugin will try to update catalog data from the internet
Definition: Quasars.hpp:156
virtual StelObjectP searchByName(const QString &name) const
Return the matching satellite if exists or NULL.
Update completed, there we no updates.
Definition: Quasars.hpp:78
void displayMessage(const QString &message, const QString hexColor="#999999")
Display a message. This is used for plugin-specific warnings and such.
int getSecondsToUpdate(void)
get the number of seconds till the next update
void saveSettingsToConfig(void)
Save the settings to the main configuration file.
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.
Other error.
Definition: Quasars.hpp:81
void restoreDefaults(void)
Set up the plugin with default values.
Update completed, there were updates.
Definition: Quasars.hpp:79
void updateStateChanged(Quasars::UpdateState state)
Main class of the Quasars plugin.
Definition: Quasars.hpp:69
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...
bool getUpdatesEnabled(void)
get whether or not the plugin will try to update catalog data from the internet
Definition: Quasars.hpp:153
UpdateState getUpdateState(void)
Get the current updateState.
Definition: Quasars.hpp:176
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...
void updateJSON(void)
Download JSON from web recources described in the module section of the module.ini file and update th...
QSharedPointer< StelTexture > StelTextureSP
Error during download phase.
Definition: Quasars.hpp:80
This class is used by Qt to manage a plug-in interface.
Definition: Quasars.hpp:285
QDateTime getLastUpdate(void)
get the date and time the TLE elements were updated
Definition: Quasars.hpp:166
int getUpdateFrequencyDays(void)
get the update frequency in days
Definition: Quasars.hpp:169
Update in progress.
Definition: Quasars.hpp:77