setAttribute(Qt::WA_TranslucentBackground);
#endif
_light = new TrafficLight (this);
- _label = new QLabel (this);
+ _label = new QLabel (tr ("No data"), this);
_timer = new QTimer (this);
_label->setAlignment (Qt::AlignHCenter | Qt::AlignVCenter);
void MainWidget::trafficUpdated ()
{
- ExtendedTrafficInfo info = _traffic->lookup_ext (_settings->regionID ());
+ CityTrafficInfo info = _traffic->lookup_ext (_settings->regionID ());
if (info.valid ()) {
QString data;
if (_settings->check (Settings::C_ShowTime)) {
if (!first)
data.append (", ");
- data.append (info.localtime ());
+ data.append (info.ts ().toString ("h:mm"));
first = false;
}
}
else {
Log::instance ()->add ("trafficUpdated, but info not valid");
- _light->setColor (ExtendedTrafficInfo::Unknown);
+ _light->setColor (CityTrafficInfo::Unknown);
_label->setText (tr ("No data"));
}
}
// --------------------------------------------------
-// TrafficInfo
+// CityTrafficInfo
// --------------------------------------------------
-TrafficInfo::TrafficInfo (const QDomElement& elem) throw (const QString&)
+CityTrafficInfo::CityTrafficInfo (const QDomElement& elem) throw (const QString&)
+ : TrafficInfo ()
{
- _valid = false;
- _len1 = getFloatNode (elem, "length_1", 0);
- _len2 = getFloatNode (elem, "length_2", 0);
- _len = getFloatNode (elem, "length", 0);
+ QString color;
+
+ setValid (false);
_ts = getTSNode (elem, "timestamp");
- _isotime = getStringNode (elem, "isotime");
- _localtime = getStringNode (elem, "localtime");
- _valid = true;
+ _level = getIntNode (elem, "level", 1);
+ _tend = getIntNode (elem, "tend", 0);
+ _hint = getStringNode (elem, "hint");
+
+ color = getStringNode (elem, "icon");
+ if (color == "green")
+ _color = Green;
+ else if (color == "yellow")
+ _color = Yellow;
+ else if (color == "red")
+ _color = Red;
+ else
+ throw "Color is unknown";
+
+ setValid (true);
+}
+
+
+void CityTrafficInfo::dump ()
+{
+ Log::instance ()->add (QString ("CityTrafficInfo: level = %1, hint = %2").arg (_level).arg (_hint));
}
-float TrafficInfo::getFloatNode (const QDomElement& elem, const char* node, float def)
+float CityTrafficInfo::getFloatNode (const QDomElement& elem, const char* node, float def)
{
QDomElement e;
bool ok;
}
-int TrafficInfo::getIntNode (const QDomElement& elem, const char* node, int def)
+int CityTrafficInfo::getIntNode (const QDomElement& elem, const char* node, int def)
{
QDomElement e;
bool ok;
}
-QString TrafficInfo::getStringNode (const QDomElement& elem, const char* node) throw (const QString&)
+QString CityTrafficInfo::getStringNode (const QDomElement& elem, const char* node) throw (const QString&)
{
QDomElement e;
QString val;
}
-QDateTime TrafficInfo::getTSNode (const QDomElement& elem, const char* node) throw (const QString&)
+QDateTime CityTrafficInfo::getTSNode (const QDomElement& elem, const char* node) throw (const QString&)
{
QDomElement e;
bool ok;
}
-void TrafficInfo::dump ()
-{
- Log::instance ()->add (QString ("TrafficInfo (%1): time = %2").arg (_valid ? "valid" : "not valid").arg (_localtime));
-}
-
-
-// --------------------------------------------------
-// ExtendedTrafficInfo
-// --------------------------------------------------
-ExtendedTrafficInfo::ExtendedTrafficInfo (const QDomElement& elem) throw (const QString&)
- : TrafficInfo (elem)
-{
- QString color;
-
- setValid (false);
- _level_raw = getFloatNode (elem, "level_raw", 0);
- _level = getIntNode (elem, "level", 1);
- _tend = getIntNode (elem, "tend", 0);
- _hint = getStringNode (elem, "hint");
-
- color = getStringNode (elem, "icon");
- if (color == "green")
- _color = Green;
- else if (color == "yellow")
- _color = Yellow;
- else if (color == "red")
- _color = Red;
- else
- throw "Color is unknown";
-
- setValid (true);
-}
-
-
-void ExtendedTrafficInfo::dump ()
-{
- TrafficInfo::dump ();
- Log::instance ()->add (QString ("ExtTrafficInfo: level = %1, hint = %2").arg (_level).arg (_hint));
-}
-
-
// --------------------------------------------------
// Traffic
// --------------------------------------------------
QDomNode n;
bool ok;
QString s;
- QMap<QString, TrafficInfo> new_info;
- QMap<QString, ExtendedTrafficInfo> new_ext_info;
+ QMap<QString, CityTrafficInfo> new_ext_info;
if (!doc.setContent (xml))
return false;
try {
// Check that it is an extended traffic info
if (!e.firstChildElement ("level").isNull ()) {
- ExtendedTrafficInfo info (e);
+ CityTrafficInfo info (e);
if (info.valid ())
new_ext_info[s] = info;
}
- else {
- TrafficInfo info (e);
- if (info.valid ())
- new_info[s] = info;
- }
}
catch (const QString& msg) {
}
}
_ts = new_ts;
- _info = new_info;
_ext_info = new_ext_info;
return true;
}
-TrafficInfo Traffic::lookup (const QString &id) const
-{
- QMap<QString, TrafficInfo>::const_iterator it = _info.find (id);
-
- if (it == _info.end ())
- return TrafficInfo ();
- else
- return it.value ();
-}
-
-
-ExtendedTrafficInfo Traffic::lookup_ext (const QString &id) const
+CityTrafficInfo Traffic::lookup_ext (const QString &id) const
{
- QMap<QString, ExtendedTrafficInfo>::const_iterator it = _ext_info.find (id);
+ QMap<QString, CityTrafficInfo>::const_iterator it = _ext_info.find (id);
if (it == _ext_info.end ())
- return ExtendedTrafficInfo ();
+ return CityTrafficInfo ();
else
return it.value ();
}
class TrafficInfo
{
private:
- float _len1, _len2, _len;
- QDateTime _ts;
- 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; };
: _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 ();
};
-class ExtendedTrafficInfo : public TrafficInfo
+class CityTrafficInfo : public TrafficInfo
{
public:
enum light_color {
};
private:
- float _level_raw;
- int _level;
+ QDateTime _ts;
+ int _level, _tend;
light_color _color;
- int _tend;
QString _hint;
+ 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&);
+
public:
- ExtendedTrafficInfo ()
+ CityTrafficInfo ()
: TrafficInfo ()
{};
- ExtendedTrafficInfo (const QDomElement& elem) throw (const QString&);
+ CityTrafficInfo (const QDomElement& elem) throw (const QString&);
+
+ QDateTime ts () const
+ { return _ts; };
int level () const
{ return _level; };
QString hint () const
{ return _hint; };
- ExtendedTrafficInfo::light_color color () const
+ CityTrafficInfo::light_color color () const
{ return _color; };
virtual void dump ();
private:
QDateTime _ts;
- QMap<QString, TrafficInfo> _info;
- QMap<QString, ExtendedTrafficInfo> _ext_info;
+ QMap<QString, CityTrafficInfo> _ext_info;
HttpFetcher _fetcher;
QDateTime ts () const
{ return _ts; };
- TrafficInfo lookup (const QString &id) const;
- ExtendedTrafficInfo lookup_ext (const QString &id) const;
+ CityTrafficInfo lookup_ext (const QString &id) const;
};