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 onlinePollerThread = NULL;
22 this->setWindowTitle(tr("Select remote"));
23 this->setMinimumHeight(320);
25 layout = new QHBoxLayout(this);
27 alphabetList = new QListWidget(this);
28 alphabetList->setMaximumWidth(96);
29 layout->addWidget(alphabetList);
31 SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
33 SLOT(alphabetItemChanged(QListWidgetItem*, QListWidgetItem*)));
35 mfgList = new QListWidget(this);
36 layout->addWidget(mfgList);
38 SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
40 SLOT(mfgItemChanged(QListWidgetItem*, QListWidgetItem*)));
42 modelList = new QListWidget(this);
43 layout->addWidget(modelList);
45 downloadBtn = new QPushButton(tr("Download"), this);
46 layout->addWidget(downloadBtn);
47 connect(downloadBtn, SIGNAL(clicked()),
48 this, SLOT(downloadRemote()));
50 this->setLayout(layout);
51 connect(&remoteDBMgr, SIGNAL(dbReady(RemoteDB*)),
52 this, SLOT(setDB(RemoteDB*)));
55 SelectRemoteDlg::~SelectRemoteDlg()
58 if (onlinePollerThread != NULL) {
59 onlinePollerThread->stop();
60 onlinePollerThread->wait();
61 delete onlinePollerThread;
62 onlinePollerThread = NULL;
66 void SelectRemoteDlg::setDB(RemoteDB *db)
69 alphabetList->addItems(remoteDB->keys());
73 void SelectRemoteDlg::setBusy(bool busy)
75 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, busy);
79 void SelectRemoteDlg::alphabetItemChanged(QListWidgetItem *current,
80 QListWidgetItem * /*previous*/)
86 mfgList->addItems((*remoteDB)[current->text()].keys());
90 void SelectRemoteDlg::mfgItemChanged(QListWidgetItem *current,
91 QListWidgetItem * /*previous*/)
97 (*remoteDB)[alphabetList->currentItem()->text()][current->text()];
98 foreach(Remote *remote, remotes) {
99 modelList->addItem(new RemoteListWidgetItem(remote));
104 void SelectRemoteDlg::downloadRemote()
106 RemoteListWidgetItem *currentModel =
107 static_cast<RemoteListWidgetItem *>(modelList->currentItem());
111 connect(currentModel->remote(), SIGNAL(saveFinished()),
112 this, SLOT(close()));
113 currentModel->remote()->saveToFile();
115 emit remoteChanged(*(currentModel->remote()));
119 void SelectRemoteDlg::getDB()
121 if (onlinePollerThread != NULL) {
122 onlinePollerThread->stop();
123 onlinePollerThread->wait();
124 delete onlinePollerThread;
125 onlinePollerThread = NULL;
127 remoteDBMgr.getDBAsync();
130 void SelectRemoteDlg::refreshDB()
133 if (onlinePollerThread != NULL) {
134 onlinePollerThread->stop();
135 onlinePollerThread->wait();
136 delete onlinePollerThread;
137 onlinePollerThread = NULL;
139 onlinePollerThread = new OnlinePollerThread();
140 connect(onlinePollerThread, SIGNAL(online()),
141 this, SLOT(getDB()));
142 onlinePollerThread->run();
145 void SelectRemoteDlg::showEvent(QShowEvent *event)
148 QDialog::showEvent(event);