Add first stub of adapter for sending X keyboard events.
[qzeecontrol] / btconnector.h
index 7ea6e63..f5a3541 100644 (file)
@@ -1,3 +1,22 @@
+/*
+ *  Copyright 2012 Ruediger Gad
+ *
+ *  This file is part of QZeeControl.
+ *
+ *  QZeeControl is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  QZeeControl is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with QZeeControl.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #ifndef BTCONNECTOR_H
 #define BTCONNECTOR_H
 
@@ -9,15 +28,25 @@ QTM_USE_NAMESPACE
 class BtConnector : public QObject
 {
     Q_OBJECT
+
+    Q_PROPERTY(int x READ x NOTIFY xChanged)
+    Q_PROPERTY(int y READ y NOTIFY yChanged)
 public:
-    explicit BtConnector(QObject *parent = 0){qDebug("BtConnector Constructor");}
-    ~BtConnector(){if(socket != NULL) delete socket;}
+    explicit BtConnector(QObject *parent = 0){
+        _x = 0;
+        _y = 0;
+    }
+    ~BtConnector(){
+        if(socket)
+            delete socket;
+    }
 
     Q_INVOKABLE void connect(QString address, int port){
         qDebug("Trying to connect to: %s--%d", address.toUtf8().constData(), port);
 
-        if(socket != NULL)
+        if(socket)
             delete socket;
+
         socket = new QBluetoothSocket(QBluetoothSocket::RfcommSocket);
         QObject::connect(socket, SIGNAL(connected()), this, SIGNAL(connected()));
         QObject::connect(socket, SIGNAL(disconnected()), this, SIGNAL(disconnected()));
@@ -30,15 +59,19 @@ public:
         QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
     }
 
+    int x(){return _x;}
+    int y(){return _y;}
+
 public slots:
     void disconnect(){
-        if(socket == NULL)
+        if(!socket)
             return;
 
         if(socket->isOpen())
             socket->close();
 
         delete socket;
+        socket = 0;
     }
 
 signals:
@@ -49,6 +82,9 @@ signals:
     void stickMoved(int x, int y);
     void buttonsChanged(bool a, bool b, bool c, bool d);
 
+    void xChanged(int);
+    void yChanged(int);
+
 private slots:
     void readData(){
 //        qDebug("readData...");
@@ -68,7 +104,12 @@ private slots:
          */
         if(data.at(0) == 5){
             // Joystick movement
-            emit(stickMoved((int)(signed char) data.at(4), (int)(signed char) data.at(5)));
+            _x = (int)(signed char) data.at(4);
+            _y = (int)(signed char) data.at(5);
+
+            emit(xChanged(_x));
+            emit(yChanged(_y));
+            emit(stickMoved(_x, _y));
         }else if(data.at(0) == 8){
             // Button press
             /*
@@ -86,7 +127,7 @@ private slots:
                 }
             }
 
-            qDebug("Button map: %d", buttonMap);
+//            qDebug("Button map: %d", buttonMap);
             emit(buttonsChanged(buttonMap & 0x01, buttonMap & 0x02, buttonMap & 0x04, buttonMap & 0x08));
         }
     }
@@ -94,6 +135,8 @@ private slots:
 private:
     QBluetoothSocket *socket;
 
+    int _x;
+    int _y;
 };
 
 #endif // BTCONNECTOR_H