summaryrefslogtreecommitdiff
path: root/channelcolumn.c
diff options
context:
space:
mode:
authorlouis <louis.braun@gmx.de>2013-05-20 11:37:37 +0200
committerlouis <louis.braun@gmx.de>2013-05-20 11:37:37 +0200
commitc611e004582067640111ef2f023410025201157d (patch)
tree3a71e9893bffa4bf9d38c49389dad5f43d046ec3 /channelcolumn.c
parent063094f442c0ac3c592d2e5bb5c416d6820d2602 (diff)
downloadvdr-plugin-tvguide-c611e004582067640111ef2f023410025201157d.tar.gz
vdr-plugin-tvguide-c611e004582067640111ef2f023410025201157d.tar.bz2
rewrote epg grid handling and scrolling, added status header
Diffstat (limited to 'channelcolumn.c')
-rw-r--r--channelcolumn.c348
1 files changed, 204 insertions, 144 deletions
diff --git a/channelcolumn.c b/channelcolumn.c
index 5590ce3..ef6e555 100644
--- a/channelcolumn.c
+++ b/channelcolumn.c
@@ -1,15 +1,17 @@
#include "channelcolumn.h"
-cChannelColumn::cChannelColumn(int num, cChannel *channel, cMyTime *myTime) {
+cChannelColumn::cChannelColumn(int num, const cChannel *channel, cMyTime *myTime) {
this->channel = channel;
this->num = num;
this->myTime = myTime;
hasTimer = channel->HasTimer();
+ schedulesLock = new cSchedulesLock(true, 100);
}
cChannelColumn::~cChannelColumn(void) {
- osdManager.releasePixmap(pixmapLogo, cString::sprintf("channelcolumn logo %s", channel->Name()));
+ delete header;
grids.Clear();
+ delete schedulesLock;
}
void cChannelColumn::clearGrids() {
@@ -17,94 +19,85 @@ void cChannelColumn::clearGrids() {
}
void cChannelColumn::createHeader() {
- color = theme.Color(clrHeader);
- colorBlending = theme.Color(clrHeaderBlending);
- caller = cString::sprintf("channelcolumn %s", channel->Name());
- pixmap = osdManager.requestPixmap(2, cRect(tvguideConfig.timeColWidth + num*tvguideConfig.colWidth, 0, tvguideConfig.colWidth, tvguideConfig.headerHeight),
- cRect::Null, *caller);
- if (!pixmap) {
- return;
- }
- pixmapLogo = osdManager.requestPixmap(3, cRect(tvguideConfig.timeColWidth + num*tvguideConfig.colWidth, 0, tvguideConfig.colWidth, tvguideConfig.headerHeight),
- cRect::Null, *caller);
- if (!pixmapLogo) {
- return;
- }
- pixmapLogo->Fill(clrTransparent);
-
- drawBackground();
- cTextWrapper tw;
- cString headerText = cString::sprintf("%d - %s", channel->Number(), channel->Name());
- tw.Set(*headerText, tvguideConfig.FontHeader, tvguideConfig.colWidth - 8);
- int lines = tw.Lines();
- int lineHeight = tvguideConfig.FontHeader->Height();
- int yStart = (tvguideConfig.headerHeight - lines*lineHeight)/2 + 8;
-
- if (!tvguideConfig.hideChannelLogos) {
- cImageLoader imgLoader;
- if (imgLoader.LoadLogo(channel->Name())) {
- cImage logo = imgLoader.GetImage();
- int logoX = (tvguideConfig.colWidth - tvguideConfig.logoWidth)/2;
- pixmapLogo->DrawImage(cPoint(logoX, 5), logo);
- }
- yStart = tvguideConfig.logoHeight + 8;
- }
- for (int i=0; i<lines; i++) {
- int textWidth = tvguideConfig.FontHeader->Width(tw.GetLine(i));
- int xText = (tvguideConfig.colWidth - textWidth) / 2;
- if (xText < 0)
- xText = 0;
- pixmap->DrawText(cPoint(xText, yStart + i*lineHeight), tw.GetLine(i), theme.Color(clrFontHeader), clrTransparent, tvguideConfig.FontHeader);
- }
- drawBorder();
+ header = new cHeaderGrid();
+ header->createBackground(num);
+ header->drawChannel(channel);
}
void cChannelColumn::drawHeader() {
- pixmap->SetViewPort(cRect(tvguideConfig.timeColWidth + num*tvguideConfig.colWidth, 0, tvguideConfig.colWidth, tvguideConfig.headerHeight));
- pixmapLogo->SetViewPort(cRect(tvguideConfig.timeColWidth + num*tvguideConfig.colWidth, 0, tvguideConfig.colWidth, tvguideConfig.headerHeight));
+ header->setPosition(num);
}
bool cChannelColumn::readGrids() {
- schedules = cSchedules::Schedules(schedulesLock);
+ schedules = cSchedules::Schedules(*schedulesLock);
const cSchedule *Schedule = NULL;
Schedule = schedules->GetSchedule(channel);
if (!Schedule) {
- return false;
+ addDummyGrid(myTime->GetStart(), myTime->GetEnd(), NULL, false);
+ return true;
}
bool eventFound = false;
- const cEvent *event = Schedule->GetEventAround(myTime->GetStart());
- if (event != NULL) {
+ bool dummyAtStart = false;
+ const cEvent *startEvent = Schedule->GetEventAround(myTime->GetStart());
+ if (startEvent != NULL) {
eventFound = true;
} else {
for (int i=1; i<6; i++) {
- event = Schedule->GetEventAround(myTime->GetStart()+i*5*60);
- if (event) {
+ startEvent = Schedule->GetEventAround(myTime->GetStart()+i*5*60);
+ if (startEvent) {
eventFound = true;
+ dummyAtStart = true;
break;
}
}
}
if (eventFound) {
bool col = true;
+ 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;
for (; event; event = Schedule->Events()->Next(event)) {
- cEpgGrid *grid = new cEpgGrid(this, event);
- grid->setText();
- grid->SetColor(col);
+ if (endLast < event->StartTime()) {
+ //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);
col = !col;
- grids.Add(grid);
- if (event->EndTime() > myTime->GetStop()) {
+ endLast = event->EndTime();
+ if (event->EndTime() > myTime->GetEnd()) {
+ dummyNeeded = false;
break;
}
+ eventLast = event;
}
+ if (dummyNeeded) {
+ addDummyGrid(eventLast->EndTime(), myTime->GetEnd(), NULL, col);
+ }
return true;
} else {
- return false;
- }
-
+ addDummyGrid(myTime->GetStart(), myTime->GetEnd(), NULL, false);
+ return true;
+ }
+ return false;
}
void cChannelColumn::drawGrids() {
- for (cEpgGrid *grid = grids.First(); grid; grid = grids.Next(grid)) {
+ for (cGrid *grid = grids.First(); grid; grid = grids.Next(grid)) {
grid->SetViewportHeight();
grid->PositionPixmap();
grid->Draw();
@@ -115,41 +108,41 @@ int cChannelColumn::getX() {
return tvguideConfig.timeColWidth + num*tvguideConfig.colWidth;
}
-cEpgGrid * cChannelColumn::getActive() {
+cGrid * cChannelColumn::getActive() {
cMyTime t;
t.Now();
- for (cEpgGrid *grid = grids.First(); grid; grid = grids.Next(grid)) {
- if (grid->isActiveInitial(t.Get()))
+ for (cGrid *grid = grids.First(); grid; grid = grids.Next(grid)) {
+ if (grid->Match(t.Get()))
return grid;
}
return grids.First();
}
-cEpgGrid * cChannelColumn::getNext(cEpgGrid *activeGrid) {
+cGrid * cChannelColumn::getNext(cGrid *activeGrid) {
if (activeGrid == NULL)
return NULL;
- cEpgGrid *next = grids.Next(activeGrid);
+ cGrid *next = grids.Next(activeGrid);
if (next)
return next;
return NULL;
}
-cEpgGrid * cChannelColumn::getPrev(cEpgGrid *activeGrid) {
+cGrid * cChannelColumn::getPrev(cGrid *activeGrid) {
if (activeGrid == NULL)
return NULL;
- cEpgGrid *prev = grids.Prev(activeGrid);
+ cGrid *prev = grids.Prev(activeGrid);
if (prev)
return prev;
return NULL;
}
-cEpgGrid * cChannelColumn::getNeighbor(cEpgGrid *activeGrid) {
+cGrid * cChannelColumn::getNeighbor(cGrid *activeGrid) {
if (!activeGrid)
return NULL;
- cEpgGrid *neighbor = NULL;
+ cGrid *neighbor = NULL;
int overlap = 0;
int overlapNew = 0;
- cEpgGrid *grid = NULL;
+ cGrid *grid = NULL;
grid = grids.First();
if (grid) {
for (; grid; grid = grids.Next(grid)) {
@@ -169,115 +162,182 @@ cEpgGrid * cChannelColumn::getNeighbor(cEpgGrid *activeGrid) {
return neighbor;
}
+bool cChannelColumn::isFirst(cGrid *grid) {
+ if (grid == grids.First())
+ return true;
+ return false;
+}
+
void cChannelColumn::AddNewGridsAtStart() {
- cEpgGrid *firstGrid = NULL;
+ cGrid *firstGrid = NULL;
firstGrid = grids.First();
- if (firstGrid == NULL) {
- //no epg, completely new.
- schedules = cSchedules::Schedules(schedulesLock);
- const cSchedule *Schedule = NULL;
- Schedule = schedules->GetSchedule(channel);
- if (!Schedule)
- return;
- const cEvent *event = Schedule->GetEventAround(myTime->GetStart());
- if (!event)
- return;
- cEpgGrid *grid = new cEpgGrid(this, event);
- grid->setText();
- grid->SetColor(true);
- grids.Ins(grid, grids.First());
+ if (firstGrid == NULL)
return;
- } else {
- //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)
- return;
- bool col = !(firstGrid->IsColor1());
- for (const cEvent *event = Schedule->GetEventAround(firstGrid->StartTime()-60); event; event = Schedule->Events()->Prev(event)) {
- if (!event)
- return;
- cEpgGrid *grid = new cEpgGrid(this, event);
- grid->setText();
- grid->SetColor(col);
- col = !col;
- grids.Ins(grid, firstGrid);
- firstGrid = grid;
- if (event->StartTime() <= myTime->GetStart()) {
- break;
- }
+ //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;
+ for (const cEvent *event = Schedule->GetEventAround(firstGrid->StartTime()-60); event; event = Schedule->Events()->Prev(event)) {
+ if (!event)
+ break;
+ if (event->EndTime() < myTime->GetStart()) {
+ break;
+ }
+ cGrid *grid = addEpgGrid(event, firstGrid, col);
+ col = !col;
+ firstGrid = grid;
+ if (event->StartTime() <= myTime->GetStart()) {
+ dummyNeeded = false;
+ break;
}
}
+ 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);
+ }
+ }
}
void cChannelColumn::AddNewGridsAtEnd() {
- cEpgGrid *lastGrid = NULL;
+ cGrid *lastGrid = NULL;
lastGrid = grids.Last();
if (lastGrid == NULL)
return;
- //if last event is long enough, nothing to do.
- if (lastGrid->EndTime() > myTime->GetStop()) {
- return;
+ //if last event is long enough, nothing to do.
+ if (lastGrid->EndTime() >= myTime->GetEnd()) {
+ return;
}
//if not, i have to add new ones to the list
- schedules = cSchedules::Schedules(schedulesLock);
+ schedules = cSchedules::Schedules(*schedulesLock);
const cSchedule *Schedule = NULL;
Schedule = schedules->GetSchedule(channel);
- if (!Schedule)
- return;
+ if (!Schedule) {
+ if (lastGrid->isDummy()) {
+ lastGrid->SetStartTime(myTime->GetStart());
+ lastGrid->SetEndTime(myTime->GetEnd());
+ }
+ return;
+ }
bool col = !(lastGrid->IsColor1());
+ bool dummyNeeded = true;
for (const cEvent *event = Schedule->GetEventAround(lastGrid->EndTime()+60); event; event = Schedule->Events()->Next(event)) {
if (!event)
- return;
- cEpgGrid *grid = new cEpgGrid(this, event);
- grid->setText();
- grid->SetColor(col);
- col = !col;
- grids.Add(grid);
- if (event->EndTime() > myTime->GetStop()) {
+ break;
+ if (event->StartTime() > myTime->GetEnd()) {
+ break;
+ }
+ addEpgGrid(event, NULL, col);
+ col = !col;
+ if (event->EndTime() > myTime->GetEnd()) {
+ dummyNeeded = false;
break;
}
}
+ 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);
+ }
+ }
}
void cChannelColumn::ClearOutdatedStart() {
- bool goOn = true;
- cEpgGrid *firstGrid = NULL;
- while (goOn) {
- firstGrid = grids.First();
- if ((firstGrid != NULL)&&(firstGrid->EndTime() < myTime->GetStart())) {
- grids.Del(firstGrid);
- firstGrid = NULL;
+ cGrid *firstGrid = NULL;
+ while (true) {
+ firstGrid = grids.First();
+ if (!firstGrid)
+ break;
+ if (firstGrid->EndTime() <= myTime->GetStart()) {
+ grids.Del(firstGrid);
+ firstGrid = NULL;
} else {
- goOn = false;
+ if (firstGrid->isDummy()) {
+ firstGrid->SetStartTime(myTime->GetStart());
+ cGrid *next = getNext(firstGrid);
+ if (next) {
+ firstGrid->SetEndTime(next->StartTime());
+ } else {
+ firstGrid->SetEndTime(myTime->GetEnd());
+ }
+ }
+ break;
}
}
}
void cChannelColumn::ClearOutdatedEnd() {
- bool goOn = true;
- cEpgGrid *lastGrid = NULL;
- while (goOn) {
+ cGrid *lastGrid = NULL;
+ while (true) {
lastGrid = grids.Last();
- if ((lastGrid != NULL)&&(lastGrid->StartTime() > myTime->GetStop())) {
- grids.Del(lastGrid);
- lastGrid = NULL;
+ if (!lastGrid)
+ break;
+ if (lastGrid->StartTime() >= myTime->GetEnd()) {
+ grids.Del(lastGrid);
+ lastGrid = NULL;
} else {
- goOn = false;
+ if (lastGrid->isDummy()) {
+ lastGrid->SetEndTime(myTime->GetEnd());
+ cGrid *prev = getPrev(lastGrid);
+ if (prev) {
+ lastGrid->SetStartTime(prev->EndTime());
+ } else {
+ lastGrid->SetStartTime(myTime->GetStart());
+ }
+ }
+ break;
}
}
}
-void cChannelColumn::dumpGrids() {
- esyslog("------Channel %s ---------", channel->Name());
-
- for (cEpgGrid *grid = grids.First(); grid; grid = grids.Next(grid)) {
- grid->debug();
- }
-
+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;
}
+
+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() {
+ esyslog("tvguide: ------Channel %s: %d entires ---------", channel->Name(), grids.Count());
+ int i=1;
+ 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()));
+ i++;
+ }
+} \ No newline at end of file