/*
 * extb plugin to VDR (C++)
 *
 * (C) 2004 - 2006 Andreas Brachold <vdr04-at-deltab-dot-de>
 *
 * This code is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This code is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
 */

#include "extb_status.h"



// ---
cExtBStatusMonitor::cExtBStatusMonitor(cExtBoardIO*    pExt)
: m_pExt(pExt)
{

}

void cExtBStatusMonitor::ChannelSwitch(const cDevice *pDevice, int nChannelNumber)
{
#ifdef MOREDEBUGMSG
  if (nChannelNumber)
    moredsyslog("extb: channel switched to %d on DVB %d", nChannelNumber, pDevice->CardIndex());
  else
    moredsyslog("extb: about to switch channel on DVB %d", pDevice->CardIndex());
#endif

  if (nChannelNumber > 0 && pDevice->IsPrimaryDevice()) {
    if (nChannelNumber == cDevice::CurrentChannel())
      m_pExt->Channel(nChannelNumber);
  }
}

void cExtBStatusMonitor::SetVolume(int Volume, bool Absolute)
{
  moredsyslog("extb: SetVolume  %d %d", Volume, Absolute);

  if(m_pExt->Volume(Volume,Absolute))
    m_pExt->Update(false);
}

void cExtBStatusMonitor::Recording(const cDevice *pDevice, const char *szName, const char *szFileName, bool bOn)
{
  moredsyslog("extb: Recording  %d %s", pDevice->CardIndex(), szName);

  m_pExt->Recording(pDevice,szName,szFileName,bOn);
}

void cExtBStatusMonitor::Replaying(const cControl *pControl, const char *szName, const char *szFileName, bool bOn)
{
  moredsyslog("extb: Replaying  %s", szName);

  m_pExt->Replaying(pControl,szName,szFileName,bOn);
}

void cExtBStatusMonitor::OsdClear(void)
{
  //fprintf(stderr,"extb: OsdClear\n");fflush( stderr );
  m_pExt->OsdHelpKeys(false,false,false,false,500);
  m_pExt->OsdActive(false,500);
}

void cExtBStatusMonitor::OsdTitle(const char *Title)
{
  moredsyslog("extb: OsdTitle '%s'", Title);
  m_pExt->OsdActive(true,200);
}

void cExtBStatusMonitor::OsdStatusMessage(const char *szMessage)
{
  if(szMessage) {
    moredsyslog("extb: OsdStatusMessage '%s'", szMessage);
  } else {
    moredsyslog("extb: OsdStatusMessage 'NULL'");
  }

  m_pExt->StatusMessage(szMessage);
}

void cExtBStatusMonitor::OsdHelpKeys(const char *Red, const char *Green, const char *Yellow, const char *Blue)
{
  //fprintf(stderr,"extb: OsdHelpKeys %s - %s - %s - %s\n", Red, Green, Yellow, Blue);fflush( stderr );
  m_pExt->OsdHelpKeys(Red != NULL && strlen(Red)>0,
                      Green != NULL && strlen(Green)>0,
                      Yellow != NULL && strlen(Yellow)>0,
                      Blue != NULL && strlen(Blue)>0,
                      200);
}

void cExtBStatusMonitor::OsdCurrentItem(const char *Text)
{
  moredsyslog("extb: OsdCurrentItem %s", Text);
}

void cExtBStatusMonitor::OsdTextItem(const char *Text, bool Scroll)
{
  moredsyslog("extb: OsdTextItem %s %d", Text, Scroll);
}

void cExtBStatusMonitor::OsdChannel(const char *Text)
{
  moredsyslog("extb: OsdChannel %s", Text);
}

void cExtBStatusMonitor::OsdProgramme(time_t PresentTime, const char *PresentTitle, const char *PresentSubtitle, time_t FollowingTime, const char *FollowingTitle, const char *FollowingSubtitle)
{
#ifdef MOREDEBUGMSG
  char buffer[25];
  struct tm tm_r;
  moredsyslog("extb: OsdProgramme");
  strftime(buffer, sizeof(buffer), "%R", localtime_r(&PresentTime, &tm_r));
  moredsyslog("%5s %s", buffer, PresentTitle);
  moredsyslog("%5s %s", "", PresentSubtitle);
  strftime(buffer, sizeof(buffer), "%R", localtime_r(&FollowingTime, &tm_r));
  moredsyslog("%5s %s", buffer, FollowingTitle);
  moredsyslog("%5s %s", "", FollowingSubtitle);
#endif
}
