/***********************************************************************
**
**   generalconfig.cpp
**
**   This file is part of Cumulus
**
************************************************************************
**
**   Copyright (c):  2004 by André Somers
**
**   This file is distributed under the terms of the General Public
**   Licence. See the file COPYING for more information.
**
**   $Id: generalconfig.cpp,v 1.19 2005/02/22 20:53:03 axel Exp $
**
***********************************************************************/

#include <stdlib.h>
#include <math.h>
#include <qdir.h>

#include "generalconfig.h"
#include "hwinfo.h"
#include "mapdefaults.h"
#include "kconfig.h"
#include "gpsnmea.h"
#include "speed.h"
#include "altitude.h"
#include "distance.h"

// set static value
GeneralConfig * GeneralConfig::_theInstance=0;

GeneralConfig::GeneralConfig(){
	_homeWp=0;
	load();
}

GeneralConfig::~GeneralConfig(){
	save();
	_theInstance=0;
	_airspaceWarningGeneral=true;
    if (_homeWp)
        delete _homeWp;
}

GeneralConfig * GeneralConfig::instance() {
	if (_theInstance==0)
		_theInstance=new GeneralConfig;

	return _theInstance;
}

void GeneralConfig::load(){
	KConfig config ("Cumulus");

	// Airspace warning distances
	config.setGroup("Airspace");
	_awd.horClose = (int) rint(config.readDoubleNumEntry("HorizontalWarningDistance", 1000.0));
	_awd.horVeryClose = (int) rint(config.readDoubleNumEntry("HorizontalWarningDistanceVC", 50.0));
	_awd.verAboveClose = (int) rint(config.readDoubleNumEntry("VerticalWarningDistanceAbove", 200.0));
	_awd.verAboveVeryClose = (int) rint(config.readDoubleNumEntry("VerticalWarningDistanceAboveVC", 25.0));
	_awd.verBelowClose = (int) rint(config.readDoubleNumEntry("VerticalWarningDistanceBelow", 100.0));
	_awd.verBelowVeryClose = (int) rint(config.readDoubleNumEntry("VerticalWarningDistanceBelowVC", 15.0));

	// Airspace warning types
	_airspaceWarning[BaseMapElement::AirA]       = config.readBoolEntry("checkAirspaceA", true);
	_airspaceWarning[BaseMapElement::AirB]       = config.readBoolEntry("checkAirspaceB", true);
	_airspaceWarning[BaseMapElement::AirC]       = config.readBoolEntry("checkAirspaceC", true);
	_airspaceWarning[BaseMapElement::ControlC]   = config.readBoolEntry("checkControlC", true);
	_airspaceWarning[BaseMapElement::AirD]       = config.readBoolEntry("checkAirspaceD", true);
	_airspaceWarning[BaseMapElement::ControlD]   = config.readBoolEntry("checkControlD", true);
	_airspaceWarning[BaseMapElement::AirElow]    = config.readBoolEntry("checkAirspaceElow", false);
	_airspaceWarning[BaseMapElement::AirEhigh]   = config.readBoolEntry("checkAirspaceEhigh", false);
	_airspaceWarning[BaseMapElement::AirF]       = config.readBoolEntry("checkAirspaceF", true);
	_airspaceWarning[BaseMapElement::Restricted] = config.readBoolEntry("checkRestricted", true);
	_airspaceWarning[BaseMapElement::Danger]     = config.readBoolEntry("checkDanger", true);
	_airspaceWarning[BaseMapElement::Tmz]        = config.readBoolEntry("checkTMZ", true);
	_airspaceWarning[BaseMapElement::LowFlight]  = config.readBoolEntry("checkLowFlight", true);

	_airspaceWarningGeneral = config.readBoolEntry("enableAirspaceWarning", true);
        
        // Personal settings
        config.setGroup("Personal Data");
	_disclaimerVersion = config.readNumEntry( "Disclaimer", 0);
        _safetyAltitude.setMeters( config.readDoubleNumEntry( "Arrival Altitude", 200.0 ) );
	_surname  = config.readEntry("SurName", "");
	_birthday = config.readEntry("Birthday", "");

	config.setGroup("Map");
	_mapDelete                      = config.readBoolEntry( "DeleteAfterMapCompile", false );
	_mapUnload                      = config.readBoolEntry( "UnloadUnneededMap", false );
	_mapBearLine                    = config.readBoolEntry( "BearLine", false );
	_mapLoadIsoLines                = config.readBoolEntry( "LoadIsoLines", true );
	_mapShowIsoLineBorders          = config.readBoolEntry( "ShowIsoLineBorders", false );
	_mapShowWaypointLabels          = config.readBoolEntry( "ShowWaypointLabels", true );
	_mapShowWaypointLabelsExtraInfo = config.readBoolEntry( "ShowWaypointLabelsExtraInfo", true );
	_mapLoadRoads                   = config.readBoolEntry( "LoadRoads", true );
	_mapLoadHighways                = config.readBoolEntry( "LoadHighways", true );
	_mapLoadRailroads               = config.readBoolEntry( "LoadRailroads", true );
	_mapLoadCities                  = config.readBoolEntry( "LoadCities", true  );
	_mapLoadWaterways               = config.readBoolEntry( "LoadWaterways", true );
	_mapLoadForests                 = config.readBoolEntry( "LoadForests", true );

	config.setGroup("Map Data");
	if (!_homeWp) {_homeWp=new wayPoint; }
	resetHomeWp();
	_homeWp->origP.setLat( config.readNumEntry( "Homesite Latitude", HOME_DEFAULT_LAT) );
	_homeWp->origP.setLon( config.readNumEntry( "Homesite Longitude", HOME_DEFAULT_LON) );
	_centerLat  = config.readNumEntry("Center Latitude", HOME_DEFAULT_LAT);
	_centerLon  = config.readNumEntry("Center Longitude", HOME_DEFAULT_LON);
	_mapScale   = config.readDoubleNumEntry("Map Scale", 200);
	_mapProjectionType = config.readNumEntry("Projection Type", ProjectionBase::Cylindric );

	config.setGroup("Scale");
	_mapLowerLimit  = config.readNumEntry("Lower Limit", VAL_BORDER_L);
	_mapUpperLimit  = config.readNumEntry("Upper Limit", VAL_BORDER_U);
	_mapBorder1     = config.readNumEntry("Border 1", VAL_BORDER_1);
	_mapBorder2     = config.readNumEntry("Border 2", VAL_BORDER_2);
	_mapBorder3     = config.readNumEntry("Border 3", VAL_BORDER_3);
	_mapSwitchScale = config.readNumEntry("Switch Scale", VAL_BORDER_S);

	config.setGroup("Lambert Projection");
	_lambertParallel1 = config.readNumEntry( "Parallel1", 32400000 );
	_lambertParallel2 = config.readNumEntry( "Parallel2", 30000000  );
	_lambertOrign     = config.readNumEntry( "Origin", 0 );

	config.setGroup("Cylindrical Projection");
	_cylinderParallel = config.readNumEntry( "Parallel", 27000000 );

	config.setGroup("Waypoint Data");
	_waypointFile = config.readEntry( "WaypointFile",
					  QDir::homeDirPath() + "/Applications/cumulus/cumulus.kwp" );

	config.setGroup("Variometer");
	_varioIntegrationTime = config.readNumEntry( "IntegrationTime", 20 );
	_varioStepWidth       = config.readNumEntry("StepWidth", 1);
	_varioTekCompensation = config.readBoolEntry( "TekCompensation", false );
	_varioTekAdjust       = config.readNumEntry( "TekAdjust", 0 );

	config.setGroup("Altimeter");
	_altimeterToggleMode = config.readBoolEntry( "Toggling_Mode", false );
	_altimeterGndMode    = config.readNumEntry( "GND_Mode", 0 );

	config.setGroup("Debug");
	_log2File  = config.readBoolEntry( "Log2File", false );
	_useSysLog = config.readBoolEntry( "UseSystemLog", false );

	config.setGroup("NearestSitesCalc");
	_nearestSiteCalculatorSwitch =
	  config.readBoolEntry( "NearestSiteCalculatorOn",
				NEAREST_SITE_CALCULATOR_DEFAULT );
	_maxNearestSiteCalculatorSites =
	  config.readNumEntry("MaxNumberOfSitesInList", 50);

	config.setGroup("Information");
	_airfieldDisplayTime   = config.readNumEntry( "AirfieldDisplayTime",
						      AIRFIELD_DISPLAY_TIME_DEFAULT );
	_airspaceDisplayTime   = config.readNumEntry( "AirspaceDisplayTime",
						      AIRSPACE_DISPLAY_TIME_DEFAULT);
	_infoDisplayTime       = config.readNumEntry( "InfoDisplayTime",
						      INFO_DISPLAY_TIME_DEFAULT);
	_waypointDisplayTime   = config.readNumEntry( "WaypointDisplayTime",
						      WAYPOINT_DISPLAY_TIME_DEFAULT);
	_warningDisplayTime    = config.readNumEntry( "WarningDisplayTime",
						      WARNING_DISPLAY_TIME_DEFAULT);
	_alarmSound            = config.readBoolEntry( "AlarmSound",
						       ALARM_SOUND_DEFAULT );
	_popupAirspaceWarnings = config.readBoolEntry( "Popup Airspace Warnings", true );

	config.setGroup("GPS");
	if( HWINFO->getType() == HwInfo::ipaq )
	  _gpsDevice        = config.readEntry( "Device", "/dev/ttySA0" );
	else
	  _gpsDevice        = config.readEntry( "Device", "/dev/ttyS0" );
	_gpsSpeed           = config.readNumEntry( "Speed", 4800 );
	_gpsAltitude        = config.readNumEntry( "Altitude", (int) GPSNMEA::MSL );
	_gpsSoftStart       = config.readBoolEntry( "SoftStart", false );
	_gpsHardStart       = config.readBoolEntry( "HardStart", false );
	_gpsSyncSystemClock = config.readBoolEntry( "SyncSystemClock", false );
	_gpsIpcPort         = config.readNumEntry( "IpcPort", 0 );
	_gpsStartClient     = config.readBoolEntry( "StartClient", true );
	_gpsClientPath      = config.readEntry( "ClientPath", "/opt/QtPalmtop/bin" );
	_gpsLastFixLat      = config.readNumEntry( "LastFixLat", 0 );
	_gpsLastFixLon      = config.readNumEntry( "LastFixLon", 0 );
	_gpsLastFixAlt      = config.readNumEntry( "LastFixAlt", 0 );
	_gpsLastFixClk      = config.readNumEntry( "LastFixClk", 0 );

	config.setGroup("Wind");
	_windMinSatCount   = config.readNumEntry( "MinSatCount", 4 );
	_windAltitudeRange = config.readNumEntry( "AltitudeRange", 1000 );
	_windTimeRange     = config.readNumEntry( "TimeRange", 7200 );

	config.setGroup ("Calculator");
	_manualNavModeAltitude = config.readNumEntry( "ManualNavModeAltitude", 1000 );

	config.setGroup("Units");
	_unitAlt   = config.readNumEntry( "Altitude", Altitude::meters);
	_unitDist  = config.readNumEntry( "Distance", Distance::kilometers);
	_unitSpeed = config.readNumEntry( "Speed",    Speed::kilometersPerHour );
	_unitVario = config.readNumEntry( "Vario",    Speed::metersPerSecond );
	_unitWind  = config.readNumEntry( "Wind",     Speed::metersPerSecond );
	_unitPos   = config.readNumEntry( "Position", WGSPoint::DMS  );
}

void GeneralConfig::save(){
	KConfig config("Cumulus");

	// Airspace warning distances
	config.setGroup("Airspace");
	config.writeEntry("HorizontalWarningDistance", _awd.horClose.getMeters());
	config.writeEntry("HorizontalWarningDistanceVC", _awd.horVeryClose.getMeters());
	config.writeEntry("VerticalWarningDistanceAbove", _awd.verAboveClose.getMeters());
	config.writeEntry("VerticalWarningDistanceAboveVC", _awd.verAboveVeryClose.getMeters());
	config.writeEntry("VerticalWarningDistanceBelow", _awd.verBelowClose.getMeters());
	config.writeEntry("VerticalWarningDistanceBelowVC", _awd.verBelowVeryClose.getMeters());

	// Airspace warning types
	config.writeEntry("checkAirspaceA", _airspaceWarning[BaseMapElement::AirA]);
	config.writeEntry("checkAirspaceB", _airspaceWarning[BaseMapElement::AirB]);
	config.writeEntry("checkAirspaceC", _airspaceWarning[BaseMapElement::AirC]);
	config.writeEntry("checkControlC", _airspaceWarning[BaseMapElement::ControlC]);
	config.writeEntry("checkAirspaceD", _airspaceWarning[BaseMapElement::AirD]);
	config.writeEntry("checkControlD", _airspaceWarning[BaseMapElement::ControlD]);
	config.writeEntry("checkAirspaceElow", _airspaceWarning[BaseMapElement::AirElow]);
	config.writeEntry("checkAirspaceEhigh", _airspaceWarning[BaseMapElement::AirEhigh]);
	config.writeEntry("checkAirspaceF", _airspaceWarning[BaseMapElement::AirF]);
	config.writeEntry("checkRestricted", _airspaceWarning[BaseMapElement::Restricted]);
	config.writeEntry("checkDanger", _airspaceWarning[BaseMapElement::Danger]);
	config.writeEntry("checkTMZ", _airspaceWarning[BaseMapElement::Tmz]);
	config.writeEntry("checkLowFlight", _airspaceWarning[BaseMapElement::LowFlight]);

	config.writeEntry("enableAirspaceWarning", _airspaceWarningGeneral);
        
        // Personal settings
        config.setGroup("Personal Data");
	config.writeEntry("Disclaimer", _disclaimerVersion);
        config.writeEntry("Arrival Altitude", _safetyAltitude.getMeters());

	// @AP: nice side effect, without calling base class methods
	// the data was stored as QColor. Don't know why.
	config.Config::writeEntry("SurName", _surname);
	config.Config::writeEntry("Birthday", _birthday);

	config.setGroup("Map");
	config.writeEntry( "DeleteAfterMapCompile", _mapDelete );
	config.writeEntry( "UnloadUnneededMap", _mapUnload );
	config.writeEntry( "BearLine", _mapBearLine );
	config.writeEntry( "LoadIsoLines", _mapLoadIsoLines );
	config.writeEntry( "ShowIsoLineBorders", _mapShowIsoLineBorders );
	config.writeEntry( "ShowWaypointLabels", _mapShowWaypointLabels );
	config.writeEntry( "ShowWaypointLabelsExtraInfo", _mapShowWaypointLabelsExtraInfo );
	config.writeEntry( "LoadRoads", _mapLoadRoads );
	config.writeEntry(  "LoadHighways", _mapLoadHighways );
	config.writeEntry( "LoadRailroads", _mapLoadRailroads );
	config.writeEntry( "LoadCities", _mapLoadCities   );
	config.writeEntry( "LoadWaterways", _mapLoadWaterways  );
	config.writeEntry( "LoadForests", _mapLoadForests );

	config.setGroup("Map Data");
	config.writeEntry("Homesite Latitude", _homeWp->origP.lat());
	config.writeEntry("Homesite Longitude", _homeWp->origP.lon());
	config.writeEntry("Center Latitude", _centerLat);
	config.writeEntry("Center Longitude", _centerLon);
	config.writeEntry("Map Scale", _mapScale);
	config.writeEntry("Projection Type", _mapProjectionType);

	config.setGroup("Scale");
	config.writeEntry( "Lower Limit", _mapLowerLimit );
	config.writeEntry( "Upper Limit", _mapUpperLimit );
	config.writeEntry( "Border 1", _mapBorder1 );
	config.writeEntry( "Border 2", _mapBorder2 );
	config.writeEntry( "Border 3", _mapBorder3 );
	config.writeEntry( "Switch Scale", _mapSwitchScale );

	config.setGroup("Lambert Projection");
	config.writeEntry( "Parallel1", _lambertParallel1 );
	config.writeEntry( "Parallel2", _lambertParallel2 );
	config.writeEntry( "Origin", _lambertOrign );

	config.setGroup("Cylindrical Projection");
	config.writeEntry( "Parallel", _cylinderParallel );

	config.setGroup("Waypoint Data");
	config.writeEntry( "WaypointFile", _waypointFile );

	config.setGroup("Variometer");
	config.writeEntry( "IntegrationTime", _varioIntegrationTime );
	config.writeEntry( "StepWidth", _varioStepWidth );
	config.writeEntry( "TekCompensation", _varioTekCompensation );
	config.writeEntry( "TekAdjust", _varioTekAdjust );

	config.setGroup("Altimeter");
	config.writeEntry( "Toggling_Mode", _altimeterToggleMode );
	config.writeEntry( "GND_Mode", _altimeterGndMode );

	config.setGroup("Debug");
	config.writeEntry( "Log2File", _log2File );
	config.writeEntry( "UseSystemLog", _useSysLog );

	config.setGroup("NearestSitesCalc");
	config.writeEntry( "NearestSiteCalculatorOn", _nearestSiteCalculatorSwitch );
	config.writeEntry( "MaxNumberOfSitesInList", _maxNearestSiteCalculatorSites );

	config.setGroup("Information");
	config.writeEntry( "AirfieldDisplayTime", _airfieldDisplayTime );
	config.writeEntry( "AirspaceDisplayTime", _airspaceDisplayTime );
	config.writeEntry( "InfoDisplayTime", _infoDisplayTime );
	config.writeEntry( "WaypointDisplayTime", _waypointDisplayTime );
	config.writeEntry( "WarningDisplayTime", _warningDisplayTime );
	config.writeEntry( "AlarmSound", _alarmSound );
	config.writeEntry( "Popup Airspace Warnings", _popupAirspaceWarnings );


	config.setGroup("GPS");
	config.writeEntry( "Device", _gpsDevice );
	config.writeEntry( "Speed", _gpsSpeed );
	config.writeEntry( "Altitude", _gpsAltitude );
	config.writeEntry( "HardStart", _gpsHardStart );
	config.writeEntry( "SoftStart", _gpsSoftStart );
	config.writeEntry( "SyncSystemClock", _gpsSyncSystemClock );
	config.writeEntry( "IpcPort", _gpsIpcPort );
	config.writeEntry( "StartClient", _gpsStartClient );
	config.writeEntry( "ClientPath", _gpsClientPath );
	config.writeEntry( "LastFixLat", _gpsLastFixLat );
	config.writeEntry( "LastFixLon", _gpsLastFixLon );
	config.writeEntry( "LastFixAlt", _gpsLastFixAlt );
	config.writeEntry( "LastFixClk", _gpsLastFixClk );

	config.setGroup("Wind");
	config.writeEntry( "MinSatCount", _windMinSatCount );
	config.writeEntry( "AltitudeRange", _windAltitudeRange );
	config.writeEntry( "TimeRange", _windTimeRange );

	config.setGroup("Calculator");
	config.writeEntry("ManualNavModeAltitude", _manualNavModeAltitude );

	config.setGroup("Units");
	config.writeEntry( "Altitude", _unitAlt );
	config.writeEntry( "Distance", _unitDist );
	config.writeEntry( "Speed", _unitSpeed );
	config.writeEntry( "Vario", _unitVario );
	config.writeEntry( "Wind", _unitWind );
	config.writeEntry( "Position", _unitPos );
}

/** gets vario integration time */
int GeneralConfig::getVarioIntegrationTime() const
{
  return _varioIntegrationTime;
}

/** sets vario integration time */
void GeneralConfig::setVarioIntegrationTime(const int newValue)
{
  _varioIntegrationTime = newValue;
}

/** gets vario vario step width */
int GeneralConfig::getVarioStepWidth() const
{
  return _varioStepWidth;
}

/** sets vario vario step width */
void GeneralConfig::setVarioStepWidth(const int newValue)
{
  _varioStepWidth = newValue;
}

/** gets vario tek adjust */
int GeneralConfig::getVarioTekAdjust() const
{
  return _varioTekAdjust;
}

/** sets vario tek adjust */
void GeneralConfig::setVarioTekAdjust(const int newValue)
{ _varioTekAdjust = newValue; };
 
/** gets vario tek compensation */
bool GeneralConfig::getVarioTekCompensation() const
{
  return _varioTekCompensation;
}

/** sets vario tek compensation */
void GeneralConfig::setVarioTekCompensation(const bool newValue)
{
  _varioTekCompensation = newValue;
}

/** gets altimeter mode */
int GeneralConfig::getAltimeterGndMode() const
{
  return _altimeterGndMode;
}

/** sets altimeter mode */
void GeneralConfig::setAltimeterGndMode(const int newValue)
{
  _altimeterGndMode = newValue;
}

/** gets altimeter toggle mode */
bool GeneralConfig::getAltimeterToggleMode() const
{
  return _altimeterToggleMode;
}

/** sets altimeter toggle mode */
void GeneralConfig::setAltimeterToggleMode(const bool newValue)
{
  _altimeterToggleMode = newValue;
}

/**
 * @returns Struct with warning distances for airspace warnings
 */
AirspaceWarningDistance GeneralConfig::getAirspaceWarningDistances()
{ 
  return _awd;
}

/**
 * Sets the warningdistances for airspaces
 */
void GeneralConfig::setAirspaceWarningDistances(const AirspaceWarningDistance& awd)
{
  _awd = awd;
}

/** gets log to file mode */
bool GeneralConfig::getLog2FileMode() const
{
  return _log2File;
}

/** sets log to file mode */
void GeneralConfig::setLog2FileMode(const bool newValue)
{
  _log2File = newValue;
}

/** gets system log mode */
bool GeneralConfig::getSystemLogMode() const
{
  return _useSysLog;
}

/** sets log to file mode */
void GeneralConfig::setSystemLogMode(const bool newValue)
{
  _useSysLog = newValue;
}

/** gets nearest site calculator switch */
bool GeneralConfig::getNearestSiteCalculatorSwitch() const
{
  return _nearestSiteCalculatorSwitch;
}

/** sets nearest site calculator switch */
void GeneralConfig::setNearestSiteCalculatorSwitch(const bool newValue)
{
  _nearestSiteCalculatorSwitch = newValue;
}

/** gets max nearest site calculator sites */
int GeneralConfig::getMaxNearestSiteCalculatorSites() const
{
  return _maxNearestSiteCalculatorSites;
}

/** sets max nearest site calculator sites */
void GeneralConfig::setMaxNearestSiteCalculatorSites(const int newValue)
{
  _maxNearestSiteCalculatorSites = newValue;
}

/** gets AirfieldDisplayTime */
int GeneralConfig::getAirfieldDisplayTime() const
{
  return _airfieldDisplayTime;
}

/** sets AirfieldDisplayTime */
void GeneralConfig::setAirfieldDisplayTime(const int newValue)
{
  _airfieldDisplayTime = newValue;
}

/** gets AirspaceDisplayTime */
int GeneralConfig::getAirspaceDisplayTime() const
{
  return _airspaceDisplayTime;
}
/** sets AirspaceDisplayTime */
void GeneralConfig::setAirspaceDisplayTime(const int newValue)
{
  _airspaceDisplayTime = newValue;
}

/** gets InfoDisplayTime */
int GeneralConfig::getInfoDisplayTime() const
{
  return _infoDisplayTime;
}

/** sets InfoDisplayTime */
void GeneralConfig::setInfoDisplayTime(const int newValue)
{
  _infoDisplayTime = newValue;
}

/** gets WaypointDisplayTime */
int GeneralConfig::getWaypointDisplayTime() const
{
  return _waypointDisplayTime;
}

/** sets WaypointDisplayTime */
void GeneralConfig::setWaypointDisplayTime(const int newValue)
{
  _waypointDisplayTime = newValue;
}

/** gets WarningDisplayTime */
int GeneralConfig::getWarningDisplayTime() const
{
  return _warningDisplayTime;
}

/** sets WarningDisplayTime */
void GeneralConfig::setWarningDisplayTime(const int newValue)
{
  _warningDisplayTime = newValue;
}

/** gets AlarmSound */
bool GeneralConfig::getAlarmSoundOn() const
{
  return _alarmSound;
}

/** sets AlarmSound */
void GeneralConfig::setAlarmSoundOn(const bool newValue)
{
  _alarmSound = newValue;
}

/** gets Popup Airspace Warnings */
bool GeneralConfig::getPopupAirspaceWarnings() const
{
  return _popupAirspaceWarnings;
}

/** sets Popup Airspace Warnings */
void GeneralConfig::setPopupAirspaceWarnings(const bool newValue)
{
  _popupAirspaceWarnings = newValue;
}

/** Gets the Gps Device */
QString &GeneralConfig::getGpsDevice()
{
  return _gpsDevice;
}

/** Sets the Gps Device */
void GeneralConfig::setGpsDevice( const QString newValue )
{
  _gpsDevice = newValue;
}
 
/** Gets the Gps Speed */
int GeneralConfig::getGpsSpeed() const
{
  return _gpsSpeed;
}

/** Sets the Gps Speed */
void GeneralConfig::setGpsSpeed( const int newValue )
{
  _gpsSpeed = newValue;
}
 
/** gets Gps altitude */
int GeneralConfig::getGpsAltitude() const
{
  return _gpsAltitude;
}

/** sets Gps altitude */
void GeneralConfig::setGpsAltitude(const int newValue)
{
  _gpsAltitude = newValue;
}

/** gets Gps soft start */
bool GeneralConfig::getGpsSoftStart() const
{
  return _gpsSoftStart;
}

/** sets Gps soft start */
void GeneralConfig::setGpsSoftStart(const bool newValue)
{
  _gpsSoftStart = newValue;
}

/** gets Gps hard start */
bool GeneralConfig::getGpsHardStart() const
{
  return _gpsHardStart;
}

/** sets Gps hard start */
void GeneralConfig::setGpsHardStart(const bool newValue)
{
  _gpsHardStart = newValue;
}

/** gets Gps sync system clock */
bool GeneralConfig::getGpsSyncSystemClock() const
{
  return _gpsSyncSystemClock;
}

/** sets Gps sync system clock */
void GeneralConfig::setGpsSyncSystemClock(const bool newValue)
{
  _gpsSyncSystemClock = newValue;
}

/** gets Gps Ipc port */
ushort GeneralConfig::getGpsIpcPort() const
{
  return _gpsIpcPort;
}

/** sets Gps Ipc port */
void GeneralConfig::setGpsIpcPort(const ushort newValue)
{
  _gpsIpcPort = newValue;
}

/** gets Gps client start option */
bool GeneralConfig::getGpsStartClientOption() const
{
  return _gpsStartClient;
}

/** sets Gps client start option */
void GeneralConfig::setGpsStartClientOption(const bool newValue)
{
  _gpsStartClient = newValue;
}

/** Gets the Gps Client path */
QString &GeneralConfig::getGpsClientPath()
{
  return _gpsClientPath;
}

/** Sets the Gps Client path */
void GeneralConfig::setGpsClientPath( const QString newValue )
{
  _gpsClientPath = newValue;
}

/** gets Gps last fix latitude */
int GeneralConfig::getGpsLastFixLat() const
{
  return _gpsLastFixLat;
}

/** sets Gps last fix latitude */
void GeneralConfig::setGpsLastFixLat(const int newValue)
{
  _gpsLastFixLat = newValue;
}

/** gets Gps last fix logitude */
int GeneralConfig::getGpsLastFixLon() const
{
  return _gpsLastFixLon;
}

/** sets Gps last fix logitude */
void GeneralConfig::setGpsLastFixLon(const int newValue)
{
  _gpsLastFixLon = newValue;
}

/** gets Gps last fix altitude */
int GeneralConfig::getGpsLastFixAlt() const
{
  return _gpsLastFixAlt;
}

/** sets Gps last fix altitude */
void GeneralConfig::setGpsLastFixAlt(const int newValue)
{
  _gpsLastFixAlt = newValue;
}

/** gets Gps last fix clock */
int GeneralConfig::getGpsLastFixClk() const
{
  return _gpsLastFixClk;
}

/** sets Gps last fix clock */
void GeneralConfig::setGpsLastFixClk(const int newValue)
{
  _gpsLastFixClk = newValue;
}

/** gets minimum sat cout for wind calculation */
int GeneralConfig::getWindMinSatCount() const
{
  return _windMinSatCount;
}

/** sets minimum sat cout for wind calculation */
void GeneralConfig::setMinSatCount(const int newValue)
{
  _windMinSatCount = newValue;
}

/** gets wind altitude range */
int GeneralConfig::getWindAltitudeRange() const
{
  return _windAltitudeRange;
}

/** sets wind altitude range */
void GeneralConfig::setWindAltitudeRange(const int newValue)
{
  _windAltitudeRange = newValue;
}
 
/** gets wind time range */
int GeneralConfig::getWindTimeRange() const
{
  return _windTimeRange;
}

/** sets wind time range */
void GeneralConfig::setWindTimeRange(const int newValue)
{
  _windTimeRange = newValue;
}

/** gets manual navigation mode altitude */
int GeneralConfig::getManualNavModeAltitude() const
{
  return _manualNavModeAltitude;
}

/** sets manual navigation mode altitude */
void GeneralConfig::setManualNavModeAltitude(const int newValue)
{
  _manualNavModeAltitude = newValue;
}

void GeneralConfig::resetHomeWp()
{
 qDebug("resetting Home Wp %d", int(_homeWp));
  _homeWp->name = "Home" ;
  _homeWp->description = "Home field" ;
  _homeWp->icao = "";
  _homeWp->elevation = 0;
  _homeWp->comment = "The information on this field is incomplete. Trust only the coordinates!";
}
  
/** Gets the waypoint file name with path */
QString &GeneralConfig::getWaypointFile()
{
  return _waypointFile;
}

/** Sets the waypoint file name with path */
void GeneralConfig::setWaypointFile( const QString newValue )
{
  _waypointFile = newValue;
}

/** Gets the unit for altitude*/
int GeneralConfig::getUnitAlt() const
{
  return _unitAlt;
}

/** Sets the unit for altitude */
void GeneralConfig::setUnitAlt(const int newValue)
{
  _unitAlt = newValue;
}

/** Gets the unit for distance*/
int GeneralConfig::getUnitDist() const
{
  return _unitDist;
}

/** Sets the unit for distance */
void GeneralConfig::setUnitDist(const int newValue)
{
  _unitDist = newValue;
}

/** Gets the unit for speed */
int GeneralConfig::getUnitSpeed() const
{
  return _unitSpeed;
}

/** Sets the unit for speed */
void GeneralConfig::setUnitSpeed(const int newValue)
{
  _unitSpeed = newValue;
}

/** Gets the unit for vario */
int GeneralConfig::getUnitVario() const
{
  return _unitVario;
}

/** Sets the unit for vario */
void GeneralConfig::setUnitVario(const int newValue)
{
  _unitVario = newValue;
}

/** Gets the unit for wind */
int GeneralConfig::getUnitWind() const
{
  return _unitWind;
}

/** Sets the unit for wind */
void GeneralConfig::setUnitWind(const int newValue)
{
  _unitWind = newValue;
}

/** Gets the unit for position */
int GeneralConfig::getUnitPos() const
{
  return _unitPos;
}

/** Sets the unit for position */
void GeneralConfig::setUnitPos(const int newValue)
{
  _unitPos = newValue;
}
