X-Git-Url: http://git.maemo.org/git/?p=yandex-traffic;a=blobdiff_plain;f=traffic.hpp;h=03283b8e6e1ce86ca54bc805e239c3fa8e8bbe5a;hp=dbbfc56a4ca1c20241d630ebbcac5745397bddca;hb=HEAD;hpb=81ce7e9126d61a657712ce01594a3280dcf6c0ee diff --git a/traffic.hpp b/traffic.hpp index dbbfc56..03283b8 100644 --- a/traffic.hpp +++ b/traffic.hpp @@ -3,6 +3,7 @@ #include #include +#include #include "http_fetcher.hpp" @@ -16,8 +17,34 @@ private: QString _isotime; QString _localtime; + bool _valid; + +protected: + float getFloatNode (const QDomElement& elem, const char* node, float def); + int getIntNode (const QDomElement& elem, const char* node, int def); + QString getStringNode (const QDomElement& elem, const char* node) throw (const QString&); + QDateTime getTSNode (const QDomElement& elem, const char* node) throw (const QString&); + + void setValid (bool new_val) + { _valid = new_val; }; + public: - TrafficInfo (); + TrafficInfo () + : _valid (false) + {}; + + TrafficInfo (const QDomElement& elem) throw (const QString&); + + bool valid () const + { return _valid; }; + + QString localtime () const + { return _localtime; }; + + QDateTime ts () const + { return _ts; }; + + virtual void dump (); }; @@ -25,6 +52,7 @@ class ExtendedTrafficInfo : public TrafficInfo { public: enum light_color { + Unknown, Red, Yellow, Green @@ -32,13 +60,31 @@ public: private: float _level_raw; - quint8 _level; + int _level; light_color _color; - quint8 _tend; + int _tend; QString _hint; public: - ExtendedTrafficInfo (); + ExtendedTrafficInfo () + : TrafficInfo () + {}; + + ExtendedTrafficInfo (const QDomElement& elem) throw (const QString&); + + int level () const + { return _level; }; + + int tend () const + { return _tend; }; + + QString hint () const + { return _hint; }; + + ExtendedTrafficInfo::light_color color () const + { return _color; }; + + virtual void dump (); }; @@ -54,6 +100,8 @@ private: HttpFetcher _fetcher; + bool parse_traffic_data (const QString& xml); + private slots: void fetchDone (const QByteArray& data); @@ -64,6 +112,12 @@ public: Traffic (); void update (); + + QDateTime ts () const + { return _ts; }; + + TrafficInfo lookup (const QString &id) const; + ExtendedTrafficInfo lookup_ext (const QString &id) const; };