Connected IrCtrl to MainWidget
authorJari Jarvi <t7jaja00@students.oamk.fi>
Tue, 22 Jun 2010 07:11:19 +0000 (10:11 +0300)
committerJari Jarvi <t7jaja00@students.oamk.fi>
Tue, 22 Jun 2010 07:11:19 +0000 (10:11 +0300)
src/irctrl.cpp
src/irctrl.h
src/mainwidget.cpp
src/mainwidget.h
src/settingsdlg.cpp

index 4f40027..92bf8b2 100644 (file)
@@ -1,6 +1,8 @@
 #include <cstdlib>
 
 #include <QSettings>
+#include <QTcpSocket>
+#include <QHostAddress>
 #include <QTimer>
 
 #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();
 }
index 3bc71b4..1cc42ed 100644 (file)
@@ -15,7 +15,7 @@ public:
     ~IrCtrl();
 
 public slots:
-    void sendCmd(const QString &remoteName, const QString &cmd);
+    void sendCmd(const QString &cmd);
 
 private:
     void startLirc();
index fe4eff2..c4b635a 100644 (file)
@@ -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();
index c39f54d..da04052 100644 (file)
@@ -2,6 +2,7 @@
 #define _MAINWIDGET_H_
 
 #include <QWidget>
+#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;
index 4b7d5b3..37295d6 100644 (file)
@@ -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();
 }