/*
 *  Copyright (C) 2007-2008 CMM Sigma Andrzej Chmielowiec <cmmsigma@cmmsigma.eu>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 3
 *  as published by the Free Software Foundation.
 *
 *  This program 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.
 */

#include "VpnInfoWindow.h"

#include <QtGui>
#include "STokenDialog.h"
#include "VpnItem.h"

VpnInfoWindow::VpnInfoWindow(VpnItem *item, QWidget *parent): QDialog(parent), mVpnItem(item)
{
	setWindowTitle(tr("Connection details"));
	setWindowIcon(QIcon(QString(":img/vpn_22.png")));
	
	mOk = new QPushButton(tr("&Close"));
	connect(mOk, SIGNAL(clicked()), this, SLOT(accept()));
	
	QGridLayout *layout = new QGridLayout;
	layout->addWidget(createNameBox(), 0, 0, 1, 3);
	layout->addWidget(createNetDetailsBox(), 1, 0, 1, 3);
	layout->addWidget(createCertsKeyBox(), 2, 0, 1, 3);
	layout->addWidget(mOk, 5, 2);
	
	layout->setColumnStretch(0, 1);
	layout->setRowStretch(4, 1);
	
	setLayout(layout);
}

QGroupBox*
VpnInfoWindow::createNameBox()
{
	QGroupBox *box = new QGroupBox(tr("VPN connection name"));
	QGridLayout *layout = new QGridLayout;
	
	layout->addWidget(new QLabel(tr("Connection name:")), 0, 0);
	layout->addWidget(new QLabel(mVpnItem->sTokenVpnName()), 0, 1);
	layout->setColumnStretch(1, 1);
	
	box->setLayout(layout);
	
	return box;
}

QGroupBox*
VpnInfoWindow::createNetDetailsBox()
{
	QGroupBox *box = new QGroupBox(tr("VPN server"));
	QGridLayout *layout = new QGridLayout;
	
	layout->addWidget(new QLabel(tr("VPN server name or IP address:")), 0, 0);
	layout->addWidget(new QLabel(mVpnItem->remoteVpnServer() + QString(":") + 
		mVpnItem->remoteVpnPort()), 0, 1);
	layout->setColumnStretch(1, 1);
	
	box->setLayout(layout);
	
	return box;
}

QGroupBox*
VpnInfoWindow::createCertsKeyBox()
{
	QGroupBox *box = new QGroupBox(tr("Certificates and key"));
	QGridLayout *layout = new QGridLayout;
	
	layout->addWidget(new QLabel(tr("CA certificate:")), 0, 0);
	layout->addWidget(new QLabel(mVpnItem->confName() + QString("/") + 
		mVpnItem->caCertFileName()), 0, 1);
	layout->addWidget(new QLabel(tr("User certificate:")), 1, 0);
	layout->addWidget(new QLabel(mVpnItem->confName() + QString("/") + 
		mVpnItem->userCertFileName()), 1, 1);
	layout->addWidget(new QLabel(tr("Key name:")), 2, 0);
	layout->addWidget(new QLabel(mVpnItem->key()), 2, 1);
	layout->setColumnStretch(1, 1);
	
	box->setLayout(layout);
	
	return box;
}
