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