#include "advsettingsdlg.h"
#include "selectremotedlg.h"
#include "aboutdlg.h"
-#include "iengine.h"
-#include "iremote.h"
+#include "remote.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLabel>
#include <QDebug>
-SettingsDlg::SettingsDlg(QWidget *parent, IEngine *engine)
+SettingsDlg::SettingsDlg(QWidget *parent)
: QDialog(parent)
- , engine(engine)
+ , remote(NULL)
{
+ QSettings settings(this);
+
layout = new QVBoxLayout(this);
btnLayout = new QHBoxLayout(this);
remoteNameLayout = new QHBoxLayout(this);
- QSettings settings(this);
advSettingsBtn = new QPushButton(tr("Advanced"), this);
selectRemoteBtn = new QPushButton(tr("Select remote"), this);
aboutBtn = new QPushButton(tr("About"), this);
-
rateUpBtn = new QPushButton(
QIcon(settings.value("rateUpIcon",
- "/usr/share/icons/hicolor/48x48/hildon/chat_smiley_happy.png").
+ "/usr/share/icons/hicolor/48x48/hildon/chat_smiley_happy.png").
toString()),
"", this);
rateDownBtn = new QPushButton(
QIcon(settings.value("rateDownIcon",
- "/usr/share/icons/hicolor/48x48/hildon/chat_smiley_sad.png").
+ "/usr/share/icons/hicolor/48x48/hildon/chat_smiley_sad.png").
toString()),
"", this);
rateUpBtn->setMaximumSize(72, 72);
btnLayout->addWidget(selectRemoteBtn);
btnLayout->addWidget(aboutBtn);
+ remoteNameLabel = new QLabel(this);
+ ratingLabel = new QLabel(this);
+ remoteNameLayout->addWidget(remoteNameLabel);
+ remoteNameLayout->addWidget(ratingLabel);
+ remoteNameLayout->addWidget(rateUpBtn);
+ remoteNameLayout->addWidget(rateDownBtn);
+
connect(advSettingsBtn, SIGNAL(clicked()),
this, SLOT(showAdvSettingsDlg()));
connect(selectRemoteBtn, SIGNAL(clicked()),
this, SLOT(showSelectRemoteDlg()));
connect(aboutBtn, SIGNAL(clicked()),
this, SLOT(showAboutDlg()));
-
- remoteNameLabel = new QLabel(
- settings.value("remoteName",
- tr("<no remote selected>")).toString(), this);
- remoteNameLayout->addWidget(new QLabel(tr("Remote name: "), this));
- remoteNameLayout->addWidget(remoteNameLabel);
- remoteNameLayout->addWidget(rateUpBtn);
- remoteNameLayout->addWidget(rateDownBtn);
+ connect(rateUpBtn, SIGNAL(clicked()),
+ this, SLOT(rateUpClicked()));
+ connect(rateDownBtn, SIGNAL(clicked()),
+ this, SLOT(rateDownClicked()));
+
+ QString selectedRemote = settings.value("remoteName", "").toString();
+ if (selectedRemote == "")
+ {
+ remoteNameLabel->setText(tr("No remote selected"));
+ enableRateBtns(false);
+ }
+ else
+ {
+ changeRemote(selectedRemote);
+ }
layout->addLayout(remoteNameLayout);
layout->addLayout(btnLayout);
this->setLayout(layout);
-
- updateRemoteName();
-
- connect(engine->remote(), SIGNAL(ratingChanged(int)),
- this, SLOT(setRating(int)));
- engine->remote()->updateRating();
}
SettingsDlg::~SettingsDlg()
{
+ delete layout;
+ delete btnLayout;
+ delete remoteNameLayout;
delete advSettingsBtn;
delete selectRemoteBtn;
- delete aboutBtn;
delete rateUpBtn;
delete rateDownBtn;
+ delete aboutBtn;
delete remoteNameLabel;
- delete remoteNameLayout;
- delete btnLayout;
- delete layout;
+ delete ratingLabel;
+ if (remote)
+ {
+ delete remote;
+ }
}
void SettingsDlg::showAdvSettingsDlg()
{
- AdvSettingsDlg dlg(this, engine);
+ AdvSettingsDlg dlg(this);
dlg.exec();
- updateRemoteName();
}
void SettingsDlg::showSelectRemoteDlg()
{
- SelectRemoteDlg dlg(this, engine);
- connect(&dlg, SIGNAL(remoteDownloaded()),
- this, SLOT(updateRemoteName()));
+ SelectRemoteDlg dlg(this);
+ connect(&dlg, SIGNAL(remoteChanged(QString)),
+ this, SLOT(updateRemoteInfo(QString)));
dlg.exec();
}
dlg.exec();
}
-void SettingsDlg::updateRemoteName()
+void SettingsDlg::changeRemote(const QString &name)
{
- QSettings settings(this);
- remoteNameLabel->setText(settings.value("remoteName",
- tr("Select remote")).toString());
+ if (remote)
+ {
+ delete remote;
+ }
+ remote = new Remote(name);
+ connect(remote, SIGNAL(infoUpdated()),
+ this, SLOT(updateRemoteInfo()));
+ remote->updateInfo();
+ enableRateBtns();
+}
+
+void SettingsDlg::updateRemoteInfo()
+{
+ remoteNameLabel->setText(remote->mfg() + " " + remote->name());
+ ratingLabel->setText(tr("Rating") + ": " + remote->rating());
+}
+
+void SettingsDlg::rateUpClicked()
+{
+ remote->sendRating(Rating::Up);
+ enableRateBtns(false);
+}
+
+void SettingsDlg::rateDownClicked()
+{
+ remote->sendRating(Rating::Down);
+ enableRateBtns(false);
}
-void SettingsDlg::setRating(int rating)
+void SettingsDlg::enableRateBtns(bool enable)
{
- qDebug() << rating;
+ rateUpBtn->setEnabled(enable);
+ rateDownBtn->setEnabled(enable);
}