// 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.
//
// hauptmodul fuer das cameraprogramm



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

#include <qvbox.h>
#include <qpushbutton.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qframe.h>
#include <qgrid.h>
#include <qpopupmenu.h>
#include <qmenubar.h>

#include <stdio.h>
#include <stdlib.h>

#include "kamera.h"
#include "settingsbox.h"
#include "aboutbox.h"
#include "malbox.h"
#include "camera_basis.h"


void initDatenStrukturen(CameraApplicationClass *cameraApplication)
{

   // ein paar default werte eintragen
   strcpy(cameraApplication->deviceName,"/dev/ttyS1");
   cameraApplication->Geschwindigkeit=19200;
   getcwd(cameraApplication->LoadDirectory,1000);
   strcpy(cameraApplication->LoadPrefix,"image");
    

   // basisdaten erzeugen
   cameraApplication->basisDaten = new BasisDatenType();

   // lesen der basisdaten
   basisDatenLesen(cameraApplication);

}


void CameraApplicationClass::setWait(bool enable)
{
   if(enable)
   {
      if(waitMode>0)
         waitMode ++;
      else
      {
         waitMode =1;
         mainApplication->setOverrideCursor(Qt::waitCursor);
      }
   }
   else
   {
      if(waitMode >0)
      {
         waitMode --;
         if(waitMode ==0)
            mainApplication->restoreOverrideCursor();
         
      }
   }
}


/*---------------------------------------------------------------*/

void CommandLineAufnahme(CameraApplicationClass *cameraApplication,
                         char *filename)
{
   CameraRealClass * cameraReal;
   
   cameraReal = new CameraRealClass(cameraApplication);
   if(cameraReal == NULL)
      return;
   cameraReal->MakeImage(filename);
   
   delete cameraReal;
}



/*---------------------------------------------------------------*/



int main(int argc, char *argv[])
{

   CameraApplicationClass cameraApplication;
   QApplication           a(argc,argv);
   Kamera                 *theApplication;
   char                   *filename = NULL;
   int                    optionGefunden;


   // application ptr eintragen
   cameraApplication.mainApplication =&a;


   initDatenStrukturen(&cameraApplication);
   
   opterr=0;
   optionGefunden = getopt(argc,argv,"f:");
   if(   optionGefunden != EOF 
      && optionGefunden != (int)'?')
   {
      filename = optarg;
      if(filename !=NULL)   
      {
         CommandLineAufnahme(&cameraApplication,filename);
         return 0;
      }
   }
   
   cameraApplication.cameraReal =  new CameraRealClass(&cameraApplication);  

   theApplication = new Kamera(0,&cameraApplication);
   
   theApplication->show();
   
   return a.exec();
   
   delete cameraApplication.cameraReal;
   
}

