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();
86 mfgList->addItems((*remoteDB)[current->text()].keys());
90 void SelectRemoteDlg::mfgItemChanged(QListWidgetItem *current,
91 QListWidgetItem * /*previous*/)
93 modelList->removeAllRows();
97 (*remoteDB)[alphabetList->currentItem()->text()][current->text()];
98 foreach(Remote *remote, remotes) {
99 modelList->addItem(remote);
104 void SelectRemoteDlg::downloadRemote()
106 Remote *currentModel = modelList->selected();
110 connect(currentModel, SIGNAL(saveFinished()),
111 this, SLOT(close()));
112 currentModel->saveToFile();
114 emit remoteChanged(*currentModel);
118 void SelectRemoteDlg::getDB()
120 if (onlinePollerThread != NULL) {
121 delete onlinePollerThread;
122 onlinePollerThread = NULL;
124 remoteDBMgr.getDBAsync();
127 void SelectRemoteDlg::refreshDB()
130 if (onlinePollerThread != NULL) {
131 delete onlinePollerThread;
132 onlinePollerThread = NULL;
134 onlinePollerThread = new OnlinePollerThread();
135 connect(onlinePollerThread, SIGNAL(online()),
136 this, SLOT(getDB()));
137 onlinePollerThread->start();
140 void SelectRemoteDlg::showEvent(QShowEvent *event)
143 QDialog::showEvent(event);