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 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 delete onlinePollerThread;
121 onlinePollerThread = NULL;
123 remoteDBMgr.getDBAsync();
126 void SelectRemoteDlg::refreshDB()
129 if (onlinePollerThread != NULL) {
130 delete onlinePollerThread;
131 onlinePollerThread = NULL;
133 onlinePollerThread = new OnlinePollerThread();
134 connect(onlinePollerThread, SIGNAL(online()),
135 this, SLOT(getDB()));
136 onlinePollerThread->start();
139 void SelectRemoteDlg::showEvent(QShowEvent *event)
142 QDialog::showEvent(event);