Read socket data if available.
authorIonutz Borcoman <iborco@gmail.com>
Thu, 24 Feb 2011 19:40:34 +0000 (21:40 +0200)
committerIonutz Borcoman <iborco@gmail.com>
Thu, 10 Mar 2011 08:10:13 +0000 (10:10 +0200)
src/mainwindow.cpp
src/mainwindow.h

index 320f7fd..e152515 100644 (file)
 #include "setupdialog.h"
 #include "json.h"
 
-#include <QtCore/QCoreApplication>
-#include <QtCore/QSettings>
-#include <QtCore/QTimer>
-#include <QtCore/QTextStream>
+#include <QCoreApplication>
+#include <QSettings>
+#include <QTimer>
+#include <QTextStream>
 
 #if defined(Q_OS_SYMBIAN) && defined(ORIENTATIONLOCK)
 #include <eikenv.h>
@@ -189,15 +189,20 @@ ConnectedState::ConnectedState(QAbstractButton *button, QTcpSocket* socket, QSta
 {
     assignProperty(button, "text", "Disconnect");
     assignProperty(button, "enabled", true);
-
 }
 
 void ConnectedState::onEntry(QEvent */*event*/)
 {
     qDebug("ConnectedState::onEntry");
 
+    connect(m_socket, SIGNAL(readyRead()), this, SLOT(onSocketData()));
     connect(m_socket, SIGNAL(disconnected()), this, SIGNAL(disconnected()));
     connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onSocketError(QAbstractSocket::SocketError)));
+
+    QTextStream stream(m_socket);
+    stream << JsonEngine().playerGetActivePlayers();
+
+    qDebug("ConnectedState::onEntry - request sent");
 }
 
 void ConnectedState::onExit(QEvent */*event*/)
@@ -211,6 +216,13 @@ void ConnectedState::onSocketError(QAbstractSocket::SocketError)
     qDebug("ConnectedState::onSocketError: %s", qPrintable(m_socket->errorString()));
 }
 
+void ConnectedState::onSocketData()
+{
+    QTextStream stream(m_socket);
+    QString msg = stream.readAll();
+    qDebug("ConnectedState::onSocketData: %s", qPrintable(msg));
+}
+
 /////////////////////////////////////////////////////////////////////
 //
 DisconnectingState::DisconnectingState(QAbstractButton *button, QTcpSocket* socket, QState *parent)
index e8c488c..beb9299 100644 (file)
@@ -58,6 +58,7 @@ public:
 
 private slots:
     void onSocketError(QAbstractSocket::SocketError err);
+    void onSocketData();
 
 signals:
     void disconnected();