#include "mymenuevent.h"

extern int keeposd;

myMenuEvent::myMenuEvent(myWhatsOnItem *Item):cOsdMenu(tr("Event"))
{
 item=Item;
 event = item->event;
 if(event)
 {
  cChannel *channel=Channels.GetByChannelID(event->ChannelID(),true);
  if(channel)
  {
   SetTitle(channel->Name());
   SetHelp(tr("Record"), NULL, NULL, tr("Switch"));
  }
 }
}

void myMenuEvent::Display(void)
{
 cOsdMenu::Display();
 DisplayMenu()->SetEvent(event);
 cStatus::MsgOsdTextItem(event->Description());
}

eOSState myMenuEvent::Switch(void)
{
 if (item)
 {
  cChannel *channel = Channels.GetByChannelID(item->event->ChannelID(), true);
  if(channel && cDevice::PrimaryDevice()->SwitchChannel(channel, true))return keeposd?osContinue:osEnd;
 }
 Skins.Message(mtError, tr("Can't switch channel!"));
 return osContinue;
}

eOSState myMenuEvent::Record(void)
{
  if (item) {
     cTimer *timer = new cTimer(item->event);
     cTimer *t = Timers.GetTimer(timer);
     if (t) {
        delete timer;
        timer = t;
        }
     return AddSubMenu(new cMenuEditTimer(timer, !t));
     }
  return osContinue;
}

eOSState myMenuEvent::ProcessKey(eKeys Key)
{
 switch(Key)
 {
  case kUp|k_Repeat:
  case kUp:
  case kDown|k_Repeat:
  case kDown:
  case kLeft|k_Repeat:
  case kLeft:
  case kRight|k_Repeat:
  case kRight:
   DisplayMenu()->Scroll(NORMALKEY(Key)==kUp||NORMALKEY(Key)==kLeft,NORMALKEY(Key)==kLeft||NORMALKEY(Key)==kRight);
   cStatus::MsgOsdTextItem(NULL,NORMALKEY(Key)==kUp);
   return osContinue;
  default: break;
 }

 eOSState state = cOsdMenu::ProcessKey(Key);

 if(state==osUnknown)
 {
  switch(Key)
  {
   case kRecord:
   case kRed:return Record();
   case kBlue:return Switch();
   case kGreen:
   case kYellow:return osContinue;
   case kOk:return osBack;
   default:break;
  }
 }
 return state;
}
