2013-01-17 13:16:44 +01:00
|
|
|
#include "channelcolumn.h"
|
|
|
|
|
2013-05-20 11:37:37 +02:00
|
|
|
cChannelColumn::cChannelColumn(int num, const cChannel *channel, cMyTime *myTime) {
|
2013-05-26 11:38:05 +02:00
|
|
|
this->channel = channel;
|
|
|
|
this->num = num;
|
|
|
|
this->myTime = myTime;
|
|
|
|
hasTimer = channel->HasTimer();
|
2013-05-26 12:00:02 +02:00
|
|
|
schedulesLock = new cSchedulesLock(false, 100);
|
2013-05-31 13:58:22 +02:00
|
|
|
header = NULL;
|
2013-01-17 13:16:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cChannelColumn::~cChannelColumn(void) {
|
2013-05-31 13:58:22 +02:00
|
|
|
if (header)
|
|
|
|
delete header;
|
2013-05-26 11:38:05 +02:00
|
|
|
grids.Clear();
|
2013-05-20 11:37:37 +02:00
|
|
|
delete schedulesLock;
|
2013-01-17 13:16:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void cChannelColumn::clearGrids() {
|
2013-05-26 11:38:05 +02:00
|
|
|
grids.Clear();
|
2013-01-17 13:16:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void cChannelColumn::createHeader() {
|
2013-05-20 11:37:37 +02:00
|
|
|
header = new cHeaderGrid();
|
|
|
|
header->createBackground(num);
|
|
|
|
header->drawChannel(channel);
|
2013-01-17 13:16:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void cChannelColumn::drawHeader() {
|
2013-05-20 11:37:37 +02:00
|
|
|
header->setPosition(num);
|
2013-01-17 13:16:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cChannelColumn::readGrids() {
|
2013-05-20 11:37:37 +02:00
|
|
|
schedules = cSchedules::Schedules(*schedulesLock);
|
2013-05-26 11:38:05 +02:00
|
|
|
const cSchedule *Schedule = NULL;
|
|
|
|
Schedule = schedules->GetSchedule(channel);
|
|
|
|
if (!Schedule) {
|
2013-05-20 11:37:37 +02:00
|
|
|
addDummyGrid(myTime->GetStart(), myTime->GetEnd(), NULL, false);
|
|
|
|
return true;
|
2013-05-26 11:38:05 +02:00
|
|
|
}
|
|
|
|
bool eventFound = false;
|
2013-05-20 11:37:37 +02:00
|
|
|
bool dummyAtStart = false;
|
2013-05-26 11:38:05 +02:00
|
|
|
const cEvent *startEvent = Schedule->GetEventAround(myTime->GetStart());
|
|
|
|
if (startEvent != NULL) {
|
|
|
|
eventFound = true;
|
|
|
|
} else {
|
|
|
|
for (int i=1; i<6; i++) {
|
|
|
|
startEvent = Schedule->GetEventAround(myTime->GetStart()+i*5*60);
|
|
|
|
if (startEvent) {
|
|
|
|
eventFound = true;
|
2013-05-20 11:37:37 +02:00
|
|
|
dummyAtStart = true;
|
2013-05-26 11:38:05 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (eventFound) {
|
|
|
|
bool col = true;
|
2013-05-20 11:37:37 +02:00
|
|
|
if (dummyAtStart) {
|
|
|
|
addDummyGrid(myTime->GetStart(), startEvent->StartTime(), NULL, col);
|
|
|
|
col = !col;
|
|
|
|
}
|
|
|
|
bool dummyNeeded = true;
|
|
|
|
bool toFarInFuture = false;
|
|
|
|
time_t endLast = myTime->GetStart();
|
|
|
|
const cEvent *event = startEvent;
|
|
|
|
const cEvent *eventLast = NULL;
|
2013-05-26 11:38:05 +02:00
|
|
|
for (; event; event = Schedule->Events()->Next(event)) {
|
|
|
|
if (endLast < event->StartTime()) {
|
2013-05-20 11:37:37 +02:00
|
|
|
//gap, dummy needed
|
|
|
|
time_t endTime = event->StartTime();
|
|
|
|
if (endTime > myTime->GetEnd()) {
|
|
|
|
endTime = myTime->GetEnd();
|
|
|
|
toFarInFuture = true;
|
|
|
|
}
|
|
|
|
addDummyGrid(endLast, endTime, NULL, col);
|
|
|
|
col = !col;
|
|
|
|
}
|
|
|
|
if (toFarInFuture) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
addEpgGrid(event, NULL, col);
|
2013-05-26 11:38:05 +02:00
|
|
|
col = !col;
|
2013-05-20 11:37:37 +02:00
|
|
|
endLast = event->EndTime();
|
2013-05-26 11:38:05 +02:00
|
|
|
if (event->EndTime() > myTime->GetEnd()) {
|
2013-05-20 11:37:37 +02:00
|
|
|
dummyNeeded = false;
|
2013-05-26 11:38:05 +02:00
|
|
|
break;
|
|
|
|
}
|
2013-05-20 11:37:37 +02:00
|
|
|
eventLast = event;
|
2013-05-26 11:38:05 +02:00
|
|
|
}
|
2013-05-20 11:37:37 +02:00
|
|
|
if (dummyNeeded) {
|
|
|
|
addDummyGrid(eventLast->EndTime(), myTime->GetEnd(), NULL, col);
|
|
|
|
}
|
2013-05-26 11:38:05 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
2013-05-20 11:37:37 +02:00
|
|
|
addDummyGrid(myTime->GetStart(), myTime->GetEnd(), NULL, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2013-01-17 13:16:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void cChannelColumn::drawGrids() {
|
2013-05-26 11:38:05 +02:00
|
|
|
for (cGrid *grid = grids.First(); grid; grid = grids.Next(grid)) {
|
|
|
|
grid->SetViewportHeight();
|
|
|
|
grid->PositionPixmap();
|
|
|
|
grid->Draw();
|
|
|
|
}
|
2013-01-17 13:16:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int cChannelColumn::getX() {
|
2013-05-24 16:23:23 +02:00
|
|
|
return tvguideConfig.timeLineWidth + num*tvguideConfig.colWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cChannelColumn::getY() {
|
|
|
|
return tvguideConfig.statusHeaderHeight + tvguideConfig.timeLineHeight + num*tvguideConfig.rowHeight;
|
2013-01-17 13:16:44 +01:00
|
|
|
}
|
|
|
|
|
2013-05-20 11:37:37 +02:00
|
|
|
cGrid * cChannelColumn::getActive() {
|
2013-05-26 11:38:05 +02:00
|
|
|
cMyTime t;
|
|
|
|
t.Now();
|
|
|
|
for (cGrid *grid = grids.First(); grid; grid = grids.Next(grid)) {
|
|
|
|
if (grid->Match(t.Get()))
|
|
|
|
return grid;
|
|
|
|
}
|
|
|
|
return grids.First();
|
2013-01-17 13:16:44 +01:00
|
|
|
}
|
|
|
|
|
2013-05-20 11:37:37 +02:00
|
|
|
cGrid * cChannelColumn::getNext(cGrid *activeGrid) {
|
2013-05-26 11:38:05 +02:00
|
|
|
if (activeGrid == NULL)
|
|
|
|
return NULL;
|
|
|
|
cGrid *next = grids.Next(activeGrid);
|
|
|
|
if (next)
|
|
|
|
return next;
|
|
|
|
return NULL;
|
2013-01-17 13:16:44 +01:00
|
|
|
}
|
|
|
|
|
2013-05-20 11:37:37 +02:00
|
|
|
cGrid * cChannelColumn::getPrev(cGrid *activeGrid) {
|
2013-05-26 11:38:05 +02:00
|
|
|
if (activeGrid == NULL)
|
|
|
|
return NULL;
|
|
|
|
cGrid *prev = grids.Prev(activeGrid);
|
|
|
|
if (prev)
|
|
|
|
return prev;
|
|
|
|
return NULL;
|
2013-01-17 13:16:44 +01:00
|
|
|
}
|
|
|
|
|
2013-05-20 11:37:37 +02:00
|
|
|
cGrid * cChannelColumn::getNeighbor(cGrid *activeGrid) {
|
2013-05-26 11:38:05 +02:00
|
|
|
if (!activeGrid)
|
|
|
|
return NULL;
|
|
|
|
cGrid *neighbor = NULL;
|
|
|
|
int overlap = 0;
|
|
|
|
int overlapNew = 0;
|
|
|
|
cGrid *grid = NULL;
|
|
|
|
grid = grids.First();
|
|
|
|
if (grid) {
|
|
|
|
for (; grid; grid = grids.Next(grid)) {
|
|
|
|
if ( (grid->StartTime() == activeGrid->StartTime()) ) {
|
|
|
|
neighbor = grid;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
overlapNew = activeGrid->calcOverlap(grid);
|
|
|
|
if (overlapNew > overlap) {
|
|
|
|
neighbor = grid;
|
|
|
|
overlap = overlapNew;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!neighbor)
|
|
|
|
neighbor = grids.First();
|
|
|
|
return neighbor;
|
2013-01-17 13:16:44 +01:00
|
|
|
}
|
|
|
|
|
2013-05-20 11:37:37 +02:00
|
|
|
bool cChannelColumn::isFirst(cGrid *grid) {
|
|
|
|
if (grid == grids.First())
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-17 13:16:44 +01:00
|
|
|
void cChannelColumn::AddNewGridsAtStart() {
|
2013-05-26 11:38:05 +02:00
|
|
|
cGrid *firstGrid = NULL;
|
|
|
|
firstGrid = grids.First();
|
2013-05-20 11:37:37 +02:00
|
|
|
if (firstGrid == NULL)
|
2013-05-26 11:38:05 +02:00
|
|
|
return;
|
2013-05-20 11:37:37 +02:00
|
|
|
//if first event is long enough, nothing to do.
|
|
|
|
if (firstGrid->StartTime() <= myTime->GetStart()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//if not, i have to add new ones to the list
|
|
|
|
schedules = cSchedules::Schedules(*schedulesLock);
|
|
|
|
const cSchedule *Schedule = NULL;
|
|
|
|
Schedule = schedules->GetSchedule(channel);
|
|
|
|
if (!Schedule) {
|
|
|
|
if (firstGrid->isDummy()) {
|
|
|
|
firstGrid->SetStartTime(myTime->GetStart());
|
|
|
|
firstGrid->SetEndTime(myTime->GetEnd());
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bool col = !(firstGrid->IsColor1());
|
|
|
|
bool dummyNeeded = true;
|
2013-05-26 11:38:05 +02:00
|
|
|
for (const cEvent *event = Schedule->GetEventAround(firstGrid->StartTime()-60); event; event = Schedule->Events()->Prev(event)) {
|
|
|
|
if (!event)
|
|
|
|
break;
|
2013-05-20 11:37:37 +02:00
|
|
|
if (event->EndTime() < myTime->GetStart()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cGrid *grid = addEpgGrid(event, firstGrid, col);
|
|
|
|
col = !col;
|
|
|
|
firstGrid = grid;
|
2013-05-26 11:38:05 +02:00
|
|
|
if (event->StartTime() <= myTime->GetStart()) {
|
2013-05-20 11:37:37 +02:00
|
|
|
dummyNeeded = false;
|
2013-05-26 11:38:05 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-05-20 11:37:37 +02:00
|
|
|
if (dummyNeeded) {
|
|
|
|
firstGrid = grids.First();
|
|
|
|
if (firstGrid->isDummy()) {
|
|
|
|
firstGrid->SetStartTime(myTime->GetStart());
|
|
|
|
if (firstGrid->EndTime() >= myTime->GetEnd())
|
|
|
|
firstGrid->SetEndTime(myTime->GetEnd());
|
|
|
|
} else {
|
|
|
|
addDummyGrid(myTime->GetStart(), firstGrid->StartTime(), firstGrid, col);
|
|
|
|
}
|
|
|
|
}
|
2013-01-17 13:16:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void cChannelColumn::AddNewGridsAtEnd() {
|
2013-05-26 11:38:05 +02:00
|
|
|
cGrid *lastGrid = NULL;
|
|
|
|
lastGrid = grids.Last();
|
|
|
|
if (lastGrid == NULL)
|
|
|
|
return;
|
2013-05-20 11:37:37 +02:00
|
|
|
//if last event is long enough, nothing to do.
|
2013-05-26 11:38:05 +02:00
|
|
|
if (lastGrid->EndTime() >= myTime->GetEnd()) {
|
2013-05-20 11:37:37 +02:00
|
|
|
return;
|
2013-05-26 11:38:05 +02:00
|
|
|
}
|
|
|
|
//if not, i have to add new ones to the list
|
|
|
|
schedules = cSchedules::Schedules(*schedulesLock);
|
|
|
|
const cSchedule *Schedule = NULL;
|
|
|
|
Schedule = schedules->GetSchedule(channel);
|
|
|
|
if (!Schedule) {
|
2013-05-20 11:37:37 +02:00
|
|
|
if (lastGrid->isDummy()) {
|
|
|
|
lastGrid->SetStartTime(myTime->GetStart());
|
|
|
|
lastGrid->SetEndTime(myTime->GetEnd());
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2013-05-26 11:38:05 +02:00
|
|
|
bool col = !(lastGrid->IsColor1());
|
2013-05-20 11:37:37 +02:00
|
|
|
bool dummyNeeded = true;
|
2013-05-26 11:38:05 +02:00
|
|
|
for (const cEvent *event = Schedule->GetEventAround(lastGrid->EndTime()+60); event; event = Schedule->Events()->Next(event)) {
|
|
|
|
if (!event)
|
|
|
|
break;
|
2013-05-20 11:37:37 +02:00
|
|
|
if (event->StartTime() > myTime->GetEnd()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
addEpgGrid(event, NULL, col);
|
|
|
|
col = !col;
|
2013-05-26 11:38:05 +02:00
|
|
|
if (event->EndTime() > myTime->GetEnd()) {
|
2013-05-20 11:37:37 +02:00
|
|
|
dummyNeeded = false;
|
2013-05-26 11:38:05 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-05-20 11:37:37 +02:00
|
|
|
if (dummyNeeded) {
|
|
|
|
lastGrid = grids.Last();
|
|
|
|
if (lastGrid->isDummy()) {
|
|
|
|
lastGrid->SetEndTime(myTime->GetEnd());
|
|
|
|
if (lastGrid->StartTime() <= myTime->GetStart())
|
|
|
|
lastGrid->SetStartTime(myTime->GetStart());
|
|
|
|
} else {
|
|
|
|
addDummyGrid(lastGrid->EndTime(), myTime->GetEnd(), NULL, col);
|
|
|
|
}
|
|
|
|
}
|
2013-01-17 13:16:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void cChannelColumn::ClearOutdatedStart() {
|
2013-05-26 11:38:05 +02:00
|
|
|
cGrid *firstGrid = NULL;
|
|
|
|
while (true) {
|
|
|
|
firstGrid = grids.First();
|
2013-05-20 11:37:37 +02:00
|
|
|
if (!firstGrid)
|
|
|
|
break;
|
2013-05-26 11:38:05 +02:00
|
|
|
if (firstGrid->EndTime() <= myTime->GetStart()) {
|
2013-05-20 11:37:37 +02:00
|
|
|
grids.Del(firstGrid);
|
|
|
|
firstGrid = NULL;
|
2013-05-26 11:38:05 +02:00
|
|
|
} else {
|
2013-05-20 11:37:37 +02:00
|
|
|
if (firstGrid->isDummy()) {
|
|
|
|
firstGrid->SetStartTime(myTime->GetStart());
|
|
|
|
cGrid *next = getNext(firstGrid);
|
|
|
|
if (next) {
|
|
|
|
firstGrid->SetEndTime(next->StartTime());
|
|
|
|
} else {
|
|
|
|
firstGrid->SetEndTime(myTime->GetEnd());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2013-05-26 11:38:05 +02:00
|
|
|
}
|
|
|
|
}
|
2013-01-17 13:16:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void cChannelColumn::ClearOutdatedEnd() {
|
2013-05-26 11:38:05 +02:00
|
|
|
cGrid *lastGrid = NULL;
|
|
|
|
while (true) {
|
|
|
|
lastGrid = grids.Last();
|
2013-05-20 11:37:37 +02:00
|
|
|
if (!lastGrid)
|
|
|
|
break;
|
|
|
|
if (lastGrid->StartTime() >= myTime->GetEnd()) {
|
|
|
|
grids.Del(lastGrid);
|
|
|
|
lastGrid = NULL;
|
2013-05-26 11:38:05 +02:00
|
|
|
} else {
|
2013-05-20 11:37:37 +02:00
|
|
|
if (lastGrid->isDummy()) {
|
|
|
|
lastGrid->SetEndTime(myTime->GetEnd());
|
|
|
|
cGrid *prev = getPrev(lastGrid);
|
|
|
|
if (prev) {
|
|
|
|
lastGrid->SetStartTime(prev->EndTime());
|
|
|
|
} else {
|
|
|
|
lastGrid->SetStartTime(myTime->GetStart());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2013-05-26 11:38:05 +02:00
|
|
|
}
|
|
|
|
}
|
2013-01-17 13:16:44 +01:00
|
|
|
}
|
|
|
|
|
2013-05-20 11:37:37 +02:00
|
|
|
cGrid *cChannelColumn::addEpgGrid(const cEvent *event, cGrid *firstGrid, bool color) {
|
|
|
|
cGrid *grid = new cEpgGrid(this, event);
|
|
|
|
grid->setText();
|
|
|
|
grid->SetColor(color);
|
|
|
|
if (!firstGrid)
|
|
|
|
grids.Add(grid);
|
|
|
|
else
|
|
|
|
grids.Ins(grid, firstGrid);
|
|
|
|
return grid;
|
2013-01-17 13:16:44 +01:00
|
|
|
}
|
2013-05-20 11:37:37 +02:00
|
|
|
|
|
|
|
cGrid *cChannelColumn::addDummyGrid(time_t start, time_t end, cGrid *firstGrid, bool color) {
|
|
|
|
cGrid *dummy = new cDummyGrid(this, start, end);
|
|
|
|
dummy->setText();
|
|
|
|
dummy->SetColor(color);
|
|
|
|
if (!firstGrid)
|
|
|
|
grids.Add(dummy);
|
|
|
|
else
|
|
|
|
grids.Ins(dummy, firstGrid);
|
|
|
|
return dummy;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cChannelColumn::dumpGrids() {
|
2013-05-26 11:38:05 +02:00
|
|
|
esyslog("tvguide: ------Channel %s: %d entires ---------", channel->Name(), grids.Count());
|
2013-05-20 11:37:37 +02:00
|
|
|
int i=1;
|
2013-05-26 11:38:05 +02:00
|
|
|
for (cGrid *grid = grids.First(); grid; grid = grids.Next(grid)) {
|
|
|
|
esyslog("tvguide: grid %d: start: %s, stop: %s", i, *cMyTime::printTime(grid->StartTime()), *cMyTime::printTime(grid->EndTime()));
|
2013-05-20 11:37:37 +02:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|