/*
 * burn.c: A plugin for the Video Disk Recorder
 *
 * See the files COPYING and README for copyright information and how to reach 
 * the author.
 *
 * $Id: burn.c,v 1.11 2006/05/16 17:30:07 lordjaxom Exp $
 */

#include "i18n.h"
#include "menuburn.h"
#include "setup.h"
#include "skins.h"
#include "manager.h"
#include "logger-vdr.h"
#include "proctools/format.h"
#include <string>
#include <vdr/plugin.h>
#include <vdr/videodir.h>
#include <vdr/config.h>

namespace vdr_burn
{

	using namespace std;
	using proctools::format;

	static const char *VERSION        = "0.1.0-pre13";
	static const char *DESCRIPTION    = "Versatile convert-and-burn plugin";
	static const char *MAINMENUENTRY  = "Write DVDs";

	class plugin: public cPlugin 
	{
	public:
		plugin(void);
		virtual ~plugin();

		virtual const char *Version(void) { return VERSION; }
		virtual const char *Description(void) { return tr(DESCRIPTION); }
		virtual const char *CommandLineHelp(void);
		virtual bool ProcessArgs(int argc, char *argv[]);
		virtual bool Start(void);
		virtual void Stop(void);
#ifndef APIVERSION
		virtual bool Active(void);
#else
		virtual cString Active(void);
#endif
		virtual const char *MainMenuEntry(void) { return tr(MAINMENUENTRY); }
		virtual cOsdObject *MainMenuAction(void);
		virtual cMenuSetupPage *SetupMenu(void);
		virtual bool SetupParse(const char *Name, const char *Value);
	};

	plugin::plugin(void) 
	{
	}

	plugin::~plugin() 
	{
	}

	const char *plugin::CommandLineHelp(void) 
	{
		static string help_str;

		if (help_str.empty())
			help_str = format(
				 "  -t DIR,   --tempdir=DIR   use DIR for temporary files\n"
				 "                            MUST be on UNIX filesystem\n"
				 "                            (default: {0})\n"
				 "  -d DIR,   --datadir=DIR   use DIR for temporary datafiles\n"
				 "                            (default: {1})\n"
				 "  -D DEV    --dvd=DEV       use DEV as DVD Writer\n"
				 "                            (default: {2})\n"
				 "  -i DIR    --iso=DIR       use DIR to store ISO images\n"
				 "                            (default: {3})\n"
				 ) % BurnParameters.TempPath % BurnParameters.DataPath
				   % BurnParameters.DvdDevice % BurnParameters.IsoPath;

		return help_str.c_str();
	}

	bool plugin::ProcessArgs(int argc, char *argv[]) 
	{
		return BurnParameters.ProcessArgs(argc, argv);
	}

	bool plugin::Start(void) 
	{
		manager::start();
		logger_vdr::start();
		RegisterI18n(i18n::get_phrases());
		return skin_list::get().load(ConfigDirectory("burn"));
	}

	void plugin::Stop(void)
	{
		manager::stop();
		logger_vdr::stop();
	}

#ifndef APIVERSION
	bool plugin::Active(void) 
#else
	cString plugin::Active(void)
#endif
	{
#ifndef APIVERSION
		return manager::get_is_busy();
#else
		if (manager::get_is_busy())
			return tr("Burn job active");
		return 0;
#endif
	}

	cOsdObject *plugin::MainMenuAction(void) 
	{
		return new menu::starter;
	}

	cMenuSetupPage *plugin::SetupMenu(void) 
	{
		return new cBurnMenuSetupPage;
	}

	bool plugin::SetupParse(const char *Name, const char *Value) 
	{
		return BurnSetup.SetupParse(Name, Value);
	}

}

VDRPLUGINCREATOR(vdr_burn::plugin); // Don't touch this!
