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  std::chrono::seconds scriptTimeout {DEFAULT_SCRIPT_TIMEOUT};
29  std::chrono::seconds updateTimeout {DEFAULT_UPDATE_TIMEOUT};
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,
43  std::chrono::seconds &updateTimeout,
44  std::chrono::seconds &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 
63  std::chrono::seconds getScriptTimeout() { return m_info->scriptTimeout; }
64  void setScriptTimeout(std::chrono::seconds timeout) { m_info->scriptTimeout = timeout; }
65 
66  std::chrono::seconds getUpdateTimeout() { return m_info->updateTimeout; }
67  void setUpdateTimeout(std::chrono::seconds timeout) { m_info->updateTimeout = timeout; }
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);
85  void processExit();
86  void updateTimeout();
87 
88  private:
89  void processData();
90 
91  bool m_ready {false};
92  bool m_inuse {false};
93  ScriptInfo *m_info {nullptr};
94  MythSystemLegacy *m_ms {nullptr};
95  QString m_dir;
96  QString m_locale;
97  QString m_cachefile;
98  QByteArray m_buffer;
100  QTimer *m_updateTimer {nullptr};
101  int m_connectCnt {0};
103 };
104 
105 #endif /* WEATHER_SOURCE_H */
WeatherSource::m_cachefile
QString m_cachefile
Definition: weatherSource.h:97
WeatherSource::inUse
bool inUse() const
Definition: weatherSource.h:72
ScriptInfo::types
QStringList types
Definition: weatherSource.h:25
DEFAULT_SCRIPT_TIMEOUT
static constexpr std::chrono::seconds DEFAULT_SCRIPT_TIMEOUT
Definition: weatherUtils.h:20
WeatherSource::ProbeTypes
static QStringList ProbeTypes(const QString &workingDirectory, const QString &program)
Definition: weatherSource.cpp:26
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:91
ScriptInfo::version
QString version
Definition: weatherSource.h:22
WeatherSource::getEmail
QString getEmail()
Definition: weatherSource.h:54
MythSystemLegacy
Definition: mythsystemlegacy.h:67
WeatherSource::getVersion
QString getVersion()
Definition: weatherSource.h:51
DEFAULT_UPDATE_TIMEOUT
static constexpr std::chrono::minutes DEFAULT_UPDATE_TIMEOUT
Definition: weatherUtils.h:19
ScriptInfo::author
QString author
Definition: weatherSource.h:23
ScriptInfo::program
QString program
Definition: weatherSource.h:26
WeatherSource::getUpdateTimeout
std::chrono::seconds getUpdateTimeout()
Definition: weatherSource.h:66
WeatherSource::m_info
ScriptInfo * m_info
Definition: weatherSource.h:93
WeatherSource::setUnits
void setUnits(units_t units)
Definition: weatherSource.h:56
WeatherSource::m_ms
MythSystemLegacy * m_ms
Definition: weatherSource.h:94
WeatherSource::m_data
DataMap m_data
Definition: weatherSource.h:102
WeatherSource::disconnectScreen
void disconnectScreen(WeatherScreen *ws)
Definition: weatherSource.cpp:370
WeatherSource::m_connectCnt
int m_connectCnt
Definition: weatherSource.h:101
WeatherSource::startUpdateTimer
void startUpdateTimer()
Definition: weatherSource.h:69
WeatherSource
Definition: weatherSource.h:33
WeatherSource::setUpdateTimeout
void setUpdateTimeout(std::chrono::seconds timeout)
Definition: weatherSource.h:67
mythsystemlegacy.h
WeatherSource::getAuthor
QString getAuthor()
Definition: weatherSource.h:53
WeatherSource::m_locale
QString m_locale
Definition: weatherSource.h:96
WeatherSource::ProbeInfo
static bool ProbeInfo(ScriptInfo &scriptInfo)
Definition: weatherSource.cpp:133
WeatherSource::processData
void processData()
Definition: weatherSource.cpp:567
WeatherSource::m_buffer
QByteArray m_buffer
Definition: weatherSource.h:98
DataMap
QMap< QString, QString > DataMap
Definition: weatherUtils.h:25
WeatherSource::newData
void newData(QString, units_t, DataMap)
WeatherSource::processExit
void processExit()
Definition: weatherSource.cpp:562
SI_UNITS
#define SI_UNITS
Definition: weatherUtils.h:17
WeatherSource::setScriptTimeout
void setScriptTimeout(std::chrono::seconds timeout)
Definition: weatherSource.h:64
WeatherSource::updateTimeout
void updateTimeout()
Definition: weatherSource.cpp:494
WeatherSource::getUnits
units_t getUnits() const
Definition: weatherSource.h:55
WeatherSource::ProbeTimeouts
static bool ProbeTimeouts(const QString &workingDirectory, const QString &program, std::chrono::seconds &updateTimeout, std::chrono::seconds &scriptTimeout)
Definition: weatherSource.cpp:65
WeatherSource::m_updateTimer
QTimer * m_updateTimer
Definition: weatherSource.h:100
WeatherSource::getScriptTimeout
std::chrono::seconds getScriptTimeout()
Definition: weatherSource.h:63
WeatherScreen
Weather screen.
Definition: weatherScreen.h:26
uint
unsigned int uint
Definition: compat.h:144
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:327
units_t
unsigned char units_t
Definition: weatherUtils.h:24
WeatherSource::getLocale
QString getLocale()
Definition: weatherSource.h:59
WeatherSource::m_dir
QString m_dir
Definition: weatherSource.h:95
WeatherSource::isReady
bool isReady() const
Definition: weatherSource.h:50
ScriptInfo::scriptTimeout
std::chrono::seconds scriptTimeout
Definition: weatherSource.h:28
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:99
WeatherSource::m_inuse
bool m_inuse
Definition: weatherSource.h:92
WeatherSource::setLocale
void setLocale(const QString &locale)
Definition: weatherSource.h:58
WeatherSource::startUpdate
void startUpdate(bool forceUpdate=false)
Definition: weatherSource.cpp:416
ScriptInfo::updateTimeout
std::chrono::seconds updateTimeout
Definition: weatherSource.h:29
WeatherSource::connectScreen
void connectScreen(WeatherScreen *ws)
Definition: weatherSource.cpp:358
ScriptInfo::name
QString name
Definition: weatherSource.h:21
WeatherSource::ProbeScript
static ScriptInfo * ProbeScript(const QFileInfo &fi)
Definition: weatherSource.cpp:198
WeatherSource::~WeatherSource
~WeatherSource() override
Definition: weatherSource.cpp:347
ScriptInfo
Definition: serverSideScripting.h:36
ScriptInfo::path
QString path
Definition: weatherSource.h:27
WeatherSource::setInUse
void setInUse(bool inuse)
Definition: weatherSource.h:73
WeatherSource::getName
QString getName()
Definition: weatherSource.h:52
WeatherSource::getLocationList
QStringList getLocationList(const QString &str)
Definition: weatherSource.cpp:376
weatherUtils.h
ScriptInfo::id
int id
Definition: weatherSource.h:30