1 #include "selectremotedlg.h"
4 #include "remotelistwidgetitem.h"
5 #include "onlinepollerthread.h"
6 #include "remotetable.h"
11 #include <QListWidget>
12 #include <QListWidgetItem>
16 #include <QMessageBox>
17 #include <QPushButton>
19 SelectRemoteDlg::SelectRemoteDlg(QWidget *parent)
22 onlinePollerThread = NULL;
23 this->setWindowTitle(tr("Select remote"));
24 this->setMinimumHeight(320);
26 layout = new QHBoxLayout(this);
28 alphabetList = new QListWidget(this);
29 alphabetList->setMaximumWidth(96);
30 layout->addWidget(alphabetList);
32 SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
34 SLOT(alphabetItemChanged(QListWidgetItem*, QListWidgetItem*)));
36 mfgList = new QListWidget(this);
37 layout->addWidget(mfgList);
39 SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
41 SLOT(mfgItemChanged(QListWidgetItem*, QListWidgetItem*)));
43 modelList = new RemoteTable(this);
44 layout->addWidget(modelList);
46 downloadBtn = new QPushButton(tr("Download"), this);
47 layout->addWidget(downloadBtn);
48 connect(downloadBtn, SIGNAL(clicked()),
49 this, SLOT(downloadRemote()));
51 this->setLayout(layout);
52 connect(&remoteDBMgr, SIGNAL(dbReady(RemoteDB*)),
53 this, SLOT(setDB(RemoteDB*)));
56 SelectRemoteDlg::~SelectRemoteDlg()
59 if (onlinePollerThread != NULL) {
60 delete onlinePollerThread;
61 onlinePollerThread = NULL;
65 void SelectRemoteDlg::setDB(RemoteDB *db)
68 alphabetList->addItems(remoteDB->keys());
72 void SelectRemoteDlg::setBusy(bool busy)
74 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, busy);
78 void SelectRemoteDlg::alphabetItemChanged(QListWidgetItem *current,
79 QListWidgetItem * /*previous*/)
82 modelList->removeAllRows();
84 mfgList->addItems((*remoteDB)[current->text()].keys());
88 void SelectRemoteDlg::mfgItemChanged(QListWidgetItem *current,
89 QListWidgetItem * /*previous*/)
91 modelList->removeAllRows();
94 (*remoteDB)[alphabetList->currentItem()->text()][current->text()];
95 foreach(Remote *remote, remotes) {
96 modelList->addItem(remote);
101 void SelectRemoteDlg::downloadRemote()
103 Remote *currentModel = modelList->selected();
105 setResult(QDialog::Accepted);
107 connect(currentModel, SIGNAL(saveFinished()),
108 this, SLOT(close()));
109 currentModel->saveToFile();
111 emit remoteChanged(*currentModel);
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);