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