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

#include <getopt.h>
#include <stdlib.h>
#include <vdr/interface.h>
#include <vdr/plugin.h>
#include "i18n.h"
#include "menuitem.h"
#include "menu.h"
#include "config.h"

static const char *VERSION       = "0.8";
static const char *DESCRIPTION   = "virtual dvd-selector";
static const char *MAINMENUENTRY = "DVDSelect";

class cPluginDVDSelect : public cPlugin {
 private:
  // Add any member variables or functions you may need here.
  void Reset(void);
 public:
  cPluginDVDSelect(void);
  virtual ~cPluginDVDSelect();
  virtual const char *Version(void) { return VERSION; }
  virtual const char *Description(void) { return tr(DESCRIPTION); }
  virtual const char *CommandLineHelp(void);
  virtual bool ProcessArgs(int argc, char *argv[]);
  virtual bool Start(void);
  virtual bool Initialize(void);
  virtual void Housekeeping(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);
};

// Global variables that control the overall behaviour:


// --- cPluginDVDSelect -------------------------------------------------------

cPluginDVDSelect::cPluginDVDSelect(void)
{
  // none needed
}

cPluginDVDSelect::~cPluginDVDSelect()
{
  // Clean up after yourself!
  // none needed
  Reset();
}

const char *cPluginDVDSelect::CommandLineHelp(void)
{
  // none needed
  return "";
}

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

bool cPluginDVDSelect::Initialize(void)
{
  // Initialize any background activities the plugin shall perform.
  RegisterI18n(Phrases);
  Reset();
  return true;
}

bool cPluginDVDSelect::Start(void)
{
  // Start any background activities the plugin shall perform.
  // none needed
  return true;
}

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

cOsdObject *cPluginDVDSelect::MainMenuAction(void)
{
  return new cDVDList();
}

cMenuSetupPage *cPluginDVDSelect::SetupMenu(void)
{
  // Return the setup menu.
  return new cMenuSetupDVDSelect;
}

bool cPluginDVDSelect::SetupParse(const char *Name, const char *Value)
{
    return DVDSelectSetup.SetupParse(Name, Value);
}

void cPluginDVDSelect::Reset(void)
{
  char *device = NULL;
  char *orgDevice = NULL;
  char *cmd = NULL;

  asprintf(&device, "%s",DVDSelectSetup.NameDevice);
  asprintf(&orgDevice, "%s",DVDSelectSetup.NameOrgDevice);
  asprintf(&cmd, "ln -nfs '%s' '%s' 2> /dev/null", orgDevice, device);

  esyslog(cmd);
  system(cmd);
}

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