#include "Client.h"
#include <QObject>

Client::Client(QObject *parent)
   : QTcpSocket(parent)
{
   connect(this, SIGNAL(readyRead()), this, SLOT(processData()));
   connect(this, SIGNAL(send(QString)), this, SLOT(sendData(QString)));
}

void Client::processData()
{

   buffer = readLine();
   qDebug() << qPrintable(buffer);
   if(buffer == "Question Answered")
   {
      emit rightAnswerS();
   }
   else if(buffer == "Next Question")
   {
      buffer = readLine();
      emit selectedQuestion(buffer.toInt());
   }
   else if(buffer == "User")
   {
      buffer = readLine();
      emit nickname(buffer);
   }
   buffer.clear();
}

void Client::sendData(const QString& text)
{
   write( text.toUtf8() );
   qDebug("Data sent: \"%s\"", qPrintable(text));
}
