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(64);
30 layout->addWidget(alphabetList);
32 SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
34 SLOT(alphabetItemChanged(QListWidgetItem*, QListWidgetItem*)));
36 mfgList = new QListWidget(this);
37 mfgList->setMaximumWidth(192);
38 layout->addWidget(mfgList);
40 SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
42 SLOT(mfgItemChanged(QListWidgetItem*, QListWidgetItem*)));
44 modelList = new RemoteTable(this);
45 layout->addWidget(modelList);
47 downloadBtn = new QPushButton(tr("Download"), this);
48 layout->addWidget(downloadBtn);
49 connect(downloadBtn, SIGNAL(clicked()),
50 this, SLOT(downloadRemote()));
52 this->setLayout(layout);
53 connect(&remoteDBMgr, SIGNAL(dbReady(RemoteDB*)),
54 this, SLOT(setDB(RemoteDB*)));
57 SelectRemoteDlg::~SelectRemoteDlg()
60 if (onlinePollerThread != NULL) {
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*/)
83 modelList->removeAllRows();
85 mfgList->addItems((*remoteDB)[current->text()].keys());
89 void SelectRemoteDlg::mfgItemChanged(QListWidgetItem *current,
90 QListWidgetItem * /*previous*/)
92 modelList->removeAllRows();
95 (*remoteDB)[alphabetList->currentItem()->text()][current->text()];
96 foreach(Remote *remote, remotes) {
97 modelList->addItem(remote);
102 void SelectRemoteDlg::downloadRemote()
104 Remote *currentModel = modelList->selected();
106 setResult(QDialog::Accepted);
108 connect(currentModel, SIGNAL(saveFinished()),
109 this, SLOT(close()));
110 currentModel->saveToFile();
112 emit remoteChanged(*currentModel);
116 void SelectRemoteDlg::getDB()
118 if (onlinePollerThread != NULL) {
119 delete onlinePollerThread;
120 onlinePollerThread = NULL;
122 remoteDBMgr.getDBAsync();
125 void SelectRemoteDlg::refreshDB()
128 if (onlinePollerThread != NULL) {
129 delete onlinePollerThread;
130 onlinePollerThread = NULL;
132 onlinePollerThread = new OnlinePollerThread();
133 connect(onlinePollerThread, SIGNAL(online()),
134 this, SLOT(getDB()));
135 onlinePollerThread->start();
138 void SelectRemoteDlg::showEvent(QShowEvent *event)
141 QDialog::showEvent(event);