From 4c03c61ff245a081b1c7bc5ac163dd03a3160a5a Mon Sep 17 00:00:00 2001 From: Max Lapan Date: Tue, 9 Mar 2010 20:41:23 +0300 Subject: [PATCH] Refresh traffic information every 5 minutes. --- mainwidget.cpp | 32 +++++++++++++++++++++++++++++++- mainwidget.hpp | 6 ++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/mainwidget.cpp b/mainwidget.cpp index 5e14ef9..343e217 100644 --- a/mainwidget.cpp +++ b/mainwidget.cpp @@ -21,7 +21,13 @@ MainWidget::MainWidget () layout->addWidget (_label); setLayout (layout); - _label->setText ("Bla-bla"); + connect (&_traffic, SIGNAL (updated ()), SLOT (trafficUpdated ())); + + // every 5 minutes (TODO, make option) + startTimer (5*60*1000); + + // perform update just after creation + _traffic.update (); } @@ -41,3 +47,27 @@ void MainWidget::paintEvent(QPaintEvent *event) QWidget::paintEvent(event); } + + +void MainWidget::timerEvent (QTimerEvent *) +{ + // Perform traffic information refresh + // TODO: only if internet connection is available + _traffic.update (); +} + + +void MainWidget::trafficUpdated () +{ + ExtendedTrafficInfo info = _traffic.lookup_ext ("1"); + + if (info.valid ()) { + _light->setColor (info.color ()); + _label->setText (QString ("%1, %2\n%3") + .arg (QString::number (info.level ())) + .arg (info.localtime ()) + .arg (info.hint ())); + } + else + _light->setColor (ExtendedTrafficInfo::Unknown); +} diff --git a/mainwidget.hpp b/mainwidget.hpp index 65f64ab..0fb63a2 100644 --- a/mainwidget.hpp +++ b/mainwidget.hpp @@ -3,6 +3,7 @@ #include +#include "traffic.hpp" #include "settings.hpp" #include "regions.hpp" #include "light.hpp" @@ -12,6 +13,7 @@ class MainWidget : public QWidget { Q_OBJECT private: + Traffic _traffic; RegionsTable _regions; Settings _settings; @@ -25,6 +27,10 @@ public: protected: void paintEvent (QPaintEvent *event); + void timerEvent (QTimerEvent *event); + +protected slots: + void trafficUpdated (); }; #endif /* __MAINWIDGET_H__ */ -- 1.7.9.5