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

#include <vdr/plugin.h>
#include "multilcd.h"
#include <vdr/status.h>
#include <vdr/channels.h>
#include <vdr/config.h>

static const char *VERSION        = "0.0.4a";
static const char *DESCRIPTION    = "Multitainer LCD-Display Driver";
static const char *MAINMENUENTRY  = NULL;
mLCD *LCD;

class clcdStatus : public cStatus {
protected:
  virtual void ChannelSwitch(const cDevice *Device, int ChannelNumber);
  virtual void SetVolume(int Volume, bool Absolute);
  //  virtual void OsdProgramme(time_t PresentTime, const char *PresentTitle, const char *PresentSubtitle, time_t FollowingTime, const char *FollowingTitle, const char *FollowingSubtitle);
  virtual void Replaying(const cControl *Control, const char *Name, const char *FileName, bool On);
  virtual void Recording(const cDevice *Device, const char *Name, const char *FileName, bool On);
  };

void clcdStatus::ChannelSwitch(const cDevice *Device, int ChannelNumber)
{
  switch (ChannelNumber)
    {
    case 0:
      break; // TODO: Indicator during Channel Switching
    default:
	if (Device->IsPrimaryDevice()){
	LCD->SetChannel(ChannelNumber);
#if VDRVERSNUM>=10315
	LCD->SetChannelName(Channels.GetByNumber(ChannelNumber)->ShortName(1));
#else
	LCD->SetChannelName(Channels.GetByNumber(ChannelNumber)->Name());
#endif	
      }
    }
}


void clcdStatus::SetVolume(int Volume, bool Absolute)
{
  LCD->display_volume(2,Volume,Absolute);
}

// Won't use this until theres a way to update epg Information on change
/*
void clcdStatus::OsdProgramme(time_t PresentTime, const char *PresentTitle, const char *PresentSubtitle, time_t FollowingTime, const char *FollowingTitle, const char *FollowingSubtitle)
{
  LCD->SetChannelInfo(PresentTitle);
}
*/

void clcdStatus::Recording(const cDevice *Device, const char *Name, const char *FileName, bool On)

{
  LCD->SetRecordingState(Device->CardIndex(), Name);
}

void clcdStatus::Replaying(const cControl *Control, const char *Name, const char *FileName, bool On)

{

  LCD->ReplayControl((cControl *) Control,Name);
}

class cPluginMlcd : public cPlugin {
private:
  // Add any member variables or functions you may need here.
  clcdStatus *statusMonitor;

public:
  cPluginMlcd(void);
  virtual ~cPluginMlcd();
  virtual const char *Version(void) { return VERSION; }
  virtual const char *Description(void) { return DESCRIPTION; }
  virtual const char *CommandLineHelp(void);
  virtual bool ProcessArgs(int argc, char *argv[]);
  virtual bool Start(void);
  virtual void Housekeeping(void);
  virtual const char *MainMenuEntry(void) { return MAINMENUENTRY; }
  virtual cOsdMenu *MainMenuAction(void);
  virtual cMenuSetupPage *SetupMenu(void);
  virtual bool SetupParse(const char *Name, const char *Value);
  };

cPluginMlcd::cPluginMlcd(void)
{
  // Initialize any member varaiables here.
  // DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
  // VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
statusMonitor = NULL;
}

cPluginMlcd::~cPluginMlcd()
{
  // Clean up after yourself!
  delete statusMonitor;
  delete LCD;
}

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

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

bool cPluginMlcd::Start(void)
{
  // Start any background activities the plugin shall perform.
  statusMonitor = new clcdStatus;
  LCD = new mLCD;
  LCD->Start();
  LCD->starttest = true; //Display Welcome Message
  return true;
}

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

cOsdMenu *cPluginMlcd::MainMenuAction(void)
{
  // Perform the action when selected from the main VDR menu.
  return NULL;
}

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

bool cPluginMlcd::SetupParse(const char *Name, const char *Value)
{
  // Parse your own setup parameters and store their values.
  return false;
}

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