Stellarium 0.14.3
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 "StelObjectModule.hpp"
27 
28 #define MS_CATALOG_VERSION 1
29 #define MS_CONFIG_PREFIX QString("MeteorShowers")
30 
31 class MeteorShowers;
32 class MSConfigDialog;
33 class MSSearchDialog;
34 
53 {
54  Q_OBJECT
55  Q_PROPERTY(bool enablePlugin READ getEnablePlugin WRITE actionEnablePlugin)
56  Q_PROPERTY(bool enableLabels READ getEnableLabels WRITE setEnableLabels)
57 
58 public:
60  enum DownloadStatus {
61  OUTDATED,
62  UPDATING,
63  UPDATED,
64  FAILED
65  };
66 
69 
71  virtual ~MeteorShowersMgr();
72 
74  bool restoreDefaultCatalog(const QString& destination);
75 
78  StelTextureSP getBolideTexture() { return m_bolideTexture; }
79 
82  StelTextureSP getPointerTexture() { return m_pointerTexture; }
83 
86  StelTextureSP getRadiantTexture() { return m_radiantTexture; }
87 
90  MeteorShowers* getMeteorShowers() { return m_meteorShowers; }
91 
93  void setEnablePlugin(const bool& b);
94  bool getEnablePlugin() { return m_enablePlugin; }
95 
97  bool getActiveRadiantOnly() { return m_activeRadiantOnly; }
98 
101  bool getShowEnableButton() { return m_showEnableButton; }
102 
105  bool getShowSearchButton() { return m_showSearchButton; }
106 
108  void setColorARG(const Vec3f& rgb);
109  Vec3f getColorARG() { return m_colorARG; }
110 
112  void setColorARC(const Vec3f& rgb);
113  Vec3f getColorARC() { return m_colorARC; }
114 
116  void setColorIR(const Vec3f& rgb);
117  Vec3f getColorIR() { return m_colorIR; }
118 
120  bool getEnableAtStartup() { return m_enableAtStartup; }
121 
123  int getFontSize() { return m_font.pixelSize(); }
124 
126  QFont getFont() { return m_font; }
127 
129  bool getEnableLabels() { return m_enableLabels; }
130 
132  bool getEnableMarker() { return m_enableMarker; }
133 
135  int getUpdateFrequencyHours() { return m_updateFrequencyHours; }
136 
138  bool getEnableAutoUpdates() { return m_enableAutoUpdates; }
139 
141  void setUrl(const QString& url);
142  QString getUrl() { return m_url; }
143 
145  void setLastUpdate(const QDateTime& datetime);
146  QDateTime getLastUpdate() { return m_lastUpdate; }
147 
149  void setStatusOfLastUpdate(const int &downloadStatus);
150  DownloadStatus getStatusOfLastUpdate() { return m_statusOfLastUpdate; }
151 
153  QDateTime getNextUpdate();
154 
156  void repaint();
157 
158  //
159  // Methods defined in the StelModule class
160  //
161  virtual void init();
162  virtual void deinit();
163  virtual void update(double deltaTime);
164  virtual void draw(StelCore* core);
165  virtual double getCallOrder(StelModuleActionName actionName) const;
166  virtual bool configureGui(bool show=true);
167 
168  //
169  // Methods defined in StelObjectModule class
170  //
171  virtual QList<StelObjectP> searchAround(const Vec3d&, double, const StelCore*) const { return QList<StelObjectP>(); }
172  virtual StelObjectP searchByNameI18n(const QString&) const { return StelObjectP(); }
173  virtual StelObjectP searchByName(const QString&) const { return StelObjectP(); }
174  virtual QStringList listMatchingObjectsI18n(const QString&, int, bool) const { return QStringList(); }
175  virtual QStringList listMatchingObjects(const QString&, int, bool) const { return QStringList(); }
176  virtual QStringList listAllObjects(bool) const { return QStringList(); }
177  virtual QStringList listAllObjectsByType(const QString&, bool) const { return QStringList(); }
178  virtual QString getName() const { return QString(); }
179 
180 signals:
181  void downloadStatusChanged(DownloadStatus);
182 
183 public slots:
185  void setEnableAtStartup(const bool& b);
186 
188  void setShowEnableButton(const bool& show);
189 
191  void setShowSearchButton(const bool& show);
192 
194  void setEnableMarker(const bool& b);
195 
197  void setActiveRadiantOnly(const bool& b);
198 
200  void setEnableLabels(const bool& b);
201 
203  void setFontSize(int pixelSize);
204 
206  void setUpdateFrequencyHours(const int& hours);
207 
209  void setEnableAutoUpdates(const bool& b);
210 
212  void updateCatalog();
213 
215  void restoreDefaultSettings();
216 
218  void displayMessage(const QString& message, const QString hexColor="#999999");
219  void messageTimeout();
220 
221 private slots:
222  void checkForUpdates();
223  void updateFinished(QNetworkReply* reply);
224  void locationChanged(StelLocation location);
225 
226 private:
227  MeteorShowers* m_meteorShowers;
228  MSConfigDialog* m_configDialog;
229  MSSearchDialog* m_searchDialog;
230 
231  QFont m_font;
232  QSettings* m_conf;
233  QString m_catalogPath;
234 
235  bool m_onEarth;
236  bool m_enablePlugin;
237  bool m_activeRadiantOnly;
238  bool m_enableAtStartup;
239  bool m_enableLabels;
240  bool m_enableMarker;
241  bool m_showEnableButton;
242  bool m_showSearchButton;
243 
244  Vec3f m_colorARG;
245  Vec3f m_colorARC;
246  Vec3f m_colorIR;
247 
248  QTimer* m_messageTimer;
249  QList<int> m_messageIDs;
250 
251  StelTextureSP m_bolideTexture;
252  StelTextureSP m_pointerTexture;
253  StelTextureSP m_radiantTexture;
254 
255  bool m_isUpdating;
256  bool m_enableAutoUpdates;
257  int m_updateFrequencyHours;
258  QString m_url;
259  QDateTime m_lastUpdate;
260  DownloadStatus m_statusOfLastUpdate;
261  QNetworkAccessManager* m_downloadMgr;
262  class StelProgressController* m_progressBar;
263 
264  void createActions();
265  void loadConfig();
266  void loadTextures();
267  bool loadCatalog(const QString& jsonPath);
268 
271  void actionEnablePlugin(const bool& b) { m_enablePlugin = b; }
272 };
273 
274 #include <QObject>
275 #include "StelPluginInterface.hpp"
276 
279 {
280  Q_OBJECT
281  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
282  Q_INTERFACES(StelPluginInterface)
283 public:
284  virtual StelModule* getStelModule() const;
285  virtual StelPluginInfo getPluginInfo() const;
286 };
287 
288 #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.
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.
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.
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.
Main class of the Meteor Showers plugin, inherits from StelObjectModule.
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.
virtual StelPluginInfo getPluginInfo() const =0
StelTextureSP getRadiantTexture()
Gets the radiant texture.
void setShowSearchButton(const bool &show)
Show/hide the button that opens the search dialog.
MeteorShowersMgr()
Constructor.
virtual class StelModule * getStelModule() const =0
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.
MeteorShowers * getMeteorShowers()
Gets the MeteorShowers instance.
void repaint()
It's useful to force the update() and draw().
void updateCatalog()
Download the Meteor Showers catalog from the Internet.
QSharedPointer< StelTexture > StelTextureSP
virtual ~MeteorShowersMgr()
Destructor.
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.
bool getEnableMarker()
Enable/disable radiant marker.
int getFontSize()
Set the font size (used on radiant labels).
void setColorIR(const Vec3f &rgb)
Set the color of the inactive radiant.