OnlinePollerThread now works as intended
authorJari Jarvi <t7jaja00@students.oamk.fi>
Wed, 7 Jul 2010 11:22:50 +0000 (14:22 +0300)
committerJari Jarvi <t7jaja00@students.oamk.fi>
Wed, 7 Jul 2010 11:22:50 +0000 (14:22 +0300)
src/onlinepollerthread.cpp
src/onlinepollerthread.h
src/selectremotedlg.cpp

index 6e1cdac..4dd8d75 100644 (file)
@@ -3,31 +3,52 @@
 #include <QDBusMessage>
 #include <QDBusConnection>
 
+OnlinePollerThread::OnlinePollerThread()
+    : m_exiting(false)
+{
+}
+
+OnlinePollerThread::~OnlinePollerThread()
+{
+    m_exiting = true;
+    stop();
+    quit();
+    wait();
+}
+
 void OnlinePollerThread::run()
 {
-    running = true;
+    m_running = true;
     QTM_PREPEND_NAMESPACE(QNetworkConfigurationManager) qncm;
-    if (!qncm.isOnline()) {
+    bool connected = qncm.isOnline();
+    if (!connected) {
         QDBusMessage m = QDBusMessage::createMethodCall(
                 "com.nokia.icd_ui", "/com/nokia/icd_ui", 
                 "com.nokia.icd_ui", "show_conn_dlg");
         m << false;
         QDBusConnection::systemBus().send(m);
-        while(running)
+        while(m_running)
         {
-            if (!qncm.isOnline()) {
-                msleep(250);
+            connected = qncm.isOnline();
+            if (connected) {
+                m_running = false;
             } else {
-                emit online();
-                break;
+                msleep(250);
             }
         }
     }
-    exec();
+
+    if (connected) {
+        emit online();
+    }
+
+    if (!m_exiting) {
+        exec();
+    }
 }
 
 void OnlinePollerThread::stop()
 {
-    running = false;
+    m_running = false;
 }
 
index 9c4c521..2bdbfb9 100644 (file)
@@ -7,17 +7,20 @@ class OnlinePollerThread : public QThread
 {
     Q_OBJECT
 public:
-    //overrides QThread::run()
-    void run();
+    OnlinePollerThread();
+    ~OnlinePollerThread();
+    void stop();
 
 signals:
     void online();
 
-public:
-    void stop();
+protected:
+    //overrides QThread::run()
+    void run();
 
 private:
-    bool running;
+    bool m_running;
+    bool m_exiting;
 };
 
 #endif //ONLINEPOLLERTHREAD_H
index dbc8115..89a69f6 100644 (file)
@@ -56,8 +56,6 @@ SelectRemoteDlg::~SelectRemoteDlg()
 {
     delete layout;
     if (onlinePollerThread != NULL) {
-        onlinePollerThread->stop();
-        onlinePollerThread->wait();
         delete onlinePollerThread;
         onlinePollerThread = NULL;
     }
@@ -119,8 +117,6 @@ void SelectRemoteDlg::downloadRemote()
 void SelectRemoteDlg::getDB()
 {
     if (onlinePollerThread != NULL) {
-        onlinePollerThread->stop();
-        onlinePollerThread->wait();
         delete onlinePollerThread;
         onlinePollerThread = NULL;
     }
@@ -131,15 +127,13 @@ void SelectRemoteDlg::refreshDB()
 {
     setBusy(true);
     if (onlinePollerThread != NULL) {
-        onlinePollerThread->stop();
-        onlinePollerThread->wait();
         delete onlinePollerThread;
         onlinePollerThread = NULL;
     }
     onlinePollerThread = new OnlinePollerThread();
     connect(onlinePollerThread, SIGNAL(online()),
             this, SLOT(getDB()));
-    onlinePollerThread->run();
+    onlinePollerThread->start();
 }
 
 void SelectRemoteDlg::showEvent(QShowEvent *event)