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*/)
83 mfgList->addItems((*remoteDB)[current->text()].keys());
87 void SelectRemoteDlg::mfgItemChanged(QListWidgetItem *current,
88 QListWidgetItem * /*previous*/)
93 (*remoteDB)[alphabetList->currentItem()->text()][current->text()];
94 foreach(Remote *remote, remotes) {
95 modelList->addItem(new RemoteListWidgetItem(remote));
100 void SelectRemoteDlg::downloadRemote()
102 RemoteListWidgetItem *currentModel =
103 static_cast<RemoteListWidgetItem *>(modelList->currentItem());
105 setResult(QDialog::Accepted);
107 connect(currentModel->remote(), SIGNAL(saveFinished()),
108 this, SLOT(close()));
109 currentModel->remote()->saveToFile();
111 emit remoteChanged(*(currentModel->remote()));
115 void SelectRemoteDlg::getDB()
117 if (onlinePollerThread != NULL) {
118 delete onlinePollerThread;
119 onlinePollerThread = NULL;
121 remoteDBMgr.getDBAsync();
124 void SelectRemoteDlg::refreshDB()
127 if (onlinePollerThread != NULL) {
128 delete onlinePollerThread;
129 onlinePollerThread = NULL;
131 onlinePollerThread = new OnlinePollerThread();
132 connect(onlinePollerThread, SIGNAL(online()),
133 this, SLOT(getDB()));
134 onlinePollerThread->start();
137 void SelectRemoteDlg::showEvent(QShowEvent *event)
140 QDialog::showEvent(event);