#include "ttxtsubschannelsettings.h"

#include <vdr/menuitems.h>
#include <vdr/device.h>

#include "ttxtsubspagemenu.h"
#include "ttxtsubsi18n.h"

const char * MODE_CHOICES[4] = {NULL, NULL, NULL, NULL};

cTtxtsubsPageMenu::~cTtxtsubsPageMenu()
{
    cTtxtSubsChannelSettings::GetInstance().SetChannelSetting(
      mChannelId, mPageMode, mPageNumber);
}

cTtxtsubsPageMenu::cTtxtsubsPageMenu()
  :cOsdMenu(tr("Subtitle Page Settings"), 30)
{
    TtxtSubsChannelSetting setting;

    cDevice *device = cDevice::ActualDevice();
    cChannel *ch = Channels.GetByNumber(device->CurrentChannel());
    mChannelId = ch->Sid();
    
    setting = cTtxtSubsChannelSettings::GetInstance().GetChannelSetting(
      mChannelId);

    mPageMode = setting.PageMode;
    mPageNumber = setting.PageNumber;

    MODE_CHOICES[0] = tr("Auto");
    MODE_CHOICES[1] = tr("Manual");
    MODE_CHOICES[2] = tr("Disabled");
    MODE_CHOICES[3] = NULL;

    Add(new cMenuEditStraItem(tr("Subtitle Mode"), &mPageMode, 3, MODE_CHOICES ));
    Add(new cMenuEditIntItem(tr("Manual Subtitle Page"), &mPageNumber, 1, 999));

    Display();
};

eOSState cTtxtsubsPageMenu::ProcessKey(eKeys Key)
{
    eOSState state = cOsdMenu::ProcessKey(Key);

    if (state == osUnknown) 
    {
        if (Key == kOk) 
        {
            state = osBack;
         }
     }

    return state;
}
