#include "settingsdlg.h"
+#include "advsettingsdlg.h"
+#include "selectremotedlg.h"
+#include "aboutdlg.h"
+#include "remote.h"
#include <QHBoxLayout>
+#include <QVBoxLayout>
+#include <QWidget>
+#include <QDialog>
+#include <QPushButton>
#include <QLabel>
-#include <QString>
-#include <QListWidget>
+#include <QDebug>
SettingsDlg::SettingsDlg(QWidget *parent)
: QDialog(parent)
+ , remote(NULL)
{
- this->setWindowTitle(tr("Settings"));
- layout = new QHBoxLayout(this);
+ layout = new QVBoxLayout(this);
+ btnLayout = new QHBoxLayout(this);
+ remoteNameLayout = new QHBoxLayout(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").
+ toString()),
+ "", this);
+ rateDownBtn = new QPushButton(
+ QIcon(settings.value("rateDownIcon",
+ "/usr/share/icons/hicolor/48x48/hildon/chat_smiley_sad.png").
+ toString()),
+ "", this);
+ rateUpBtn->setMaximumSize(72, 72);
+ rateDownBtn->setMaximumSize(72, 72);
+
+ btnLayout->addWidget(advSettingsBtn);
+ 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);
- alphabetList = new QListWidget(this);
- for (char c = 'a'; c <= 'z'; ++c)
+ connect(advSettingsBtn, SIGNAL(clicked()),
+ this, SLOT(showAdvSettingsDlg()));
+ connect(selectRemoteBtn, SIGNAL(clicked()),
+ this, SLOT(showSelectRemoteDlg()));
+ connect(aboutBtn, SIGNAL(clicked()),
+ this, SLOT(showAboutDlg()));
+ connect(rateUpBtn, SIGNAL(clicked()),
+ this, SLOT(rateUpClicked()));
+ connect(rateDownBtn, SIGNAL(clicked()),
+ this, SLOT(rateDownClicked()));
+
+ QString selectedRemote = settings.value("remoteName", "").toString();
+ if (selectedRemote == "")
{
- alphabetList->addItem(QString(c));
+ remoteNameLabel->setText(tr("No remote selected"));
+ enableRateBtns(false);
+ }
+ else
+ {
+ changeRemote();
}
- layout->addWidget(alphabetList);
-
- mfgList = new QListWidget(this);
- mfgList->addItem("foo");
- layout->addWidget(mfgList);
-
- modelList = new QListWidget(this);
- modelList->addItem("bar");
- layout->addWidget(modelList);
+ layout->addLayout(remoteNameLayout);
+ layout->addLayout(btnLayout);
this->setLayout(layout);
}
SettingsDlg::~SettingsDlg()
{
delete layout;
+ delete btnLayout;
+ delete remoteNameLayout;
+ delete advSettingsBtn;
+ delete selectRemoteBtn;
+ delete rateUpBtn;
+ delete rateDownBtn;
+ delete aboutBtn;
+ delete remoteNameLabel;
+ delete ratingLabel;
+ if (remote)
+ {
+ delete remote;
+ }
}
-QString& SettingsDlg::getRemoteName()
+void SettingsDlg::showAdvSettingsDlg()
{
- return remoteName;
+ AdvSettingsDlg dlg(this);
+ dlg.exec();
}
+void SettingsDlg::showSelectRemoteDlg()
+{
+ SelectRemoteDlg dlg(this);
+ changeRemote();
+ dlg.exec();
+}
+
+void SettingsDlg::showAboutDlg()
+{
+ AboutDlg dlg(this);
+ dlg.exec();
+}
+
+void SettingsDlg::changeRemote()
+{
+ if (remote)
+ {
+ delete remote;
+ }
+ remote = new Remote(settings.value("remoteName", "").toString());
+ 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::enableRateBtns(bool enable)
+{
+ rateUpBtn->setEnabled(enable);
+ rateDownBtn->setEnabled(enable);
+}
+
+