#include <vdr/plugin.h>

#include "device.h"
#include "global.h"
#include "menu.h"
#include "plugin.h"


static const char *VERSION        = "2007-11-29";
static const char *DESCRIPTION    = tr("Setup.pvrinput$use Hauppauge PVR as input device");
static const char *MAINMENUENTRY  = tr("Setup.pvrinput$PVR picture settings");


cPluginPvrInput * PluginPvrInput;

cPluginPvrInput::cPluginPvrInput(void) {
  PluginPvrInput = this;
}

cPluginPvrInput::~cPluginPvrInput() {
  PluginPvrInput = NULL;
}

const char * cPluginPvrInput::Version(void) {
  return VERSION;
}

const char * cPluginPvrInput::Description(void) {
  return tr(DESCRIPTION);
}

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

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

bool cPluginPvrInput::Initialize(void) {
#if VDRVERSNUM < 10507
  RegisterI18n(pvrinput_Phrases); 
#endif //VDRVERSNUM < 10507
  return true;
}

bool cPluginPvrInput::Start(void) {
/* Start() is called after the primary device and user interface has
   been set up, but before the main program loop is entered. Is called
   after Initialize(). */
  cPvrDevice::Initialize();
  return true;
}

void cPluginPvrInput::Stop(void) {
/* Any threads the plugin may have created shall be stopped
   in the Stop() function. See VDR/PLUGINS.html */
  cPvrDevice::Stop();
};

void cPluginPvrInput::Housekeeping(void) {
}

const char * cPluginPvrInput::MainMenuEntry(void) {
  if (PvrSetup.HideMainMenuEntry)
     return NULL;
  else
    return tr(MAINMENUENTRY);
}


cOsdObject * cPluginPvrInput::MainMenuAction(void) {
  cChannel * channel = Channels.GetByNumber(cDevice::CurrentChannel());
  if (channel &&
     (channel->IsCable() && channel->Ca() == kPvrCa))
    return new cPvrMenuMain();
  Skins.Message(mtError, tr("Setup.pvrinput$Not on an analogue channel!"), 2);
  return NULL;
}

cMenuSetupPage * cPluginPvrInput::SetupMenu(void) {
  return new cPvrMenuSetup();
}

bool cPluginPvrInput::SetupParse(const char * Name, const char * Value) {
  if      (!strcasecmp(Name, "LogLevel"))                 PvrSetup.LogLevel                       = atoi(Value);
  else if (!strcasecmp(Name, "SliceVBI"))                 PvrSetup.SliceVBI                       = atoi(Value);
  else if (!strcasecmp(Name, "Brightness"))               PvrSetup.Brightness.value               = atoi(Value);
  else if (!strcasecmp(Name, "Contrast"))                 PvrSetup.Contrast.value                 = atoi(Value);
  else if (!strcasecmp(Name, "Saturation"))               PvrSetup.Saturation.value               = atoi(Value);
  else if (!strcasecmp(Name, "Hue"))                      PvrSetup.Hue.value                      = atoi(Value);
  else if (!strcasecmp(Name, "AudioVolumeTV"))            PvrSetup.AudioVolumeTV.value            = atoi(Value);
  else if (!strcasecmp(Name, "AudioVolumeFM"))            PvrSetup.AudioVolumeFM.value            = atoi(Value);
  else if (!strcasecmp(Name, "AudioSampling"))            PvrSetup.AudioSampling.value            = atoi(Value);
  else if (!strcasecmp(Name, "VideoBitrateTV"))           PvrSetup.VideoBitrateTV.value           = atoi(Value) * 1000;
  else if (!strcasecmp(Name, "VideoBitrateFM"))           PvrSetup.VideoBitrateFM.value           = atoi(Value) * 1000;
  else if (!strcasecmp(Name, "AudioBitrate"))             PvrSetup.AudioBitrate.value             = atoi(Value);
  else if (!strcasecmp(Name, "BitrateMode"))              PvrSetup.BitrateMode.value              = atoi(Value);
  else if (!strcasecmp(Name, "AspectRatio"))              PvrSetup.AspectRatio.value              = atoi(Value);
  else if (!strcasecmp(Name, "FilterSpatialMode"))        PvrSetup.FilterSpatialMode.value        = atoi(Value);
  else if (!strcasecmp(Name, "FilterSpatial"))            PvrSetup.FilterSpatial.value            = atoi(Value);
  else if (!strcasecmp(Name, "FilterLumaSpatialType"))    PvrSetup.FilterLumaSpatialType.value    = atoi(Value);
  else if (!strcasecmp(Name, "FilterChromaSpatialType"))  PvrSetup.FilterChromaSpatialType.value  = atoi(Value);
  else if (!strcasecmp(Name, "FilterTemporalMode"))       PvrSetup.FilterTemporalMode.value       = atoi(Value);
  else if (!strcasecmp(Name, "FilterTemporal"))           PvrSetup.FilterTemporal.value           = atoi(Value);
  else if (!strcasecmp(Name, "FilterMedianType"))         PvrSetup.FilterMedianType.value         = atoi(Value);
  else if (!strcasecmp(Name, "FilterLumaMedianBottom"))   PvrSetup.FilterLumaMedianBottom.value   = atoi(Value);
  else if (!strcasecmp(Name, "FilterLumaMedianTop"))      PvrSetup.FilterLumaMedianTop.value      = atoi(Value);
  else if (!strcasecmp(Name, "FilterChromaMedianBottom")) PvrSetup.FilterChromaMedianBottom.value = atoi(Value);
  else if (!strcasecmp(Name, "FilterChromaMedianTop"))    PvrSetup.FilterChromaMedianTop.value    = atoi(Value);
  else if (!strcasecmp(Name, "HideMainMenuEntry"))        PvrSetup.HideMainMenuEntry              = atoi(Value);
  else
    return false;
  return true;
}

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