#include "status.h"
#include "menu.h"


cStatusMonitor::cStatusMonitor()

{
  data.ActualSource=0;
  transfer=false;
}

void cStatusMonitor::ChannelSwitch(const cDevice *Device, int ChannelNumber)
{
  Aktiv=false;
  device=cDevice::GetDevice(data.DvbCard);
  if (ChannelNumber)
  {
    if ((Device!=cDevice::PrimaryDevice()) || (cDevice::ActualDevice()==cDevice::PrimaryDevice()) || (cDevice::PrimaryDevice()->cDevice::HasProgramme()) && transfer)
    {
      Channel = Channels.GetByNumber(ChannelNumber);
      if (data.DvbCard==Device->CardIndex())      
        if ((*Channel).Source()!=data.ActualSource)  
        {
          if (data.UseGotoX)
          {
            data.ActualSource=(*Channel).Source();
            GotoX(data.ActualSource);
          }
         /* if (data.ShowInfo && (cDevice::PrimaryDevice()==cDevice::ActualDevice()))
          {
            Wait.WaitForLock(device);
          }*/
        }
    }
    if ((cDevice::ActualDevice()!=cDevice::PrimaryDevice()) && (Device==cDevice::PrimaryDevice()) )
      transfer=true;
    if ((cDevice::ActualDevice()==cDevice::PrimaryDevice()) && (Device==cDevice::PrimaryDevice())) transfer=false;
  }
}

// cWaitForLockThread Wait;

cWaitForLockThread::cWaitForLockThread()
{
  active=false;
}

cWaitForLockThread::~cWaitForLockThread()
{
  if (active)
    Cancel(3);
}

void cWaitForLockThread::WaitForLock(cDevice *Device)
{
  device=Device;
  if (!active)
    Start();
}

void cWaitForLockThread::Restart()
{
  if (!active)
    Start();  
}

void cWaitForLockThread::Action()
{
  active=true;
  Skins.Message(mtStatus,tr("Rotating Dish"));
  for (int i=0; active && i<=100; )
  {
    if (!Skins.IsOpen()) 
      Skins.Message(mtStatus,tr("Rotating Dish"));
    if (device->HasLock())
      dsyslog("%d ",i++);
    else 
      i=0;
    usleep(100000);
  }
  Skins.Message(mtStatus,NULL);
  active=false;
}
