/*
 * osd.c: The actual menu implementations
 *
 * See the main source file 'vdr.c' for copyright information and
 * how to reach the author.
 *
 * $Id: 
 */
 
#include "osd.h" 
 
cMenuZappedChannels::cMenuZappedChannels(cChannelList *zChannels)
:cOsdMenu(tr("Zapping History"), CHNUMWIDTH)
{
	zappedChannels=zChannels;
  	Setup();
}

cMenuZappedChannels::~cMenuChannels()
{

}

void cMenuZappedChannels::Setup(void)
{
  cMenuChannelItem *currentItem = NULL;
  Clear();
  for (cChannel *channel = zappedChannels.First(); channel; channel = zappedChannels.Next(channel)) {
      if (!channel->GroupSep() || cMenuChannelItem::SortMode() == cMenuChannelItem::csmNumber && *channel->Name()) {
         cMenuChannelItem *item = new cMenuChannelItem(channel);
         Add(item);
         if (channel == currentChannel)
            currentItem = item;
         }
      }
  if (cMenuChannelItem::SortMode() != cMenuChannelItem::csmNumber)
     Sort();
  SetCurrent(currentItem);
  Display();
}

cChannel *cMenuZappedChannels::GetChannel(int Index)
{
  cMenuChannelItem *p = (cMenuChannelItem *)Get(Index);
  return p ? (cChannel *)p->Channel() : NULL;
}

eOSState cMenuZappedChannels::Switch(void)
{
  cChannel *ch = GetChannel(Current());
  if (ch)
     return cDevice::PrimaryDevice()->SwitchChannel(ch, true) ? osEnd : osContinue;
  return osEnd;
}

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

  switch (state) {
    default:
         if (state == osUnknown) {
            switch (Key) {
              case kOk:     return Switch();
              default: break;
              }
            }
    }
  return state;
} 
