// 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.
//

#include <qdialog.h>
#include <qpushbutton.h>
#include <qgrid.h>
#include <qlayout.h>
#include <qlabel.h>


#include <stdio.h>

#include "progressbox.h"
#include "texte.h"

#define KCAMEDIA_VERSION 1



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

ProgressBox::ProgressBox(QWidget *parent,
               CameraApplicationClass *theCameraApplication) :
		QSemiModal(parent,"progress",true)
{
   QGridLayout *grid;
   QBoxLayout  *topLayout;

   cameraApplication = theCameraApplication;

   topLayout = new QVBoxLayout( this, 2 );

   //topLayout->addWidget(new QLabel(TextGet(TEXT_WARTE_TITEL),this),0,AlignHCenter);
   //topLayout->addWidget(new QLabel(" ",this));

   grid = new QGridLayout( topLayout, 3, 2,10);

   grid->addWidget(new QLabel(TextGet(TEXT_WARTE_BILDNAME),this),0,0);
   grid->addWidget(new QLabel(TextGet(TEXT_WARTE_GELADEN),this),1,0);
   grid->addWidget(new QLabel(TextGet(TEXT_WARTE_PROZENT),this),2,0);
   
   nameLabel     = new QLabel("actual name",this);
   loadedSlider  = new QSlider(QSlider::Horizontal,this);
   percentSlider = new QSlider(QSlider::Horizontal,this);
   percentSlider->setRange(0,100);
   
   grid->addWidget(nameLabel    ,0,1);
   grid->addWidget(loadedSlider ,1,1);
   grid->addWidget(percentSlider,2,1);

   // disable input in the sliders
   loadedSlider->setEnabled(false);
   percentSlider->setEnabled(false);
   
   setCaption(TextGet(TEXT_WARTE_TITEL));




   // --- the abort button

   abortButton = new QPushButton( TextGet(TEXT_WARTE_ABBRUCH), this );

   topLayout->addWidget(abortButton,20,AlignCenter);   

   abortPressed = false;
   connect(abortButton,SIGNAL(clicked()),this,SLOT(DoAbort()) );



   
} // progressbox constructor

//=============================================================================

void ProgressBox::DoAbort()
{
   //fprintf(stderr,"abort pressed");
   abortPressed = true;
}

//=============================================================================

bool ProgressBox::update(char *name,int images,int maximages,int percent)
{
      
   if(name != NULL)
   {
      nameLabel ->setText(name);
   }

   if(maximages >=0)
   {
      loadedSlider->setValue(0);
      loadedSlider->setRange(0,maximages);
   }
   
   if(images >=0)
   {
      loadedSlider->setValue(images);
   }

   if(percent>=0)
   {
      percentSlider->setValue(percent);
   }


   return abortPressed;
}
