Connection status checker outline.
authorMax Lapan <max.lapan@gmail.com>
Wed, 10 Mar 2010 13:18:55 +0000 (16:18 +0300)
committerMax Lapan <max.lapan@gmail.com>
Wed, 10 Mar 2010 13:18:55 +0000 (16:18 +0300)
Class is not finished yet. It lacks the core: DBus messages.

connection.cpp [new file with mode: 0644]
connection.hpp [new file with mode: 0644]
tests/conn/conn.pro [new file with mode: 0644]
tests/conn/main.cpp [new file with mode: 0644]
tests/conn/mainwindow.hpp [new file with mode: 0644]
tests/tests.pro
yandex-traffic-core.pri

diff --git a/connection.cpp b/connection.cpp
new file mode 100644 (file)
index 0000000..18a2ee0
--- /dev/null
@@ -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 (file)
index 0000000..1840ae8
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef __CONNECTION_H__
+#define __CONNECTION_H__
+
+#include <QtCore>
+
+
+// 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 (file)
index 0000000..3fcd4c9
--- /dev/null
@@ -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 (file)
index 0000000..2673345
--- /dev/null
@@ -0,0 +1,13 @@
+#include <QtGui>
+#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 (file)
index 0000000..0892bef
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef __MAINWINDOW_H__
+#define __MAINWINDOW_H__
+
+#include <QtGui>
+#include <connection.hpp>
+
+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__
index 191d687..0edec27 100644 (file)
@@ -1,2 +1,2 @@
 TEMPLATE = subdirs
-SUBDIRS = regions traffic widget
+SUBDIRS = regions traffic widget conn
index 6d6a881..425c2b1 100644 (file)
@@ -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