From: Max Lapan Date: Wed, 10 Mar 2010 13:18:55 +0000 (+0300) Subject: Connection status checker outline. X-Git-Tag: v0.1~51 X-Git-Url: http://vcs.maemo.org/git/?p=yandex-traffic;a=commitdiff_plain;h=9abc6b6bdcf836b282b88198df95b5aadb917bd3 Connection status checker outline. Class is not finished yet. It lacks the core: DBus messages. --- diff --git a/connection.cpp b/connection.cpp new file mode 100644 index 0000000..18a2ee0 --- /dev/null +++ b/connection.cpp @@ -0,0 +1,27 @@ +#include "connection.hpp" + +static ConnectionChecker *_instance = NULL; + + +// -------------------------------------------------- +// ConnectionChecker singleton +// -------------------------------------------------- +ConnectionChecker *ConnectionChecker::instance () +{ + if (!_instance) + _instance = new ConnectionChecker; + return _instance; +} + + +ConnectionChecker::ConnectionChecker () +{ + // start timer which will check connection + startTimer (15*1000); +} + + +void ConnectionChecker::timerEvent (QTimerEvent *) +{ + // check for connection +} diff --git a/connection.hpp b/connection.hpp new file mode 100644 index 0000000..1840ae8 --- /dev/null +++ b/connection.hpp @@ -0,0 +1,25 @@ +#ifndef __CONNECTION_H__ +#define __CONNECTION_H__ + +#include + + +// Singleton, which periodically checks for connection state and notifies when it changed. +class ConnectionChecker : public QObject +{ + Q_OBJECT + +private: + ConnectionChecker (); + +protected: + void timerEvent (QTimerEvent *event); + +public: + static ConnectionChecker *instance (); + +signals: + void connected (bool active); +}; + +#endif // __CONNECTION_H__ diff --git a/tests/conn/conn.pro b/tests/conn/conn.pro new file mode 100644 index 0000000..3fcd4c9 --- /dev/null +++ b/tests/conn/conn.pro @@ -0,0 +1,7 @@ +TEMPLATE = app + +SOURCES += main.cpp +HEADERS += mainwindow.hpp + +include (../../yandex-traffic-core.pri) + diff --git a/tests/conn/main.cpp b/tests/conn/main.cpp new file mode 100644 index 0000000..2673345 --- /dev/null +++ b/tests/conn/main.cpp @@ -0,0 +1,13 @@ +#include +#include "mainwindow.hpp" + + +int main(int argc, char *argv[]) +{ + QApplication app (argc, argv); + MainWindow w; + + w.show (); + + return app.exec (); +} diff --git a/tests/conn/mainwindow.hpp b/tests/conn/mainwindow.hpp new file mode 100644 index 0000000..0892bef --- /dev/null +++ b/tests/conn/mainwindow.hpp @@ -0,0 +1,29 @@ +#ifndef __MAINWINDOW_H__ +#define __MAINWINDOW_H__ + +#include +#include + +class MainWindow : public QWidget +{ + Q_OBJECT +public: + MainWindow () + : QWidget () + { + ConnectionChecker *cc = ConnectionChecker::instance (); + + connect (cc, SIGNAL (connected (bool)), SLOT (connected (bool))); + } + +protected slots: + void connected (bool active) + { + if (active) + printf ("Device connected\n"); + else + printf ("Device not connected\n"); + } +}; + +#endif // __MAINWINDOW_H__ diff --git a/tests/tests.pro b/tests/tests.pro index 191d687..0edec27 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -1,2 +1,2 @@ TEMPLATE = subdirs -SUBDIRS = regions traffic widget +SUBDIRS = regions traffic widget conn diff --git a/yandex-traffic-core.pri b/yandex-traffic-core.pri index 6d6a881..425c2b1 100644 --- a/yandex-traffic-core.pri +++ b/yandex-traffic-core.pri @@ -1,6 +1,11 @@ -HEADERS += $$PWD/regions.hpp $$PWD/settings.hpp $$PWD/traffic.hpp $$PWD/http_fetcher.hpp -SOURCES += $$PWD/regions.cpp $$PWD/settings.cpp $$PWD/traffic.cpp $$PWD/http_fetcher.cpp +HEADERS += $$PWD/regions.hpp $$PWD/settings.hpp $$PWD/traffic.hpp $$PWD/http_fetcher.hpp $$PWD/connection.hpp +SOURCES += $$PWD/regions.cpp $$PWD/settings.cpp $$PWD/traffic.cpp $$PWD/http_fetcher.cpp $$PWD/connection.cpp -QT += network xml +QT += network xml dbus +CONFIG += qdbus + +maemo5 { + CONFIG += icd2 +} INCLUDEPATH += $$PWD