From 9cb0ca7e6de20439f0df7c0121061c9f17c632b4 Mon Sep 17 00:00:00 2001 From: Jari Jarvi Date: Tue, 22 Jun 2010 10:11:19 +0300 Subject: [PATCH] Connected IrCtrl to MainWidget --- src/irctrl.cpp | 27 +++++++++++++++------------ src/irctrl.h | 2 +- src/mainwidget.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++-------- src/mainwidget.h | 11 +++++++++++ src/settingsdlg.cpp | 5 +++-- 5 files changed, 72 insertions(+), 23 deletions(-) diff --git a/src/irctrl.cpp b/src/irctrl.cpp index 4f40027..92bf8b2 100644 --- a/src/irctrl.cpp +++ b/src/irctrl.cpp @@ -1,6 +1,8 @@ #include #include +#include +#include #include #include "irctrl.h" @@ -14,7 +16,7 @@ IrCtrl::~IrCtrl() { } -void IrCtrl::sendCmd(const QString &remoteName, const QString &cmd) +void IrCtrl::sendCmd(const QString &cmd) { if (!killLircTimer->isActive()) { startLirc(); @@ -22,17 +24,18 @@ void IrCtrl::sendCmd(const QString &remoteName, const QString &cmd) killLircTimer->stop(); } -// QTcpSocket sock; -// QSettings settings(this); -// sock.setSocketOption(QAbstractSocket::LowDelayOption, 1); -// sock.connectToHost(QHostAddress::LocalHost, -// settings.value("lircPort", LIRC_PORT).toInt(), -// QIODevice::WriteOnly|QIODevice::Unbuffered); -// sock.waitForConnected(); -// QString cmdStr = "SEND_ONCE " + cmd.remoteName + " " + cmd.cmd + "\n"; -// sock.write(cmdStr.toAscii()); -// sock.waitForBytesWritten(); -// sock.close(); + QTcpSocket sock; + QSettings settings(this); + sock.setSocketOption(QAbstractSocket::LowDelayOption, 1); + sock.connectToHost(QHostAddress::LocalHost, + settings.value("lircPort", LIRC_PORT).toInt(), + QIODevice::WriteOnly | QIODevice::Unbuffered); + sock.waitForConnected(); + QString remoteName = settings.value("remoteName", "").toString(); + QString cmdStr = "SEND_ONCE " + remoteName + " " + cmd + "\n"; + sock.write(cmdStr.toAscii()); + sock.waitForBytesWritten(); + sock.close(); killLircTimer->start(); } diff --git a/src/irctrl.h b/src/irctrl.h index 3bc71b4..1cc42ed 100644 --- a/src/irctrl.h +++ b/src/irctrl.h @@ -15,7 +15,7 @@ public: ~IrCtrl(); public slots: - void sendCmd(const QString &remoteName, const QString &cmd); + void sendCmd(const QString &cmd); private: void startLirc(); diff --git a/src/mainwidget.cpp b/src/mainwidget.cpp index fe4eff2..c4b635a 100644 --- a/src/mainwidget.cpp +++ b/src/mainwidget.cpp @@ -23,8 +23,7 @@ MainWidget::MainWidget (QWidget *parent) "/usr/share/icons/hicolor/48x48/hildon/statusarea_volume_mute.png" }; - for (int i = 0; i < BUTTON_COUNT; ++i) - { + for (int i = 0; i < BUTTON_COUNT; ++i) { QToolButton *button = new QToolButton(this); button->setIcon(QIcon(QString( settings->value(QString("buttonIcon") + QString::number(i), @@ -35,14 +34,19 @@ MainWidget::MainWidget (QWidget *parent) layout->addWidget(button, i%2, i/2); } - this->setContentsMargins(0, 0, 0, 0); + connect(buttons[0], SIGNAL(clicked()), this, SLOT(sendCmdVolUp())); + connect(buttons[1], SIGNAL(clicked()), this, SLOT(sendCmdVolDown())); + connect(buttons[2], SIGNAL(clicked()), this, SLOT(sendCmdChUp())); + connect(buttons[3], SIGNAL(clicked()), this, SLOT(sendCmdChDown())); + connect(buttons[4], SIGNAL(clicked()), this, SLOT(sendCmdPower())); + connect(buttons[5], SIGNAL(clicked()), this, SLOT(sendCmdMute())); + + setContentsMargins(0, 0, 0, 0); layout->setContentsMargins(0, 0, 0, 0); - this->setLayout(layout); - this->setAttribute(Qt::WA_TranslucentBackground); - this->setAttribute(Qt::WA_OpaquePaintEvent); + setLayout(layout); + setAttribute(Qt::WA_TranslucentBackground); + setAttribute(Qt::WA_OpaquePaintEvent); resize(); - - showSettingsDialog(); } MainWidget::~MainWidget() @@ -50,6 +54,36 @@ MainWidget::~MainWidget() delete settings; } +void MainWidget::sendCmdVolUp() +{ + irCtrl.sendCmd(settings->value("volUpCmd", "VOLUP").toString()); +} + +void MainWidget::sendCmdVolDown() +{ + irCtrl.sendCmd(settings->value("volDownCmd", "VOLDOWN").toString()); +} + +void MainWidget::sendCmdChUp() +{ + irCtrl.sendCmd(settings->value("chUpCmd", "CHUP").toString()); +} + +void MainWidget::sendCmdChDown() +{ + irCtrl.sendCmd(settings->value("chDownCmd", "CHDOWN").toString()); +} + +void MainWidget::sendCmdPower() +{ + irCtrl.sendCmd(settings->value("powerCmd", "POWER").toString()); +} + +void MainWidget::sendCmdMute() +{ + irCtrl.sendCmd(settings->value("muteCmd", "MUTE").toString()); +} + void MainWidget::paintEvent(QPaintEvent*) { int bgAlpha = settings->value("bgAlpha", "192").toInt(); diff --git a/src/mainwidget.h b/src/mainwidget.h index c39f54d..da04052 100644 --- a/src/mainwidget.h +++ b/src/mainwidget.h @@ -2,6 +2,7 @@ #define _MAINWIDGET_H_ #include +#include "irctrl.h" class IEngine; class QGridLayout; @@ -19,6 +20,14 @@ public: public slots: void showSettingsDialog(); +private slots: + void sendCmdVolUp(); + void sendCmdVolDown(); + void sendCmdChUp(); + void sendCmdChDown(); + void sendCmdPower(); + void sendCmdMute(); + protected: void paintEvent(QPaintEvent *event); @@ -26,6 +35,8 @@ private: void resize(); private: + IrCtrl irCtrl; + QSettings *settings; static const int BUTTON_COUNT = 6; QGridLayout *layout; diff --git a/src/settingsdlg.cpp b/src/settingsdlg.cpp index 4b7d5b3..37295d6 100644 --- a/src/settingsdlg.cpp +++ b/src/settingsdlg.cpp @@ -20,7 +20,7 @@ SettingsDlg::SettingsDlg(QWidget *parent) m_remoteNameLayout = new QHBoxLayout(this); m_advSettingsBtn = new QPushButton(tr("Advanced"), this); - m_selectRemoteBtn = new QPushButton(tr("Select m_remote"), this); + m_selectRemoteBtn = new QPushButton(tr("Select remote"), this); m_aboutBtn = new QPushButton(tr("About"), this); m_rateUpBtn = new QPushButton( QIcon(settings.value("rateUpIcon", @@ -41,6 +41,7 @@ SettingsDlg::SettingsDlg(QWidget *parent) 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); @@ -89,6 +90,7 @@ void SettingsDlg::showSelectRemoteDlg() SelectRemoteDlg dlg(this); connect(&dlg, SIGNAL(m_remoteChanged(Remote)), this, SLOT(setRemote(Remote))); + updateRemoteInfo(); dlg.exec(); } @@ -116,7 +118,6 @@ void SettingsDlg::initRemote() void SettingsDlg::setRemote(Remote r) { m_remote = r; - updateRemoteInfo(); enableRateBtns(); } -- 1.7.9.5