/*
 * menu.c: Configuration menu
 *
 * $Id: menu.c,v 1.1 2005/02/15 10:08:00 opj Exp $
 */


#include "menu.h"
#include "configuration.h"
#include <vdr/menuitems.h>

// Modified from Teletext subtitles

class cMenuSetupDvbSubs : public cMenuSetupPage {
 public:
  cMenuSetupDvbSubs();
 protected:
  virtual void Store(void);
  virtual eOSState ProcessKey(eKeys Key);
 private:
  virtual void Setup(void);
  int sync;
};


cMenuSetupPage *GetSetup()
{
    return new cMenuSetupDvbSubs();
}

cMenuSetupDvbSubs::cMenuSetupDvbSubs()
{

  Setup();
}

void cMenuSetupDvbSubs::Setup(void)
{

  int current = Current();

  if (gSubtitlesConfiguration.language >= I18nNumLanguages )
    gSubtitlesConfiguration.language = I18nNumLanguages-1;
  if (gSubtitlesConfiguration.language < 0)
    gSubtitlesConfiguration.language = 0;

  if (gSubtitlesConfiguration.language2 >= I18nNumLanguages )
    gSubtitlesConfiguration.language2 = I18nNumLanguages-1;
  if (gSubtitlesConfiguration.language2 < 0)
    gSubtitlesConfiguration.language2 = 0;

  Clear();
  Add(new cMenuEditBoolItem(tr("Subtitles Enabled"), &gSubtitlesConfiguration.enabled, tr("no"), tr("yes")));
  Add(new cMenuEditStraItem(tr("Primary Language"), &gSubtitlesConfiguration.language, 
			    I18nNumLanguages, I18nLanguages()));
  Add(new cMenuEditStraItem(tr("Secondary Language"), &gSubtitlesConfiguration.language2, 
			    I18nNumLanguages, I18nLanguages()));
//  Add(new cMenuEditBoolItem(tr("Hearing Impaired"), &gSubtitlesConfiguration.hearingImpaired, tr("no"), tr("yes")));
//  Add(new cMenuEditBoolItem(tr("Video format"), &gSubtitlesConfiguration.widescreen, "4:3","16:9"));
  if (gSubtitlesConfiguration.enabled)
  {
    Add(new cMenuEditBoolItem(tr("Synchronization"), &gSubtitlesConfiguration.sync));
    if (gSubtitlesConfiguration.sync==0)
    {
      Add(new cMenuEditIntItem(tr("Delay"), &gSubtitlesConfiguration.delay, -5, 10));
    }
    Add(new cMenuEditIntItem(tr("Offset"), &gSubtitlesConfiguration.offset, -50, 50));
  }
  Add(new cMenuEditBoolItem(tr("Record Subtitles"), &gSubtitlesConfiguration.recording, tr("no"), tr("yes")));

  Add(new cMenuEditBoolItem(tr("DXR3 Compability"), &gSubtitlesConfiguration.dxr3comp, tr("no"), tr("yes")));
  Add(new cMenuEditBoolItem(tr("Show Language Selector"), &gSubtitlesConfiguration.mainmenu, tr("no"), tr("yes")));
  Add(new cMenuEditIntItem(tr("Background Transparency"), &gSubtitlesConfiguration.bgTransparency, 0, 10));
  Add(new cMenuEditIntItem(tr("Foreground Transparency"), &gSubtitlesConfiguration.fgTransparency, 0, 9));

  SetCurrent(Get(current));
  Display();

}
eOSState  cMenuSetupDvbSubs::ProcessKey(eKeys Key)
{
    int oldEnabled = gSubtitlesConfiguration.enabled;
    int oldSync = gSubtitlesConfiguration.sync;

    eOSState state = cMenuSetupPage::ProcessKey(Key);

    if (Key != kNone && (gSubtitlesConfiguration.enabled != oldEnabled ||
			 gSubtitlesConfiguration.sync != oldSync))
	Setup();

    return state;

}
void cMenuSetupDvbSubs::Store(void)
{
  SetupStore("Language", gSubtitlesConfiguration.language);
  SetupStore("HearingImpaired", gSubtitlesConfiguration.hearingImpaired);
  SetupStore("VideoFormat", gSubtitlesConfiguration.widescreen);
  SetupStore("Record", gSubtitlesConfiguration.recording);
  SetupStore("Enabled", gSubtitlesConfiguration.enabled);
  SetupStore("Offset", gSubtitlesConfiguration.offset);
  SetupStore("Sync", gSubtitlesConfiguration.sync);
  SetupStore("Delay", gSubtitlesConfiguration.delay);
  SetupStore("Language2",gSubtitlesConfiguration.language2);
  SetupStore("Mainmenu", gSubtitlesConfiguration.mainmenu);
  SetupStore("Dxr3comp", gSubtitlesConfiguration.dxr3comp);
  SetupStore("BackgroundTransparency", gSubtitlesConfiguration.bgTransparency);
  SetupStore("ForegroundTransparency", gSubtitlesConfiguration.fgTransparency);
}
