/*
 * PhotoCD Player plugin for VDR
 * pcd.c: main
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id$
 */

#include <getopt.h>
#include <stdlib.h>
#include <vdr/plugin.h>
#include "pcd_func.h"
#include "pcd_i18n.h"
#include "pcd_menu.h"
#include "pcd_setup.h"

static const char *VERSION        = "0.0.3";
static const char *DESCRIPTION    = "PhotoCD Player";
static const char *MAINMENUENTRY  = "PhotoCD";

class cPluginPcd : public cPlugin {
private:
  // Add any member variables or functions you may need here.
  cPCD *pcd;
public:
  cPluginPcd(void);
  virtual ~cPluginPcd();
  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 Start(void);
  virtual void Housekeeping(void);
  virtual const char *MainMenuEntry(void);
  virtual cOsdObject *MainMenuAction(void);
  virtual cMenuSetupPage *SetupMenu(void);
  virtual bool SetupParse(const char *Name, const char *Value);
  };

cPluginPcd::cPluginPcd(void)
{
  // Initialize any member variables here.
  // DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
  // VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
  pcd = NULL;
}

cPluginPcd::~cPluginPcd()
{
  // Clean up after yourself!
  delete pcd;
}

const char *cPluginPcd::CommandLineHelp(void)
{
  // Return a string that describes all known command line options.
  return NULL;
}

bool cPluginPcd::ProcessArgs(int argc, char *argv[])
{
  // Implement command line argument processing here if applicable.
  return true;
}

bool cPluginPcd::Start(void)
{
  // Start any background activities the plugin shall perform.
  RegisterI18n(Phrases);
  pcd = new cPCD("/dev/cdrom");
  return true;
}

void cPluginPcd::Housekeeping(void)
{
  // Perform any cleanup or other regular tasks.
}

const char *cPluginPcd::MainMenuEntry(void)
{
  if (PcdSetupData.HideMainMenuEntry)
     return NULL;
  if (pcd->DriveExists())
     return tr(MAINMENUENTRY);
  else
     return NULL;
}

cOsdObject *cPluginPcd::MainMenuAction(void)
{
  // Perform the action when selected from the main VDR menu.
  return new cPcdMenu(pcd);
}

cMenuSetupPage *cPluginPcd::SetupMenu(void)
{
  // Return a setup menu in case the plugin supports one.
  return new cPcdSetupMenu(pcd);
}

bool cPluginPcd::SetupParse(const char *Name, const char *Value)
{
  // Parse your own setup parameters and store their values.
  if (!strcasecmp(Name, "DriveSpeed"))
     PcdSetupData.DriveSpeed = atoi(Value);
  else if (!strcasecmp(Name, "HideMainMenuEntry"))
     PcdSetupData.HideMainMenuEntry = atoi(Value);
  else if (!strcasecmp(Name, "Quality"))
     PcdSetupData.Quality = atoi(Value);
  else if (!strcasecmp(Name, "Pal"))
     PcdSetupData.Pal = atoi(Value);
  else if (!strcasecmp(Name, "Quickscaling"))
     PcdSetupData.QuickScaling = atoi(Value);
  else if (!strcasecmp(Name, "Noadjust"))
     PcdSetupData.NoAdjust = atoi(Value);
  else if (!strcasecmp(Name, "SlideshowInterval"))
     PcdSetupData.SlideInterval = atoi(Value);
  else
     return false;
  return true;
}

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