/*
 * X10 controller plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id: X10.c,v 1.7 2005/03/17 13:06:34 toni Exp $
 */

#include "i18n.h"
#include "deviceListMenu.h"
#include "deviceSetupMenu.h"
#include "X10Device.h"
#include "X10Setup.h"
#include <vdr/plugin.h>

static const char *VERSION        = "0.0.1";
static const char *DESCRIPTION    = "Controller for X10 devices";
static const char *MAINMENUENTRY  = "X10 Controller";

class cPluginX10 : public cPlugin {
private:
public:
  cPluginX10(void);
  virtual ~cPluginX10();
  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 Initialize(void);
  virtual bool Start(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);
  };

cPluginX10::cPluginX10(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!
}

cPluginX10::~cPluginX10()
{
  // Clean up after yourself!
}

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

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

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

bool cPluginX10::Start(void)
{
  // Start any background activities the plugin shall perform.
  if (devices.Load(AddDirectory(ConfigDirectory(), "X10.conf"), true))
     return true;
  return false;
}

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

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

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

bool cPluginX10::SetupParse(const char *Name, const char *Value)
{
  // Parse your own setup parameters and store their values.
  if ( !strcasecmp(Name, "step") )
    globalSetup.step = atoi(Value);
  else
    return false;
  return true;
}

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