/***********************************************************************
**
**   generalconfig.h
**
**   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.h,v 1.16 2005/02/22 20:53:03 axel Exp $
**
***********************************************************************/

#ifndef GENERALCONFIG_H
#define GENERALCONFIG_H

#include <qobject.h>
#include "airspace.h"
#include "basemapelement.h"
#include "altitude.h"
#include "wp.h"

/**
  * @short Configuration encapsulation class
  * @author André Somers
  *
  * This class is used to store and retreive all kinds of
  * configuration options.  This class is a singleton class. Use the
  * static @ref instance method to get a reference to the instance.
  */

class GeneralConfig
{
public:

/**
 * Constructor. The relevant settings are loaded on construction.
 * @see load
 */
 
 GeneralConfig();
/**
 * Destructor. The contained settings are stored before destruction.
 * @see save
 */
 ~GeneralConfig();
 
 /**
  * @returns The instance of GeneralConfig. Creates an instance if nessecairy.
  */
 static GeneralConfig * instance();
 
 /**
  * Saves the configuration settings.
  */
 void save();
 
 /**
  * Loads the configuration settings.
  */
 void load();
 
 //---------------------------
 // properties get/set methods
 //---------------------------

 /**
  * @returns Struct with warning distances for airspace warnings
  */
 AirspaceWarningDistance getAirspaceWarningDistances();
 /**
  * Sets the warningdistances for airspaces
  */
 void setAirspaceWarningDistances(const AirspaceWarningDistance& awd);
 /**
  * @return True if warnings are enabled for the given type.
  * @param objectType The type of object (defined in @ref BaseMapElement) to query
  */
 bool getAirspaceWarningEnabled (BaseMapElement::objectType type) const { return _airspaceWarning [type]; };
 /**
  * Enables or disables the airspacewarnings for this type of airspace
  */
 void setAirspaceWarningEnabled (BaseMapElement::objectType type, bool enable=true) { _airspaceWarning [type]=enable; };
 /**
  * @return True if warnings are enabled in general
  */
 bool getAirspaceWarningEnabled () const { return _airspaceWarningGeneral; };
 /**
  * Enables or disables the airspacewarnings in general
  */
 void setAirspaceWarningEnabled (bool enable=true) { _airspaceWarningGeneral=enable; };

 /** gets disclaimer version */
 int getDisclaimerVersion() const
   { return _disclaimerVersion; };
 /** sets disclaimer version */
 void setDisclaimerVersion( const int newValue )
   { _disclaimerVersion = newValue; };
 /**
  * return the set safety altitude
  */
 Altitude &getSafetyAltitude () { return _safetyAltitude; }; 
 /**
  * Sets the safety altitude
  */
 void setSafetyAltitude( const Altitude& alt ) { _safetyAltitude=alt; };
 
 /** Gets the surname */
 QString &getSurname() { return _surname; };
 /** Sets the surname */
 void setSurname( const QString newValue ) { _surname = newValue; };
 
 /** Gets the birthday */
 QString &getBirthday() { return _birthday; };
 /** Sets the birthday */
 void setBirthday( const QString newValue ) { _birthday = newValue; };
 
 /** gets Homesite Latitude */
 int getHomeLat() const { return _homeWp->origP.lat(); };
 /** sets Homesite Latitude */
 void setHomeLat( const int newValue ) { _homeWp->origP.setLat( newValue ); resetHomeWp();};
 
 /** gets Homesite  Longitude */
 int getHomeLon()  const { return _homeWp->origP.lon(); };
 /** sets Homesite  Longitude */
 void setHomeLon( const int newValue ) { _homeWp->origP.setLon( newValue ); resetHomeWp();};
 
 /** gets Homesite waypoint */
 wayPoint * getHomeWp()  const { return _homeWp; };
 /** sets Homesite  Longitude */
 void setHomeWp( wayPoint * newValue ) { if(_homeWp) delete _homeWp; _homeWp = newValue; };
 void resetHomeWp();
 
 /** gets Center Latitude */
 int getCenterLat()  const { return _centerLat; };
 /** sets Center Latitude */
 void setCenterLat( const int newValue ) { _centerLat = newValue; };
 
 /** gets Center  Longitude */
 int getCenterLon()  const { return _centerLon; };
 /** sets Center  Longitude */
 void setCenterLon( const int newValue ) { _centerLon = newValue; };
 
 /** gets map scale */
 double getMapScale() const { return _mapScale; };
 /** sets map scale */
 void setMapScale( const double newValue ) { _mapScale = newValue; };

 /** gets map Lower Limit */
 int getMapLowerLimit() const { return _mapLowerLimit; };
 /** sets map  */
 void setMapLowerLimit( const int newValue ) { _mapLowerLimit = newValue; };

 /** gets map Upper Limit */
 int getMapUpperLimit() const { return _mapUpperLimit; };
 /** sets map Upper Limit */
 void setMapUpperLimit( const int newValue ) { _mapUpperLimit = newValue; };

 /** gets map Border 1 */
 int getMapBorder1() const { return _mapBorder1; };
 /** sets map Border 1 */
 void setMapBorder1( const int newValue ) { _mapBorder1 = newValue; };

 /** gets map Border 2 */
 int getMapBorder2() const { return _mapBorder2; };
 /** sets map Border 2 */
 void setMapBorder2( const int newValue ) { _mapBorder2 = newValue; };

 /** gets map Border 3 */
 int getMapBorder3() const { return _mapBorder3; };
 /** sets map Border 3 */
 void setMapBorder3( const int newValue ) { _mapBorder3 = newValue; };

 /** gets map Switch Scale */
 int getMapSwitchScale() const { return _mapSwitchScale; };
 /** sets map Switch Scale */
 void setMapSwitchScale( const int newValue ) { _mapSwitchScale = newValue; };
 
 /** gets Map BearLine */
 bool getMapBearLine() const { return _mapBearLine; };
 /** sets Map BearLine */
 void setMapBearLine(const bool newValue) { _mapBearLine = newValue; };

 /** gets Map LoadIsoLines */
 bool getMapLoadIsoLines() const { return _mapLoadIsoLines; };
 /** sets Map LoadIsoLines */
 void setMapLoadIsoLines(const bool newValue) { _mapLoadIsoLines = newValue; };

 /** gets Map ShowIsoLineBorders */
 bool getMapShowIsoLineBorders() const { return _mapShowIsoLineBorders; };
 /** sets Map ShowIsoLineBorders */
 void setMapShowIsoLineBorders(const bool newValue) { _mapShowIsoLineBorders = newValue; };

 /** gets Map ShowWaypointLabels */
 bool getMapShowWaypointLabels() const { return _mapShowWaypointLabels; };
 /** sets Map ShowWaypointLabels */
 void setMapShowWaypointLabels(const bool newValue) { _mapShowWaypointLabels = newValue; };

 /** gets Map ShowWaypointLabelsExtraInfo */
 bool getMapShowWaypointLabelsExtraInfo() const { return _mapShowWaypointLabelsExtraInfo; };
 /** sets Map ShowWaypointLabelsExtraInfo */
 void setMapShowWaypointLabelsExtraInfo(const bool newValue) { _mapShowWaypointLabelsExtraInfo = newValue; };

 /** gets Map LoadRoads */
 bool getMapLoadRoads() const { return _mapLoadRoads; };
 /** sets Map LoadRoads */
 void setMapLoadRoads(const bool newValue) { _mapLoadRoads = newValue; };

 /** gets Map LoadHighways */
 bool getMapLoadHighways() const { return _mapLoadHighways; };
 /** sets Map LoadHighways */
 void setMapLoadHighways(const bool newValue) { _mapLoadHighways = newValue; };

 /** gets Map LoadRailroads */
 bool getMapLoadRailroads() const { return _mapLoadRailroads; };
 /** sets Map LoadRailroads */
 void setMapLoadRailroads(const bool newValue) { _mapLoadRailroads = newValue; };

 /** gets Map LoadCities */
 bool getMapLoadCities() const { return _mapLoadCities; };
 /** sets Map LoadCities */
 void setMapLoadCities(const bool newValue) { _mapLoadCities = newValue; };

 /** gets Map LoadWaterways */
 bool getMapLoadWaterways() const { return _mapLoadWaterways; };
 /** sets Map LoadWaterways */
 void setMapLoadWaterways(const bool newValue) { _mapLoadWaterways = newValue; };

 /** gets Map LoadForests */
 bool getMapLoadForests() const { return _mapLoadForests; };
 /** sets Map LoadForests */
 void setMapLoadForests(const bool newValue) { _mapLoadForests = newValue; };

 /** gets Map delete after compile */
 bool getMapDeleteAfterCompile() const { return _mapDelete; };
 /** sets Map delete after compile*/
 void setMapDeleteAfterCompile(const bool newValue) { _mapDelete = newValue; };
 
 /** gets Map unload unneeded */
 bool getMapUnload() const { return _mapUnload; };
 /** sets Map unload unneeded */
 void setMapUnload(const bool newValue) { _mapUnload = newValue; };

 /** gets map Projection Type */
 int getMapProjectionType()  const { return _mapProjectionType; };
 /** sets map Projection Type */
 void setMapProjectionType( const int newValue ) { _mapProjectionType = newValue; };

 /** gets Lambert Parallel1 */
 int getLambertParallel1()  const { return _lambertParallel1; };
 /** sets map Projection Type */
 void setLambertParallel1( const int newValue ) { _lambertParallel1 = newValue; };

 /** gets Lambert Parallel2 */
 int getLambertParallel2()  const { return _lambertParallel2; };
 /** sets map Projection Type */
 void setLambertParallel2( const int newValue ) { _lambertParallel2 = newValue; };

 /** gets Lambert Orign */
 int getLambertOrign()  const { return _lambertOrign; };
 /** sets Lambert Orign */
 void setLambertOrign( const int newValue ) { _lambertOrign = newValue; };

 /** gets Cylinder Parallel */
 int getCylinderParallel()  const { return _cylinderParallel; };
 /** sets Cylinder Parallel */
 void setCylinderParallel( const int newValue ) { _cylinderParallel = newValue; };

 // NOTICE! @AP: got some trouble with inline function
 // definition. They didn't work up to here. Not clear why.

 /** gets vario integration time */
 int getVarioIntegrationTime() const;
 /** sets vario integration time */
 void setVarioIntegrationTime(const int newValue);
 
 /** gets vario vario step width */
 int getVarioStepWidth() const;
 /** sets vario vario step width */
 void setVarioStepWidth(const int newValue);
 
 /** gets vario tek adjust */
 int getVarioTekAdjust() const;
 /** sets vario tek adjust */
 void setVarioTekAdjust(const int newValue);
 
 /** gets vario tek compensation */
 bool getVarioTekCompensation() const;
 /** sets vario tek compensation */
 void setVarioTekCompensation(const bool newValue);
 
 /** gets altimeter mode */
 int getAltimeterGndMode() const;
 /** sets altimeter mode */
 void setAltimeterGndMode(const int newValue);

 /** gets altimeter toggle mode */
 bool getAltimeterToggleMode() const;
 /** sets altimeter toggle mode */
 void setAltimeterToggleMode(const bool newValue);
 
 /** gets log to file mode */
 bool getLog2FileMode() const;
 /** sets log to file mode */
 void setLog2FileMode(const bool newValue);

 /** gets sys log mode flag */
 bool getSystemLogMode() const;
 /** sets sys log mode flag */
 void setSystemLogMode(const bool newValue);
 
 /** gets nearest site calculator switch */
 bool getNearestSiteCalculatorSwitch() const;
 /** sets nearest site calculator switch */
 void setNearestSiteCalculatorSwitch(const bool newValue);

 /** gets max nearest site calculator sites */
 int getMaxNearestSiteCalculatorSites() const;
 /** sets max nearest site calculator sites */
 void setMaxNearestSiteCalculatorSites(const int newValue);
 
 /** gets AirfieldDisplayTime */
 int getAirfieldDisplayTime() const;
 /** sets AirfieldDisplayTime */
 void setAirfieldDisplayTime(const int newValue);

 /** gets AirspaceDisplayTime */
 int getAirspaceDisplayTime() const;
 /** sets AirspaceDisplayTime */
 void setAirspaceDisplayTime(const int newValue);
 
 /** gets InfoDisplayTime */
 int getInfoDisplayTime() const;
 /** sets InfoDisplayTime */
 void setInfoDisplayTime(const int newValue);
 
 /** gets WaypointDisplayTime */
 int getWaypointDisplayTime() const;
 /** sets WaypointDisplayTime */
 void setWaypointDisplayTime(const int newValue);
 
 /** gets WarningDisplayTime */
 int getWarningDisplayTime() const;
 /** sets WarningDisplayTime */
 void setWarningDisplayTime(const int newValue);
 
 /** gets AlarmSound */
 bool getAlarmSoundOn() const;
 /** sets AlarmSound */
 void setAlarmSoundOn(const bool newValue);

 /** gets Popup Airspace Warnings */
 bool getPopupAirspaceWarnings() const;
 /** sets Popup Airspace Warnings */
 void setPopupAirspaceWarnings(const bool newValue);

 /** Gets the Gps Device */
 QString &getGpsDevice();
 /** Sets the Gps Device */
 void setGpsDevice( const QString newValue );
 
 /** Gets the Gps Speed */
 int getGpsSpeed() const;
 /** Sets the Gps Speed */
 void setGpsSpeed( const int newValue );
 
 /** gets Gps altitude */
 int getGpsAltitude() const;
 /** sets Gps altitude */
 void setGpsAltitude(const int newValue);
 
 /** gets Gps soft start */
 bool getGpsSoftStart() const;
 /** sets Gps soft start */
 void setGpsSoftStart(const bool newValue);

 /** gets Gps hard start */
 bool getGpsHardStart() const;
 /** sets Gps hard start */
 void setGpsHardStart(const bool newValue);

 /** gets Gps sync system clock */
 bool getGpsSyncSystemClock() const;
 /** sets Gps sync system clock */
 void setGpsSyncSystemClock(const bool newValue);

 /** gets Gps Ipc port */
 ushort getGpsIpcPort() const;
 /** sets Gps Ipc port */
 void setGpsIpcPort(const ushort newValue);

 /** gets Gps client start option */
 bool getGpsStartClientOption() const;
 /** sets Gps client start option */
 void setGpsStartClientOption(const bool newValue);

 /** Gets the Gps Client path */
 QString &getGpsClientPath();
 /** Sets the Gps Client path */
 void setGpsClientPath( const QString newValue );
 
 /** gets Gps last fix latitude */
 int getGpsLastFixLat() const;
 /** sets Gps last fix latitude */
 void setGpsLastFixLat(const int newValue);

 /** gets Gps last fix logitude */
 int getGpsLastFixLon() const;
 /** sets Gps last fix logitude */
 void setGpsLastFixLon(const int newValue);

 /** gets Gps last fix altitude */
 int getGpsLastFixAlt() const;
 /** sets Gps last fix altitude */
 void setGpsLastFixAlt(const int newValue);

 /** gets Gps last fix clock */
 int getGpsLastFixClk() const;
 /** sets Gps last fix clock */
 void setGpsLastFixClk(const int newValue);

 /** gets minimum sat cout for wind calculation */
 int getWindMinSatCount() const;
 /** sets minimum sat cout for wind calculation */
 void setMinSatCount(const int newValue);
 
 /** gets wind altitude range */
 int getWindAltitudeRange() const;
 /** sets wind altitude range */
 void setWindAltitudeRange(const int newValue);
 
 /** gets wind time range */
 int getWindTimeRange() const;
 /** sets wind time range */
 void setWindTimeRange(const int newValue);
 
 /** gets manual navigation mode altitude */
 int getManualNavModeAltitude() const;
 /** sets manual navigation mode altitude */
 void setManualNavModeAltitude(const int newValue);
 
 /** Gets the waypoint file name with path */
 QString &getWaypointFile();
 /** Sets the waypoint file name with path */
 void setWaypointFile( const QString newValue );

 /** Gets the unit for altitude*/
 int getUnitAlt() const;
 /** Sets the unit for altitude */
 void setUnitAlt(const int newValue);

 /** Gets the unit for distance*/
 int getUnitDist() const;
 /** Sets the unit for distance */
 void setUnitDist(const int newValue);

 /** Gets the unit for speed */
 int getUnitSpeed() const;
 /** Sets the unit for speed */
 void setUnitSpeed(const int newValue);

 /** Gets the unit for vario */
 int getUnitVario() const;
 /** Sets the unit for vario */
 void setUnitVario(const int newValue);

 /** Gets the unit for wind */
 int getUnitWind() const;
 /** Sets the unit for wind */
 void setUnitWind(const int newValue);

 /** Gets the unit for position */
 int getUnitPos() const;
 /** Sets the unit for position */
 void setUnitPos(const int newValue);

private:

 static GeneralConfig * _theInstance;

 //properties
 //used to store the distances for airspace warnings
 AirspaceWarningDistance _awd;
 //display a warning for this type?
 bool _airspaceWarning [BaseMapElement::objectTypeSize];
 //display airspace warnings at all?
 bool _airspaceWarningGeneral;
 
 // disclaimer version
 int _disclaimerVersion;
 Altitude _safetyAltitude;
 // surname
 QString _surname;
 // birthday
 QString _birthday;
 
 // Homesite
 wayPoint * _homeWp;
 // Center Latitude
 int _centerLat;
 // Center Longitude
 int _centerLon;

 // Map Scale
 double _mapScale;
 // Map Data Projection Type
 int _mapProjectionType;

 // Map delete after comlile
 bool _mapDelete;
 // Map unload unneeded
 bool _mapUnload;

 // Map BearLine
 bool _mapBearLine;
 // Map LoadIsoLines
 bool _mapLoadIsoLines;
 // Map ShowIsoLineBorders
 bool _mapShowIsoLineBorders;
 // Map ShowWaypointLabels
 bool _mapShowWaypointLabels;
 // Map ShowWaypointLabelsExtraInfo
 bool _mapShowWaypointLabelsExtraInfo;
 // Map LoadRoads
 bool _mapLoadRoads;
 // Map LoadHighways
 bool _mapLoadHighways;
 // Map LoadRailroads
 bool _mapLoadRailroads;
 // Map LoadCities
 bool _mapLoadCities;
 // Map LoadWaterways
 bool _mapLoadWaterways;
 // Map LoadForests
 bool _mapLoadForests;

 // Map Lower Limit
 int _mapLowerLimit;
 // Map Upper Limit
 int _mapUpperLimit;
 // Map Border 1
 int _mapBorder1;
 // Map Border 2
 int _mapBorder2;
 // Map Border 3
 int _mapBorder3;
 // Map Switch Scale
 int _mapSwitchScale;

 // Lambert Projection
 int _lambertParallel1;
 // Lambert Projection
 int _lambertParallel2;
 // Lambert Projection
 int _lambertOrign;
 // Cylindrical Projection
 int _cylinderParallel;

 // vario integration time
 int _varioIntegrationTime;
 // vario step width
 int _varioStepWidth;
 // vario tek compensation
 bool _varioTekCompensation;
 // vario tek adjust
 int _varioTekAdjust;

 // altimeter mode
 int _altimeterGndMode;
 // altimeter toggle mode
 bool _altimeterToggleMode;

 // logging into a fixed file for debugging purposes
 bool _log2File;
 // use syslog facility instead of stderr
 bool _useSysLog;

 // nearest site calculator switch
 bool _nearestSiteCalculatorSwitch;
 // maximum sites considered by nearest site calculator
 int _maxNearestSiteCalculatorSites;

 // AirfieldDisplayTime
 int _airfieldDisplayTime;
 // AirspaceDisplayTime
 int _airspaceDisplayTime;
 // InfoDisplayTime
 int _infoDisplayTime;
 // WaypointDisplayTime
 int _waypointDisplayTime;
 // WarningDisplayTime
 int _warningDisplayTime;
 // AlarmSound
 bool _alarmSound;
 // Popup Airspace Warnings
 bool _popupAirspaceWarnings;

 // Gps device
 QString _gpsDevice;
 // Gps speed
 int _gpsSpeed;
 // Gps delivered altitude
 int _gpsAltitude;
 // Gps soft start
 bool _gpsSoftStart;
 // Gps hard start
 bool _gpsHardStart;
 // Gps synchronize system clock
 bool _gpsSyncSystemClock;
 // Gps IPC port
 ushort _gpsIpcPort;
 // Gps client start option
 bool _gpsStartClient;
 // Gps client path
 QString _gpsClientPath;
 // Gps last fix latitude
 int _gpsLastFixLat;
 // Gps last fix logitude
 int _gpsLastFixLon;
 // Gps last fix altitude
 int _gpsLastFixAlt;
 // Gps last fix clock
 int _gpsLastFixClk;

 // minimum sat count for wind calculation
 int _windMinSatCount;
 // wind altitude range
 int _windAltitudeRange;
 // wind time range
 int _windTimeRange;
 // manual navigation mode altitude
 int _manualNavModeAltitude;

 // Waypoint data file name
 QString _waypointFile;

 // unit altitude
 int _unitAlt;
 // unit distance
 int _unitDist;
 // unit speed
 int _unitSpeed;
 // unit vario
 int _unitVario;
 // unit wind
 int _unitWind;
 // unit position
 int _unitPos;

};

#endif
