//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "Frm_Wait4Jobs.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

#include "../sources.cc/jobs/jobs.h"

#include "localiser/locale_set.h"
#ifdef __gettext__
 #include<libintl.h>
#endif


TFrm_WaitForJobs *Frm_WaitForJobs;


//---------------------------------------------------------------------------
__fastcall TFrm_WaitForJobs::TFrm_WaitForJobs(TComponent* Owner): TForm(Owner)
{
  Jobs2Finish = -1;
}


//---------------------------------------------------------------------------
void __fastcall TFrm_WaitForJobs::Btn_IgnoreClick(TObject *Sender)
{
  Timer1->Enabled = false;
  Close();
}


//---------------------------------------------------------------------------
void __fastcall TFrm_WaitForJobs::Timer1Timer(TObject *Sender)
{
  if(JobBase::JobCount <= 0)
  {
    Timer1->Enabled = false;
    Close();
    return;
  }

  TicksWaiting++;
  if(Jobs2Finish!=JobBase::JobCount || SecondsDisplayed!=(TicksWaiting*1000)/Timer1->Interval)
  {
    SecondsDisplayed = (TicksWaiting*1000) / Timer1->Interval;
    Jobs2Finish = JobBase::JobCount;
    AnsiString msg;
    msg.printf(_("Waiting for %d jobs %d[s]"), Jobs2Finish, SecondsDisplayed);
    Label1->Caption = msg;
  }
}


//---------------------------------------------------------------------------
void __fastcall TFrm_WaitForJobs::FormCreate(TObject *Sender)
{
#ifdef __gettext__
  TranslateStrings(this);
#endif
}


//---------------------------------------------------------------------------
void __fastcall TFrm_WaitForJobs::FormShow(TObject *Sender)
{
  Timer1->Enabled = true;
  TicksWaiting = 0;
  SecondsDisplayed = -1;
}
//---------------------------------------------------------------------------
