/*
 * Archive.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/status.h>
#include <vdr/recording.h>

#include "myosd.h"
#include <string>

static const char *VERSION        = "0.0.2";
static const char *DESCRIPTION    = "Multimedia-Archive";
static const char *MAINMENUENTRY  = "Multimedia-Archive";


int  iFileformat    = 1;


class cPluginArchive : public cPlugin {
private:
 
public:
  cPluginArchive(void);
  virtual ~cPluginArchive();
  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);
  };

cPluginArchive::cPluginArchive(void)
{

}

cPluginArchive::~cPluginArchive()
{

}

const char *cPluginArchive::CommandLineHelp(void)
{

  return NULL;
}

bool cPluginArchive::ProcessArgs(int argc, char *argv[])
{

  return true;
}

bool cPluginArchive::Initialize(void)
{

  return true;
}

bool cPluginArchive::Start(void)
{
	

  return true;
}

void cPluginArchive::Stop(void)
{

}

void cPluginArchive::Housekeeping(void)
{

}

cOsdObject *cPluginArchive::MainMenuAction(void)
{
	// VDR ConfigDirectory bestimmen
	const char* MyConfigDir = cPlugin::ConfigDirectory();
	std::string MyPath = MyConfigDir;
	std::string MyPlug = "/archive/sort_archive";
	std::string PATH = MyPath + MyPlug + " " + MyPath + "/archive/archive";
	const char* RPATH = PATH.c_str();
	
	dsyslog("CONFIG: %s",RPATH);

	// Ausführung von sort_entries 
	// -> Erstellung von /tmp/sortbytitle und /tmp/sortbytitle
	system(RPATH);
	if (system(RPATH) != 0){
		Skins.Message(mtError, "ERROR: Kann sort_archive nicht ausführen");
		dsyslog("ERROR: Kann %s nicht ausfuehren!",RPATH);
  		return false;
	}else{
		dsyslog("INFO: %s wurde erfolgreich ausgefhrt!",RPATH);	
	}
	return new cMyOsd();
}

cMenuSetupPage *cPluginArchive::SetupMenu(void)
{
	
	return NULL; 
}

bool cPluginArchive::SetupParse(const char *Name, const char *Value)
{
   return false;
}

bool cPluginArchive::Service(const char *Id, void *Data)
{
   return false;
}

const char **cPluginArchive::SVDRPHelpPages(void)
{
   return NULL;
}

cString cPluginArchive::SVDRPCommand(const char *Command, const char *Option, int &ReplyCode)
{
  return NULL;
}

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