/* 
 * This file is part of DesktopBSD, see the README file.
 *
 * Author: Christian Eichinger <ce@desktopbsd.net>
 *         (C) 2006
 *
 * Copyright: BSD, see the COPYING file included in this distribution
 *
 */
#include "pppconnectiondata.h"
#include "ipv4addr.h"
#include "netinterface.h"

#include <qstringlist.h>

PPPConnectionData::PPPConnectionData()
{
	account  = "";
	password = "";
	device = "";
	connectiontype = Invalid;
}

PPPConnectionData::PPPConnectionData(const QString& acc, const QString& pass, const QString& mip, const QString& pdip, const QString& sdip, PPPConnectionData::ConnectionType contype, const QString& dev)
{
	account  = acc;
	password = pass;
	modemip.setAddr(mip);
	primdns.setAddr(pdip);
	secdns.setAddr(sdip);
	connectiontype = contype;
	device = dev;
}

void PPPConnectionData::setAcccountName(const QString& acc)
{
	account = acc;
}

QString PPPConnectionData::getAccountName()
{
	return account;
}

void PPPConnectionData::setPassword(const QString& pass)
{
	password = pass;
}

QString PPPConnectionData::getPassword()
{
	return password;
}

void PPPConnectionData::setModemIP(const QString& mip)
{
	modemip.setAddr(mip);
}

IPv4Addr PPPConnectionData::getModemIP()
{
	return modemip;
}

void PPPConnectionData::setPrimaryDNS(const QString& dip)
{
	primdns.setAddr(dip);
}

void PPPConnectionData::setSecondaryDNS(const QString& dip)
{
	secdns.setAddr(dip);
}

IPv4Addr PPPConnectionData::getPrimaryDNS()
{
	return primdns;
}

IPv4Addr PPPConnectionData::getSecondaryDNS()
{
	return secdns;
}

void PPPConnectionData::setConnectionType(ConnectionType contype)
{
	connectiontype = contype;
}

PPPConnectionData::ConnectionType PPPConnectionData::getConnectionType()
{
	return connectiontype;
}

void PPPConnectionData::setNetworkDevice(const QString& dev)
{
	device = dev;
}

QString PPPConnectionData::getNetworkDevice()
{
	return device;
}

/**
  * Checks the provided data.
  *
  * @return 0 when all data is valid, otherwise negative values:
  * -1: No account ID given
  * -2: No password given
  * -3: Modem IP invalid (PPTP only)
  * -4: Primary DNS invalid
  * -5: Secondary DNS invalid
  */
int PPPConnectionData::checkData()
{
	 if(account.isEmpty())
		return -1;
		
	 if(password.isEmpty())
		return -2;

	// Modem IP invalid (PPTP only)
	if(connectiontype == PPTP)
		if(!modemip.isValid())	
			return -3;

	if(!primdns.isValid())
		return -4;

	if(!secdns.isValid())
		return -5;
	
	return 0;
}
