00001 #ifndef __WEATHER_SOURCE_H__ 00002 #define __WEATHER_SOURCE_H__ 00003 00004 #include <QStringList> 00005 #include <QObject> 00006 #include <QTimer> 00007 #include <QFileInfo> 00008 #include "mythsystem.h" 00009 00010 // MythWeather headers 00011 #include "weatherUtils.h" 00012 00013 class WeatherScreen; 00014 00015 /* 00016 * Instance independent information about a script 00017 */ 00018 class ScriptInfo 00019 { 00020 public: 00021 QString name; 00022 QString version; 00023 QString author; 00024 QString email; 00025 QStringList types; 00026 QString program; 00027 QString path; 00028 unsigned int scriptTimeout; 00029 unsigned int updateTimeout; 00030 int id; 00031 }; 00032 00033 class WeatherSource : public QObject 00034 { 00035 Q_OBJECT 00036 00037 public: 00038 static ScriptInfo *ProbeScript(const QFileInfo &fi); 00039 static QStringList ProbeTypes(QString workingDirectory, 00040 QString program); 00041 static bool ProbeTimeouts(QString workingDirectory, 00042 QString program, 00043 uint &updateTimeout, 00044 uint &scriptTimeout); 00045 static bool ProbeInfo(struct ScriptInfo &scriptInfo); 00046 00047 WeatherSource(ScriptInfo *info); 00048 ~WeatherSource(); 00049 00050 bool isReady() { return m_ready; } 00051 QString getVersion() { return m_info->version; } 00052 QString getName() { return m_info->name; } 00053 QString getAuthor() { return m_info->author; } 00054 QString getEmail() { return m_info->email; } 00055 units_t getUnits() { return m_units; } 00056 void setUnits(units_t units) { m_units = units; } 00057 QStringList getLocationList(const QString &str); 00058 void setLocale(const QString &locale) { m_locale = locale; } 00059 QString getLocale() { return m_locale; } 00060 00061 void startUpdate(bool forceUpdate = false); 00062 00063 int getScriptTimeout() { return m_info->scriptTimeout; } 00064 void setScriptTimeout(int timeout) { m_info->scriptTimeout = timeout; } 00065 00066 int getUpdateTimeout() { return m_info->updateTimeout; } 00067 void setUpdateTimeout(int timeout) { m_info->updateTimeout = timeout; } 00068 00069 void startUpdateTimer() { m_updateTimer->start(m_info->updateTimeout); } 00070 void stopUpdateTimer() { m_updateTimer->stop(); } 00071 00072 bool inUse() { return m_inuse; } 00073 void setInUse(bool inuse) { m_inuse = inuse; } 00074 00075 int getId() { return m_info->id; } 00076 00077 void connectScreen(WeatherScreen *ws); 00078 void disconnectScreen(WeatherScreen *ws); 00079 00080 signals: 00081 void newData(QString, units_t, DataMap); 00082 00083 private slots: 00084 void processExit(uint status = 0); 00085 void updateTimeout(); 00086 00087 private: 00088 void processData(); 00089 00090 bool m_ready; 00091 bool m_inuse; 00092 ScriptInfo *m_info; 00093 MythSystem *m_ms; 00094 QString m_dir; 00095 QString m_locale; 00096 QString m_cachefile; 00097 QByteArray m_buffer; 00098 units_t m_units; 00099 QTimer *m_updateTimer; 00100 int m_connectCnt; 00101 DataMap m_data; 00102 }; 00103 00104 #endif
1.6.3