#include "settingsdlg.h"
+#include "advsettingsdlg.h"
+#include "selectremotedlg.h"
+#include "aboutdlg.h"
#include <QHBoxLayout>
+#include <QVBoxLayout>
+#include <QWidget>
+#include <QDialog>
+#include <QPushButton>
#include <QLabel>
-#include <QString>
-#include <QListWidget>
-#include <QListWidgetItem>
-#include <QSettings>
-#include <QtNetwork/QNetworkAccessManager>
-#include <QtNetwork/QNetworkReply>
-#include <QBuffer>
-#include <QByteArray>
+#include <QDebug>
+#include <QNetworkConfiguration>
+#include <QShowEvent>
SettingsDlg::SettingsDlg(QWidget *parent)
: QDialog(parent)
+ , m_busy(false)
+ , m_netConfMan(NULL)
{
- this->setWindowTitle(tr("Settings"));
-
- //TODO caching?
- netAM = new QNetworkAccessManager(this);
+ QSettings settings(this);
+ m_layout = new QVBoxLayout(this);
+ m_btnLayout = new QHBoxLayout();
+ m_remoteNameLayout = new QHBoxLayout();
- settings = new QSettings(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);
- layout = new QHBoxLayout(this);
+ m_btnLayout->addWidget(m_advSettingsBtn);
+ m_btnLayout->addWidget(m_selectRemoteBtn);
+ m_btnLayout->addWidget(m_aboutBtn);
- alphabetList = new QListWidget(this);
- for (char c = 'a'; c <= 'z'; ++c)
- {
- alphabetList->addItem(QString(c));
- }
- layout->addWidget(alphabetList);
- connect(alphabetList, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
- this, SLOT(alphabetItemChanged(QListWidgetItem*, QListWidgetItem*)));
-
- mfgList = new QListWidget(this);
- layout->addWidget(mfgList);
- connect(mfgList, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
- this, SLOT(mfgItemChanged(QListWidgetItem*, QListWidgetItem*)));
+ m_remoteNameLabel = new QLabel(this);
+ m_ratingLabel = new QLabel(this);
+ m_remoteNameLayout->addWidget(m_remoteNameLabel);
+ m_remoteNameLayout->addWidget(m_ratingLabel);
+ m_remoteNameLayout->addWidget(m_rateUpBtn);
+ m_remoteNameLayout->addWidget(m_rateDownBtn);
- modelList = new QListWidget(this);
- layout->addWidget(modelList);
- connect(modelList, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
- this, SLOT(modelItemChanged(QListWidgetItem*, QListWidgetItem*)));
+ connect(m_advSettingsBtn, SIGNAL(clicked()),
+ this, SLOT(showAdvSettingsDlg()));
+ connect(m_selectRemoteBtn, SIGNAL(clicked()),
+ this, SLOT(showSelectRemoteDlg()));
+ 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);
- this->setLayout(layout);
+ QString selectedRemote = settings.value("remoteName", "").toString();
+ if (selectedRemote == "") {
+ m_remoteNameLabel->setText(tr("No remote selected"));
+ enableRateBtns(false);
+ } else {
+ // Create remote by name and update it's info if online
+ m_busy = true;
+ m_remote = Remote(selectedRemote);
+ connect(&m_remote, SIGNAL(infoUpdated()),
+ this, SLOT(updateRemoteInfo()));
+ m_remoteNameLabel->setText(selectedRemote);
+ m_netConfMan = new QTM_PREPEND_NAMESPACE(
+ QNetworkConfigurationManager)(this);
+ connect(m_netConfMan, SIGNAL(updateCompleted()),
+ this, SLOT(onNetworkStatusUpdate()));
+ m_netConfMan->updateConfigurations();
+ enableRateBtns(false);
+ }
}
SettingsDlg::~SettingsDlg()
{
- delete layout;
- delete settings;
- delete netAM;
+ 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;
+ delete m_netConfMan;
}
-void SettingsDlg::alphabetItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
+void SettingsDlg::setBusy(bool busy)
{
- QNetworkReply* reply = netAM->get(
- QNetworkRequest(
- QUrl(
- settings->value(
- "remoteUrl",
- "http://mercury.wipsl.com/irwi/remotes/"
- ).toString() + current->text() + ".txt"
- )
- )
- );
- connect(netAM, SIGNAL(finished(QNetworkReply*)),
- this, SLOT(mfgListDownloadFinished(QNetworkReply*)));
+ setAttribute(Qt::WA_Maemo5ShowProgressIndicator, busy);
+ m_busy = busy;
}
-#include <QDebug>
-void SettingsDlg::mfgListDownloadFinished(QNetworkReply *reply)
+void SettingsDlg::showAdvSettingsDlg()
{
- mfgList->clear();
- QByteArray ba = reply->readAll();
- qDebug() << ba;
- QBuffer buf(&ba, this);
- buf.open(QIODevice::ReadOnly);
- buf.seek(0);
- qDebug() << buf.canReadLine();
- while (buf.canReadLine())
- {
- QString str(buf.readLine());
- mfgList->addItem(str);
- }
- reply->deleteLater();
+ AdvSettingsDlg dlg;
+ dlg.exec();
}
-void SettingsDlg::mfgItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
+void SettingsDlg::showSelectRemoteDlg()
{
+ SelectRemoteDlg dlg;
+ connect(&dlg, SIGNAL(remoteChanged(Remote)),
+ this, SLOT(setRemote(Remote)));
+ dlg.exec();
+ onNetworkStatusUpdate();
}
-void SettingsDlg::modelItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
+void SettingsDlg::showAboutDlg()
{
- if (current)
- {
- settings->setValue("remoteName", current->text());
- //TODO save remote from server to /etc/lircd.conf
- //maybe lirc needs restart after that?
+ AboutDlg dlg;
+ dlg.exec();
+}
+
+void SettingsDlg::setRemote(Remote r)
+{
+ m_remote = r;
+ connect(&m_remote, SIGNAL(infoUpdated()),
+ this, SLOT(updateRemoteInfo()));
+ updateRemoteInfo();
+ enableRateBtns();
+}
+
+void SettingsDlg::onNetworkStatusUpdate()
+{
+ if (m_netConfMan->isOnline()) {
+ setBusy();
+ m_remote.updateInfo();
+ enableRateBtns();
+ } else {
+ m_ratingLabel->setText(tr("Offline"));
+ setBusy(false);
}
}
+void SettingsDlg::updateRemoteInfo()
+{
+ setBusy(false);
+ m_remoteNameLabel->setText(m_remote.mfg() + " " + m_remote.name());
+ m_ratingLabel->setText(tr("Rating") + ": "
+ + QString::number(m_remote.rating()));
+}
+
+void SettingsDlg::rateUpClicked()
+{
+ processRatingSent();
+ m_remote.sendRating(Rating::Up);
+}
+
+void SettingsDlg::rateDownClicked()
+{
+ processRatingSent();
+ m_remote.sendRating(Rating::Down);
+}
+
+void SettingsDlg::processRatingSent()
+{
+ setBusy();
+ enableRateBtns(false);
+}
+
+void SettingsDlg::enableRateBtns(bool enable)
+{
+ m_rateUpBtn->setEnabled(enable);
+ m_rateDownBtn->setEnabled(enable);
+}
+
+void SettingsDlg::showEvent(QShowEvent *event)
+{
+ setBusy(m_busy);
+ QDialog::showEvent(event);
+}
+
+
+