1 #include "selectremotedlg.h"
4 #include "remotelistwidgetitem.h"
10 #include <QListWidgetItem>
14 #include <QMessageBox>
15 #include <QPushButton>
17 SelectRemoteDlg::SelectRemoteDlg(QWidget *parent)
20 this->setWindowTitle(tr("Select remote"));
21 this->setMinimumHeight(320);
23 layout = new QHBoxLayout(this);
25 alphabetList = new QListWidget(this);
26 alphabetList->setMaximumWidth(96);
27 layout->addWidget(alphabetList);
29 SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
31 SLOT(alphabetItemChanged(QListWidgetItem*, QListWidgetItem*)));
33 mfgList = new QListWidget(this);
34 layout->addWidget(mfgList);
36 SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
38 SLOT(mfgItemChanged(QListWidgetItem*, QListWidgetItem*)));
40 modelList = new QListWidget(this);
41 layout->addWidget(modelList);
43 downloadBtn = new QPushButton(tr("Download"), this);
44 layout->addWidget(downloadBtn);
45 connect(downloadBtn, SIGNAL(clicked()),
46 this, SLOT(downloadRemote()));
48 this->setLayout(layout);
49 connect(&remoteDBMgr, SIGNAL(dbReady(RemoteDB*)),
50 this, SLOT(setDB(RemoteDB*)));
53 SelectRemoteDlg::~SelectRemoteDlg()
56 if (onlinePollerThread != NULL) {
57 onlinePollerThread->quit();
58 delete onlinePollerThread;
59 onlinePollerThread = NULL;
63 void SelectRemoteDlg::setDB(RemoteDB *db)
66 alphabetList->addItems(remoteDB->keys());
70 void SelectRemoteDlg::setBusy(bool busy)
72 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, busy);
76 void SelectRemoteDlg::alphabetItemChanged(QListWidgetItem *current,
77 QListWidgetItem * /*previous*/)
83 mfgList->addItems((*remoteDB)[current->text()].keys());
87 void SelectRemoteDlg::mfgItemChanged(QListWidgetItem *current,
88 QListWidgetItem * /*previous*/)
94 (*remoteDB)[alphabetList->currentItem()->text()][current->text()];
95 foreach(Remote *remote, remotes) {
96 modelList->addItem(new RemoteListWidgetItem(remote));
101 void SelectRemoteDlg::downloadRemote()
103 RemoteListWidgetItem *currentModel =
104 static_cast<RemoteListWidgetItem *>(modelList->currentItem());
108 connect(currentModel->remote(), SIGNAL(saveFinished()),
109 this, SLOT(close()));
110 currentModel->remote()->saveToFile();
112 emit remoteChanged(*(currentModel->remote()));
116 void SelectRemoteDlg::getDB()
118 if (onlinePollerThread != NULL) {
119 onlinePollerThread->quit();
120 delete onlinePollerThread;
121 onlinePollerThread = NULL;
123 remoteDBMgr.getDBAsync();
126 void SelectRemoteDlg::refreshDB()
129 if (onlinePollerThread != NULL) {
130 delete onlinePollerThread;
132 onlinePollerThread = new OnlinePollerThread(this);
133 connect(onlinePollerThread, SIGNAL(online()),
134 this, SLOT(getDB()));
135 onlinePollerThread->run();
138 void SelectRemoteDlg::showEvent(QShowEvent *event)
141 QDialog::showEvent(event);