/*
 * $Id: status.c,v 1.2 2007/05/08 10:16:23 thomas Exp $
 */

#include <vdr/channels.h>

#include "status.h"
#include "control.h"
#include "event.h"

cStatusTaste::cStatusTaste(void):
    cStatus(),
    mLastChannel(0) // int
{
}

void cStatusTaste::ChannelSwitch(const cDevice *Device, int ChannelNumber)
{
  printf("cStatusTaste::ChannelSwitch(%p, %d)\n", Device, ChannelNumber);

	if ((Device == cDevice::ActualDevice()) && !Device->Replaying()) {
		if (mLastChannel == 0) { // Since starting VDR we didn't zap yet
			if (ChannelNumber != 0 && ChannelNumber == cDevice::CurrentChannel()) // Channelswitch has been done
				mLastChannel = ChannelNumber;
			return;
		}

		if (ChannelNumber == 0) { // Switch ist geplant
			mLastChannel = cDevice::CurrentChannel();
			return;
		}

		const cChannel *channel = Channels.GetByNumber(ChannelNumber);
		if (channel != NULL && !channel->GroupSep()) {
			cSchedulesLock schedLock;
			const cSchedules *scheds = cSchedules::Schedules(schedLock);
			if (scheds == NULL)
				return;

			const cSchedule *sched = scheds->GetSchedule(channel->GetChannelID());
			if (sched == NULL)
				return;

			const cEvent *present = sched->GetPresentEvent();
			const cEvent *follow  = sched->GetFollowingEvent();
			if (present == NULL)
				return;
			
			if (!cControlTaste::IsRequested() && !EventsTaste.Acceptable(present->Title())) {
				isyslog("channel %d is not acceptable at present", ChannelNumber);
				cControl::Launch(new cControlTaste(mLastChannel, channel, present, follow));
			}
		}
	}
}
  
