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;
30  int id {0};
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);
48  ~WeatherSource() override;
49 
50  bool isReady() const { 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() const { 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() const { 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 /* WEATHER_SOURCE_H */
WeatherSource::m_cachefile
QString m_cachefile
Definition: weatherSource.h:96
WeatherSource::inUse
bool inUse() const
Definition: weatherSource.h:72
WeatherSource::setScriptTimeout
void setScriptTimeout(int timeout)
Definition: weatherSource.h:64
ScriptInfo::types
QStringList types
Definition: weatherSource.h:25
WeatherSource::ProbeTypes
static QStringList ProbeTypes(const QString &workingDirectory, const QString &program)
Definition: weatherSource.cpp:22
WeatherSource::stopUpdateTimer
void stopUpdateTimer()
Definition: weatherSource.h:70
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:103
WeatherSource::m_ready
bool m_ready
Definition: weatherSource.h:90
ScriptInfo::version
QString version
Definition: weatherSource.h:22
WeatherSource::getEmail
QString getEmail()
Definition: weatherSource.h:54
MythSystemLegacy
Definition: mythsystemlegacy.h:68
WeatherSource::getVersion
QString getVersion()
Definition: weatherSource.h:51
DEFAULT_UPDATE_TIMEOUT
#define DEFAULT_UPDATE_TIMEOUT
Definition: weatherUtils.h:19
ScriptInfo::author
QString author
Definition: weatherSource.h:23
ScriptInfo::program
QString program
Definition: weatherSource.h:26
WeatherSource::m_info
ScriptInfo * m_info
Definition: weatherSource.h:92
WeatherSource::setUnits
void setUnits(units_t units)
Definition: weatherSource.h:56
WeatherSource::m_ms
MythSystemLegacy * m_ms
Definition: weatherSource.h:93
WeatherSource::m_data
DataMap m_data
Definition: weatherSource.h:101
slots
unsigned int slots[4]
Definition: element.cpp:38
WeatherSource::disconnectScreen
void disconnectScreen(WeatherScreen *ws)
Definition: weatherSource.cpp:368
WeatherSource::m_connectCnt
int m_connectCnt
Definition: weatherSource.h:100
WeatherSource::startUpdateTimer
void startUpdateTimer()
Definition: weatherSource.h:69
WeatherSource
Definition: weatherSource.h:33
ScriptInfo::scriptTimeout
unsigned int scriptTimeout
Definition: weatherSource.h:28
mythsystemlegacy.h
WeatherSource::getAuthor
QString getAuthor()
Definition: weatherSource.h:53
WeatherSource::m_locale
QString m_locale
Definition: weatherSource.h:95
WeatherSource::ProbeInfo
static bool ProbeInfo(ScriptInfo &scriptInfo)
Definition: weatherSource.cpp:129
WeatherSource::processData
void processData()
Definition: weatherSource.cpp:562
WeatherSource::m_buffer
QByteArray m_buffer
Definition: weatherSource.h:97
DataMap
QMap< QString, QString > DataMap
Definition: weatherUtils.h:25
WeatherSource::newData
void newData(QString, units_t, DataMap)
SI_UNITS
#define SI_UNITS
Definition: weatherUtils.h:17
WeatherSource::updateTimeout
void updateTimeout()
Definition: weatherSource.cpp:494
WeatherSource::getUnits
units_t getUnits() const
Definition: weatherSource.h:55
WeatherSource::m_updateTimer
QTimer * m_updateTimer
Definition: weatherSource.h:99
WeatherScreen
Weather screen.
Definition: weatherScreen.h:26
uint
unsigned int uint
Definition: compat.h:140
WeatherSource::WeatherSource
WeatherSource(ScriptInfo *info)
Watch out, we store the parameter as a member variable, don't go deleting it, that wouldn't be good.
Definition: weatherSource.cpp:325
units_t
unsigned char units_t
Definition: weatherUtils.h:24
ScriptInfo::updateTimeout
unsigned int updateTimeout
Definition: weatherSource.h:29
WeatherSource::getLocale
QString getLocale()
Definition: weatherSource.h:59
WeatherSource::processExit
void processExit(uint status=0)
Definition: weatherSource.cpp:500
WeatherSource::getScriptTimeout
int getScriptTimeout()
Definition: weatherSource.h:63
WeatherSource::m_dir
QString m_dir
Definition: weatherSource.h:94
WeatherSource::isReady
bool isReady() const
Definition: weatherSource.h:50
DEFAULT_SCRIPT_TIMEOUT
#define DEFAULT_SCRIPT_TIMEOUT
Definition: weatherUtils.h:20
ScriptInfo::email
QString email
Definition: weatherSource.h:24
WeatherSource::getId
int getId()
Definition: weatherSource.h:75
WeatherSource::m_units
units_t m_units
Definition: weatherSource.h:98
WeatherSource::getUpdateTimeout
int getUpdateTimeout()
Definition: weatherSource.h:66
WeatherSource::m_inuse
bool m_inuse
Definition: weatherSource.h:91
WeatherSource::setLocale
void setLocale(const QString &locale)
Definition: weatherSource.h:58
WeatherSource::startUpdate
void startUpdate(bool forceUpdate=false)
Definition: weatherSource.cpp:418
WeatherSource::connectScreen
void connectScreen(WeatherScreen *ws)
Definition: weatherSource.cpp:356
ScriptInfo::name
QString name
Definition: weatherSource.h:21
WeatherSource::ProbeScript
static ScriptInfo * ProbeScript(const QFileInfo &fi)
Definition: weatherSource.cpp:194
WeatherSource::~WeatherSource
~WeatherSource() override
Definition: weatherSource.cpp:345
WeatherSource::ProbeTimeouts
static bool ProbeTimeouts(const QString &workingDirectory, const QString &program, uint &updateTimeout, uint &scriptTimeout)
Definition: weatherSource.cpp:61
ScriptInfo
Definition: serverSideScripting.h:36
ScriptInfo::path
QString path
Definition: weatherSource.h:27
WeatherSource::setInUse
void setInUse(bool inuse)
Definition: weatherSource.h:73
WeatherSource::setUpdateTimeout
void setUpdateTimeout(int timeout)
Definition: weatherSource.h:67
WeatherSource::getName
QString getName()
Definition: weatherSource.h:52
WeatherSource::getLocationList
QStringList getLocationList(const QString &str)
Definition: weatherSource.cpp:374
weatherUtils.h
ScriptInfo::id
int id
Definition: weatherSource.h:30