/*
 * subtitles.c: A plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id: subtitles.c,v 1.5 2006/01/21 12:51:50 opj Exp $
 */

#include <map>
#include <vdr/plugin.h>
#include <vdr/device.h>
#include <vdr/i18n.h>
#include <vdr/tools.h>
#include <vdr/config.h> // VDRVERSION
#include "subfilter.h"
#include "configuration.h"
#include "i18n.h"
#include "menu.h"

static const char *VERSION        = "0.3.11";
static const char *DESCRIPTION    = "DVB subtitles decoder";

static const char *MAINMENUENTRY  = "Choose Language (DVB Subtitles)";

#if VDRVERSNUM && VDRVERSNUM < 10325
#error "This version of DVB subtitles only works with vdr  version >= 1.3.25"
#endif

class cOsdObject;
class cMenuSetupPage;

class cPluginSubtitles : public cPlugin
{
private:
  // Add any member variables or functions you may need here.

  cSubFilter* iFilters[MAXDEVICES];

public:
  cPluginSubtitles(void);
  virtual ~cPluginSubtitles();
  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 Housekeeping(void);
  virtual const char *MainMenuEntry(void) { return (gSubtitlesConfiguration.mainmenu>0?tr(MAINMENUENTRY):NULL); }
  virtual cOsdObject *MainMenuAction(void);
  virtual cMenuSetupPage *SetupMenu(void);
  virtual bool SetupParse(const char *Name, const char *Value);

  };

cPluginSubtitles::cPluginSubtitles(void)
{

    for (int i = 0; i < MAXDEVICES; i++)
    {
	iFilters[i] = NULL;
    }
  // 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!
}

cPluginSubtitles::~cPluginSubtitles()
{
  // Clean up after yourself!ss

    SaveChannels();

    for (int i=0; i < MAXDEVICES; i++)
    {
	DELETENULL(iFilters[i]);
    }
  
}

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

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

bool cPluginSubtitles::Start(void)
{

  RegisterI18n(Phrases);

  

  LoadChannels(AddDirectory(ConfigDirectory(),"subchannels.conf"));
  
  // Start any background activities the plugin shall perform.

  for (int i= 0; i < cDevice::NumDevices();i++)
  {
      iFilters[i] = new cSubFilter();
      cDevice *device = cDevice::GetDevice(i);
      device->AttachFilter(iFilters[i]);
  }
  return true;

}

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

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

}

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

bool cPluginSubtitles::SetupParse(const char *Name, const char *Value)
{
    return gSubtitlesConfiguration.Parse(Name,Value);
}
VDRPLUGINCREATOR(cPluginSubtitles); // Don't touch this!
