#include <qsocket.h>
#include <qobject.h>
#include <qserversocket.h>
#include <qmessagebox.h>
#include "formconfig.h"

void FormChat::init()
{
    qDebug("FormChat::init()");
    serveur=FALSE;
    AdrServeur="localhost";
    port=4242;
    textEdit2->setText("Connection au serveur impossible...");
}

void FormChat::a_propos_de()
{
    QMessageBox::information(this,"A propos de...","Ce logiciel a été créé par MARIN Jean-Christophe.\nPour le contacter : triscorp@ifrance.com");
}


void FormChat::configuration()
{
    qDebug("FormChat::configuration()");
    FormConfig * fconfig=new FormConfig(this,"FormConfig",true,Qt::WStyle_Dialog);
    fconfig->show();
}



void FormChat::envoie_message()
{
    // Ajout du message aux autres messages
    QString Texte_present=textEdit2->text();
    QString Texte_envoie=lineEditSend->text();
    Texte_present+="\n";
    Texte_present+=Texte_envoie;
    textEdit2->setText(Texte_present);
    // Envoie du message vers le serveur
    QTextStream os(masocket);
    os << lineEditSend->text() << "\n";
    lineEditSend->setText("");
}


void FormChat::connecter()
{
    qDebug("FormChat::connecter()");
    if (serveur)
    {
	// Création du serveur
	qDebug("Création du serveur");
	maServeurSocket= new jcServeurSocket (4242,1, this, "Masocket");
    }
    else
    {
	// Connection au serveur
	masocket=new QSocket( this );
	qDebug("Connection au client");
	masocket->connectToHost(AdrServeur, port);
	qDebug("Création réalisé");
    }
}
