1 #include "selectremotedlg.h"
4 #include "remotelistwidgetitem.h"
5 #include "onlinepollerthread.h"
10 #include <QListWidget>
11 #include <QListWidgetItem>
15 #include <QMessageBox>
16 #include <QPushButton>
18 SelectRemoteDlg::SelectRemoteDlg(QWidget *parent)
21 this->setWindowTitle(tr("Select remote"));
22 this->setMinimumHeight(320);
24 layout = new QHBoxLayout(this);
26 alphabetList = new QListWidget(this);
27 alphabetList->setMaximumWidth(96);
28 layout->addWidget(alphabetList);
30 SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
32 SLOT(alphabetItemChanged(QListWidgetItem*, QListWidgetItem*)));
34 mfgList = new QListWidget(this);
35 layout->addWidget(mfgList);
37 SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
39 SLOT(mfgItemChanged(QListWidgetItem*, QListWidgetItem*)));
41 modelList = new QListWidget(this);
42 layout->addWidget(modelList);
44 downloadBtn = new QPushButton(tr("Download"), this);
45 layout->addWidget(downloadBtn);
46 connect(downloadBtn, SIGNAL(clicked()),
47 this, SLOT(downloadRemote()));
49 this->setLayout(layout);
50 connect(&remoteDBMgr, SIGNAL(dbReady(RemoteDB*)),
51 this, SLOT(setDB(RemoteDB*)));
54 SelectRemoteDlg::~SelectRemoteDlg()
57 if (onlinePollerThread != NULL) {
58 onlinePollerThread->quit();
59 delete onlinePollerThread;
60 onlinePollerThread = NULL;
64 void SelectRemoteDlg::setDB(RemoteDB *db)
67 alphabetList->addItems(remoteDB->keys());
71 void SelectRemoteDlg::setBusy(bool busy)
73 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, busy);
77 void SelectRemoteDlg::alphabetItemChanged(QListWidgetItem *current,
78 QListWidgetItem * /*previous*/)
84 mfgList->addItems((*remoteDB)[current->text()].keys());
88 void SelectRemoteDlg::mfgItemChanged(QListWidgetItem *current,
89 QListWidgetItem * /*previous*/)
95 (*remoteDB)[alphabetList->currentItem()->text()][current->text()];
96 foreach(Remote *remote, remotes) {
97 modelList->addItem(new RemoteListWidgetItem(remote));
102 void SelectRemoteDlg::downloadRemote()
104 RemoteListWidgetItem *currentModel =
105 static_cast<RemoteListWidgetItem *>(modelList->currentItem());
109 connect(currentModel->remote(), SIGNAL(saveFinished()),
110 this, SLOT(close()));
111 currentModel->remote()->saveToFile();
113 emit remoteChanged(*(currentModel->remote()));
117 void SelectRemoteDlg::getDB()
119 if (onlinePollerThread != NULL) {
120 onlinePollerThread->quit();
121 delete onlinePollerThread;
122 onlinePollerThread = NULL;
124 remoteDBMgr.getDBAsync();
127 void SelectRemoteDlg::refreshDB()
130 if (onlinePollerThread != NULL) {
131 delete onlinePollerThread;
133 onlinePollerThread = new OnlinePollerThread();
134 connect(onlinePollerThread, SIGNAL(online()),
135 this, SLOT(getDB()));
136 onlinePollerThread->run();
139 void SelectRemoteDlg::showEvent(QShowEvent *event)
142 QDialog::showEvent(event);