Fix typo
[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     QString localtime () const
42     { return _localtime; };
43
44     QDateTime ts () const
45     { return _ts; };
46
47     virtual void dump ();
48 };
49
50
51 class ExtendedTrafficInfo : public TrafficInfo
52 {
53 public:
54     enum light_color {
55         Unknown,
56         Red,
57         Yellow,
58         Green
59     };
60
61 private:
62     float _level_raw;
63     int _level;
64     light_color _color;
65     int _tend;
66     QString _hint;
67
68 public:
69     ExtendedTrafficInfo ()
70         : TrafficInfo ()
71     {};
72
73     ExtendedTrafficInfo (const QDomElement& elem) throw (const QString&);
74
75     int level () const
76     { return _level; };
77
78     int tend () const
79     { return _tend; };
80
81     QString hint () const
82     { return _hint; };
83
84     ExtendedTrafficInfo::light_color color () const
85     { return _color; };
86
87     virtual void dump ();
88 };
89
90
91 class Traffic : public QObject
92 {
93     Q_OBJECT
94
95 private:
96     QDateTime _ts;
97
98     QMap<QString, TrafficInfo> _info;
99     QMap<QString, ExtendedTrafficInfo> _ext_info;
100
101     HttpFetcher _fetcher;
102
103     bool parse_traffic_data (const QString& xml);
104
105 private slots:
106     void fetchDone (const QByteArray& data);
107
108 signals:
109     void updated ();
110
111 public:
112     Traffic ();
113
114     void update ();
115
116     QDateTime ts () const
117     { return _ts; };
118
119     TrafficInfo lookup (const QString &id) const;
120     ExtendedTrafficInfo lookup_ext (const QString &id) const;
121 };
122
123
124 #endif // __TRAFFIC_H__