/*
 * DV Player plugin for VDR
 *
 * Copyright (C) 2003, 2004 Erich Bachl <erich.bachl@vr-web.de>
 *
 * This code is distributed under the terms and conditions of the
 * GNU GENERAL PUBLIC LICENSE. See the file COPYING for details.
 *
 */

#include "menusetup.h"
#include "shellthread.h"

#include "i18n.h"
#include "status.h"
#include "dv.h"


cMenuSetupAnalogtv::cMenuSetupAnalogtv(cPluginDV *PluginDV) :
   PluginDV(PluginDV)
{
  Clear();
  SetSection(tr("Setup.DV$DV"));
  bool bDriverNotFound = true;
  bool bCamcorderNotFound = true;
  if(FILE* fd = fopen("/proc/bus/ieee1394/devices", "r"))
  {
    char szLine[256];
    char szVendor[256];
    while(fgets(szLine, sizeof(szLine), fd))
    {
      if(strstr(szLine, "Vendor ID"))
      {
        strcpy(szVendor, szLine);
      }
      else if(strstr(szLine, "Unit Directory"))
      {
        bCamcorderNotFound = false;
        cOsdItem* camcorderitem = new cOsdItem(szVendor);
        Add(camcorderitem);
        Add(new cOsdItem(""));
        Add(new cOsdItem(tr("1\tBackward Scan")));
        Add(new cOsdItem(tr("3\tForward Scan")));
        Add(new cOsdItem(tr("4\tRewind")));
        Add(new cOsdItem(tr("6\tFast Forward")));
        Add(new cOsdItem(tr("Red\tPlay")));
        Add(new cOsdItem(tr("Blue\tStop")));
      }
      else if(strstr(szLine, "Host Node Status"))
      {
        bDriverNotFound = false;
      }
    }
    fclose(fd);
  }
  if(bDriverNotFound) SetStatus(tr("Firewire Driver NOT loaded!"));
  else if(bCamcorderNotFound) SetStatus(tr("Camcorder NOT found!"));
}

eOSState cMenuSetupAnalogtv::ProcessKey(eKeys Key)
{
  switch (Key)
  {
    case k1     : write(inpipe[1], "j\n", 2);  break;
    case k3     : write(inpipe[1], "l\n", 2);  break;
    case k4     : write(inpipe[1], "a\n", 2);  break;
    case k5     : write(inpipe[1], "k\n", 2);  break;
    case k6     : write(inpipe[1], "z\n", 2);  break;
    case kRed   : write(inpipe[1], "p\n", 2);  break;
    case kBlue  : write(inpipe[1], "\x1b\n", 2);  break;
    default        : break;
  }

  eOSState state = cOsdMenu::ProcessKey(Key);

  switch (Key)
  {
    case kRed    : state = osUser1;
                   break;

    case kGreen  : state = osUser2;
                   break;

    case kYellow : state = osUser3;
                   break;

    case kBlue   : state = osUser4;
                   break;

    default      : break;
  }

  return state;
}

void cMenuSetupAnalogtv::Store(void)
{
}
