OnlinePollerThread now works as intended
[irwi] / src / selectremotedlg.cpp
index a3c315f..89a69f6 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "remote.h"
 #include "remotelistwidgetitem.h"
+#include "onlinepollerthread.h"
 
 #include <QHBoxLayout>
 #include <QLabel>
@@ -17,6 +18,7 @@
 SelectRemoteDlg::SelectRemoteDlg(QWidget *parent)
     : QDialog(parent)
 {
+    onlinePollerThread = NULL;
     this->setWindowTitle(tr("Select remote"));
     this->setMinimumHeight(320);
 
@@ -48,14 +50,15 @@ SelectRemoteDlg::SelectRemoteDlg(QWidget *parent)
     this->setLayout(layout);
     connect(&remoteDBMgr, SIGNAL(dbReady(RemoteDB*)),
             this, SLOT(setDB(RemoteDB*)));
-    remoteDBMgr.getDBAsync();
-    setBusy(true);
 }
 
-
 SelectRemoteDlg::~SelectRemoteDlg()
 {
     delete layout;
+    if (onlinePollerThread != NULL) {
+        delete onlinePollerThread;
+        onlinePollerThread = NULL;
+    }
 }
 
 void SelectRemoteDlg::setDB(RemoteDB *db)
@@ -106,6 +109,36 @@ void SelectRemoteDlg::downloadRemote()
         connect(currentModel->remote(), SIGNAL(saveFinished()),
                 this, SLOT(close()));
         currentModel->remote()->saveToFile();
+
+        emit remoteChanged(*(currentModel->remote()));
+    }
+}
+
+void SelectRemoteDlg::getDB()
+{
+    if (onlinePollerThread != NULL) {
+        delete onlinePollerThread;
+        onlinePollerThread = NULL;
     }
+    remoteDBMgr.getDBAsync();
+}
+
+void SelectRemoteDlg::refreshDB()
+{
+    setBusy(true);
+    if (onlinePollerThread != NULL) {
+        delete onlinePollerThread;
+        onlinePollerThread = NULL;
+    }
+    onlinePollerThread = new OnlinePollerThread();
+    connect(onlinePollerThread, SIGNAL(online()),
+            this, SLOT(getDB()));
+    onlinePollerThread->start();
+}
+
+void SelectRemoteDlg::showEvent(QShowEvent *event)
+{
+    refreshDB();
+    QDialog::showEvent(event);
 }