Stellarium 0.14.3
Exoplanets.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 _EXOPLANETS_HPP_
20 #define _EXOPLANETS_HPP_
21 
22 #include "StelObjectModule.hpp"
23 #include "StelObject.hpp"
24 #include "StelFader.hpp"
25 #include "StelTextureTypes.hpp"
26 #include "Exoplanet.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 ExoplanetsDialog;
38 class StelPainter;
39 class StelButton;
40 
63 typedef QSharedPointer<Exoplanet> ExoplanetP;
65 
71 {
72  Q_OBJECT
73  Q_PROPERTY(bool showExoplanets READ getFlagShowExoplanets WRITE setFlagShowExoplanets)
74 public:
77  enum UpdateState {
83  };
84 
85  Exoplanets();
86  virtual ~Exoplanets();
87 
89  // Methods defined in the StelModule class
90  virtual void init();
91  virtual void deinit();
92  virtual void update(double deltaTime);
93  virtual void draw(StelCore* core);
94  virtual void drawPointer(StelCore* core, StelPainter& painter);
95  virtual double getCallOrder(StelModuleActionName actionName) const;
96 
98  // Methods defined in StelObjectManager class
104  virtual QList<StelObjectP> searchAround(const Vec3d& v, double limitFov, const StelCore* core) const;
105 
108  virtual StelObjectP searchByNameI18n(const QString& nameI18n) const;
109 
112  virtual StelObjectP searchByName(const QString& name) const;
113 
119  virtual QStringList listMatchingObjectsI18n(const QString& objPrefix, int maxNbItem=5, bool useStartOfWords=false) const;
120 
126  virtual QStringList listMatchingObjects(const QString& objPrefix, int maxNbItem=5, bool useStartOfWords=false) const;
127 
128  virtual QStringList listAllObjects(bool inEnglish) const;
129  virtual QStringList listAllObjectsByType(const QString& objType, bool inEnglish) const { Q_UNUSED(objType) Q_UNUSED(inEnglish) return QStringList(); }
130 
131  virtual QString getName() const { return "Exoplanets"; }
132 
134  ExoplanetP getByID(const QString& id);
135 
138  virtual bool configureGui(bool show=true);
139 
143  void restoreDefaults(void);
144 
147  void loadConfiguration(void);
148 
150  void saveConfiguration(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 getTimelineMode(void);
163  void setTimelineMode(bool b);
164 
165  bool getHabitableMode(void);
166  void setHabitableMode(bool b);
167 
168  QString getMarkerColor(bool habitable);
169  void setMarkerColor(QString c, bool h);
170 
171  void setEnableAtStartup(bool b) { enableAtStartup=b; }
172  bool getEnableAtStartup(void) { return enableAtStartup; }
173 
175  QDateTime getLastUpdate(void) {return lastUpdate;}
176 
178  int getUpdateFrequencyHours(void) {return updateFrequencyHours;}
179  void setUpdateFrequencyHours(int hours) {updateFrequencyHours = hours;}
180 
182  int getSecondsToUpdate(void);
183 
185  UpdateState getUpdateState(void) {return updateState;}
186 
188  int getCountPlanetarySystems(void) const
189  {
190  return PSCount;
191  }
192 
194  int getCountAllExoplanets(void) const
195  {
196  return EPCountAll;
197  }
198 
201  {
202  return EPCountPH;
203  }
204 
205 signals:
208 
210  void jsonUpdateComplete(void);
211 
212 public slots:
215  void updateJSON(void);
216 
217  void setFlagShowExoplanets(bool b) { flagShowExoplanets=b; }
218  bool getFlagShowExoplanets(void) { return flagShowExoplanets; }
219 
221  void setFlagShowExoplanetsButton(bool b);
222  bool getFlagShowExoplanetsButton(void) { return flagShowExoplanetsButton; }
223 
225  void displayMessage(const QString& message, const QString hexColor="#999999");
226  void messageTimeout(void);
227 
228 private:
229  // Font used for displaying our text
230  QFont font;
231 
232  // if existing, delete Satellites section in main config.ini, then create with default values
233  void resetConfiguration(void);
234 
235  // Upgrade config.ini: rename old key settings to new
236  void upgradeConfigIni(void);
237 
239  void restoreDefaultJsonFile(void);
240 
242  void readJsonFile(void);
243 
247  bool backupJsonFile(bool deleteOriginal=false);
248 
251  int getJsonFileFormatVersion(void);
252 
255  bool checkJsonFileFormat(void);
256 
258  QVariantMap loadEPMap(QString path=QString());
259 
261  void setEPMap(const QVariantMap& map);
262 
267  static void translations();
268 
269  QString jsonCatalogPath;
270 
271  int PSCount;
272  int EPCountAll;
273  int EPCountPH;
274 
275  StelTextureSP texPointer;
276  QList<ExoplanetP> ep;
277 
278  // variables and functions for the updater
279  UpdateState updateState;
280  QNetworkAccessManager* downloadMgr;
281  QString updateUrl;
282  QTimer* updateTimer;
283  QTimer* messageTimer;
284  QList<int> messageIDs;
285  bool updatesEnabled;
286  QDateTime lastUpdate;
287  int updateFrequencyHours;
288  bool enableAtStartup;
289 
290  QSettings* conf;
291 
292  // GUI
293  ExoplanetsDialog* exoplanetsConfigDialog;
294  bool flagShowExoplanets;
295  bool flagShowExoplanetsButton;
296  StelButton* toolbarButton;
297  class StelProgressController* progressBar;
298 
299 private slots:
303  void checkForUpdate(void);
304  void updateDownloadComplete(QNetworkReply* reply);
305 
306 };
307 
308 
309 
310 #include <QObject>
311 #include "StelPluginInterface.hpp"
312 
315 {
316  Q_OBJECT
317  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
318  Q_INTERFACES(StelPluginInterface)
319 public:
320  virtual StelModule* getStelModule() const;
321  virtual StelPluginInfo getPluginInfo() const;
322 };
323 
324 #endif /*_EXOPLANETS_HPP_*/
void jsonUpdateComplete(void)
emitted after a JSON update has run.
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.
bool getUpdatesEnabled(void)
get whether or not the plugin will try to update TLE data from the internet
Definition: Exoplanets.hpp:154
void setFlagShowExoplanetsButton(bool b)
Define whether the button toggling exoplanets should be visible.
QDateTime getLastUpdate(void)
get the date and time the TLE elements were updated
Definition: Exoplanets.hpp:175
This class is used by Qt to manage a plug-in interface.
Definition: Exoplanets.hpp:314
UpdateState
Used for keeping for track of the download/update status.
Definition: Exoplanets.hpp:77
void displayMessage(const QString &message, const QString hexColor="#999999")
Display a message. This is used for plugin-specific warnings and such.
Error during download phase.
Definition: Exoplanets.hpp:81
UpdateState getUpdateState(void)
Get the current updateState.
Definition: Exoplanets.hpp:185
void saveConfiguration(void)
Save the settings to the main configuration file.
Update in progress.
Definition: Exoplanets.hpp:78
void updateStateChanged(Exoplanets::UpdateState state)
void updateJSON(void)
Download JSON from web recources described in the module section of the module.ini file and update th...
int getCountAllExoplanets(void) const
Get count of exoplanets from catalog.
Definition: Exoplanets.hpp:194
void setUpdatesEnabled(bool b)
set whether or not the plugin will try to update TLE data from the internet
Definition: Exoplanets.hpp:157
Main class of the Exoplanets plugin.
Definition: Exoplanets.hpp:70
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 loadConfiguration(void)
Read (or re-read) settings from the main config file.
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...
virtual StelObjectP searchByName(const QString &name) const
Return the matching satellite if exists or NULL.
Update completed, there were updates.
Definition: Exoplanets.hpp:80
Main window of the Exoplanets plugin.
int getSecondsToUpdate(void)
get the number of seconds till the next update
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 restoreDefaults(void)
Set up the plugin with default values.
virtual StelObjectP searchByNameI18n(const QString &nameI18n) const
Return the matching satellite object's pointer if exists or NULL.
QSharedPointer< StelTexture > StelTextureSP
int getCountHabitableExoplanets(void) const
Get count of potentially habitable exoplanets from catalog.
Definition: Exoplanets.hpp:200
Update completed, there we no updates.
Definition: Exoplanets.hpp:79
int getUpdateFrequencyHours(void)
get the update frequency in hours
Definition: Exoplanets.hpp:178
ExoplanetP getByID(const QString &id)
get a exoplanet object by identifier
int getCountPlanetarySystems(void) const
Get count of planetary systems from catalog.
Definition: Exoplanets.hpp:188