Merge branch 'master' of ssh://mercury/var/git/irwi
[irwi] / src / selectremotedlg.cpp
index dbc8115..9c8b009 100644 (file)
@@ -3,6 +3,7 @@
 #include "remote.h"
 #include "remotelistwidgetitem.h"
 #include "onlinepollerthread.h"
+#include "remotetable.h"
 
 #include <QHBoxLayout>
 #include <QLabel>
@@ -39,7 +40,7 @@ SelectRemoteDlg::SelectRemoteDlg(QWidget *parent)
             this,
             SLOT(mfgItemChanged(QListWidgetItem*, QListWidgetItem*)));
 
-    modelList = new QListWidget(this);
+    modelList = new RemoteTable(this);
     layout->addWidget(modelList);
 
     downloadBtn = new QPushButton(tr("Download"), this);
@@ -56,8 +57,6 @@ SelectRemoteDlg::~SelectRemoteDlg()
 {
     delete layout;
     if (onlinePollerThread != NULL) {
-        onlinePollerThread->stop();
-        onlinePollerThread->wait();
         delete onlinePollerThread;
         onlinePollerThread = NULL;
     }
@@ -80,9 +79,8 @@ void SelectRemoteDlg::alphabetItemChanged(QListWidgetItem *current,
                                       QListWidgetItem * /*previous*/)
 {
     mfgList->clear();
-    modelList->clear();
-    if (current)
-    {
+    modelList->removeAllRows();
+    if (current) {
         mfgList->addItems((*remoteDB)[current->text()].keys());
     }
 }
@@ -90,37 +88,33 @@ void SelectRemoteDlg::alphabetItemChanged(QListWidgetItem *current,
 void SelectRemoteDlg::mfgItemChanged(QListWidgetItem *current,
                                      QListWidgetItem * /*previous*/)
 {
-    modelList->clear();
-    if (current)
-    {
+    modelList->removeAllRows();
+    if (current) {
         RemoteList remotes =
             (*remoteDB)[alphabetList->currentItem()->text()][current->text()];
         foreach(Remote *remote, remotes) {
-            modelList->addItem(new RemoteListWidgetItem(remote));
+            modelList->addItem(remote);
         }
     }
 }
 
 void SelectRemoteDlg::downloadRemote()
 {
-    RemoteListWidgetItem *currentModel =
-        static_cast<RemoteListWidgetItem *>(modelList->currentItem());
-    if (currentModel)
-    {
+    Remote *currentModel = modelList->selected();
+    if (currentModel) {
+        setResult(QDialog::Accepted);
         setBusy();
-        connect(currentModel->remote(), SIGNAL(saveFinished()),
+        connect(currentModel, SIGNAL(saveFinished()),
                 this, SLOT(close()));
-        currentModel->remote()->saveToFile();
+        currentModel->saveToFile();
 
-        emit remoteChanged(*(currentModel->remote()));
+        emit remoteChanged(*currentModel);
     }
 }
 
 void SelectRemoteDlg::getDB()
 {
     if (onlinePollerThread != NULL) {
-        onlinePollerThread->stop();
-        onlinePollerThread->wait();
         delete onlinePollerThread;
         onlinePollerThread = NULL;
     }
@@ -131,15 +125,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)