// This sourcefile is created by Peter Jodda / peter@jodda.de
// It is under the Peter Jodda license:
// Everyboy may use it on his own risk. This header must stay in the file!
// If you expand this file, please contact me, that I can integrate the
// enhancemants in the original file.
//
// connection camera to basisdata


#include <stdlib.h>

#include <qapplication.h>
#include <qcursor.h>


#include "kamera.h"
#include "camera_def.h"
#include "basisdaten.h"

/*---------------------------------------------------------------*/
#define BASISDATENNAME       ".KCamediarc"
#define BASISDATENPREFIX     "PREFIX"
#define BASISDATENDIRECTORY  "DIRECTORY"
#define BASISDATENSPEED      "SPEED"
#define BASISDATENDEVICE     "DEVICE"
#define BASISDATENAUTOUHR    "AUTOCLOCK"

static char *basisDatenName()
{
   static char exportName[500];

   char *envReturn;
   
   
   envReturn =getenv("HOME");
   if(envReturn ==NULL)
   {
      strcpy(exportName,BASISDATENNAME);
   }
   else
   {
      strcpy(exportName,envReturn);
      strcat(exportName,"/");
      strcat(exportName,BASISDATENNAME);
   }
   return exportName;
}

//-------------------------------------------------------------------

void basisDatenLesen(CameraApplicationClass *app)
{
   bool gelungen;

   gelungen = app->basisDaten->BasisDatenLesen(basisDatenName());
   if(!gelungen)
      return;
   gelungen = app->basisDaten->BasisDatenReadString(
   		BASISDATENPREFIX,
   		app->LoadPrefix);
   gelungen = app->basisDaten->BasisDatenReadString(
   		BASISDATENDIRECTORY,
   		app->LoadDirectory);
   gelungen = app->basisDaten->BasisDatenReadString(
   		BASISDATENDEVICE,
   		app->deviceName);
   gelungen = app->basisDaten->BasisDatenReadInt(
   		BASISDATENSPEED,
   		&app->Geschwindigkeit);
   if(   app->Geschwindigkeit != 9600 
      && app->Geschwindigkeit != 19200
      && app->Geschwindigkeit != 38400
      && app->Geschwindigkeit != 57600
      && app->Geschwindigkeit != 115200
     )
   {
      app->Geschwindigkeit = 19200;
   }

   gelungen = app->basisDaten->BasisDatenReadInt(
   		BASISDATENAUTOUHR,
   		&app->AutoSetUhr);

   if(app->AutoSetUhr<0)
      app->AutoSetUhr = 0;
   else if(app->AutoSetUhr>1)
      app->AutoSetUhr = 1;
   

} // basisDatenLesen

//-------------------------------------------------------------------

void basisDatenSchreiben(CameraApplicationClass *app)
{
   bool gelungen;

   gelungen = app->basisDaten->BasisDatenWriteString(
   		BASISDATENPREFIX,
   		app->LoadPrefix);
   gelungen = app->basisDaten->BasisDatenWriteString(
   		BASISDATENDIRECTORY,
   		app->LoadDirectory);
   gelungen = app->basisDaten->BasisDatenWriteString(
   		BASISDATENDEVICE,
   		app->deviceName);
   gelungen = app->basisDaten->BasisDatenWriteInt(
   		BASISDATENSPEED,
   		app->Geschwindigkeit);

   gelungen = app->basisDaten->BasisDatenWriteInt(
   		BASISDATENAUTOUHR,
   		app->AutoSetUhr);
   gelungen = app->basisDaten->BasisDatenSchreiben(basisDatenName());
  
} // basisDatenSchreiben

