/*
 * setuploadandsave.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 <vdr/config.h>
#include <vdr/device.h>

static const char *VERSION        = "0.0.1";
static const char *DESCRIPTION    = "save and load the setup.conf";
static const char *MAINMENUENTRY  = NULL;

class cPluginSetuploadandsave : public cPlugin {
private:
  // Add any member variables or functions you may need here.
public:
  cPluginSetuploadandsave(void);
  virtual ~cPluginSetuploadandsave();
  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 Initialize(void);
  virtual bool Start(void);
  virtual void Stop(void);
  virtual void Housekeeping(void);
  virtual const char *MainMenuEntry(void) { return MAINMENUENTRY; }
  virtual cOsdObject *MainMenuAction(void);
  virtual cMenuSetupPage *SetupMenu(void);
  virtual bool SetupParse(const char *Name, const char *Value);
  virtual bool Service(const char *Id, void *Data = NULL);
  virtual const char **SVDRPHelpPages(void);
  virtual cString SVDRPCommand(const char *Command, const char *Option, int &ReplyCode);
  };

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

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

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

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

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

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

void cPluginSetuploadandsave::Stop(void)
{
  // Stop any background activities the plugin shall perform.
}

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

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

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

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

bool cPluginSetuploadandsave::Service(const char *Id, void *Data)
{
  // Handle custom service requests from other plugins
  return false;
}

const char **cPluginSetuploadandsave::SVDRPHelpPages(void)
{
  static const char *HelpPages[] = {
    "SAVE\n"
    "    save the setup.conf.",
    "LOAD\n"
    "    load the setup.conf.",
    NULL
    };
  return HelpPages;
}

cString cPluginSetuploadandsave::SVDRPCommand(const char *Command, const char *Option, int &ReplyCode)
{
  if (strcasecmp(Command, "SAVE") == 0) {
     ReplyCode = 901;
     Setup.CurrentChannel = cDevice::CurrentChannel();
     Setup.CurrentVolume  = cDevice::CurrentVolume();
     Setup.Save();
     return cString::sprintf("setup is saved as: %s", Setup.FileName());
     }
  else if (strcasecmp(Command, "LOAD") == 0) {
     ReplyCode = 902;
     Setup.Load(Setup.FileName());
//   cFont::SetCode(I18nCharSets()[Setup.OSDLanguage]);
//   Skins.SetCurrent(Setup.OSDSkin);
//   cThemes::Load(Skins.Current()->Name(), Setup.OSDTheme, Skins.Current()->Theme());
     return cString::sprintf("setup is loaded from: %s", Setup.FileName());
     }
  return NULL;
}

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