Add new color to ExtendedTrafficInformation -- Unknown.
[yandex-traffic] / traffic.hpp
1 #ifndef __TRAFFIC_H__
2 #define __TRAFFIC_H__
3
4 #include <QtCore>
5 #include <QtNetwork>
6 #include <QtXml>
7
8
9 #include "http_fetcher.hpp"
10
11 // Base data of traffic information
12 class TrafficInfo
13 {
14 private:
15     float _len1, _len2, _len;
16     QDateTime _ts;
17     QString _isotime;
18     QString _localtime;
19
20     bool _valid;
21
22 protected:
23     float getFloatNode (const QDomElement& elem, const char* node, float def);
24     int getIntNode (const QDomElement& elem, const char* node, int def);
25     QString getStringNode (const QDomElement& elem, const char* node) throw (const QString&);
26     QDateTime getTSNode (const QDomElement& elem, const char* node) throw (const QString&);
27
28     void setValid (bool new_val)
29     { _valid = new_val; };
30
31 public:
32     TrafficInfo ()
33         : _valid (false)
34     {};
35
36     TrafficInfo (const QDomElement& elem) throw (const QString&);
37
38     bool valid () const
39     { return _valid; };
40 };
41
42
43 class ExtendedTrafficInfo : public TrafficInfo
44 {
45 public:
46     enum light_color {
47         Unknown,
48         Red,
49         Yellow,
50         Green
51     };
52
53 private:
54     float _level_raw;
55     int _level;
56     light_color _color;
57     int _tend;
58     QString _hint;
59
60 public:
61     ExtendedTrafficInfo ()
62         : TrafficInfo ()
63     {};
64
65     ExtendedTrafficInfo (const QDomElement& elem) throw (const QString&);
66
67     int level () const
68     { return _level; };
69
70     int tend () const
71     { return _tend; };
72
73     QString hint () const
74     { return _hint; };
75 };
76
77
78 class Traffic : public QObject
79 {
80     Q_OBJECT
81
82 private:
83     QDateTime _ts;
84
85     QMap<QString, TrafficInfo> _info;
86     QMap<QString, ExtendedTrafficInfo> _ext_info;
87
88     HttpFetcher _fetcher;
89
90     bool parse_traffic_data (const QString& xml);
91
92 private slots:
93     void fetchDone (const QByteArray& data);
94
95 signals:
96     void updated ();
97
98 public:
99     Traffic ();
100
101     void update ();
102
103     QDateTime ts () const
104     { return _ts; };
105
106     TrafficInfo lookup (const QString &id) const;
107     ExtendedTrafficInfo lookup_ext (const QString &id) const;
108 };
109
110
111 #endif // __TRAFFIC_H__