#include <QWidget>
#include <QDialog>
#include <QPushButton>
-#include <QSettings>
#include <QLabel>
+#include <QDebug>
SettingsDlg::SettingsDlg(QWidget *parent)
: QDialog(parent)
{
- 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);
+ m_layout = new QVBoxLayout(this);
+ m_btnLayout = new QHBoxLayout(this);
+ m_remoteNameLayout = new QHBoxLayout(this);
+
+ m_advSettingsBtn = new QPushButton(tr("Advanced"), this);
+ m_selectRemoteBtn = new QPushButton(tr("Select remote"), this);
+ m_aboutBtn = new QPushButton(tr("About"), this);
+ m_rateUpBtn = new QPushButton(
+ QIcon(settings.value("rateUpIcon",
+ "/usr/share/icons/hicolor/48x48/hildon/chat_smiley_happy.png").
+ toString()),
+ "", this);
+ m_rateDownBtn = new QPushButton(
+ QIcon(settings.value("rateDownIcon",
+ "/usr/share/icons/hicolor/48x48/hildon/chat_smiley_sad.png").
+ toString()),
+ "", this);
+ m_rateUpBtn->setMaximumSize(72, 72);
+ m_rateDownBtn->setMaximumSize(72, 72);
+
+ m_btnLayout->addWidget(m_advSettingsBtn);
+ m_btnLayout->addWidget(m_selectRemoteBtn);
+ m_btnLayout->addWidget(m_aboutBtn);
- btnLayout->addWidget(advSettingsBtn);
- btnLayout->addWidget(selectRemoteBtn);
- btnLayout->addWidget(aboutBtn);
+ m_remoteNameLabel = new QLabel(this);
+ m_ratingLabel = new QLabel(this);
+ m_ratingLabel->setText(tr("Rating"));
+ m_remoteNameLayout->addWidget(m_remoteNameLabel);
+ m_remoteNameLayout->addWidget(m_ratingLabel);
+ m_remoteNameLayout->addWidget(m_rateUpBtn);
+ m_remoteNameLayout->addWidget(m_rateDownBtn);
- connect(advSettingsBtn, SIGNAL(clicked()),
+ connect(m_advSettingsBtn, SIGNAL(clicked()),
this, SLOT(showAdvSettingsDlg()));
- connect(selectRemoteBtn, SIGNAL(clicked()),
+ connect(m_selectRemoteBtn, SIGNAL(clicked()),
this, SLOT(showSelectRemoteDlg()));
- connect(aboutBtn, SIGNAL(clicked()),
+ connect(m_aboutBtn, SIGNAL(clicked()),
this, SLOT(showAboutDlg()));
+ connect(m_rateUpBtn, SIGNAL(clicked()),
+ this, SLOT(rateUpClicked()));
+ connect(m_rateDownBtn, SIGNAL(clicked()),
+ this, SLOT(rateDownClicked()));
+
+ m_layout->addLayout(m_remoteNameLayout);
+ m_layout->addLayout(m_btnLayout);
+ this->setLayout(m_layout);
- remoteNameLabel = new QLabel(
- settings.value("remoteName",
- tr("<no remote selected>")).toString(), this);
- remoteNameLayout->addWidget(new QLabel(tr("Remote name: "), this));
- remoteNameLayout->addWidget(remoteNameLabel);
-
- layout->addLayout(remoteNameLayout);
- layout->addLayout(btnLayout);
- this->setLayout(layout);
-
- updateRemoteName();
+ initRemote();
}
SettingsDlg::~SettingsDlg()
{
- delete advSettingsBtn;
- delete selectRemoteBtn;
- delete aboutBtn;
- delete remoteNameLabel;
- delete remoteNameLayout;
- delete btnLayout;
- delete layout;
+ delete m_advSettingsBtn;
+ delete m_selectRemoteBtn;
+ delete m_rateUpBtn;
+ delete m_rateDownBtn;
+ delete m_aboutBtn;
+ delete m_remoteNameLabel;
+ delete m_ratingLabel;
+ delete m_btnLayout;
+ delete m_remoteNameLayout;
+ delete m_layout;
}
void SettingsDlg::showAdvSettingsDlg()
{
AdvSettingsDlg dlg(this);
dlg.exec();
- updateRemoteName();
}
void SettingsDlg::showSelectRemoteDlg()
{
SelectRemoteDlg dlg(this);
- connect(&dlg, SIGNAL(remoteDownloaded()),
- this, SLOT(updateRemoteName()));
+ connect(&dlg, SIGNAL(m_remoteChanged(Remote)),
+ this, SLOT(setRemote(Remote)));
+ updateRemoteInfo();
dlg.exec();
}
dlg.exec();
}
-void SettingsDlg::updateRemoteName()
+void SettingsDlg::initRemote()
{
- QSettings settings(this);
- remoteNameLabel->setText(settings.value("remoteName",
- tr("Select remote")).toString());
+ QString selectedRemote = QSettings(this).value("remoteName", "").toString();
+ if (selectedRemote == "") {
+ m_remoteNameLabel->setText("No remote selected");
+ enableRateBtns(false);
+ } else {
+ m_remote = Remote(selectedRemote);
+ connect(&m_remote, SIGNAL(infoUpdated()),
+ this, SLOT(updateRemoteInfo()));
+ m_remote.updateInfo();
+ enableRateBtns();
+ }
+}
+
+void SettingsDlg::setRemote(Remote r)
+{
+ m_remote = r;
+ enableRateBtns();
+}
+
+void SettingsDlg::updateRemoteInfo()
+{
+ m_remoteNameLabel->setText(m_remote.mfg() + " " + m_remote.name());
+ m_ratingLabel->setText(tr("Rating") + ": "
+ + QString::number(m_remote.rating()));
+}
+
+void SettingsDlg::rateUpClicked()
+{
+ m_remote.sendRating(Rating::Up);
+ enableRateBtns(false);
+}
+
+void SettingsDlg::rateDownClicked()
+{
+ m_remote.sendRating(Rating::Down);
+ enableRateBtns(false);
+}
+
+void SettingsDlg::enableRateBtns(bool enable)
+{
+ m_rateUpBtn->setEnabled(enable);
+ m_rateDownBtn->setEnabled(enable);
}