1 #include "selectremotedlg.h"
4 #include "onlinepollerthread.h"
5 #include "remotetable.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(64);
29 layout->addWidget(alphabetList);
31 SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
33 SLOT(alphabetItemChanged(QListWidgetItem*, QListWidgetItem*)));
35 mfgList = new QListWidget(this);
36 mfgList->setMaximumWidth(192);
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*)));
54 connect(&remoteDBMgr, SIGNAL(downloadFailed(int)),
55 this, SLOT(onDBError(int)));
58 SelectRemoteDlg::~SelectRemoteDlg()
61 if (onlinePollerThread != NULL) {
62 delete onlinePollerThread;
63 onlinePollerThread = NULL;
67 void SelectRemoteDlg::setDB(RemoteDB *db)
70 alphabetList->addItems(remoteDB->keys());
74 void SelectRemoteDlg::setBusy(bool busy)
77 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, busy);
82 void SelectRemoteDlg::alphabetItemChanged(QListWidgetItem *current,
83 QListWidgetItem * /*previous*/)
86 modelList->removeAllRows();
88 mfgList->addItems((*remoteDB)[current->text()].keys());
92 void SelectRemoteDlg::mfgItemChanged(QListWidgetItem *current,
93 QListWidgetItem * /*previous*/)
95 modelList->removeAllRows();
98 (*remoteDB)[alphabetList->currentItem()->text()][current->text()];
99 foreach(Remote *remote, remotes) {
100 modelList->addItem(remote);
105 void SelectRemoteDlg::downloadRemote()
107 Remote *currentModel = modelList->selected();
109 setResult(QDialog::Accepted);
111 connect(currentModel, SIGNAL(saveFinished()),
112 this, SLOT(close()));
113 currentModel->saveToFile();
115 emit remoteChanged(*currentModel);
119 void SelectRemoteDlg::getDB()
121 if (onlinePollerThread != NULL) {
122 delete onlinePollerThread;
123 onlinePollerThread = NULL;
125 remoteDBMgr.getDBAsync();
128 void SelectRemoteDlg::refreshDB()
131 if (onlinePollerThread != NULL) {
132 delete onlinePollerThread;
133 onlinePollerThread = NULL;
135 onlinePollerThread = new OnlinePollerThread();
136 connect(onlinePollerThread, SIGNAL(online()),
137 this, SLOT(getDB()));
138 onlinePollerThread->start();
141 void SelectRemoteDlg::showEvent(QShowEvent *event)
144 QDialog::showEvent(event);
147 void SelectRemoteDlg::onDBError(int error)
149 this->setWindowTitle(tr("Network error") + " " + QString::number(error));
151 downloadBtn->setVisible(false);