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();
85 mfgList->addItems((*remoteDB)[current->text()].keys());
89 void SelectRemoteDlg::mfgItemChanged(QListWidgetItem *current,
90 QListWidgetItem * /*previous*/)
92 modelList->removeAllRows();
96 (*remoteDB)[alphabetList->currentItem()->text()][current->text()];
97 foreach(Remote *remote, remotes) {
98 modelList->addItem(remote);
103 void SelectRemoteDlg::downloadRemote()
105 Remote *currentModel = modelList->selected();
109 connect(currentModel, SIGNAL(saveFinished()),
110 this, SLOT(close()));
111 currentModel->saveToFile();
113 emit remoteChanged(*currentModel);
117 void SelectRemoteDlg::getDB()
119 if (onlinePollerThread != NULL) {
120 delete onlinePollerThread;
121 onlinePollerThread = NULL;
123 remoteDBMgr.getDBAsync();
126 void SelectRemoteDlg::refreshDB()
129 if (onlinePollerThread != NULL) {
130 delete onlinePollerThread;
131 onlinePollerThread = NULL;
133 onlinePollerThread = new OnlinePollerThread();
134 connect(onlinePollerThread, SIGNAL(online()),
135 this, SLOT(getDB()));
136 onlinePollerThread->start();
139 void SelectRemoteDlg::showEvent(QShowEvent *event)
142 QDialog::showEvent(event);