-#include "irctrl.h"
-
#include <cstdlib>
#include <QTcpSocket>
#include <QIODevice>
#include <QHostAddress>
#include <QAbstractSocket>
+#include <QSettings>
+
+#include "irctrl.h"
IrCtrl::IrCtrl()
+ : settings(NULL)
{
+ settings = new QSettings(this);
std::system("lircctl start");
}
IrCtrl::~IrCtrl()
{
+ delete settings;
+ settings = NULL;
std::system("lircctl stop");
}
void IrCtrl::genericSendCmd(const QString &commandName)
{
- QSettings settings(this);
QTcpSocket sock(this);
// sock.setSocketOption(QAbstractSocket::LowDelayOption, 1);
sock.connectToHost(QHostAddress::LocalHost,
- settings.value("lircPort", LIRC_PORT).toInt(),
+ settings->value("lircPort", LIRC_PORT).toInt(),
QIODevice::WriteOnly|QIODevice::Unbuffered);
sock.waitForConnected();
- QString remoteName = settings.value("remoteName", "REMOTE_NAME_MISSING").toString();
+ QString remoteName =
+ settings->value("remoteName", "REMOTE_NAME_MISSING").toString();
QString cmd = "SEND_ONCE " + remoteName + " " + commandName + "\n";
sock.write(cmd.toAscii());
sock.waitForBytesWritten();
sock.close();
}
-void IrCtrl::sendCmd0(bool)
+void IrCtrl::sendCmd0()
{
- genericSendCmd(settings.value("cmd0", "VOL+").toString());
+ genericSendCmd(settings->value("cmd0", "VOL+").toString());
}
-void IrCtrl::sendCmd1(bool)
+void IrCtrl::sendCmd1()
{
- genericSendCmd(settings.value("cmd1", "VOL-"));
+ genericSendCmd(settings->value("cmd1", "VOL-").toString());
}
-void IrCtrl::sendCmd2(bool)
+void IrCtrl::sendCmd2()
{
- genericSendCmd(settings.value("cmd2", "P+"));
+ genericSendCmd(settings->value("cmd2", "P+").toString());
}
-void IrCtrl::sendCmd3(bool)
+void IrCtrl::sendCmd3()
{
- genericSendCmd(settings.value("cmd3", "P-"));
+ genericSendCmd(settings->value("cmd3", "P-").toString());
}
-void IrCtrl::sendCmd4(bool)
+void IrCtrl::sendCmd4()
{
- genericSendCmd(settings.value("cmd4", "ON/OFF"));
+ genericSendCmd(settings->value("cmd4", "ON/OFF").toString());
}
-void IrCtrl::sendCmd5(bool)
+void IrCtrl::sendCmd5()
{
- genericSendCmd(settings.value("cmd5", "MUTE"));
+ genericSendCmd(settings->value("cmd5", "MUTE").toString());
}
#include <QObject>
#include <QString>
+class QSettings;
+
class IrCtrl : public QObject
{
Q_OBJECT
~IrCtrl();
public slots:
- void sendCmd0(bool);
- void sendCmd1(bool);
- void sendCmd2(bool);
- void sendCmd3(bool);
- void sendCmd4(bool);
- void sendCmd5(bool);
+ void sendCmd0();
+ void sendCmd1();
+ void sendCmd2();
+ void sendCmd3();
+ void sendCmd4();
+ void sendCmd5();
private:
+ QSettings *settings;
static const quint16 LIRC_PORT = 8765;
void genericSendCmd(const QString &commandName);
};
#include <QPainter>
#include <QGridLayout>
#include <QToolButton>
+#include <QSettings>
#include "settingsdlg.h"
QToolButton *button = new QToolButton(this);
button->setIcon(QIcon(QString(
settings.value(QString("buttonIcon") + QString::number(i),
- iconNames[i]))));
+ iconNames[i]).toString())));
buttons[i] = button;
button->setPalette(QPalette(QColor(0, 0, 0, 192)));
layout->addWidget(button, i%2, i/2);
}
- connect(buttons[0], SIGNAL(clicked(bool)), &irCtrl, SLOT(sendCmd0(bool)));
- connect(buttons[1], SIGNAL(clicked(bool)), &irCtrl, SLOT(sendCmd1(bool)));
- connect(buttons[2], SIGNAL(clicked(bool)), &irCtrl, SLOT(sendCmd2(bool)));
- connect(buttons[3], SIGNAL(clicked(bool)), &irCtrl, SLOT(sendCmd3(bool)));
- connect(buttons[4], SIGNAL(clicked(bool)), &irCtrl, SLOT(sendCmd4(bool)));
- connect(buttons[5], SIGNAL(clicked(bool)), &irCtrl, SLOT(sendCmd5(bool)));
+ connect(buttons[0], SIGNAL(clicked()), &irCtrl, SLOT(sendCmd0()));
+ connect(buttons[1], SIGNAL(clicked()), &irCtrl, SLOT(sendCmd1()));
+ connect(buttons[2], SIGNAL(clicked()), &irCtrl, SLOT(sendCmd2()));
+ connect(buttons[3], SIGNAL(clicked()), &irCtrl, SLOT(sendCmd3()));
+ connect(buttons[4], SIGNAL(clicked()), &irCtrl, SLOT(sendCmd4()));
+ connect(buttons[5], SIGNAL(clicked()), &irCtrl, SLOT(sendCmd5()));
this->setContentsMargins(0, 0, 0, 0);
layout->setContentsMargins(0, 0, 0, 0);
SettingsDlg::~SettingsDlg()
{
delete layout;
+ layout = NULL;
delete settings;
+ settings = NULL;
delete mfgNetAM;
+ mfgNetAM = NULL;
delete modelNetAM;
+ modelNetAM = NULL;
delete remoteNetAM;
+ remoteNetAM = NULL;
delete deviceNameMap;
+ deviceNameMap = NULL;
}
void SettingsDlg::beginDownload(const QString &url, QNetworkAccessManager *nam)
nam->get(QNetworkRequest(QUrl(url)));
}
-void SettingsDlg::alphabetItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
+void SettingsDlg::alphabetItemChanged(QListWidgetItem *current,
+ QListWidgetItem *previous)
{
- QString url = settings->value("remoteUrl", "http://mercury.wipsl.com/irwi/remotes/").toString()
- + current->text() + ".txt";
+ QString url = settings->value("remoteUrl",
+ "http://mercury.wipsl.com/irwi/remotes/").toString() +
+ current->text() + ".txt";
beginDownload(url, mfgNetAM);
}
{
if (!current->text().isEmpty()) {
QString url = settings->value(
- "remoteUrl", "http://mercury.wipsl.com/irwi/remotes/").toString()
- + alphabetList->currentItem()->text()
- + "/" + mfgList->currentItem()->text()
- + "/" + (*deviceNameMap)[current->text()];
+ "remoteUrl",
+ "http://mercury.wipsl.com/irwi/remotes/").toString()
+ + alphabetList->currentItem()->text()
+ + "/" + mfgList->currentItem()->text()
+ + "/" + (*deviceNameMap)[current->text()];
beginDownload(url, remoteNetAM);
settings->setValue("remoteName", current->text());
}
void SettingsDlg::remoteDownloadFinished(QNetworkReply *reply)
{
if (reply->error() == QNetworkReply::NoError) {
- QFile file(settings->value("lircConf", "/etc/lircd.conf"));
+ QFile file(settings->value("lircConf", "/etc/lircd.conf").toString());
if(file.open(QIODevice::WriteOnly))
{
file.write(reply->readAll());