MythTV  master
weatherSource.h
Go to the documentation of this file.
1 #ifndef __WEATHER_SOURCE_H__
2 #define __WEATHER_SOURCE_H__
3 
4 #include <QStringList>
5 #include <QObject>
6 #include <QTimer>
7 #include <QFileInfo>
8 #include "mythsystemlegacy.h"
9 
10 // MythWeather headers
11 #include "weatherUtils.h"
12 
13 class WeatherScreen;
14 
15 /*
16  * Instance independent information about a script
17  */
18 class ScriptInfo
19 {
20  public:
21  QString name;
22  QString version;
23  QString author;
24  QString email;
25  QStringList types;
26  QString program;
27  QString path;
28  unsigned int scriptTimeout;
29  unsigned int updateTimeout;
30  int id;
31 };
32 
33 class WeatherSource : public QObject
34 {
35  Q_OBJECT
36 
37  public:
38  static ScriptInfo *ProbeScript(const QFileInfo &fi);
39  static QStringList ProbeTypes(const QString& workingDirectory,
40  const QString& program);
41  static bool ProbeTimeouts(const QString& workingDirectory,
42  const QString& program,
44  uint &scriptTimeout);
45  static bool ProbeInfo(ScriptInfo &scriptInfo);
46 
47  explicit WeatherSource(ScriptInfo *info);
49 
50  bool isReady() { return m_ready; }
51  QString getVersion() { return m_info->version; }
52  QString getName() { return m_info->name; }
53  QString getAuthor() { return m_info->author; }
54  QString getEmail() { return m_info->email; }
55  units_t getUnits() { return m_units; }
56  void setUnits(units_t units) { m_units = units; }
57  QStringList getLocationList(const QString &str);
58  void setLocale(const QString &locale) { m_locale = locale; }
59  QString getLocale() { return m_locale; }
60 
61  void startUpdate(bool forceUpdate = false);
62 
65 
68 
70  void stopUpdateTimer() { m_updateTimer->stop(); }
71 
72  bool inUse() { return m_inuse; }
73  void setInUse(bool inuse) { m_inuse = inuse; }
74 
75  int getId() { return m_info->id; }
76 
77  void connectScreen(WeatherScreen *ws);
79 
80  signals:
81  void newData(QString, units_t, DataMap);
82 
83  private slots:
84  void processExit(uint status = 0);
85  void updateTimeout();
86 
87  private:
88  void processData();
89 
90  bool m_ready {false};
91  bool m_inuse {false};
92  ScriptInfo *m_info {nullptr};
93  MythSystemLegacy *m_ms {nullptr};
94  QString m_dir;
95  QString m_locale;
96  QString m_cachefile;
97  QByteArray m_buffer;
99  QTimer *m_updateTimer {nullptr};
100  int m_connectCnt {0};
102 };
103 
104 #endif
void connectScreen(WeatherScreen *ws)
unsigned int slots[4]
Definition: element.c:38
static QStringList ProbeTypes(const QString &workingDirectory, const QString &program)
static ScriptInfo * ProbeScript(const QFileInfo &fi)
QString name
Definition: weatherSource.h:21
QString m_locale
Definition: weatherSource.h:95
MythSystemLegacy * m_ms
Definition: weatherSource.h:93
void disconnectScreen(WeatherScreen *ws)
units_t m_units
Definition: weatherSource.h:98
QStringList types
Definition: weatherSource.h:25
void setInUse(bool inuse)
Definition: weatherSource.h:73
QString path
Definition: weatherSource.h:27
QTimer * m_updateTimer
Definition: weatherSource.h:99
QString version
Definition: weatherSource.h:22
static bool ProbeInfo(ScriptInfo &scriptInfo)
QString getLocale()
Definition: weatherSource.h:59
static bool ProbeTimeouts(const QString &workingDirectory, const QString &program, uint &updateTimeout, uint &scriptTimeout)
void newData(QString, units_t, DataMap)
void setScriptTimeout(int timeout)
Definition: weatherSource.h:64
void processExit(uint status=0)
QStringList getLocationList(const QString &str)
unsigned int uint
Definition: compat.h:140
ScriptInfo * m_info
Definition: weatherSource.h:92
QByteArray m_buffer
Definition: weatherSource.h:97
int getUpdateTimeout()
Definition: weatherSource.h:66
QString getVersion()
Definition: weatherSource.h:51
void setUnits(units_t units)
Definition: weatherSource.h:56
int getScriptTimeout()
Definition: weatherSource.h:63
QString getName()
Definition: weatherSource.h:52
unsigned char units_t
Definition: weatherUtils.h:22
QMap< QString, QString > DataMap
Definition: weatherUtils.h:23
QString getEmail()
Definition: weatherSource.h:54
void startUpdate(bool forceUpdate=false)
units_t getUnits()
Definition: weatherSource.h:55
QString getAuthor()
Definition: weatherSource.h:53
QString author
Definition: weatherSource.h:23
WeatherSource(ScriptInfo *info)
void setUpdateTimeout(int timeout)
Definition: weatherSource.h:67
Weather screen.
Definition: weatherScreen.h:26
void startUpdateTimer()
Definition: weatherSource.h:69
#define SI_UNITS
Definition: weatherUtils.h:15
QString program
Definition: weatherSource.h:26
unsigned int scriptTimeout
Definition: weatherSource.h:28
QString m_cachefile
Definition: weatherSource.h:96
void setLocale(const QString &locale)
Definition: weatherSource.h:58
QString email
Definition: weatherSource.h:24
unsigned int updateTimeout
Definition: weatherSource.h:29
void stopUpdateTimer()
Definition: weatherSource.h:70