/*$cb
 *    This file is a part of OpenMHP VDR plugin.
 *
 *    Copyright (C) 2005 Mikko Novaro <miknov@gmail.com>
 *
 *    See README file for licensing and contact information.
 $ce*/

#include "openmhp.h"

cPluginOpenmhp::cPluginOpenmhp(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!
  // DitheringEnabled = false;
  setup = new cOpenmhpSetup();
  xlet = NULL;
}

cPluginOpenmhp::~cPluginOpenmhp()
{
  // Clean up after yourself!
  delete setup;
  if (xlet) {
    delete(xlet);
    xlet = NULL;
    delete(setup);
    setup = NULL;
  }
}

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

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

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

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

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

cOsdObject *cPluginOpenmhp::MainMenuAction(void)
{
  // Perform the action when selected from the main VDR menu.
  if (xlet == NULL) {
    return new cOpenmhpMenu(this);
  }
  else {
    cXlet *x = xlet;
    xlet = NULL;
    return new cOpenmhpOsd(this, x);
  }
}

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

bool cPluginOpenmhp::SetupParse(const char *Name, const char *Value)
{
  // extern int DitheringEnabled;
  // Parse your own setup parameters and store their values.

  if (!strcasecmp(Name, "DitheringEnabled"))
    { setup->DitheringEnabled = atoi(Value); return true; }
  if (!strcasecmp(Name, "OsdBitdepth"))
    { setup->OsdBitdepth = atoi(Value); return true; }
  if (!strcasecmp(Name, "OsdScale"))
    { setup->OsdScale = atoi(Value); return true; }
  if (!strcasecmp(Name, "MhpCacheDir"))
    { strncpy(setup->MhpCacheDir, Value, MAXPATHLENGTH); return true; }
  if (!strcasecmp(Name, "VirtualXServer"))
    { setup->VirtualXServer = atoi(Value); return true; }
  if (!strcasecmp(Name, "VirtualXDisplay"))
    { setup->VirtualXDisplay = atoi(Value); return true; }
  if (!strcasecmp(Name, "OpenmhpOutput"))
    { setup->OpenmhpOutput = atoi(Value); return true; }
  
  return false;
}

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


// ------ cOpenmhpSetup class ------------------

cOpenmhpSetup::cOpenmhpSetup(void) {
  // default options:
  DitheringEnabled = false;
  OsdBitdepth = 1; // 8 bpp
  VirtualXServer = 0; // none
  VirtualXDisplay = 10;
  OpenmhpOutput = 0; // discard
  OsdScale = 100;
  MhpCacheDir = new char[MAXPATHLENGTH+1];
  strcpy(MhpCacheDir, "/video/plugins/mhp-cache/");
}

cOpenmhpSetup::~cOpenmhpSetup(void) {
  delete(MhpCacheDir);
}
