Stellarium  0.90.0
MeteorShowersMgr.hpp
1 /*
2  * Stellarium: Meteor Showers Plug-in
3  * Copyright (C) 2013-2015 Marcos Cardinot
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 #ifndef METEORSHOWERSMGR_HPP_
21 #define METEORSHOWERSMGR_HPP_
22 
23 #include <QNetworkReply>
24 
25 #include "StelGuiItems.hpp"
26 #include "StelTextureMgr.hpp"
27 #include "StelObjectModule.hpp"
28 
29 #define MS_CATALOG_VERSION 1
30 #define MS_CONFIG_PREFIX QString("MeteorShowers")
31 
32 class MeteorShowers;
33 class MSConfigDialog;
34 class MSSearchDialog;
35 
49 class MeteorShowersMgr : public StelModule
54 {
55  Q_OBJECT
56  Q_PROPERTY(bool enablePlugin READ getEnablePlugin WRITE actionEnablePlugin NOTIFY enablePluginChanged)
57  Q_PROPERTY(bool enableLabels READ getEnableLabels WRITE setEnableLabels NOTIFY enableLabelsChanged)
58 
59 public:
61  enum DownloadStatus {
62  OUTDATED,
63  UPDATING,
64  UPDATED,
65  FAILED
66  };
67 
70 
72  virtual ~MeteorShowersMgr();
73 
75  bool restoreDefaultCatalog(const QString& destination);
76 
79  StelTextureSP getBolideTexture() { return m_bolideTexture; }
80 
83  StelTextureSP getPointerTexture() { return m_pointerTexture; }
84 
87  StelTextureSP getRadiantTexture() { return m_radiantTexture; }
88 
91  MeteorShowers* getMeteorShowers() { return m_meteorShowers; }
92 
94  void setEnablePlugin(const bool& b);
95  bool getEnablePlugin() { return m_enablePlugin; }
96 
98  QFont getFont() { return m_font; }
99 
101  void setUrl(const QString& url);
102  QString getUrl() { return m_url; }
103 
105  void setLastUpdate(const QDateTime& datetime);
106  QDateTime getLastUpdate() { return m_lastUpdate; }
107 
109  void setStatusOfLastUpdate(const int &downloadStatus);
110  DownloadStatus getStatusOfLastUpdate() { return m_statusOfLastUpdate; }
111 
113  QDateTime getNextUpdate();
114 
116  void repaint();
117 
118  //
119  // Methods defined in the StelModule class
120  //
121  virtual void init();
122  virtual void deinit();
123  virtual void update(double deltaTime);
124  virtual void draw(StelCore* core);
125  virtual double getCallOrder(StelModuleActionName actionName) const;
126  virtual bool configureGui(bool show=true);
127 
128 signals:
129  void downloadStatusChanged(DownloadStatus);
130  void enablePluginChanged(bool b);
131  void enableLabelsChanged(bool b);
132 
133 public slots:
136  void setEnableAtStartup(const bool& b);
139  bool getEnableAtStartup() { return m_enableAtStartup; }
140 
143  void setShowEnableButton(const bool& show);
146  bool getShowEnableButton() { return m_showEnableButton; }
147 
150  void setShowSearchButton(const bool& show);
153  bool getShowSearchButton() { return m_showSearchButton; }
154 
161  void setEnableMarker(const bool& b);
168  bool getEnableMarker() { return m_enableMarker; }
169 
176  void setActiveRadiantOnly(const bool& b);
183  bool getActiveRadiantOnly() { return m_activeRadiantOnly; }
184 
191  void setEnableLabels(const bool& b);
198  bool getEnableLabels() { return m_enableLabels; }
199 
206  void setFontSize(int pixelSize);
213  int getFontSize() { return m_font.pixelSize(); }
214 
217  void setUpdateFrequencyHours(const int& hours);
220  int getUpdateFrequencyHours() { return m_updateFrequencyHours; }
221 
224  void setEnableAutoUpdates(const bool& b);
227  bool getEnableAutoUpdates() { return m_enableAutoUpdates; }
228 
234  void setColorARG(const Vec3f& rgb);
240  Vec3f getColorARG() { return m_colorARG; }
241 
247  void setColorARC(const Vec3f& rgb);
253  Vec3f getColorARC() { return m_colorARC; }
254 
260  void setColorIR(const Vec3f& rgb);
266  Vec3f getColorIR() { return m_colorIR; }
267 
269  void updateCatalog();
270 
272  void restoreDefaultSettings();
273 
275  void displayMessage(const QString& message, const QString hexColor="#999999");
276  void messageTimeout();
277 
278 private slots:
279  void checkForUpdates();
280  void updateFinished(QNetworkReply* reply);
281  void locationChanged(StelLocation location);
282 
283 private:
284  MeteorShowers* m_meteorShowers;
285  MSConfigDialog* m_configDialog;
286  MSSearchDialog* m_searchDialog;
287 
288  QFont m_font;
289  QSettings* m_conf;
290  QString m_catalogPath;
291 
292  bool m_onEarth;
293  bool m_enablePlugin;
294  bool m_activeRadiantOnly;
295  bool m_enableAtStartup;
296  bool m_enableLabels;
297  bool m_enableMarker;
298  bool m_showEnableButton;
299  bool m_showSearchButton;
300 
301  Vec3f m_colorARG;
302  Vec3f m_colorARC;
303  Vec3f m_colorIR;
304 
305  QTimer* m_messageTimer;
306  QList<int> m_messageIDs;
307 
308  StelTextureSP m_bolideTexture;
309  StelTextureSP m_pointerTexture;
310  StelTextureSP m_radiantTexture;
311 
312  bool m_isUpdating;
313  bool m_enableAutoUpdates;
314  int m_updateFrequencyHours;
315  QString m_url;
316  QDateTime m_lastUpdate;
317  DownloadStatus m_statusOfLastUpdate;
318  QNetworkAccessManager* m_downloadMgr;
319  class StelProgressController* m_progressBar;
320 
321  void createActions();
322  void loadConfig();
323  void loadTextures();
324  bool loadCatalog(const QString& jsonPath);
325 
328  void actionEnablePlugin(const bool& b) { if (m_enablePlugin != b) { m_enablePlugin = b; emit enablePluginChanged(b);} }
329 };
330 
331 #include <QObject>
332 #include "StelPluginInterface.hpp"
333 
336 {
337  Q_OBJECT
338  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
339  Q_INTERFACES(StelPluginInterface)
340 public:
341  virtual StelModule* getStelModule() const;
342  virtual StelPluginInfo getPluginInfo() const;
343  virtual QObjectList getExtensionList() const { return QObjectList(); }
344 };
345 
346 #endif /*METEORSHOWERSMGR_HPP_*/
void setColorARG(const Vec3f &rgb)
Set the color of the active radiant based on generic data.
StelTextureSP getBolideTexture()
Gets the bolide texture.
QFont getFont()
Get the font.
void setShowEnableButton(const bool &show)
Show/hide the button that enable/disable the meteor showers plugin.
bool getEnableAutoUpdates()
Enable/disable catalog updates from the internet.
bool getActiveRadiantOnly()
True if user wants to see the active radiants only.
Store the informations for a location on a planet.
void setEnableAutoUpdates(const bool &b)
Enable/disable automatic catalog updates from the internet.
void setLastUpdate(const QDateTime &datetime)
Set the date and time of last update.
void setColorARC(const Vec3f &rgb)
Set the color of the active radiant based on confirmed data.
void displayMessage(const QString &message, const QString hexColor="#999999")
Display a message. This is used for plugin-specific warnings and such.
Define the interface to implement when creating a plugin.
void restoreDefaultSettings()
Restore default settings.
StelTextureSP getPointerTexture()
Gets the pointer texture.
void setFontSize(int pixelSize)
Set the font size (used on radiant labels).
void setUrl(const QString &url)
Set the URL for downloading the meteor showers catalog.
This class manages a collection of MeteorShower objects.
Main class for Stellarium core processing.
Definition: StelCore.hpp:48
This class is used by Qt to manage a plug-in interface.
void setEnableMarker(const bool &b)
Enable/disable radiant marker.
bool getShowEnableButton()
Get the status of the enable button on the toolbar.
bool getShowSearchButton()
Get the status of the search button on the toolbar.
void setEnableLabels(const bool &b)
Enable/disable radiant labels.
virtual bool configureGui(bool show=true)
Detect or show the configuration GUI elements for the module.
Main class of the Meteor Showers plugin, inherits from StelModule.
bool getEnableLabels()
Enable/disable radiant labels.
void setActiveRadiantOnly(const bool &b)
True if user wants to see the active radiants only.
void setEnablePlugin(const bool &b)
Enable/disable the meteor showers plugin.
bool restoreDefaultCatalog(const QString &destination)
Restore default catalog.
StelTextureSP getRadiantTexture()
Gets the radiant texture.
void setShowSearchButton(const bool &show)
Show/hide the button that opens the search dialog.
virtual void init()
Initialize itself.
virtual void deinit()
Called before the module will be delete, and before the openGL context is suppressed.
MeteorShowersMgr()
Constructor.
void setStatusOfLastUpdate(const int &downloadStatus)
Set the status of the last update.
void setUpdateFrequencyHours(const int &hours)
Set the update frequency in hours.
Configuration window.
StelModuleActionName
Define the possible action for which an order is defined.
Definition: StelModule.hpp:121
Maintain the state of a progress bar.
MeteorShowers * getMeteorShowers()
Gets the MeteorShowers instance.
void repaint()
It&#39;s useful to force the update() and draw().
void updateCatalog()
Download the Meteor Showers catalog from the Internet.
QSharedPointer< StelTexture > StelTextureSP
Use shared pointer to simplify memory managment.
virtual ~MeteorShowersMgr()
Destructor.
virtual double getCallOrder(StelModuleActionName actionName) const
Return the value defining the order of call for the given action For example if stars.callOrder[ActionDraw] == 10 and constellation.callOrder[ActionDraw] == 11, the stars module will be drawn before the constellations.
virtual void draw(StelCore *core)
Execute all the drawing functions for this module.
void setEnableAtStartup(const bool &b)
Enable the meteor showers plugin at Stellarium startup.
bool getEnableAtStartup()
True if the plugin is enabled at Stellarium startup.
int getUpdateFrequencyHours()
Gets the update frequency in hours.
QDateTime getNextUpdate()
Gets the date of the next update.
This is the common base class for all the main components of stellarium.
Definition: StelModule.hpp:49
bool getEnableMarker()
Enable/disable radiant marker.
virtual void update(double deltaTime)
Update the module with respect to the time.
int getFontSize()
Set the font size (used on radiant labels).
virtual QObjectList getExtensionList() const
A mechanism to provide abitrary QObjects to the StelModuleMgr.
Contains information about a Stellarium plugin.
void setColorIR(const Vec3f &rgb)
Set the color of the inactive radiant.