#include <math.h>
#include "mywhatsonitem.h"

myWhatsOnItem::myWhatsOnItem(const cEvent *Event,cChannel *Channel,bool next)
{
 event=Event;
 channel=Channel;
 char *buffer = NULL,t;
 int TimerMatch,i;

 cTimer *timer=Timers.GetMatch(Event,&TimerMatch);
 if(TimerMatch!=tmNone)
 {
  if(timer->Recording())t=char(128);
  else t=char(129);
 }
 else t=' ';

 int progress=(int)roundf((float)(time(NULL)-event->StartTime())/(float)(event->Duration())*8.0);
 if(progress<0)progress=0;
 else if(progress>7)progress=8;

 char ProgressBar[9]={' ',' ',' ',' ',' ',' ',' ',' ',0};
 for(i=0;i<progress;i++)ProgressBar[i]=127;

 asprintf(&buffer,"%-10s\t %s\t%c\t%s",channel->ShortName(true),next?*event->GetTimeString():ProgressBar,t,event->Title());
 SetText(buffer, false);
}
