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

#include "filter.h"
#include "i18n.h"
#include "transponders.h"
#include "channelscan.h"
#include "csmenu.h"
#include <vdr/channels.h>
#include <vdr/device.h>

bool scanning_by_channelscan = false;
int oldChannelNumbers = 0;
int oldUpdateChannels = 0;

int setupServiceType;

// --- cMenuChannelscanSetup  ------------------------------------------------------

cMenuChannelscanSetup::cMenuChannelscanSetup()
{

	serviceType = setupServiceType;
	serviceTypeTexts[0]=tr("Radio only");
	serviceTypeTexts[1]=tr("TV only");
	serviceTypeTexts[2]=tr("Radio + TV");
	serviceTypeTexts[3]=tr("Radio + TV + NVOD"); // near on Video on Demand
	Setup();
}

void cMenuChannelscanSetup::Setup()
{
   int current = Current();
	Clear();
	serviceType = setupServiceType;
	Add(new cMenuEditStraItem(tr("Service Type"), &serviceType, 4, serviceTypeTexts));

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

}

eOSState cMenuChannelscanSetup::ProcessKey(eKeys Key)
{
  int oldServiceType = setupServiceType;

  eOSState state = cMenuSetupPage::ProcessKey(Key);

  if(Key != kNone && (serviceType != oldServiceType))
  {
	   setupServiceType = serviceType;
      Setup();
  }
  return state;
}


void cMenuChannelscanSetup::Store(void)
{
	SetupStore("ServiceType", setupServiceType = serviceType);
}


// --- cPluginChannelscan  ---------------------------------------------------------

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

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

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

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

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

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

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

cOsdObject *cPluginChannelscan::MainMenuAction(void) {

	// Perform the action when selected from the main VDR menu.

	oldChannelNumbers = Channels.MaxNumber();
	oldUpdateChannels = Setup.UpdateChannels;
   int currentChannel = cDevice::CurrentChannel();
	return new cMenuChannelscan(currentChannel);

}

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

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

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

