Move implementation out of header
[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         Red,
48         Yellow,
49         Green
50     };
51
52 private:
53     float _level_raw;
54     int _level;
55     light_color _color;
56     int _tend;
57     QString _hint;
58
59 public:
60     ExtendedTrafficInfo ()
61         : TrafficInfo ()
62     {};
63
64     ExtendedTrafficInfo (const QDomElement& elem) throw (const QString&);
65
66     int level () const
67     { return _level; };
68
69     int tend () const
70     { return _tend; };
71
72     QString hint () const
73     { return _hint; };
74 };
75
76
77 class Traffic : public QObject
78 {
79     Q_OBJECT
80
81 private:
82     QDateTime _ts;
83
84     QMap<QString, TrafficInfo> _info;
85     QMap<QString, ExtendedTrafficInfo> _ext_info;
86
87     HttpFetcher _fetcher;
88
89     bool parse_traffic_data (const QString& xml);
90
91 private slots:
92     void fetchDone (const QByteArray& data);
93
94 signals:
95     void updated ();
96
97 public:
98     Traffic ();
99
100     void update ();
101
102     QDateTime ts () const
103     { return _ts; };
104
105     TrafficInfo lookup (const QString &id) const;
106     ExtendedTrafficInfo lookup_ext (const QString &id) const;
107 };
108
109
110 #endif // __TRAFFIC_H__