/*
 * Least Cost Routing plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id$
 */

#include "lcrcfg.h"
#include "lcri18n.h"
#include "lcrosd.h"
#include "lcr.h"

#if VDRVERSNUM && VDRVERSNUM < 10321
#error "Sorry, not tested yet!"
#endif

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

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

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

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

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

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

void cPluginLcr::Stop(void)
{
  // Stop the background activities.
}

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

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

bool cPluginLcr::SetupParse(const char *Name, const char *Value)
{
  // Parse your own setup parameters and store their values.
  if      (!strcasecmp(Name, "ZoomIn"))         lcrConfig.zoomIn         = atoi(Value);
  else if (!strcasecmp(Name, "LogoFrame"))      lcrConfig.logoFrame      = atoi(Value);
  else if (!strcasecmp(Name, "HideMenu"))       lcrConfig.hidemenu       = atoi(Value);
  else if (!strcasecmp(Name, "OSDOffsetX"))     lcrConfig.osdoffsetX     = atoi(Value);
  else if (!strcasecmp(Name, "OSDOffsetY"))     lcrConfig.osdoffsetY     = atoi(Value);
  else if (!strcasecmp(Name, "Theme"))          lcrConfig.theme          = atoi(Value);
  else
    return false;
  if (lcrConfig.displaymode < 0 || lcrConfig.displaymode >= eLcrModeMaxNumber) lcrConfig.displaymode = 0;

  return true;
}

cMenuLcrSetup::cMenuLcrSetup(void)
{
  themes[eLcrThemeClassic]       = tr("Classic");
  themes[eLcrThemeElchi]         = tr("Elchi");
  themes[eLcrThemeDeepBlue]      = tr("DeepBlue");
  themes[eLcrThemeMoronimo]      = tr("Moronimo");

  Setup();
}

void cMenuLcrSetup::Setup(void)
{
  int current = Current();

  Clear();
  Add(new cMenuEditBoolItem(  tr("Zoom-in"),                     &lcrConfig.zoomIn,         tr("no"),            tr("yes")));
  Add(new cMenuEditBoolItem(  tr("Frame around Logo"),           &lcrConfig.logoFrame,      tr("no"),            tr("yes")));
  Add(new cMenuEditBoolItem(  tr("Hide main menu entry"),        &lcrConfig.hidemenu,       tr("no"),            tr("yes")));
  Add(new cMenuEditStraItem(  tr("Theme"),                       &lcrConfig.theme,          eLcrThemeMaxNumber,themes));
  Add(new cMenuEditIntItem(   tr("Horizontal offset"),           &lcrConfig.osdoffsetX,     -50,                 50));
  Add(new cMenuEditIntItem(   tr("Vertical offset"),             &lcrConfig.osdoffsetY,       0,                 300));


  SetCurrent(Get(current));
  Display();
}

void cMenuLcrSetup::Store(void)
{
  SetupStore("ZoomIn",         lcrConfig.zoomIn);
  SetupStore("LogoFrame",      lcrConfig.logoFrame);
  SetupStore("HideMenu",       lcrConfig.hidemenu);
  SetupStore("Theme",          lcrConfig.theme);
  SetupStore("OSDOffsetX",     lcrConfig.osdoffsetX);
  SetupStore("OSDOffsetY",     lcrConfig.osdoffsetY);
}

eOSState cMenuLcrSetup::ProcessKey(eKeys Key)
{
  int oldAnalyzestream = lcrConfig.analyzestream;

  eOSState state = cMenuSetupPage::ProcessKey(Key);

  if (Key != kNone && (lcrConfig.analyzestream != oldAnalyzestream)) {
     Setup();
     }

  return state;
}

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

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