#include <vdr/plugin.h>

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


static const char *VERSION        = "0.1.1";
static const char *DESCRIPTION    = "use Hauppauge PVR as input device";
static const char *MAINMENUENTRY  = "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 DESCRIPTION;
}

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

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

bool cPluginPvrInput::Initialize(void)
{
	return true;
}

bool cPluginPvrInput::Start(void)
{
	cPvrDevice::Initialize();
	return true;
}

void cPluginPvrInput::Housekeeping(void)
{
}

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

cOsdObject * cPluginPvrInput::MainMenuAction(void)
{
	cChannel * channel = Channels.GetByNumber(cDevice::CurrentChannel());
	if (channel && channel->Source() == cSource::FromString(kPvrSource) && channel->Ca() == kPvrCa)
		return new cPvrMenu();
	Skins.Message(mtError, tr("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, "HideMainMenuEntry")) PvrSetup.HideMainMenuEntry = atoi(Value);
	else if (!strcasecmp(Name, "WaitAfterTuning")) PvrSetup.WaitAfterTuning = atoi(Value);
	else if (!strcasecmp(Name, "LogLevel")) PvrSetup.LogLevel = atoi(Value);
	else if (!strcasecmp(Name, "Brightness")) PvrSetup.Brightness = atoi(Value);
	else if (!strcasecmp(Name, "Contrast")) PvrSetup.Contrast = atoi(Value);
	else if (!strcasecmp(Name, "Saturation")) PvrSetup.Saturation = atoi(Value);
	else if (!strcasecmp(Name, "Hue")) PvrSetup.Hue = atoi(Value);
	else if (!strcasecmp(Name, "AudioVolume")) PvrSetup.AudioVolume = atoi(Value);
	else if (!strcasecmp(Name, "VideoBitrate")) PvrSetup.VideoBitrate = atoi(Value);
	else if (!strcasecmp(Name, "AudioBitrate")) PvrSetup.AudioBitrate = atoi(Value);
	else if (!strcasecmp(Name, "BitrateMode")) PvrSetup.BitrateMode = atoi(Value);
	else if (!strcasecmp(Name, "AspectRatio")) PvrSetup.AspectRatio = atoi(Value);
	else if (!strcasecmp(Name, "Pulldown")) PvrSetup.Pulldown = atoi(Value);
	else if (!strcasecmp(Name, "FramesPerGop")) PvrSetup.FramesPerGop = atoi(Value);
	else if (!strcasecmp(Name, "BFrames")) PvrSetup.BFrames = atoi(Value);
	else if (!strcasecmp(Name, "GopClosure")) PvrSetup.GopClosure = atoi(Value);
	else if (!strcasecmp(Name, "DnrMode")) PvrSetup.DnrMode = atoi(Value);
	else if (!strcasecmp(Name, "DnrSpatial")) PvrSetup.DnrSpatial = atoi(Value);
	else if (!strcasecmp(Name, "DnrTemporal")) PvrSetup.DnrTemporal = atoi(Value);
	else if (!strcasecmp(Name, "DnrType")) PvrSetup.DnrType = atoi(Value);
	else
		return false;
	return true;
}

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