/***************************************************************************
 *   Copyright (C) 2004 by Christoph Thielecke                             *
 *   crissi99@gmx.de                                                       *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   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.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
//BEGIN INCLUDES

#include <klocale.h>
#include <qlabel.h>
#include <qhbox.h>
#include <qvbox.h>
#include <qpushbutton.h>
#include <qradiobutton.h>
#include <qcheckbox.h>
#include <klineedit.h>
#include <qlineedit.h>
#include <kmessagebox.h>
#include <kcombobox.h>
#include <kurlrequester.h>
#include <knuminput.h>
#include <kpassdlg.h>
#include <qspinbox.h>

#include <iostream>

#include <kstddirs.h>

#include "kvpncconfig.h"
#include "networkinterface.h"
#include "newprofilewizard.h"
#include "utils.h"
//END INCLUDES

NewProfileWizard::NewProfileWizard(KVpncConfig* GlobalConfig)
{
	this->GlobalConfig = GlobalConfig;

	newProfileCreated=false;
	setCaption(i18n("Add new profile..."));
	//setMinimumSize( 400,300);

	SetupPixmap = new QPixmap(locate("data","kvpnc/newprofilewizard.png"));

	// currently static for new profile
	VpnAccountData::ConnectionType ConnType = VpnAccountData::ConnectionType(VpnAccountData::other);
	Port = 500;
	Gateway = "";
	ID = "";
	Username = "";
	UserPassword = "";
	PreSharedKey = "";
	ApplicationVersion = "";
	NtDomainName = "";
	PerfectForwardSecrecy = "";
	IkeGroup = "";
	Description ="";
	useApplicationVersion = false;
	useGlobalIpsecSecret = false;
	useIkeGroup = false;
	useLocalPort = false;
	useNtDomainName = false;
	useSingleDes = false;
	useAdvancedSettings = false;
	usePerfectSecrecy = false;
	saveUserPassword = false;
	savePsk = false;
	useUdp=false;
	useUdpPort=false;
	useDnsServer=false;
	DnsServer="";
	useGetDnsFromPeer=true;
	refuse40BitEncryption=true;
	refuse128BitEncryption=false;
	allowStatefulMode=false;
	requireMppe=true;
	refuseEap=false;
	useNoBsdComp=true;
	useNoDeflate=true;
	savePsk=false;
	connectaftercreating=true;
	deamonavailable=false;
	enterdatamanually=false;
	importOK=false;

	currentpage=0;
	previouspage=0;

	profileData = new VpnAccountData( ConnType, Name );
	profileData->setGateway ( Gateway );
	profileData->setID( ID );
	profileData->setPreSharedKey( PreSharedKey);
	profileData->setSavePsk( savePsk );
	profileData->setUserName( Username );
	profileData->setUserPassword( UserPassword );
	profileData->setSaveUserPassword( saveUserPassword );
	profileData->setSavePsk(  savePsk );
	profileData->setApplicationVersion( ApplicationVersion );
	profileData->setUseLocalPort( useLocalPort );
	profileData->setLocalPort( Port );
	profileData->setUseSingleDes ( useSingleDes );
	profileData->setPerfectForwardSecrety ( PerfectForwardSecrecy );
	profileData->setIkeGroup( IkeGroup );
	profileData->setUseGlobalIpsecSecret (useGlobalIpsecSecret );
	profileData->setUseIkeGroup ( useIkeGroup );
	profileData->setNtDomainName (NtDomainName );
	profileData->setUseAdvancedSettings ( useAdvancedSettings );
	profileData->setUsePerfectForwardSecrety (usePerfectSecrecy );
	profileData->setUseTlsAuth (false );

	setupPages();

	// 	// tmp
	// 	newprofilewizardtypeselectionpagecontent->FreeswanRadioButton->setEnabled(false);
	// 	newprofilewizardtypeselectionpagecontent->RacoonRadioButton->setEnabled(false);
}

void NewProfileWizard::accept()
{

	if (!enterdatamanually)
	{
		if ( profileData->getConnectionType() == VpnAccountData::cisco )
		{
			importProfile(VpnAccountData::cisco);
			if (importOK)
				newProfileCreated=true;
			else
				newProfileCreated=false;
		}
		else	if ( profileData->getConnectionType() == VpnAccountData::openvpn )
		{
			importProfile(VpnAccountData::openvpn);
			if (importOK)
				newProfileCreated=true;
			else
				newProfileCreated=false;
		}
	}
	else
	{
		newProfileCreated=true;
	}
	finished=true;

	if (newProfileCreated && profileData->getAuthType() == VpnAccountData::cert)
	{}

	QWizard::accept();
}

void NewProfileWizard::reject()
{
	finished=false;
	QWizard::reject();
}

void NewProfileWizard::setupPages()
{

	// setup start page
	page1 = new QHBox( 0 );
	// 	page1->setSpacing(8);
	QLabel *setupPixmapContent1 = new QLabel( page1);
	setupPixmapContent1->setPixmap(*SetupPixmap);
	setupPixmapContent1->resize(setupPixmapContent1->sizeHint());
	newprofilewizardstartcontent = new NewProfileWizardStart ( page1 );
	newprofilewizardstartcontent->resize( newprofilewizardstartcontent->sizeHint() );
	page1->sizeHint();
	addPage(page1,"<b>"+i18n("Welcome")+"</b>");

	// type selection
	newprofilewizardtypeselectionpage = new QHBox( 0 );
	// 	newprofilewizardtypeselectionpage->setSpacing(8);
	QLabel *setupPixmapContent2 = new QLabel( newprofilewizardtypeselectionpage);
	setupPixmapContent2->setPixmap(*SetupPixmap);
	setupPixmapContent2->resize(setupPixmapContent2->sizeHint());
	newprofilewizardtypeselectionpagecontent = new NewProfileWizardTypeSelection(newprofilewizardtypeselectionpage);
	newprofilewizardtypeselectionpage->sizeHint();
	addPage(newprofilewizardtypeselectionpage,"<b>"+i18n("Type selection")+"</b>");

	// cisco
	newprofilewizardciscoselectionpage = new QHBox( 0 );
	// 	newprofilewizardciscoselectionpage->setSpacing(8);
	QLabel *setupPixmapContent3 = new QLabel( newprofilewizardciscoselectionpage);
	setupPixmapContent3->setPixmap(*SetupPixmap);
	setupPixmapContent3->resize(setupPixmapContent3->sizeHint());
	newprofilewizardciscoselectionpagecontent = new NewProfileWizardCiscoSelection(newprofilewizardciscoselectionpage);
	newprofilewizardciscoselectionpage->sizeHint();

	newprofilewizardciscomanuallypage = new QHBox( 0 );
	// 	newprofilewizardciscomanuallypage->setSpacing(8);
	QLabel *setupPixmapContent4 = new QLabel( newprofilewizardciscomanuallypage);
	setupPixmapContent4->setPixmap(*SetupPixmap);
	setupPixmapContent4->resize(setupPixmapContent4->sizeHint());
	newprofilewizardciscomanuallypagecontent = new NewProfileWizardCiscoManually(newprofilewizardciscomanuallypage);
	newprofilewizardciscomanuallypage->sizeHint();

	// racoon
	newprofilewizardracoonpage = new QHBox( 0 );
	// 	newprofilewizardracoonpage->setSpacing(8);
	QLabel *setupPixmapContent5 = new QLabel( newprofilewizardracoonpage);
	setupPixmapContent5->setPixmap(*SetupPixmap);
	setupPixmapContent5->resize(setupPixmapContent5->sizeHint());
	newprofilewizardracoonpagecontent = new NewProfileWizardRacoon(newprofilewizardracoonpage);
	newprofilewizardracoonpagecontent->ExchangeModeComboBox->insertItem("main",0);
	newprofilewizardracoonpagecontent->ExchangeModeComboBox->insertItem("aggressive",1);
	newprofilewizardracoonpagecontent->ExchangeModeComboBox->insertItem("base",2);
	newprofilewizardracoonpagecontent->ExchangeModeComboBox->setCurrentItem(0); // main
	newprofilewizardracoonpage->sizeHint();

	//freeswan
	newprofilewizardfreeswanpage = new QHBox( 0 );
	// 	newprofilewizardfreeswanpage->setSpacing(8);
	QLabel *setupPixmapContent6 = new QLabel( newprofilewizardfreeswanpage);
	setupPixmapContent6->setPixmap(*SetupPixmap);
	setupPixmapContent6->resize(setupPixmapContent6->sizeHint());
	newprofilewizardfreeswanpagecontent = new NewProfileWizardFreeswan(newprofilewizardfreeswanpage);
	newprofilewizardfreeswanpage->sizeHint();

	// openvpn
	newprofilewizardopenvpnselectionpage = new QHBox( 0 );
	// 	newprofilewizardopenvpnselectionpage->setSpacing(8);
	QLabel *setupPixmapContent7 = new QLabel( newprofilewizardopenvpnselectionpage);
	setupPixmapContent7->setPixmap(*SetupPixmap);
	setupPixmapContent7->resize(setupPixmapContent7->sizeHint());
	newprofilewizardopenvpnselectionpagecontent = new NewProfileWizardOpenvpnSelection(newprofilewizardopenvpnselectionpage);
	newprofilewizardopenvpnselectionpage->sizeHint();

	newprofilewizardopenvpnpage = new QHBox( 0 );
	// 	newprofilewizardopenvpnpage->setSpacing(8);
	QLabel *setupPixmapContent8 = new QLabel( newprofilewizardopenvpnpage);
	setupPixmapContent8->setPixmap(*SetupPixmap);
	setupPixmapContent8->resize(setupPixmapContent8->sizeHint());
	newprofilewizardopenvpnpagecontent = new NewProfileWizardOpenvpn(newprofilewizardopenvpnpage);
	newprofilewizardopenvpnpage->sizeHint();
	newprofilewizardopenvpnpagecontent->TunnelDeviceTypeComboBox->insertItem( "tun" );
	newprofilewizardopenvpnpagecontent->TunnelDeviceTypeComboBox->insertItem( "tap" );
	newprofilewizardopenvpnpagecontent->NsCertTypeComboBox->insertItem( "client" );
	newprofilewizardopenvpnpagecontent->NsCertTypeComboBox->insertItem( "server" );
	newprofilewizardopenvpnpagecontent->NsCertTypeComboBox->setEnabled ( false );
	newprofilewizardopenvpnpagecontent->UserdefinedPortSpinBox->setEnabled ( false );

	newprofilewizardopenvpnpagecontent->UseUserdefinedPortCheckBox->setChecked(false);
	newprofilewizardopenvpnpagecontent->UseNsCertTypeCheckBox->setChecked(false);
	newprofilewizardopenvpnpagecontent->UseTlsAuthCheckBox->setChecked(false);
	newprofilewizardopenvpnpagecontent->UseTlsRemoteHostCheckBox->setChecked(false);
	newprofilewizardopenvpnpagecontent->UseUserdefiniedCipherCheckBox->setChecked(false);
	newprofilewizardopenvpnpagecontent->UseHttpProxyCheckBox->setChecked(false);

	connect( newprofilewizardopenvpnpagecontent->UseUserdefinedPortCheckBox , SIGNAL(toggled (bool)), this, SLOT(userdefinedOpenvpnPortToggeled(bool)));
	connect( newprofilewizardopenvpnpagecontent->UseNsCertTypeCheckBox , SIGNAL(toggled (bool)), this, SLOT(nsCertTypeOpenvpnToggled(bool)));
	connect( newprofilewizardopenvpnpagecontent->UseUserdefinedPortCheckBox, SIGNAL( toggled(bool) ), this, SLOT( userdefinedOpenvpnPortToggeled(bool) ) );
	connect( newprofilewizardopenvpnpagecontent->UseTlsAuthCheckBox, SIGNAL( toggled(bool) ), this, SLOT( useTlsAuthToggled(bool) ) );
	connect( newprofilewizardopenvpnpagecontent->UseTlsRemoteHostCheckBox, SIGNAL( toggled(bool) ), this, SLOT( useTlsRemoteHostToggled(bool) ) );
	connect( newprofilewizardopenvpnpagecontent->UseUserdefiniedCipherCheckBox, SIGNAL( toggled(bool) ), this, SLOT( useUserdefiniedCipherToggled(bool) ) );
	connect( newprofilewizardopenvpnpagecontent->UseHttpProxyCheckBox, SIGNAL( toggled(bool) ), this, SLOT( useHttpProxyToggeled(bool) ) );

	QStringList ciphers = Utils(GlobalConfig).getOpenvpnCiphers();

	for ( QStringList::Iterator it = ciphers.begin(); it != ciphers.end(); ++it )
	{
		newprofilewizardopenvpnpagecontent->UserdefiniedCipherComboBox->insertItem( *it );
	}

	// pptp
	newprofilewizardpptppage = new QHBox( 0 );
	// 	newprofilewizardpptppage->setSpacing(8);
	QLabel *setupPixmapContent9 = new QLabel( newprofilewizardpptppage);
	setupPixmapContent9->setPixmap(*SetupPixmap);
	setupPixmapContent9->resize(setupPixmapContent9->sizeHint());
	newprofilewizardpptppagecontent = new NewProfileWizardPptp(newprofilewizardpptppage);
	newprofilewizardpptppage->sizeHint();
	newprofilewizardpptppagecontent->DnsServerLineedit->setEnabled( false );
	newprofilewizardpptppagecontent->MtuSpinbox->setEnabled( false );
	newprofilewizardpptppagecontent->Refuse40BitEncryptionCheckbox->setChecked ( profileData->getRefuse40BitEncryption());
	newprofilewizardpptppagecontent->Refuse40BitEncryptionCheckbox->setChecked( profileData->getRefuse128BitEncryption());
	newprofilewizardpptppagecontent->RequireMppeCheckbox->setChecked( profileData->getRequireMppe());
	newprofilewizardpptppagecontent->AllowStatefulModeCheckbox->setChecked( profileData->getAllowStatefulMode());
	newprofilewizardpptppagecontent->UseNoMPPECompressionCheckbox->setChecked( profileData->getDisableMPPEComp());
	newprofilewizardpptppagecontent->UseNoDeflateCheckbox->setChecked(profileData->getUseNoDeflate());

	// general settings
	newprofilewizardgeneralpage = new QHBox( 0 );
	// 	newprofilewizardgeneralpage->setSpacing(8);
	QLabel *setupPixmapContent10 = new QLabel( newprofilewizardgeneralpage);
	setupPixmapContent10->setPixmap(*SetupPixmap);
	setupPixmapContent10->resize(setupPixmapContent10->sizeHint());
	newprofilewizardgeneralpagecontent = new NewProfileWizardGeneral(newprofilewizardgeneralpage);
	newprofilewizardgeneralpage->sizeHint();

	newprofilewizardauthselectionpage = new QHBox( 0 );
	// 	newprofilewizardauthselectionpage->setSpacing(8);
	QLabel *setupPixmapContent71 = new QLabel( newprofilewizardauthselectionpage);
	setupPixmapContent71->setPixmap(*SetupPixmap);
	setupPixmapContent71->resize(setupPixmapContent71->sizeHint());
	newprofilewizardauthselectioncontent = new NewProfileWizardAuthSelection(newprofilewizardauthselectionpage);
	newprofilewizardauthselectionpage->sizeHint();

	// psk
	newprofilewizardpskpage = new QHBox( 0 );
	// 	newprofilewizardpskpage->setSpacing(8);
	QLabel *setupPixmapContent72 = new QLabel( newprofilewizardpskpage);
	setupPixmapContent72->setPixmap(*SetupPixmap);
	setupPixmapContent72->resize(setupPixmapContent72->sizeHint());
	newprofilewizardpskcontent = new NewProfileWizardPsk(newprofilewizardpskpage);
	newprofilewizardpskpage->sizeHint();

	connect ( newprofilewizardpskcontent->PskInFileCheckBox , SIGNAL(toggled (bool)), this, SLOT(pskIsInFileToggled(bool)));

	newprofilewizardp12certselectionpage = new QHBox( 0 );
	// 	newprofilewizardp12certselectionpage->setSpacing(8);
	QLabel *setupPixmapContent74 = new QLabel( newprofilewizardp12certselectionpage);
	setupPixmapContent74->setPixmap(*SetupPixmap);
	setupPixmapContent74->resize(setupPixmapContent74->sizeHint());
	newprofilewizardp12certselectioncontent = new NewProfileWizardP12CertSelection(newprofilewizardp12certselectionpage);
	newprofilewizardp12certselectionpage->sizeHint();

	// cert
	newprofilewizardcertpage = new QHBox( 0 );
	// 	newprofilewizardcertpage->setSpacing(8);
	QLabel *setupPixmapContent73 = new QLabel( newprofilewizardcertpage);
	setupPixmapContent73->setPixmap(*SetupPixmap);
	setupPixmapContent73->resize(setupPixmapContent73->sizeHint());
	newprofilewizardcertcontent = new NewProfileWizardCert(newprofilewizardcertpage);
	newprofilewizardcertpage->sizeHint();

	// user
	newprofilewizarduserpage = new QHBox( 0 );
	// 	newprofilewizarduserpage->setSpacing(8);
	QLabel *setupPixmapContent75 = new QLabel( newprofilewizarduserpage);
	setupPixmapContent75->setPixmap(*SetupPixmap);
	setupPixmapContent75->resize(setupPixmapContent75->sizeHint());
	newprofilewizarduserpagecontent = new NewProfileWizardUser(newprofilewizarduserpage);
	newprofilewizarduserpage->sizeHint();

	// network
	newprofilewizardnetworkpage = new QHBox( 0 );
	// 	newprofilewizardnetworkpage->setSpacing(8);
	QLabel *setupPixmapContent76 = new QLabel( newprofilewizardnetworkpage);
	setupPixmapContent76->setPixmap(*SetupPixmap);
	setupPixmapContent76->resize(setupPixmapContent76->sizeHint());
	newprofilewizardnetworkcontent = new NewProfileWizardNetwork(newprofilewizardnetworkpage);
	newprofilewizardnetworkpage->sizeHint();

	NetworkInterface iface(GlobalConfig,GlobalConfig->appPointer);
	QStringList list = iface.getAllNetworkInterfaces();
	newprofilewizardnetworkcontent->NetworkDeviceComboBox->insertItem( "default" );

	for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
		newprofilewizardnetworkcontent->NetworkDeviceComboBox->insertItem( QString( *it ) );


	// nat
	newprofilewizardnatpage = new QHBox( 0 );
	// 	newprofilewizardnatpage->setSpacing(8);
	QLabel *setupPixmapContent77 = new QLabel( newprofilewizardnatpage);
	setupPixmapContent77->setPixmap(*SetupPixmap);
	setupPixmapContent77->resize(setupPixmapContent77->sizeHint());
	newprofilewizardnatcontent = new NewProfileWizardNat(newprofilewizardnatpage);
	newprofilewizardnatpage->sizeHint();
	newprofilewizardnatcontent->UseUdpCheckbox->setChecked(true);
	connect( newprofilewizardnatcontent->UseUdpCheckbox, SIGNAL( toggled(bool) ), this, SLOT( useUdpToggled(bool) ) );
	connect( newprofilewizardnatcontent->UdpPortCheckbox, SIGNAL( toggled(bool) ), this, SLOT( udpPortToggled(bool) ) );

	// general
	newprofilewizardgeneralpage = new QHBox( 0 );
	// 	newprofilewizardgeneralpage->setSpacing(8);
	QLabel *setupPixmapContent78 = new QLabel( newprofilewizardgeneralpage);
	setupPixmapContent78->setPixmap(*SetupPixmap);
	setupPixmapContent78->resize(setupPixmapContent78->sizeHint());
	newprofilewizardgeneralpagecontent = new NewProfileWizardGeneral(newprofilewizardgeneralpage);
	newprofilewizardgeneralpage->sizeHint();
	insertPage(newprofilewizardgeneralpage,"<b>"+i18n("General settings")+"</b>", -1);

	// connectionstatuscheck
	newprofilewizardconnectionstatuscheckpage = new QHBox( 0 );
	// 	newprofilewizardconnectionstatuscheckpage->setSpacing(8);
	QLabel *setupPixmapContent79 = new QLabel( newprofilewizardconnectionstatuscheckpage);
	setupPixmapContent79->setPixmap(*SetupPixmap);
	setupPixmapContent79->resize(setupPixmapContent79->sizeHint());
	newprofilewizardconnectionstatuscheckcontent = new NewProfileWizardConnectionStatusCheck(newprofilewizardconnectionstatuscheckpage);
	newprofilewizardconnectionstatuscheckpage->sizeHint();
	insertPage(newprofilewizardconnectionstatuscheckpage,"<b>"+i18n("Connection status check")+"</b>", -1);
	connect( newprofilewizardconnectionstatuscheckcontent->PingUserdefiniedAddressCheckBox, SIGNAL( toggled(bool) ), this, SLOT( pingIpAfterConnectToggled(bool) ) );
	connect( newprofilewizardconnectionstatuscheckcontent->UseConnectionStatusCheckCheckBox, SIGNAL( toggled(bool) ), this, SLOT( connectionStatusCheckToggled(bool) ) );

	// connectoptions
	newprofilewizardconnectoptionspage = new QHBox( 0 );
	// 	newprofilewizardconnectoptionspage->setSpacing(8);
	QLabel *setupPixmapContent80 = new QLabel( newprofilewizardconnectoptionspage);
	setupPixmapContent80->setPixmap(*SetupPixmap);
	setupPixmapContent80->resize(setupPixmapContent80->sizeHint());
	newprofilewizardconnectoptionscontent = new NewProfileWizardConnectOptions(newprofilewizardconnectoptionspage);
	newprofilewizardconnectoptionspage->sizeHint();
	newprofilewizardconnectoptionscontent->DoAutoConnectCheckBox->hide(); //TODO later
	newprofilewizardconnectoptionscontent->AutoConnectProfileComboBox->hide(); //TODO_ later
	insertPage(newprofilewizardconnectoptionspage,"<b>"+i18n("Connect options")+"</b>", -1);


	// setup end page
	endpage = new QHBox( 0 );
	// 	endpage->setSpacing(8);
	QLabel *setupPixmapContent11 = new QLabel( endpage);
	setupPixmapContent11->setPixmap(*SetupPixmap);
	setupPixmapContent11->resize(setupPixmapContent11->sizeHint());
	QLabel *endpagecontent = new QLabel( endpage );
	endpagecontent->setMargin( 11 );
	endpagecontent->setText( i18n("Now you have completed all steps for creating a new profile.\nClick \"Finish\" to continue." ));
	endpagecontent->setMaximumSize ( endpagecontent->sizeHint() );
	endpage->sizeHint();
	insertPage(endpage,"<b>"+i18n("Finish")+"</b>", -1); // last page
}

void NewProfileWizard::next ()
{
	// called at each finish of a page
	bool ok=true;
	QString msg=i18n( "Please fill in all fields!");

	if ( currentpage == page1 )
	{
		// nothing here
	}
	else if ( currentpage == newprofilewizardgeneralpage )
	{
		msg=i18n("These fields must be filled in:\n");
		if (newprofilewizardgeneralpagecontent->NameLineEdit->text().isEmpty())
		{
			ok=false;
			msg+="- "+i18n("Name")+"\n";
			GlobalConfig->appendLogEntry( i18n( "Name is empty!"), GlobalConfig->error);
		}
		else
		{
			QString Name = newprofilewizardgeneralpagecontent->NameLineEdit->text();


			bool nameOk=true;
			if (Name.contains(' '))
			{
				KMessageBox::error ( this, i18n( "Profile name can not contain spaces!" ), i18n( "Spaces Not Allowed" ) );
				GlobalConfig->appendLogEntry( i18n( "Profile name can not contain spaces!" ) ,GlobalConfig->error);

				nameOk = FALSE;
			}

			if (Name.isEmpty())
			{
				KMessageBox::error ( this, i18n( "Profile name can not be empty!" ), i18n( "No Name Entered" ) );
				GlobalConfig->appendLogEntry( i18n( "Profile name can not be empty!" ) ,GlobalConfig->error);

				nameOk = FALSE;
			}

			VpnAccountData * it;
			for ( it = GlobalConfig->AccountList->first(); it; it = GlobalConfig->AccountList->next() )
			{
				if ( it->getName() == Name )
				{
					KMessageBox::error ( this, i18n( "Profile name already exists!" ), i18n( "Name Already Exists" ) );
					GlobalConfig->appendLogEntry(i18n( "Profile name already exists!" ) ,GlobalConfig->error);

					nameOk = FALSE;
					break;
				}
			}

			if ( nameOk )
			{
				profileData->setName(Name);
				newProfileCreated = TRUE;
			}
			else
			{
				return;
			}


			if ( GlobalConfig->KvpncDebugLevel > 0 )
				GlobalConfig->appendLogEntry(i18n("Name: %1").arg(newprofilewizardgeneralpagecontent->NameLineEdit->text()), KVpncConfig::debug);
		}

		if (newprofilewizardgeneralpagecontent->gatewayLineEdit->text().isEmpty())
		{
			ok=false;
			msg+="- "+i18n("Gateway")+"\n";
			GlobalConfig->appendLogEntry( i18n( "Gateway is empty!"), GlobalConfig->error);
		}
		else
		{
			profileData->setGateway(newprofilewizardgeneralpagecontent->gatewayLineEdit->text());
			if ( GlobalConfig->KvpncDebugLevel > 0 )
				GlobalConfig->appendLogEntry(i18n("Gateway: %1").arg(newprofilewizardgeneralpagecontent->gatewayLineEdit->text()), KVpncConfig::debug);
		}
		profileData->setDescription(newprofilewizardgeneralpagecontent->DescriptionLineEdit->text() );
		if ( GlobalConfig->KvpncDebugLevel > 0 )
			GlobalConfig->appendLogEntry(i18n("Description: %1").arg(newprofilewizardgeneralpagecontent->DescriptionLineEdit->text()), KVpncConfig::debug);
	}
	else if ( currentpage == newprofilewizardtypeselectionpage )
	{
		if (newprofilewizardtypeselectionpagecontent->CiscoRadioButton->isChecked())
		{
			profileData->setConnectionType( VpnAccountData::cisco );
			removePage( newprofilewizardcertpage );
			removePage( newprofilewizardpskpage );
			removePage( newprofilewizardp12certselectionpage );
			removePage( newprofilewizardfreeswanpage );
			removePage( newprofilewizardracoonpage);
			removePage( newprofilewizardopenvpnpage);
			removePage( newprofilewizardopenvpnselectionpage);
			removePage( newprofilewizardpptppage);
			newprofilewizardnetworkcontent->LabelRemoteNetwork->hide();
			newprofilewizardnetworkcontent->RemoteNetMaskComboBox->hide();
			newprofilewizardnetworkcontent->RemoteNetAddrLineEdit->hide();
			newprofilewizardnetworkcontent->RemoteNetDividetextLabel->hide();
			insertPage( newprofilewizardciscoselectionpage,"<b>"+ i18n("Cisco selection")+"</b>", indexOf(currentpage)+1 );

			if ( GlobalConfig->KvpncDebugLevel > 0 )
				GlobalConfig->appendLogEntry(i18n("Selected type: %1").arg("Cisco"), KVpncConfig::debug);
		}
		else if (newprofilewizardtypeselectionpagecontent->FreeswanRadioButton->isChecked())
		{
			profileData->setConnectionType( VpnAccountData::freeswan );
			removePage( newprofilewizardciscoselectionpage);
			removePage( newprofilewizardciscomanuallypage);
			removePage( newprofilewizardopenvpnpage);
			removePage( newprofilewizardopenvpnselectionpage);
			removePage( newprofilewizardpptppage);

			insertPage(newprofilewizardracoonpage,"<b>"+ i18n("FreeSWAN/OpenSWAN settings")+"</b>", indexOf(currentpage)+1);

			newprofilewizardracoonpagecontent->ExchangeModeComboBox->insertItem("main",0);
			newprofilewizardracoonpagecontent->ExchangeModeComboBox->insertItem("aggressive",1);
			newprofilewizardracoonpagecontent->ExchangeModeComboBox->setCurrentItem(0); // main
			newprofilewizardracoonpagecontent->ExchangeModeComboBox->setEnabled(true);

			newprofilewizardracoonpagecontent->HashAlgoComboBox->hide();
			newprofilewizardracoonpagecontent->HashAlgoTextLabel->hide();
			newprofilewizardracoonpagecontent->UseModeConfigCheckBox->hide();
			newprofilewizardracoonpagecontent->DisablePfsCheckBox->setEnabled(true);
			newprofilewizardracoonpagecontent->InfoLabel->setText(i18n("Please enter FreeSWAN/OpenSWAN specific settings:"));

			insertPage( newprofilewizardauthselectionpage,i18n("Authentication settings"), indexOf(currentpage)+1 );
			insertPage(newprofilewizardnetworkpage,"<b>"+ i18n("Network settings")+"</b>", indexOf(currentpage)+2);

			if ( GlobalConfig->KvpncDebugLevel > 0 )
				GlobalConfig->appendLogEntry(i18n("Selected type: %1").arg("FreeS/WAN"), KVpncConfig::debug);
		}
		else if (newprofilewizardtypeselectionpagecontent->RacoonRadioButton->isChecked())
		{
			profileData->setConnectionType( VpnAccountData::racoon );
			removePage( newprofilewizardciscoselectionpage);
			removePage( newprofilewizardciscomanuallypage);
			removePage( newprofilewizardopenvpnpage);
			removePage( newprofilewizardopenvpnselectionpage);
			removePage( newprofilewizardpptppage);

			newprofilewizardracoonpagecontent->FreeswanGroupBox->hide();
			newprofilewizardracoonpagecontent->DisablePfsCheckBox->setEnabled(false);

			insertPage(newprofilewizardracoonpage,"<b>"+ i18n("Racoon settings")+"</b>", indexOf(currentpage)+1);
			insertPage( newprofilewizardauthselectionpage,i18n("Authentication settings"), indexOf(currentpage)+2 );
			insertPage(newprofilewizardnetworkpage,"<b>"+ i18n("Network settings")+"</b>", indexOf(currentpage)+3);

			if ( GlobalConfig->KvpncDebugLevel > 0 )
				GlobalConfig->appendLogEntry(i18n("Selected type: %1").arg("Racoon"), KVpncConfig::debug);
		}
		else if (newprofilewizardtypeselectionpagecontent->OpenvpnRadioButton->isChecked())
		{
			profileData->setConnectionType( VpnAccountData::openvpn );
			profileData->setLocalPort(1194);
			profileData->setRemotePort(1194);
			profileData->setUserdefinedPort(1194);
			profileData->setCertPath("/etc/openvpn");
			removePage( newprofilewizardciscoselectionpage);
			removePage( newprofilewizardciscomanuallypage);
			removePage( newprofilewizardracoonpage);
			removePage( newprofilewizardpptppage);
			newprofilewizardnetworkcontent->LabelRemoteNetwork->hide();
			newprofilewizardnetworkcontent->RemoteNetMaskComboBox->hide();
			newprofilewizardnetworkcontent->RemoteNetAddrLineEdit->hide();
			newprofilewizardnetworkcontent->RemoteNetDividetextLabel->hide();
			insertPage ( newprofilewizardopenvpnselectionpage,"<b>"+ i18n("OpenVPN selection")+"</b>", indexOf(currentpage)+1);

			if ( GlobalConfig->KvpncDebugLevel > 0 )
				GlobalConfig->appendLogEntry(i18n("Selected type: %1").arg("OpenVPN"), KVpncConfig::debug);
		}
		else if (newprofilewizardtypeselectionpagecontent->PptpRadioButton->isChecked())
		{
			profileData->setConnectionType( VpnAccountData::pptp );
			removePage( newprofilewizardciscoselectionpage);
			removePage( newprofilewizardciscomanuallypage);
			removePage( newprofilewizardcertpage );
			removePage( newprofilewizardpskpage );
			removePage( newprofilewizardp12certselectionpage );
			removePage( newprofilewizardfreeswanpage );
			removePage( newprofilewizardracoonpage);
			removePage( newprofilewizardopenvpnpage);
			removePage( newprofilewizardopenvpnselectionpage);
			insertPage(newprofilewizardpptppage,"<b>"+ i18n("PPTP settings")+"</b>", indexOf(currentpage)+1);
			insertPage(newprofilewizardnetworkpage,"<b>"+ i18n("Network settings")+"</b>", indexOf(currentpage)+2);

			if ( GlobalConfig->KvpncDebugLevel > 0 )
				GlobalConfig->appendLogEntry(i18n("Selected type: %1").arg("PPTP"), KVpncConfig::debug);
		}

		QString type=""; // visible name
		QString bin="";  // executable name
		if ( profileData->getConnectionType() == VpnAccountData::cisco )
		{
			type = "vpnc";
			bin = "vpnc";
		}
		else if ( profileData->getConnectionType() == VpnAccountData::freeswan )
		{
			type = "freeswan";
			bin="ipsec";
		}
		else if ( profileData->getConnectionType() == VpnAccountData::racoon )
		{
			type = "racoon";
			bin="racoon";
		}
		else if ( profileData->getConnectionType() == VpnAccountData::pptp )
		{
			type = "pptp";
			bin="pppd pptp";
		}
		else if ( profileData->getConnectionType() == VpnAccountData::openvpn )
		{
			type = "openvpn";
			bin="openvpn";
		}
		else
		{
			type = "other";
			bin="";
		}

		ToolInfo *it;
		//std::cout << "Tool (bin): " << bin << std::endl;

		if (!GlobalConfig->ToolList->isEmpty())
		{
			if (type!="pptp")
			{
				it = Utils(GlobalConfig).getToolInfo(GlobalConfig, bin);
				if (it->PathToExec.section('/',-1) == bin )
				{
					if (GlobalConfig->KvpncDebugLevel > 0)
						GlobalConfig->appendLogEntry(i18n("The required deamon (%1) is available, you will be able to use this connection.").arg(bin),KVpncConfig::info);
					deamonavailable=true;
				}
				else
				{
					KMessageBox::information ( this, i18n("The required deamon (%1) isn't available, you will not be able to use this connection until the deamon is not installed.").arg(bin));
					if (GlobalConfig->KvpncDebugLevel > 0)
						GlobalConfig->appendLogEntry(i18n("The required deamon (%1) isn't available, you will not be able to use this connection until the deamon is not installed.").arg(bin),KVpncConfig::error);
					deamonavailable=false;
					removePage(newprofilewizardconnectoptionspage);
				}

				if (type == "ipsec")
				{

					QString realversion=it->Version.section(' ',1,1).section('/',0,0).right(it->Version.section(' ',1,1).section('/',0,0).length()-1);
					QString realtype=it->Version.section(' ',0,0).lower();

					if ( realversion.find("1.",0,-1) > -1)
					{
						KMessageBox::information ( this, i18n("The required version (%1) of FreeSWAN/OpenSWAN was not found. You will not be able to use the Agressive Mode. It will be used the Main Mode.").arg("2"));
					if (GlobalConfig->KvpncDebugLevel > 0)
						GlobalConfig->appendLogEntry(i18n("The required version (%1) of FreeSWAN/OpenSWAN was not found. You will not be able to use the Agressive Mode. It will be used the Main Mode.").arg("2").arg(bin),KVpncConfig::error);
					}
				}
			}
			else
			{
				bool pppd_and_pptp_available=false;
				it = Utils(GlobalConfig).getToolInfo(GlobalConfig, "pppd");
				if (it->PathToExec.section('/',-1) == "pppd" )
				{
					it = Utils(GlobalConfig).getToolInfo(GlobalConfig, "pptp");
					if (it->PathToExec.section('/',-1) == "pptp" )
						pppd_and_pptp_available=true;
				}
				if ( pppd_and_pptp_available )
				{
					// programs are installed
					deamonavailable=true;
					if (GlobalConfig->KvpncDebugLevel > 0)
						GlobalConfig->appendLogEntry(i18n("The required deamons (%2 and %2) are available.").arg("pppd").arg("pptp"),KVpncConfig::info);
				}
				else
				{
					KMessageBox::information ( this, i18n("The required deamons (%1 and %2) aren't available, you will not be able to use this connection until the deamons are not installed.").arg("pppd").arg("pptpd"));
					GlobalConfig->appendLogEntry(i18n("The required deamons (%1 and %2) are not available, connect will be disabled.").arg("pppd").arg("pptpd"),KVpncConfig::error);
					deamonavailable=false;
					removePage(newprofilewizardconnectoptionspage);
				}
			}

		}

	}
	else if ( currentpage == newprofilewizardciscoselectionpage )
	{
		if (newprofilewizardciscoselectionpagecontent->PcfImportRadioButton->isChecked() )
		{
			enterdatamanually=false;
			removePage( newprofilewizardciscomanuallypage );
			removePage ( newprofilewizardgeneralpage );
			if ( GlobalConfig->KvpncDebugLevel > 0 )
				GlobalConfig->appendLogEntry(i18n("Cisco selection: import PCF file"), KVpncConfig::debug);
		}
		else
		{
			enterdatamanually=true;
			insertPage(newprofilewizardciscomanuallypage,"<b>"+ i18n("Cisco settings")+"</b>", indexOf(currentpage)+1);
			insertPage(newprofilewizardnetworkpage,"<b>"+ i18n("Network settings")+"</b>", indexOf(currentpage)+2);
			if ( GlobalConfig->KvpncDebugLevel > 0 )
				GlobalConfig->appendLogEntry(i18n("Cisco selection: enter data manually"), KVpncConfig::debug);
		}
	}
	else if ( currentpage == newprofilewizardciscomanuallypage )
	{
		msg=i18n("These fields must be filled in:\n");
		if (newprofilewizardciscomanuallypagecontent->IDLineEdit->text().isEmpty())
		{
			ok=false;
			msg+="- "+i18n("Cisco IPSec ID")+"\n";
			GlobalConfig->appendLogEntry( i18n( "Cisco IPSec ID is empty!"), GlobalConfig->error);
		}
		profileData->setGateway(newprofilewizardciscomanuallypagecontent->IDLineEdit->text());
		if ( GlobalConfig->KvpncDebugLevel > 0 )
			GlobalConfig->appendLogEntry(i18n("Cisco IPSec ID: %1").arg(newprofilewizardciscomanuallypagecontent->IDLineEdit->text()), KVpncConfig::debug);

		profileData->setAllowEmptyGroupPassword(newprofilewizardciscomanuallypagecontent->AllowEmptyGroupPasswordCheckBox->isChecked());
		if ( GlobalConfig->KvpncDebugLevel > 0 )
		{
			if ( newprofilewizardciscomanuallypagecontent->AllowEmptyGroupPasswordCheckBox->isChecked())
				GlobalConfig->appendLogEntry(i18n("Allow empty group password: true"), KVpncConfig::debug);
			else
				GlobalConfig->appendLogEntry(i18n("Allow empty group password: false"), KVpncConfig::debug);
		}

		if (  !newprofilewizardciscomanuallypagecontent->AllowEmptyGroupPasswordCheckBox->isChecked() && newprofilewizardciscomanuallypagecontent->GroupPasswordLineEdit->text().isEmpty())
		{
			ok=false;
			msg+="- "+i18n("Group password")+"\n";
			GlobalConfig->appendLogEntry( i18n( "Group password  is empty but you dont have checked to allow that!"), GlobalConfig->error);
		}
		else
			profileData->setPreSharedKey(newprofilewizardciscomanuallypagecontent->GroupPasswordLineEdit->text());

		profileData->setID(newprofilewizardciscomanuallypagecontent->IDLineEdit->text());
		profileData->setAllowEmptyGroupPassword(newprofilewizardciscomanuallypagecontent->AllowEmptyGroupPasswordCheckBox->isChecked());

		insertPage(newprofilewizarduserpage,"<b>"+i18n("User settings")+"</b>", indexOf(currentpage)+1);
		insertPage(newprofilewizardnatpage,"<b>"+i18n("NAT settings")+"</b>", indexOf(currentpage)+2 );

	}
	else if ( currentpage == newprofilewizardfreeswanpage )
	{}
	else if ( currentpage == newprofilewizardracoonpage )
	{
		profileData->setHashAlgo(newprofilewizardracoonpagecontent->HashAlgoComboBox->currentText());
		if ( GlobalConfig->KvpncDebugLevel > 0 )
			GlobalConfig->appendLogEntry(i18n("Hash algorithm (%1): %2").arg("racoon").arg(newprofilewizardracoonpagecontent->HashAlgoComboBox->currentText()), KVpncConfig::debug);

		if (newprofilewizardtypeselectionpagecontent->RacoonRadioButton->isChecked())
		{
			profileData->setUseModeConfig(newprofilewizardracoonpagecontent->UseModeConfigCheckBox->isChecked());
			if ( GlobalConfig->KvpncDebugLevel > 0 )

				if (newprofilewizardracoonpagecontent->UseModeConfigCheckBox->isChecked())
					GlobalConfig->appendLogEntry(i18n("Use Mode Config: %1").arg("yes"), KVpncConfig::debug);
				else
					GlobalConfig->appendLogEntry(i18n("Use Mode Config: %1").arg("no"), KVpncConfig::debug);
		}

		profileData->setExchangeMode(newprofilewizardracoonpagecontent->ExchangeModeComboBox->currentText());

		if (newprofilewizardtypeselectionpagecontent->FreeswanRadioButton->isChecked())
		{
				profileData->setLeftNextHop(newprofilewizardracoonpagecontent->LeftNextHopLineEdit->text() ); //TODO check valid IP
				profileData->setRightNextHop( newprofilewizardracoonpagecontent->RightNextHopLineEdit->text( ) );//TODO check valid IP
				profileData->setDisableOpportunisticEncryption( newprofilewizardracoonpagecontent->DisableOpportunisticEncryptionCheckBox->isChecked( ) );
				if (newprofilewizardracoonpagecontent->DisablePfsCheckBox->isChecked())
					profileData->setPerfectForwardSecrety("false");
				else
					profileData->setPerfectForwardSecrety("true");

				if ( GlobalConfig->KvpncDebugLevel > 0 )
				{
					if (newprofilewizardracoonpagecontent->DisableOpportunisticEncryptionCheckBox->isChecked())
						GlobalConfig->appendLogEntry(i18n("Disable opportunistic encryption: %1").arg("yes").arg(newprofilewizardracoonpagecontent->HashAlgoComboBox->currentText()), KVpncConfig::debug);
					else
						GlobalConfig->appendLogEntry(i18n("Disable opportunistic encryption: %1").arg("no").arg(newprofilewizardracoonpagecontent->HashAlgoComboBox->currentText()), KVpncConfig::debug);
					GlobalConfig->appendLogEntry(i18n("Right next hop: %1").arg(newprofilewizardracoonpagecontent->RightNextHopLineEdit->text()), KVpncConfig::debug);
					GlobalConfig->appendLogEntry(i18n("Left next hop: %1").arg(newprofilewizardracoonpagecontent->LeftNextHopLineEdit->text()), KVpncConfig::debug);
					GlobalConfig->appendLogEntry(i18n("Disable PFS: %1").arg(profileData->getPerfectForwardSecrety()), KVpncConfig::debug);
				}
		}

		profileData->setExchangeMode( newprofilewizardracoonpagecontent->ExchangeModeComboBox->currentText());

		if ( GlobalConfig->KvpncDebugLevel > 0 )
			GlobalConfig->appendLogEntry(i18n("Exchange Mode: %1").arg(newprofilewizardracoonpagecontent->ExchangeModeComboBox->currentText()), KVpncConfig::debug);

		insertPage(newprofilewizardnatpage,"<b>"+i18n("NAT settings")+"</b>", indexOf(currentpage)+1 );
	}
	else if ( currentpage == newprofilewizardopenvpnpage )
	{
		msg=i18n("These fields must be filled in:\n");
		profileData->setTunnelDeviceType( newprofilewizardopenvpnpagecontent->TunnelDeviceTypeComboBox->currentText() );
		if ( GlobalConfig->KvpncDebugLevel > 0 )
			GlobalConfig->appendLogEntry(i18n("Tunnel device type (%1): %2").arg("OpenVPN").arg(newprofilewizardopenvpnpagecontent->TunnelDeviceTypeComboBox->currentText()), KVpncConfig::debug);

		if (newprofilewizardopenvpnpagecontent->NsCertTypeComboBox->currentText() == "client")
			profileData->setNsCertType("client");
		else
			profileData->setNsCertType("server");

		profileData->setTunnelDeviceType( newprofilewizardopenvpnpagecontent->TunnelDeviceTypeComboBox->currentText() );

		profileData->setUseRedirectGateway( newprofilewizardopenvpnpagecontent->UseRedirectGatewayCheckBox->isChecked() );

		insertPage( newprofilewizardauthselectionpage,"<b>"+ i18n("Authentication settings")+"</b>", indexOf(currentpage)+1);
		if ( newprofilewizardopenvpnpagecontent->AuthWithUsernameAndPasswordCheckBox->isChecked())
		{
			insertPage(newprofilewizarduserpage,"<b>"+i18n("User settings")+"</b>", indexOf(currentpage)+2);
			insertPage(newprofilewizardnetworkpage,"<b>"+ i18n("Network settings")+"</b>", indexOf(currentpage)+3);
			insertPage(newprofilewizardnatpage,"<b>"+i18n("NAT settings")+"</b>", indexOf(currentpage)+4 );
		}
		else
		{
			insertPage(newprofilewizardnetworkpage,"<b>"+ i18n("Network settings")+"</b>", indexOf(currentpage)+2);
			insertPage(newprofilewizardnatpage,"<b>"+i18n("NAT settings")+"</b>", indexOf(currentpage)+3 );
		}

		profileData->setUserdefiniedCipher(newprofilewizardopenvpnpagecontent->UserdefiniedCipherComboBox->currentText());
		profileData->setUseUserdefiniedCipher(newprofilewizardopenvpnpagecontent->UseUserdefiniedCipherCheckBox->isChecked());

		profileData->setUserdefinedPort(newprofilewizardopenvpnpagecontent->UserdefinedPortSpinBox->value());
		profileData->setUseUserdefinedPort(newprofilewizardopenvpnpagecontent->UseUserdefinedPortCheckBox->isChecked());

		if (newprofilewizardopenvpnpagecontent->UseTlsAuthCheckBox->isChecked())
		{
			if( newprofilewizardopenvpnpagecontent->TlsAuthURLRequester->url().isEmpty())
			{
				ok=false;
				msg+=i18n("TLS auth file")+"\n";
			}
			else
			{
				profileData->setUseTlsAuth( true );
				profileData->setTlsAuthFile( newprofilewizardopenvpnpagecontent->TlsAuthURLRequester->url());
			}
		}

		if ( newprofilewizardopenvpnpagecontent->UseTlsRemoteHostCheckBox->isChecked() )
		{
			if (newprofilewizardopenvpnpagecontent->TlsRemoteHostLineEdit->text().isEmpty())
			{
				ok=false;
				msg+=i18n("TLS remote host")+"\n";
			}
			else
			{
				profileData->setUseTlsRemoteHost( newprofilewizardopenvpnpagecontent->UseTlsAuthCheckBox->isChecked() );
				profileData->setTlsRemoteHost( newprofilewizardopenvpnpagecontent->TlsRemoteHostLineEdit->text());
			}
		}

		profileData->setAuthWithUsernameAndPassword( newprofilewizardopenvpnpagecontent->AuthWithUsernameAndPasswordCheckBox->isChecked());
		profileData->setDisableLzoCompression( newprofilewizardopenvpnpagecontent->DisableLzoCompressionCheckBox->isChecked());

		if ( newprofilewizardopenvpnpagecontent->UseHttpProxyCheckBox->isChecked() )
		{
			if (newprofilewizardopenvpnpagecontent->HttpProxyLineEdit->text().isEmpty() )
			{
				ok=false;
				msg+=i18n("HTTP proxy host")+"\n";
			}
			else
			{
				profileData->setUseHttpProxy( newprofilewizardopenvpnpagecontent->UseHttpProxyCheckBox->isChecked() );
				profileData->setHttpProxy( newprofilewizardopenvpnpagecontent->HttpProxyLineEdit->text( ) );
			}
		}

		profileData->setHttpProxyPort( newprofilewizardopenvpnpagecontent->HttpProxyPortIntNumInput->value( ) );
		profileData->setHttpProxyTimeout( newprofilewizardopenvpnpagecontent->HttpProxyTimeoutIntSpinBox->value() );

	}
	else if ( currentpage == newprofilewizardauthselectionpage )
	{
		if (newprofilewizardauthselectioncontent->PskRadioButton->isChecked() )
		{
			useCert=false;

			profileData->setAuthType( VpnAccountData::psk);
			insertPage(newprofilewizardpskpage,"<b>"+ i18n("PSK settings")+"</b>", indexOf(currentpage)+1);

			// racoon or freeswan
			if ( profileData->getConnectionType() == VpnAccountData::freeswan || profileData->getConnectionType() == VpnAccountData::racoon )
			{
				newprofilewizardpskcontent->PSKLineEdit->setEnabled( true );
			}

			else if (profileData->getConnectionType() == VpnAccountData::openvpn)
			{
				newprofilewizardpskcontent->PSKLineEdit->setEnabled( true );
				newprofilewizardpskcontent->LabelPsk->setEnabled( true );
			}
			if ( GlobalConfig->KvpncDebugLevel > 0 )
				GlobalConfig->appendLogEntry(i18n("Auth selection: use PSK"), KVpncConfig::debug);
		}
		else
		{
			useCert=true;
			profileData->setAuthType( VpnAccountData::cert);
			insertPage(newprofilewizardp12certselectionpage,"<b>"+ i18n("Certificate format")+"</b>", indexOf(currentpage)+1);
			// racoon or freeswan
			if ( profileData->getConnectionType() == VpnAccountData::freeswan || profileData->getConnectionType() == VpnAccountData::racoon )
			{
				newprofilewizardcertcontent->x509certURLRequester->setEnabled( true );
				newprofilewizardcertcontent->LabelCertificate->setEnabled( true );
				newprofilewizardcertcontent->certpathURLRequester->setEnabled( true );
				newprofilewizardcertcontent->LabelCertificatePath->setEnabled( true );
			}

			else if (profileData->getConnectionType() == VpnAccountData::openvpn)
			{
				newprofilewizardcertcontent->x509certURLRequester->setEnabled( true );
				newprofilewizardcertcontent->CaCertpathURLRequester->setEnabled( true );
				newprofilewizardcertcontent->LabelCertificate->setEnabled( true );
				newprofilewizardcertcontent->certpathURLRequester->setEnabled( true );
				newprofilewizardcertcontent->LabelCertificatePath->setEnabled( true );
				newprofilewizardcertcontent->privkeypathURLRequester->setEnabled( true );
				newprofilewizardcertcontent->LabelPrivateKeyPath->setEnabled( true );
				newprofilewizardcertcontent->LabelPrivateKeyPath->setEnabled( true );
			}
			if ( GlobalConfig->KvpncDebugLevel > 0 )
				GlobalConfig->appendLogEntry(i18n("Auth selection: use certificate"), KVpncConfig::debug);
		}
	}
	else if ( currentpage == newprofilewizardp12certselectionpage )
	{
		insertPage(newprofilewizardcertpage,"<b>"+ i18n("Certificate settings")+"</b>", indexOf(currentpage)+1);
		if (newprofilewizardp12certselectioncontent->P12CertYesRadioButton->isChecked() )
		{
			// yes we have p12 cert
			if ( GlobalConfig->KvpncDebugLevel > 0 )
				GlobalConfig->appendLogEntry(i18n("P12 cert selection: cert type is PKCS12"), KVpncConfig::debug);

			if (importP12Certificate())
			{
				// success :)
			}
			else
			{
				newProfileCreated=false;
			}
		}
		else
		{

			if ( GlobalConfig->KvpncDebugLevel > 0 )
				GlobalConfig->appendLogEntry(i18n("P12 cert selection: cert type is other"), KVpncConfig::debug);
		}

	}
	else if ( currentpage == newprofilewizardopenvpnselectionpage )
	{
		if (newprofilewizardopenvpnselectionpagecontent->OpenvpnImportRadioButton->isChecked() )
		{
			enterdatamanually=false;
			removePage( newprofilewizardopenvpnpage );
			removePage ( newprofilewizardgeneralpage );
			if ( GlobalConfig->KvpncDebugLevel > 0 )
				GlobalConfig->appendLogEntry(i18n("OpenVPN selection: import profile file"), KVpncConfig::debug);
		}
		else
		{
			enterdatamanually=true;
			insertPage(newprofilewizardopenvpnpage,"<b>"+ i18n("OpenVPN settings")+"</b>", indexOf(currentpage)+1);
			if ( GlobalConfig->KvpncDebugLevel > 0 )
				GlobalConfig->appendLogEntry(i18n("OpenVPN selection: enter data manually"), KVpncConfig::debug);
		}
	}
	else if ( currentpage == newprofilewizardpptppage )
	{

		profileData->setRefuseEap(newprofilewizardpptppagecontent->RefuseEapCheckbox->isChecked() );
		profileData->setRequireMppe(newprofilewizardpptppagecontent->RequireMppeCheckbox->isChecked()  );
		profileData->setRefuse128BitEncryption(newprofilewizardpptppagecontent->Refuse128BitEncryptionCheckbox->isChecked() );
		profileData->setRefuse40BitEncryption(newprofilewizardpptppagecontent->Refuse40BitEncryptionCheckbox->isChecked() );
		profileData->setDisableMPPEComp(newprofilewizardpptppagecontent->UseNoMPPECompressionCheckbox->isChecked() );
		profileData->setUseGetDnsFromPeer(newprofilewizardpptppagecontent->GetDnsFromPeerCheckbox->isChecked());
		profileData->setUseDnsServer(newprofilewizardpptppagecontent->DnsServerCheckbox->isChecked() );
		profileData->setDnsServer(newprofilewizardpptppagecontent->DnsServerLineedit->text() );
		profileData->setUseNoBsdComp(newprofilewizardpptppagecontent->UseNoBsdCompCheckbox->isChecked());
		profileData->setUseNoDeflate(newprofilewizardpptppagecontent->UseNoDeflateCheckbox->isChecked());
		profileData->setSetDefaultRoute(newprofilewizardpptppagecontent->SetDefaultRouteCheckbox->isChecked());
		profileData->setReplaceDefaultRoute(newprofilewizardpptppagecontent->ReplaceDefaultRouteCheckbox->isChecked());
		profileData->setUseMtu(newprofilewizardpptppagecontent->MtuCheckbox->isChecked());
		profileData->setMtu(newprofilewizardpptppagecontent->MtuSpinbox->value());
		profileData->setAllowStatefulMode(newprofilewizardpptppagecontent->AllowStatefulModeCheckbox->isChecked());
		profileData->setUseNoIpDefault(newprofilewizardpptppagecontent->UseNoIpDefaultCheckbox->isChecked());
		profileData->setDisableMPPEComp(newprofilewizardpptppagecontent->UseNoMPPECompressionCheckbox->isChecked());
		profileData->setKeepDefaultRoute( newprofilewizardpptppagecontent->KeepDefaultRouteCheckBox->isChecked());

		insertPage(newprofilewizarduserpage,"<b>"+i18n("User settings")+"</b>", indexOf(currentpage)+1);

	}
	else if ( currentpage == newprofilewizardpskpage )
	{
		msg=i18n("These fields must be filled in:\n");
		if (newprofilewizardpskcontent->CheckSavePsk->isChecked() )
		{
			if ( !newprofilewizardpskcontent->PskInFileCheckBox->isChecked() )
			{
				profileData->setSavePsk(true);
				profileData->setPskIsInFile( false );
				if( !newprofilewizardpskcontent->PSKLineEdit->text().isEmpty() )
				{
					profileData->setPreSharedKey(newprofilewizardpskcontent->PSKLineEdit->text());
				}
				else
				{
					msg+="- "+i18n("Pre shared key")+"\n";
					ok=false;
				}
			}
			else
			{
				profileData->setSavePsk(true);
				profileData->setPskIsInFile( true );
				if(!newprofilewizardpskcontent->PSKFileURLRequester->url().isEmpty() )
				{
					profileData->setPreSharedKey(newprofilewizardpskcontent->PSKLineEdit->text());
				}
				else
				{
					ok=false;
					msg+="- "+i18n("Pre shared key file")+"\n";
				}
			}

		}
		else
		{
			profileData->setSavePsk(false);
		}

		if (newprofilewizardpskcontent->PskInFileCheckBox->isChecked())
		{
			profileData->setSavePsk( newprofilewizardpskcontent->CheckSavePsk->isChecked() );
			if (!newprofilewizardpskcontent->PSKFileURLRequester->url().isEmpty() )
			{
				profileData->setPreSharedKeyFile(newprofilewizardpskcontent->PSKFileURLRequester->url());
			}
			else
			{
				ok=false;
				msg+="- "+i18n("Pre shared key file")+"\n";
			}
		}
		if (newprofilewizardpskcontent->CheckSavePsk->isChecked())
			profileData->setPreSharedKey( newprofilewizardpskcontent->PSKLineEdit->text( ) );
		else
			profileData->setPreSharedKey( "" );

		profileData->setPreSharedKey( newprofilewizardpskcontent->PSKLineEdit->text() );

	}
	else if ( currentpage == newprofilewizardcertpage )
	{
		profileData->setSpecialRemoteID( newprofilewizardcertcontent->RemoteIDLineEdit->text() );
		profileData->setUseSpecialRemoteID( newprofilewizardcertcontent->UseSpecialRemoteIDcheckBox->isChecked() );
		profileData->setX509Certificate( newprofilewizardcertcontent->x509certURLRequester->url() );
		profileData->setCaCertificate( newprofilewizardcertcontent->CaCertpathURLRequester->url() );
		profileData->setCertPath( newprofilewizardcertcontent->certpathURLRequester->url() );
		profileData->setPrivateKey ( newprofilewizardcertcontent->privkeypathURLRequester->url());
		profileData->setPrivateKeyPass ( newprofilewizardcertcontent->PrivkeyPasswordEdit->text());
		profileData->setX509Certificate( newprofilewizardcertcontent->x509certURLRequester->url() );
		profileData->setCertPath( newprofilewizardcertcontent->certpathURLRequester->url() );
		profileData->setUseSpecialServerCertificate(newprofilewizardcertcontent->UseSpecialServerCertificateCheckBox->isChecked());
		profileData->setSpecialServerCertificate(newprofilewizardcertcontent->SpecialServerCertificateURLRequester->url());

		msg=i18n("These fields must be filled in:\n");

		if ( newprofilewizardcertcontent->UseSpecialServerCertificateCheckBox->isChecked())
		{
			if (newprofilewizardcertcontent->SpecialServerCertificateURLRequester->url().isEmpty())
			{
				ok=false;
				msg+="- "+i18n("Special server certificate")+"\n";
				// 				KMessageBox::error ( this, i18n( "Special server certificate can't be empty!" ), i18n( "No Server Certificate" ) );
				GlobalConfig->appendLogEntry( i18n( "Special server certificate can't be empty!" ) ,GlobalConfig->error);
			}
		}
		if ( newprofilewizardcertcontent->x509certURLRequester->url().isEmpty())
		{
			ok=false;
			msg+="- "+i18n("Certificate")+"\n";
			GlobalConfig->appendLogEntry( i18n( "Certificate can't be empty!" ) ,GlobalConfig->error);
		}
		if ( newprofilewizardcertcontent->CaCertpathURLRequester->url().isEmpty())
		{
			ok=false;
			msg+="- "+i18n("CA certificate")+"\n";
			GlobalConfig->appendLogEntry( i18n( "CA Certificate can't be empty!" ) ,GlobalConfig->error);
		}
		if ( newprofilewizardcertcontent->privkeypathURLRequester->url().isEmpty())
		{
			ok=false;
			msg+="- "+i18n("Path to private key")+"\n";
			GlobalConfig->appendLogEntry( i18n( "Path to private key can't be empty!" ) ,GlobalConfig->error);
		}
		if ( newprofilewizardcertcontent->PrivkeyPasswordEdit->text().isEmpty())
		{
			ok=false;
			msg+="- "+i18n("Private key password")+"\n";
			GlobalConfig->appendLogEntry( i18n( "Private key password can't be empty!" ) ,GlobalConfig->error);
		}
		if ( newprofilewizardcertcontent->UseSpecialRemoteIDcheckBox->isChecked())
		{
			if (newprofilewizardcertcontent->RemoteIDLineEdit->text().isEmpty())
			{
				ok=false;
				msg+="- "+i18n("Special remote ID")+"\n";
				// 				KMessageBox::error ( this, i18n( "Special server certificate can't be empty!" ), i18n( "No Server Certificate" ) );
				GlobalConfig->appendLogEntry( i18n( "Special remote ID can't be empty!" ) ,GlobalConfig->error);
			}
		}
	}
	else if ( currentpage == newprofilewizarduserpage )
	{
		msg=i18n("These fields must be filled in:\n");
		if ( newprofilewizarduserpagecontent->UsernameLineEdit->text().isEmpty() )
		{
			ok=false;
			msg+="- "+i18n("Username")+"\n";
			GlobalConfig->appendLogEntry( i18n( "Username  is empty!"), GlobalConfig->error);
		}
		else
			profileData->setUserName(newprofilewizarduserpagecontent->UsernameLineEdit->text());

		if ( !newprofilewizarduserpagecontent->PasswordEdit->text().isEmpty())
		{
			profileData->setUserPassword( newprofilewizarduserpagecontent->PasswordEdit->text() );
		}
		else
		{
			if ( newprofilewizarduserpagecontent->CheckUserPass->isChecked() )
			{
				ok=false;
				msg+="- "+i18n("Password")+"\n";
				GlobalConfig->appendLogEntry( i18n( "Password  is empty but you have checked to store it!"), GlobalConfig->error);
			}
		}
		profileData->setUserPassword(newprofilewizarduserpagecontent->PasswordEdit->text());
		profileData->setSaveUserPassword(newprofilewizarduserpagecontent->CheckUserPass->isChecked());


	}
	else if ( currentpage == newprofilewizardnetworkpage )
	{
		msg=i18n("These fields must be filled in:\n");
		bool validAddr = true;
		if ( ( profileData->getConnectionType() == VpnAccountData::freeswan || profileData->getConnectionType() == VpnAccountData::racoon || profileData->getConnectionType() == VpnAccountData::pptp ) )
		{
			if  ( !newprofilewizardnetworkcontent->RemoteNetAddrLineEdit->text().isEmpty() )
			{
				if ( newprofilewizardnetworkcontent->RemoteNetAddrLineEdit->text().contains( '.' ) != 3 )
				{
					KMessageBox::error ( this, i18n( "No IP address entered!" ), i18n( "No IP Address" ) );
					validAddr = false;
					return;
				}
				else
				{
					QString addr = newprofilewizardnetworkcontent->RemoteNetAddrLineEdit->text();
					int part0 = addr.section( '.', 0, 0 ).toInt();
					int part1 = addr.section( '.', 1, 1 ).toInt();
					int part2 = addr.section( '.', 2, 2 ).toInt();
					int part3 = addr.section( '.', 3, 3 ).toInt();

					/*
								LogOutput->append ("part0: "+QString().setNum(part0));
								LogOutput->append ("part1: "+QString().setNum(part1));
								LogOutput->append ("part2: "+QString().setNum(part2));
								LogOutput->append ("part3: "+QString().setNum(part3));
					*/

					if ( ( part0 < 1 || part0 > 254 ) || ( part1 < 0 || part1 > 254 ) || ( part2 < 0 || part2 > 254 ) || ( part3 < 0 || part3 > 254 ) )
					{
						KMessageBox::error ( this, i18n( "Invalid values in IP address (remote net)!" ), i18n( "Invalid Values in IP Address" ) );
						GlobalConfig->appendLogEntry(i18n( "Invalid values in IP address (remote net)!" ) ,GlobalConfig->error);
						validAddr = false;
						return;
					}

					if ( validAddr == true )
					{
						profileData->setRemoteNetAddr( addr);
						profileData->setRemoteNetMask (newprofilewizardnetworkcontent->RemoteNetMaskComboBox->currentText() );
					}

				}
			}


			else
			{
				ok=false;
				msg+="- "+i18n("Remote network")+"\n";
				GlobalConfig->appendLogEntry( i18n( "Remote network  is empty!"), GlobalConfig->error);
			}
		}
		profileData->setNetworkDevice( newprofilewizardnetworkcontent->NetworkDeviceComboBox->currentText());

	}
	else if ( currentpage == newprofilewizardnatpage )
	{
		profileData->setUseUdp( newprofilewizardnatcontent->UseUdpCheckbox->isChecked());
		profileData->setUseUdpPort ( newprofilewizardnatcontent->UdpPortCheckbox->isChecked());
		profileData->setUdpPort( newprofilewizardnatcontent->UdpPortSpinbox->value());
		if ( GlobalConfig->KvpncDebugLevel > 0 )
		{
			if (profileData->getUseUdp())
				GlobalConfig->appendLogEntry(i18n("NAT settings: use NAT"), KVpncConfig::debug);
			else
				GlobalConfig->appendLogEntry(i18n("NAT settings: use no NAT"), KVpncConfig::debug);

			if (profileData->getUseUdpPort())
				GlobalConfig->appendLogEntry(i18n("NAT settings: use userdefinied Port: %1").arg(QString().setNum(profileData->getUdpPort())), KVpncConfig::debug);
		}


	}
	else if ( currentpage == newprofilewizardconnectoptionspage )
	{
		connectaftercreating=newprofilewizardconnectoptionscontent->ConnectAfterCreatingProfileCheckBox->isChecked();

		if (GlobalConfig->KvpncDebugLevel > 0)
			if (connectaftercreating)
				GlobalConfig->appendLogEntry ( i18n( "Connect options: connecting to profile \"%1\" after creating it." ).arg( profileData->getName() ) ,GlobalConfig->debug);

	}
	else if ( currentpage == newprofilewizardconnectionstatuscheckpage )
	{
		msg=i18n("These fields must be filled in:\n");
		if (newprofilewizardconnectionstatuscheckcontent->UseConnectionStatusCheckCheckBox->isChecked())
		{
			profileData->setUseConnectionStatusCheck(true);
			if ( GlobalConfig->KvpncDebugLevel > 0 )
				GlobalConfig->appendLogEntry(i18n("Connection status check: use connection status check"), KVpncConfig::debug);
		}
		else
		{
			profileData->setUseConnectionStatusCheck(false);
			if ( GlobalConfig->KvpncDebugLevel > 0 )
				GlobalConfig->appendLogEntry(i18n("Connection status check: dont use connection status check"), KVpncConfig::debug);
		}

		if (newprofilewizardconnectionstatuscheckcontent->DoReconnectAfterConnectionLostCheckBox->isChecked())
		{
			profileData->setDoReconnectAfterConnectionLost( true);
			if ( GlobalConfig->KvpncDebugLevel > 0 )
				GlobalConfig->appendLogEntry(i18n("Connection status check: do reconnect after connection lost"), KVpncConfig::debug);
		}
		else
		{
			profileData->setDoReconnectAfterConnectionLost( false);
			if ( GlobalConfig->KvpncDebugLevel > 0 )
				GlobalConfig->appendLogEntry(i18n("Connection status check: dont reconnect after connection lost"), KVpncConfig::debug);
		}

		if (newprofilewizardconnectionstatuscheckcontent->PingUserdefiniedAddressCheckBox->isChecked())
		{
			profileData->setDoPingIP( true);
			if ( GlobalConfig->KvpncDebugLevel > 0 )
				GlobalConfig->appendLogEntry(i18n("Connection status check: ping userdefinied IP address"), KVpncConfig::debug);
		}
		else
		{
			profileData->setDoPingIP( false);
			if ( GlobalConfig->KvpncDebugLevel > 0 )
				GlobalConfig->appendLogEntry(i18n("Connection status check: dont ping userdefinied IP address"), KVpncConfig::debug);
		}

		profileData->setConnectionStatusInterval( newprofilewizardconnectionstatuscheckcontent->ConnectionStatusCheckIntervalNumInput->value());
		profileData->setConnectionStatusCheckSuccessCount( newprofilewizardconnectionstatuscheckcontent->ConnectionStatusSuccessCountNumInput->value());

		if ( GlobalConfig->KvpncDebugLevel > 0 )
		{
			GlobalConfig->appendLogEntry(i18n("Connection status check: use connection interval: %1").arg(QString().setNum(newprofilewizardconnectionstatuscheckcontent->ConnectionStatusCheckIntervalNumInput->value())), KVpncConfig::debug);
			GlobalConfig->appendLogEntry(i18n("Connection status check: success count: %1").arg(QString().setNum(newprofilewizardconnectionstatuscheckcontent->ConnectionStatusSuccessCountNumInput->value())), KVpncConfig::debug);
		}

		if (newprofilewizardconnectionstatuscheckcontent->UseConnectionStatusCheckCheckBox->isChecked())
		{
			if (newprofilewizardconnectionstatuscheckcontent->PingUserdefiniedAddressCheckBox->isChecked())
			{
				if (!newprofilewizardconnectionstatuscheckcontent->UserdefiniedPingIPLineEdit->text().isEmpty())
				{
					if (Utils(GlobalConfig).isValidIPv4Address(newprofilewizardconnectionstatuscheckcontent->UserdefiniedPingIPLineEdit->text()))
						profileData->setPingHostIP( newprofilewizardconnectionstatuscheckcontent->UserdefiniedPingIPLineEdit->text());
					else
					{
						ok=false;
						msg=i18n("The value of userdefinied IP address is not a valid IP address!");
					}
				}
				else
				{
					ok=false;
					msg+=i18n("Userdefinied IP for ping")+"\n";
				}
			}
		}
	}
	else if ( currentpage == endpage )
	{}
	if (ok)
	{
		previouspage=currentpage;
		QWizard::next();
	}
	else
	{
		KMessageBox::error( this, msg);
	}
}

void NewProfileWizard::back()
{
	/*
	currentpage=previouspage;
	// 	showPage(previouspage);

	if ( currentpage == page1 )
	{
		// nothing here
	}
	else if ( currentpage == newprofilewizardgeneralpage )
	{
		newprofilewizardgeneralpagecontent->NameLineEdit->setText(profileData->getName());
		newprofilewizardgeneralpagecontent->gatewayLineEdit->setText(profileData->getGateway());
		newprofilewizardgeneralpagecontent->DescriptionLineEdit->setText(profileData->getDescription());
	}
	else if ( currentpage == newprofilewizardtypeselectionpage )
	{
		if ( profileData->getConnectionType() == VpnAccountData::cisco )
			newprofilewizardtypeselectionpagecontent->CiscoRadioButton->setChecked(true);
		else if ( profileData->getConnectionType() == VpnAccountData::freeswan )
			newprofilewizardtypeselectionpagecontent->FreeswanRadioButton->setChecked(true);
		else if ( profileData->getConnectionType() == VpnAccountData::racoon )
			newprofilewizardtypeselectionpagecontent->FreeswanRadioButton->setChecked(true);
		else if ( profileData->getConnectionType() == VpnAccountData::pptp )
			newprofilewizardtypeselectionpagecontent->PptpRadioButton->setChecked(true);
		else if ( profileData->getConnectionType() == VpnAccountData::openvpn )
			newprofilewizardtypeselectionpagecontent->OpenvpnRadioButton->setChecked(true);
	}
	else if ( currentpage == newprofilewizardciscoselectionpage )
	{}
	else if ( currentpage == newprofilewizardciscomanuallypage )
	{
		newprofilewizardciscomanuallypagecontent->IDLineEdit->setText(profileData->getGateway());
		newprofilewizardciscomanuallypagecontent->AllowEmptyGroupPasswordCheckBox->setChecked(profileData->getAllowEmptyGroupPassword());
		newprofilewizardciscomanuallypagecontent->GroupPasswordLineEdit->setText(profileData->getPreSharedKey());
		profileData->setID(newprofilewizardciscomanuallypagecontent->IDLineEdit->text());

		insertPage ( newprofilewizardciscoselectionpage, "<b>"+ i18n("Cisco selection")+"</b>", 2 );

	}
	else if ( currentpage == newprofilewizardracoonpage )
	{
		newprofilewizardracoonpagecontent->HashAlgoComboBox->setCurrentText(profileData->getHashAlgo());

		insertPage ( newprofilewizardciscoselectionpage,"<b>"+ i18n("Cisco selection")+"</b>" ,  2 );
		insertPage ( newprofilewizardciscomanuallypage, "<b>"+ i18n("Cisco settings")+"</b>",  3 );
		insertPage ( newprofilewizardopenvpnselectionpage, "<b>"+ i18n("FreeS/WAN settings")  , 4 );
		insertPage ( newprofilewizardopenvpnselectionpage, "<b>"+ i18n("OpenVPN settings")+"</b>"  , 5 );
		insertPage ( newprofilewizardpptppage,  "<b>"+ i18n("PPTP settings")+"</b>",  6 );
	}
	else if ( currentpage == newprofilewizardfreeswanpage )
	{
		insertPage ( newprofilewizardciscoselectionpage,"<b>"+ i18n("Cisco selection")+"</b>" ,  2 );
		insertPage ( newprofilewizardciscomanuallypage, "<b>"+ i18n("Cisco settings")+"</b>",  3 );
		insertPage ( newprofilewizardracoonpage, "<b>"+ i18n("Racoon settings")+"</b>"  , 4 );
		insertPage ( newprofilewizardopenvpnselectionpage, "<b>"+ i18n("FreeS/WAN settings")  , 4 );
		insertPage ( newprofilewizardpptppage,  "<b>"+ i18n("PPTP settings")+"</b>",  5 );
	}
	else if ( currentpage == newprofilewizardopenvpnpage )
	{
		newprofilewizardopenvpnpagecontent->TunnelDeviceTypeComboBox->setCurrentText(profileData->getTunnelDeviceType() );
		newprofilewizardopenvpnpagecontent->NsCertTypeComboBox->setCurrentText(profileData->getNsCertType());
		newprofilewizardopenvpnpagecontent->TunnelDeviceTypeComboBox->setCurrentText(profileData->getTunnelDeviceType() );
		newprofilewizardopenvpnpagecontent->UseRedirectGatewayCheckBox->setChecked(profileData->getUseRedirectGateway() );

		newprofilewizardopenvpnpagecontent->UserdefiniedCipherComboBox->setCurrentText(profileData->getUserdefiniedCipher());
		newprofilewizardopenvpnpagecontent->UseUserdefiniedCipherCheckBox->setChecked(profileData->getUseUserdefiniedCipher());
		newprofilewizardopenvpnpagecontent->UseTlsAuthCheckBox->setChecked(profileData->getUseTlsAuth());
		newprofilewizardopenvpnpagecontent->TlsAuthURLRequester->setURL(profileData->getTlsAuthFile());

		profileData->setUseTlsRemoteHost( newprofilewizardopenvpnpagecontent->UseTlsAuthCheckBox->isChecked());
		profileData->setTlsRemoteHost( newprofilewizardopenvpnpagecontent->TlsRemoteHostLineEdit->text());

		profileData->setUseHttpProxy( newprofilewizardopenvpnpagecontent->UseHttpProxyCheckBox->isChecked() );
		profileData->setHttpProxy( newprofilewizardopenvpnpagecontent->HttpProxyLineEdit->text( ) );
		profileData->setHttpProxyPort( newprofilewizardopenvpnpagecontent->HttpProxyPortIntNumInput->value( ) );
		profileData->setHttpProxyTimeout( newprofilewizardopenvpnpagecontent->HttpProxyTimeoutIntSpinBox->value() );

		insertPage ( newprofilewizardciscoselectionpage,"<b>"+ i18n("Cisco selection")+"</b>" , 2 );
		insertPage ( newprofilewizardciscomanuallypage, "<b>"+ i18n("Cisco settings")+"</b>",  3 );
		insertPage ( newprofilewizardfreeswanpage, "<b>"+ i18n("FreeS/WAN settings")  ,  4 );
		insertPage ( newprofilewizardracoonpage, "<b>"+ i18n("Racoon settings")+"</b>"  ,  5 );
		insertPage ( newprofilewizardpptppage,  "<b>"+ i18n("PPTP settings")+"</b>",  6 );
	}
	else if ( currentpage == newprofilewizardpptppage )
	{
		insertPage ( newprofilewizardciscoselectionpage,"<b>"+ i18n("Cisco selection")+"</b>" , 2 );
		insertPage ( newprofilewizardciscomanuallypage, "<b>"+ i18n("Cisco settings")+"</b>",  3 );
		insertPage ( newprofilewizardfreeswanpage, "<b>"+ i18n("FreeS/WAN settings")  ,  4 );
		insertPage ( newprofilewizardracoonpage, "<b>"+ i18n("Racoon settings")+"</b>"  ,  5 );
		insertPage ( newprofilewizardopenvpnpage,   "<b>"+i18n("OpenVPN settings")+"</b>", 6 );
	}
	else if ( currentpage == newprofilewizarduserpage )
	{
		newprofilewizarduserpagecontent->UsernameLineEdit->setText(profileData->getUserName());
		newprofilewizarduserpagecontent->PasswordEdit->setText(profileData->getUserPassword() );
		newprofilewizarduserpagecontent->CheckUserPass->setChecked(profileData->getSaveUserPassword());
	}
	else if ( currentpage == newprofilewizardnetworkpage )
	{
		newprofilewizardnetworkcontent->RemoteNetAddrLineEdit->setText(profileData->getRemoteNetAddr() );
		newprofilewizardnetworkcontent->RemoteNetMaskComboBox->setCurrentText(profileData->getRemoteNetMask());
		newprofilewizardnetworkcontent->NetworkDeviceComboBox->setCurrentText(profileData->getNetworkDevice());
	}
	else if ( currentpage == newprofilewizardnatpage )
	{
		newprofilewizardnatcontent->UseUdpCheckbox->setChecked(profileData->getUseUdp());
		newprofilewizardnatcontent->UdpPortCheckbox->setChecked(profileData->getUseUdpPort ());
		newprofilewizardnatcontent->UdpPortSpinbox->setValue(profileData->getUdpPort());
	}
	*/
	QWizard::back();
}

QString NewProfileWizard::getName()
{
	return profileData->getName();
}

bool NewProfileWizard::getFinished()
{
	return finished;
}

void NewProfileWizard::showPage( QWidget* page )
{
	currentpage= page;
	QWizard::showPage(page);

	// FIXME set currentpage at back()
	//backButton()->setEnabled(false);

	helpButton()->setEnabled(false);

	if ( page == endpage )
	{
		finishButton()->setEnabled( TRUE );
		finishButton()->setFocus();
	}
}

void NewProfileWizard::dataChanged( const QString & )
{
	//     if ( !firstName->text().isEmpty() &&
	//          !lastName->text().isEmpty() &&
	//          !email->text().isEmpty() )
	//         nextButton()->setEnabled( TRUE );
	//     else
	//         nextButton()->setEnabled( FALSE );
}

void NewProfileWizard::userdefinedOpenvpnPortToggeled(bool)
{
	if (newprofilewizardopenvpnpagecontent->UseUserdefinedPortCheckBox->isChecked())
		newprofilewizardopenvpnpagecontent->UserdefinedPortSpinBox->setEnabled(true);
	else
		newprofilewizardopenvpnpagecontent->UserdefinedPortSpinBox->setEnabled(false);
}

void NewProfileWizard::nsCertTypeOpenvpnToggled(bool)
{
	if (newprofilewizardopenvpnpagecontent->UseNsCertTypeCheckBox->isChecked())
		newprofilewizardopenvpnpagecontent->NsCertTypeComboBox->setEnabled(true);
	else
		newprofilewizardopenvpnpagecontent->NsCertTypeComboBox->setEnabled(false);
}

void NewProfileWizard::pskIsInFileToggled(bool)
{
	if (newprofilewizardpskcontent->PskInFileCheckBox->isChecked())
	{
		newprofilewizardpskcontent->LabelPskFile->setEnabled(TRUE);
		newprofilewizardpskcontent->PSKFileURLRequester->setEnabled(TRUE);
		newprofilewizardpskcontent->LabelPsk->setEnabled(FALSE);
		newprofilewizardpskcontent->PSKLineEdit->setEnabled(FALSE);
	}
	else
	{
		newprofilewizardpskcontent->LabelPskFile->setEnabled(FALSE);
		newprofilewizardpskcontent->PSKFileURLRequester->setEnabled(FALSE);
		newprofilewizardpskcontent->LabelPsk->setEnabled(TRUE);
		newprofilewizardpskcontent->PSKLineEdit->setEnabled(TRUE);
	}
}

void NewProfileWizard::useUdpToggled(bool)
{
	if (newprofilewizardnatcontent->UseUdpCheckbox->isChecked())
	{
		newprofilewizardnatcontent->UdpPortCheckbox->setEnabled(TRUE);
		newprofilewizardnatcontent->UdpPortSpinbox->setEnabled(FALSE);
	}
	else
	{
		newprofilewizardnatcontent->UdpPortCheckbox->setEnabled(FALSE);
		newprofilewizardnatcontent->UdpPortSpinbox->setEnabled(FALSE);
	}
}

void NewProfileWizard::udpPortToggled(bool)
{
	if (newprofilewizardnatcontent->UdpPortCheckbox->isChecked())
	{
		newprofilewizardnatcontent->UdpPortSpinbox->setEnabled(TRUE);
	}
	else
	{
		newprofilewizardnatcontent->UdpPortSpinbox->setEnabled(FALSE);
	}
}

void NewProfileWizard::pingIpAfterConnectToggled(bool)
{
	if (newprofilewizardconnectionstatuscheckcontent->PingUserdefiniedAddressCheckBox->isChecked())
		newprofilewizardconnectionstatuscheckcontent->UserdefiniedPingIPLineEdit->setEnabled(true);
	else
		newprofilewizardconnectionstatuscheckcontent->UserdefiniedPingIPLineEdit->setEnabled(false);
}

void NewProfileWizard::useUserdefiniedCipherToggled(bool)
{
	if (newprofilewizardopenvpnpagecontent->UseUserdefiniedCipherCheckBox->isChecked())
		newprofilewizardopenvpnpagecontent->UserdefiniedCipherComboBox->setEnabled(true);
	else
		newprofilewizardopenvpnpagecontent->UserdefiniedCipherComboBox->setEnabled(false);
}

void NewProfileWizard::useTlsAuthToggled(bool)
{
	if (newprofilewizardopenvpnpagecontent->UseTlsAuthCheckBox ->isChecked())
	{
		newprofilewizardopenvpnpagecontent->TlsAuthURLRequester->setEnabled(true);
		newprofilewizardopenvpnpagecontent->UseTlsRemoteHostCheckBox->setEnabled(true);
	}
	else
	{
		newprofilewizardopenvpnpagecontent->TlsAuthURLRequester->setEnabled(false);
		newprofilewizardopenvpnpagecontent->UseTlsRemoteHostCheckBox->setEnabled(false);
	}
}

void NewProfileWizard::useHttpProxyToggeled(bool)
{
	if ( newprofilewizardopenvpnpagecontent->UseHttpProxyCheckBox->isChecked())
	{
		newprofilewizardopenvpnpagecontent->HostTextLabel->setEnabled(true);
		newprofilewizardopenvpnpagecontent->HttpProxyLineEdit->setEnabled(true);
		newprofilewizardopenvpnpagecontent->TimeoutTextLabel->setEnabled(true);
		newprofilewizardopenvpnpagecontent->HttpProxyTimeoutIntSpinBox->setEnabled(true);
		newprofilewizardopenvpnpagecontent->PortTextextLabel->setEnabled(true);
		newprofilewizardopenvpnpagecontent->HttpProxyPortIntNumInput->setEnabled(true);
	}
	else
	{
		newprofilewizardopenvpnpagecontent->HostTextLabel->setEnabled(false);
		newprofilewizardopenvpnpagecontent->HttpProxyLineEdit->setEnabled(false);
		newprofilewizardopenvpnpagecontent->TimeoutTextLabel->setEnabled(false);
		newprofilewizardopenvpnpagecontent->HttpProxyTimeoutIntSpinBox->setEnabled(false);
		newprofilewizardopenvpnpagecontent->PortTextextLabel->setEnabled(false);
		newprofilewizardopenvpnpagecontent->HttpProxyPortIntNumInput->setEnabled(false);
	}
}

void NewProfileWizard::useTlsRemoteHostToggled(bool)
{
	if (newprofilewizardopenvpnpagecontent->UseTlsRemoteHostCheckBox->isChecked())
		newprofilewizardopenvpnpagecontent->TlsRemoteHostLineEdit->setEnabled(true);
	else
		newprofilewizardopenvpnpagecontent->TlsRemoteHostLineEdit->setEnabled(false);
}

void NewProfileWizard::connectionStatusCheckToggled(bool)
{
	if (!newprofilewizardconnectionstatuscheckcontent->UseConnectionStatusCheckCheckBox->isChecked())
	{
		newprofilewizardconnectionstatuscheckcontent->ConnectionStatusCheckIntervalNumInput->setEnabled(false);
		newprofilewizardconnectionstatuscheckcontent->ConnectionStatusSuccessCountNumInput->setEnabled(false);
	}
	else
	{
		newprofilewizardconnectionstatuscheckcontent->ConnectionStatusCheckIntervalNumInput->setEnabled(true);
		newprofilewizardconnectionstatuscheckcontent->ConnectionStatusSuccessCountNumInput->setEnabled(true);
	}
}

bool NewProfileWizard::importProfile(VpnAccountData::ConnectionType ConnType)
{
	// FIXME make dlg dynamiclly

	bool success=true;

	if ( ConnType == VpnAccountData::cisco)
	{
		ImportProfileDialog dlg(GlobalConfig, this,i18n("Import Cisco PCF profile"));
		dlg.exec();
		importOK = dlg.importOk;
		if ( importOK )
		{
			profileData = dlg.acc;
			KMessageBox::information( 0, i18n( "Import of \"%1\" was successful." ).arg( profileData->getName() ) );
			GlobalConfig->appendLogEntry ( i18n( "Import of \"%1\" (%2) was successful." ).arg( profileData->getName() ).arg("PCF"), GlobalConfig->info );
		}
		else
		{
			KMessageBox::information( 0, i18n( "Import of \"%1\" has been failed." ).arg( profileData->getName() ) );
			GlobalConfig->appendLogEntry ( i18n( "Import of \"%1\" (%2) has been failed." ).arg( profileData->getName() ).arg("PCF"), GlobalConfig->error );
			success=false;
		}
	}
	if ( ConnType == VpnAccountData::openvpn)
	{
		ImportOpenvpnProfileDialog dlg(GlobalConfig, this,i18n("Import OpenVPN profile"));
		dlg.exec();
		importOK = dlg.importOk;
		if ( importOK )
		{
			profileData = dlg.acc;
			KMessageBox::information( 0, i18n( "Import of \"%1\" was successful." ).arg( profileData->getName() ) );
			GlobalConfig->appendLogEntry ( i18n( "Import of \"%1\" (%2) was successful." ).arg( profileData->getName() ).arg("OpenVPN"), GlobalConfig->info );
		}
		else
		{
			KMessageBox::information( 0, i18n( "Import of \"%1\" has been failed." ).arg( profileData->getName() ) );
			GlobalConfig->appendLogEntry ( i18n( "Import of \"%1\" (%2) has been failed." ).arg( profileData->getName() ).arg("OpenVPN"), GlobalConfig->error );
			success=false;
		}
	}
	return success;

}

bool NewProfileWizard::importP12Certificate()
{
	bool success=true;

	newprofilewizardcertcontent->CaCertpathURLRequester->clear();
	newprofilewizardcertcontent->certpathURLRequester->clear();
	newprofilewizardcertcontent->PrivkeyPasswordEdit->clear();
	ImportCertificateDialog dlg( this, i18n("Import Certificate...").ascii(), GlobalConfig);

	if (profileData->getConnectionType() == VpnAccountData::freeswan)
		dlg.main->ImporttypeComboBox->setCurrentItem(ImportCertificateDialog::pkcs12_freeswan);
	else if (profileData->getConnectionType() == VpnAccountData::racoon)
	{
		dlg.main->ImporttypeComboBox->setCurrentItem(ImportCertificateDialog::pkcs12_racoon);
		dlg.main->FreeswanGroupBox->setEnabled(false);
	}
	else if (profileData->getConnectionType() == VpnAccountData::openvpn)
	{
		dlg.main->ImporttypeComboBox->setCurrentItem(ImportCertificateDialog::pkcs12_openvpn);
		dlg.main->RacoonCertificatePathUrlrequester->setEnabled(true);
		dlg.main->RacoonCertificatePathUrlrequester->setURL(profileData->getCertPath());
		dlg.main->FreeswanGroupBox->setEnabled(false);
		dlg.main->PrivateKeyPasswordEdit->setEnabled( true );
		dlg.main->PrivateKeyAgainPasswordEdit->setEnabled( true );

	}
	dlg.exec();
	importOK = dlg.importOk;
	QString filename = dlg.filename;
	if ( importOK )
	{
		QString certpath=dlg.certpath;
		QString CertFullPath=dlg.CertFullPath;
		QString CaCertFullPath=dlg.CaCertFullPath;
		QString importpassword = dlg.importpassword;
		QString privatekeypassword = dlg.privatekeyagainpassword;
		QString certificate = QString("mykeys_" + dlg.certName + ".pem");

		newprofilewizardcertcontent->CaCertpathURLRequester->setURL (CaCertFullPath);
		newprofilewizardcertcontent->privkeypathURLRequester->setURL (certpath+"/"+certificate);

		if (profileData->getConnectionType() == VpnAccountData::openvpn)
			newprofilewizardcertcontent->PrivkeyPasswordEdit->setText(importpassword);
		else
			newprofilewizardcertcontent->PrivkeyPasswordEdit->setText(privatekeypassword);
		newprofilewizardcertcontent->certpathURLRequester->setURL(certpath);
		newprofilewizardcertcontent->x509certURLRequester->setURL(certpath+"/"+certificate);

		KMessageBox::information( 0, i18n( "Import of \"%1\" was successful." ).arg( filename ) );
		GlobalConfig->appendLogEntry ( i18n( "Import of \"%1\" (%2) was successful." ).arg( filename ).arg("P12 certificate"), GlobalConfig->info );
	}
	else
	{
		GlobalConfig->appendLogEntry ( i18n( "Import of \"%1\" (%2) has been failed." ).arg( filename ).arg("P12 certificate"), GlobalConfig->info );
		success=false;
	}
	return success;
}
