#include "remote.h"
#include "remotelistwidgetitem.h"
+#include "onlinepollerthread.h"
#include <QHBoxLayout>
#include <QLabel>
SelectRemoteDlg::SelectRemoteDlg(QWidget *parent)
: QDialog(parent)
{
+ onlinePollerThread = NULL;
this->setWindowTitle(tr("Select remote"));
this->setMinimumHeight(320);
this, SLOT(downloadRemote()));
this->setLayout(layout);
- connect(&remoteDBMgr, SIGNAL(RemoteDBMgr::dbReady(RemoteDB*)),
+ connect(&remoteDBMgr, SIGNAL(dbReady(RemoteDB*)),
this, SLOT(setDB(RemoteDB*)));
- remoteDBMgr.getDBAsync();
- setBusy(true);
}
-
SelectRemoteDlg::~SelectRemoteDlg()
{
delete layout;
+ if (onlinePollerThread != NULL) {
+ onlinePollerThread->stop();
+ onlinePollerThread->wait();
+ delete onlinePollerThread;
+ onlinePollerThread = NULL;
+ }
}
void SelectRemoteDlg::setDB(RemoteDB *db)
{
remoteDB = db;
+ alphabetList->addItems(remoteDB->keys());
setBusy(false);
}
modelList->clear();
if (current)
{
- QList <Remote> remotes =
- (*remoteDB)[alphabetList->currentItem()->text()][current->text()];
- foreach(Remote remote, remotes) {
+ RemoteList remotes =
+ (*remoteDB)[alphabetList->currentItem()->text()][current->text()];
+ foreach(Remote *remote, remotes) {
modelList->addItem(new RemoteListWidgetItem(remote));
}
}
void SelectRemoteDlg::downloadRemote()
{
- RemoteListWidgetItem *currentModel = static_cast<RemoteListWidgetItem *>(modelList->currentItem());
+ RemoteListWidgetItem *currentModel =
+ static_cast<RemoteListWidgetItem *>(modelList->currentItem());
if (currentModel)
{
- currentModel->remote().saveToFile();
+ setBusy();
+ connect(currentModel->remote(), SIGNAL(saveFinished()),
+ this, SLOT(close()));
+ currentModel->remote()->saveToFile();
+
+ emit remoteChanged(*(currentModel->remote()));
+ }
+}
+
+void SelectRemoteDlg::getDB()
+{
+ if (onlinePollerThread != NULL) {
+ onlinePollerThread->stop();
+ onlinePollerThread->wait();
+ delete onlinePollerThread;
+ onlinePollerThread = NULL;
}
+ remoteDBMgr.getDBAsync();
+}
+
+void SelectRemoteDlg::refreshDB()
+{
+ setBusy(true);
+ if (onlinePollerThread != NULL) {
+ delete onlinePollerThread;
+ }
+ onlinePollerThread = new OnlinePollerThread();
+ connect(onlinePollerThread, SIGNAL(online()),
+ this, SLOT(getDB()));
+ onlinePollerThread->run();
+}
+
+void SelectRemoteDlg::showEvent(QShowEvent *event)
+{
+ refreshDB();
+ QDialog::showEvent(event);
}