/*
 * em84_eject.c: A plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id$
 */

#include "common.h"
#include <vdr/plugin.h>
#include <vdr/config.h>
#include <fmp.h>

static const char *VERSION        = "0.0.1";
static const char *DESCRIPTION    = "DVD eject for em84xx DVD player";
static const char *MAINMENUENTRY  = "Open/close disctray";

class cPluginEm84_eject : public cPlugin {

private:
   bool mDriveOpen;

public:
   cPluginEm84_eject(void);
   virtual ~cPluginEm84_eject();
   virtual const char *Version(void) { return VERSION;}
   virtual const char *Description(void) { return DESCRIPTION;}
   virtual const char *CommandLineHelp(void);
   virtual bool ProcessArgs(int argc, char *argv[]);
   virtual bool Initialize(void);
   virtual bool Start(void);
   virtual void Stop(void);
   virtual const char *MainMenuEntry(void) { return tr(MAINMENUENTRY);}
   virtual cOsdObject *MainMenuAction(void);
   virtual cMenuSetupPage *SetupMenu(void);
   virtual bool SetupParse(const char *Name, const char *Value);

};

cPluginEm84_eject::cPluginEm84_eject(void)
{
   mDriveOpen = false;
}

cPluginEm84_eject::~cPluginEm84_eject()
{
}

const char *cPluginEm84_eject::CommandLineHelp(void)
{
   return NULL;
}

bool cPluginEm84_eject::ProcessArgs(int argc, char *argv[])
{
   return true;
}

bool cPluginEm84_eject::Initialize(void)
{
   return true;
}

bool cPluginEm84_eject::Start(void)
{
   return true;
}

void cPluginEm84_eject::Stop(void)
{
}


cOsdObject *cPluginEm84_eject::MainMenuAction(void)
{
   if (FMPTrayOperation(FMPT_TRAYCHECK) == FMPT_TRAYCLOSE) {
      FMPTrayOperation(FMPT_TRAYOPEN);
      mDriveOpen = true;

   }
   else {
      if (mDriveOpen) {
         FMPTrayOperation(FMPT_TRAYCLOSE);
         mDriveOpen = false;
      }
      else {
         FMPTrayOperation(FMPT_TRAYOPEN);
         mDriveOpen = true;
      }
   }
   return NULL;
}


cMenuSetupPage *cPluginEm84_eject::SetupMenu(void)
{
   return NULL;
}


bool cPluginEm84_eject::SetupParse(const char *Name, const char *Value)
{
   return false;
}


VDRPLUGINCREATOR(cPluginEm84_eject); // Don't touch this!
