//
// C++ Implementation: main
//
// Description: 
//
//
// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2006
//
// Copyright: See COPYING file that comes with this distribution
//
//

#include <QApplication>
#include <QLineEdit>
#include <QLabel>
#include <QIntValidator>
#include <QPushButton>
#include <QMenuBar>
#include <QMenu>
#include <QGridLayout>
#include <QHBoxLayout>

#include "main.h"
#include "client.h"
#include "server.h"

CMain::CMain()
{
	//create menu
	QMenu *m=menuBar()->addMenu("&File");
	m->addAction("E&xit",QApplication::instance(),SLOT(quit()));
	//create main widget
	QWidget*w=new QWidget;
	setCentralWidget(w);
	QGridLayout*gl=new QGridLayout;
	w->setLayout(gl);
	//create edits
	gl->addWidget(new QLabel("Host:"),0,0);
	gl->addWidget(host=new QLineEdit,0,1);
	gl->addWidget(new QLabel("Port:"),1,0);
	gl->addWidget(port=new QLineEdit,1,1);
	port->setValidator(new QIntValidator(1,65535,port));
	//create buttons
	gl->setRowMinimumHeight(2,15);
	QHBoxLayout*hl;
	gl->addLayout(hl=new QHBoxLayout,2,0,1,2);
	hl->addStretch(10);
	QPushButton*p;
	hl->addWidget(p=new QPushButton("Create Server"));
	connect(p,SIGNAL(clicked()),this,SLOT(newServer()));
	hl->addWidget(p=new QPushButton("Create Client"));
	connect(p,SIGNAL(clicked()),this,SLOT(newClient()));
}

void CMain::newClient()
{
	CClient *c=new CClient(host->text(),port->text().toInt(),this);
	c->show();
}

void CMain::newServer()
{
	CServer *s=new CServer(port->text().toInt(),this);
	s->show();
}

int main(int argc,char**argv)
{
	QApplication app(argc,argv);
	CMain cm;
	cm.show();
	return app.exec();
}
