Stellarium 0.15.2
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 
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  //
129  // Methods defined in StelObjectModule class
130  //
131  virtual QList<StelObjectP> searchAround(const Vec3d&, double, const StelCore*) const { return QList<StelObjectP>(); }
132  virtual StelObjectP searchByNameI18n(const QString&) const { return StelObjectP(); }
133  virtual StelObjectP searchByName(const QString&) const { return StelObjectP(); }
134  virtual QStringList listMatchingObjects(const QString&, int, bool, bool) const { return QStringList(); }
135  virtual QStringList listAllObjects(bool) const { return QStringList(); }
136  virtual QString getName() const { return QString(); }
137 
138 signals:
139  void downloadStatusChanged(DownloadStatus);
140  void enablePluginChanged(bool b);
141  void enableLabelsChanged(bool b);
142 
143 public slots:
146  void setEnableAtStartup(const bool& b);
149  bool getEnableAtStartup() { return m_enableAtStartup; }
150 
153  void setShowEnableButton(const bool& show);
156  bool getShowEnableButton() { return m_showEnableButton; }
157 
160  void setShowSearchButton(const bool& show);
163  bool getShowSearchButton() { return m_showSearchButton; }
164 
171  void setEnableMarker(const bool& b);
178  bool getEnableMarker() { return m_enableMarker; }
179 
186  void setActiveRadiantOnly(const bool& b);
193  bool getActiveRadiantOnly() { return m_activeRadiantOnly; }
194 
201  void setEnableLabels(const bool& b);
208  bool getEnableLabels() { return m_enableLabels; }
209 
216  void setFontSize(int pixelSize);
223  int getFontSize() { return m_font.pixelSize(); }
224 
227  void setUpdateFrequencyHours(const int& hours);
230  int getUpdateFrequencyHours() { return m_updateFrequencyHours; }
231 
234  void setEnableAutoUpdates(const bool& b);
237  bool getEnableAutoUpdates() { return m_enableAutoUpdates; }
238 
244  void setColorARG(const Vec3f& rgb);
250  Vec3f getColorARG() { return m_colorARG; }
251 
257  void setColorARC(const Vec3f& rgb);
263  Vec3f getColorARC() { return m_colorARC; }
264 
270  void setColorIR(const Vec3f& rgb);
276  Vec3f getColorIR() { return m_colorIR; }
277 
279  void updateCatalog();
280 
282  void restoreDefaultSettings();
283 
285  void displayMessage(const QString& message, const QString hexColor="#999999");
286  void messageTimeout();
287 
288 private slots:
289  void checkForUpdates();
290  void updateFinished(QNetworkReply* reply);
291  void locationChanged(StelLocation location);
292 
293 private:
294  MeteorShowers* m_meteorShowers;
295  MSConfigDialog* m_configDialog;
296  MSSearchDialog* m_searchDialog;
297 
298  QFont m_font;
299  QSettings* m_conf;
300  QString m_catalogPath;
301 
302  bool m_onEarth;
303  bool m_enablePlugin;
304  bool m_activeRadiantOnly;
305  bool m_enableAtStartup;
306  bool m_enableLabels;
307  bool m_enableMarker;
308  bool m_showEnableButton;
309  bool m_showSearchButton;
310 
311  Vec3f m_colorARG;
312  Vec3f m_colorARC;
313  Vec3f m_colorIR;
314 
315  QTimer* m_messageTimer;
316  QList<int> m_messageIDs;
317 
318  StelTextureSP m_bolideTexture;
319  StelTextureSP m_pointerTexture;
320  StelTextureSP m_radiantTexture;
321 
322  bool m_isUpdating;
323  bool m_enableAutoUpdates;
324  int m_updateFrequencyHours;
325  QString m_url;
326  QDateTime m_lastUpdate;
327  DownloadStatus m_statusOfLastUpdate;
328  QNetworkAccessManager* m_downloadMgr;
329  class StelProgressController* m_progressBar;
330 
331  void createActions();
332  void loadConfig();
333  void loadTextures();
334  bool loadCatalog(const QString& jsonPath);
335 
338  void actionEnablePlugin(const bool& b) { if (m_enablePlugin != b) { m_enablePlugin = b; emit enablePluginChanged(b);} }
339 };
340 
341 #include <QObject>
342 #include "StelPluginInterface.hpp"
343 
346 {
347  Q_OBJECT
348  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
349  Q_INTERFACES(StelPluginInterface)
350 public:
351  virtual StelModule* getStelModule() const;
352  virtual StelPluginInfo getPluginInfo() const;
353 };
354 
355 #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.
virtual StelObjectP searchByNameI18n(const QString &) const
Find a StelObject by name.
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.
virtual QStringList listAllObjects(bool) const
List all StelObjects.
void restoreDefaultSettings()
Restore default settings.
virtual StelObjectP searchByName(const QString &) const
Return the matching StelObject if exists or the empty StelObject if not found.
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 StelObjectModule.
Specialization of StelModule which manages a collection of StelObject.
QSharedPointerNoDelete< StelObject > StelObjectP
Intrusive pointer used to manage StelObject with smart pointers.
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.
virtual QStringList listMatchingObjects(const QString &, int, bool, bool) const
Find and return the list of at most maxNbItem objects auto-completing passed object name...
virtual QList< StelObjectP > searchAround(const Vec3d &, double, const StelCore *) const
Search for StelObject in an area around a specifid point.
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).
Contains information about a Stellarium plugin.
void setColorIR(const Vec3f &rgb)
Set the color of the inactive radiant.