2013-05-31 13:58:22 +02:00
|
|
|
#include <vector>
|
2019-07-11 12:41:19 +02:00
|
|
|
#include "config.h"
|
2013-05-31 13:58:22 +02:00
|
|
|
#include "channelgroups.h"
|
|
|
|
|
|
|
|
cChannelGroups::cChannelGroups(void) {
|
|
|
|
}
|
|
|
|
|
|
|
|
cChannelGroups::~cChannelGroups(void) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void cChannelGroups::ReadChannelGroups(void) {
|
|
|
|
bool setStart = false;
|
|
|
|
int lastChannelNumber = 0;
|
2018-03-08 13:30:41 +01:00
|
|
|
#if VDRVERSNUM >= 20301
|
2018-03-08 13:02:38 +01:00
|
|
|
LOCK_CHANNELS_READ;
|
2019-07-11 13:40:00 +02:00
|
|
|
const cChannels *channels = Channels;
|
2018-03-08 13:02:38 +01:00
|
|
|
#else
|
2019-07-11 13:40:00 +02:00
|
|
|
const cChannels *channels = &Channels;
|
2018-03-08 13:02:38 +01:00
|
|
|
#endif
|
2019-07-11 13:40:00 +02:00
|
|
|
const cChannel *first = channels->First();
|
2013-05-31 13:58:22 +02:00
|
|
|
if (!first->GroupSep()) {
|
|
|
|
channelGroups.push_back(cChannelGroup(tr("Main Program")));
|
|
|
|
setStart = true;
|
|
|
|
}
|
2019-07-11 13:40:00 +02:00
|
|
|
for (const cChannel *channel = channels->First(); channel; channel = channels->Next(channel)) {
|
2013-05-31 13:58:22 +02:00
|
|
|
if (setStart && (channelGroups.size() > 0)) {
|
2019-07-11 13:40:00 +02:00
|
|
|
channelGroups[channelGroups.size() - 1].SetChannelStart(channel->Number());
|
2013-05-31 13:58:22 +02:00
|
|
|
setStart = false;
|
|
|
|
}
|
|
|
|
if (channel->GroupSep()) {
|
|
|
|
if (channelGroups.size() > 0) {
|
2019-07-11 13:40:00 +02:00
|
|
|
channelGroups[channelGroups.size() - 1].SetChannelStop(lastChannelNumber);
|
2013-05-31 13:58:22 +02:00
|
|
|
}
|
|
|
|
channelGroups.push_back(cChannelGroup(channel->Name()));
|
|
|
|
setStart = true;
|
|
|
|
} else {
|
|
|
|
lastChannelNumber = channel->Number();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (channelGroups.size() > 0) {
|
2019-07-11 13:40:00 +02:00
|
|
|
channelGroups[channelGroups.size() - 1].SetChannelStop(lastChannelNumber);
|
|
|
|
if ((config.hideLastGroup) && (channelGroups.size() > 1)) {
|
2013-05-31 13:58:22 +02:00
|
|
|
channelGroups.pop_back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int cChannelGroups::GetGroup(const cChannel *channel) {
|
|
|
|
int channelNumber = channel->Number();
|
|
|
|
int numGroups = channelGroups.size();
|
|
|
|
if (numGroups) {
|
|
|
|
for (int i=0; i<numGroups; i++) {
|
|
|
|
if ((channelGroups[i].StartChannel() <= channelNumber) && ((channelGroups[i].StopChannel() >= channelNumber))) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* cChannelGroups::GetPrev(int group) {
|
|
|
|
if (group > 0) {
|
|
|
|
return channelGroups[group-1].GetName();
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* cChannelGroups::GetNext(int group) {
|
|
|
|
if (group > -1) {
|
2019-03-23 13:43:37 +01:00
|
|
|
if ((group+1) < (int)channelGroups.size())
|
2013-05-31 13:58:22 +02:00
|
|
|
return channelGroups[group+1].GetName();
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
int cChannelGroups::GetPrevGroupChannelNumber(const cChannel *channel) {
|
|
|
|
int currentGroup = GetGroup(channel);
|
|
|
|
if (currentGroup == -1)
|
|
|
|
return 0;
|
|
|
|
if (currentGroup > 0) {
|
|
|
|
return channelGroups[currentGroup-1].StartChannel();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cChannelGroups::GetNextGroupChannelNumber(const cChannel *channel) {
|
|
|
|
int currentGroup = GetGroup(channel);
|
|
|
|
if (currentGroup == -1)
|
|
|
|
return 0;
|
2019-03-23 13:43:37 +01:00
|
|
|
if ((currentGroup+1) < (int)channelGroups.size()) {
|
2013-05-31 13:58:22 +02:00
|
|
|
return channelGroups[currentGroup+1].StartChannel();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cChannelGroups::IsInLastGroup(const cChannel *channel) {
|
2019-07-11 11:28:11 +02:00
|
|
|
if (!config.hideLastGroup)
|
2013-05-31 13:58:22 +02:00
|
|
|
return false;
|
|
|
|
if (channelGroups.size() > 0) {
|
|
|
|
if (channel->Number() > channelGroups[channelGroups.size()-1].StopChannel()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cChannelGroups::DrawChannelGroups(const cChannel *start, const cChannel *stop) {
|
|
|
|
groupGrids.Clear();
|
|
|
|
int group = GetGroup(start);
|
|
|
|
int groupLast = group;
|
|
|
|
int line = 0;
|
|
|
|
int lineStart = 0;
|
2018-03-08 13:30:41 +01:00
|
|
|
#if VDRVERSNUM >= 20301
|
2018-03-08 13:02:38 +01:00
|
|
|
LOCK_CHANNELS_READ;
|
|
|
|
for (const cChannel *channel = Channels->Next(start); channel; channel = Channels->Next(channel)) {
|
|
|
|
#else
|
2013-05-31 13:58:22 +02:00
|
|
|
for (const cChannel *channel = Channels.Next(start); channel; channel = Channels.Next(channel)) {
|
2018-03-08 13:02:38 +01:00
|
|
|
#endif
|
2013-05-31 13:58:22 +02:00
|
|
|
if (channel->GroupSep())
|
|
|
|
continue;
|
|
|
|
group = GetGroup(channel);
|
|
|
|
if (group != groupLast) {
|
|
|
|
CreateGroupGrid(channelGroups[groupLast].GetName(), group, lineStart, line);
|
|
|
|
lineStart = line + 1;
|
|
|
|
}
|
|
|
|
line++;
|
|
|
|
groupLast = group;
|
|
|
|
if (channel == stop) {
|
2013-06-03 10:01:52 +02:00
|
|
|
CreateGroupGrid(channelGroups[groupLast].GetName(), group+1, lineStart, line);
|
2013-05-31 13:58:22 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void cChannelGroups::CreateGroupGrid(const char *name, int number, int start, int end) {
|
|
|
|
cChannelGroupGrid *groupGrid = new cChannelGroupGrid(name);
|
|
|
|
groupGrid->SetColor(number%2);
|
|
|
|
groupGrid->SetBackground();
|
|
|
|
groupGrid->SetGeometry(start, end);
|
|
|
|
groupGrid->Draw();
|
|
|
|
groupGrids.Add(groupGrid);
|
|
|
|
}
|
|
|
|
|
2013-12-23 09:12:19 +01:00
|
|
|
int cChannelGroups::GetLastValidChannel(void) {
|
2019-07-11 12:41:19 +02:00
|
|
|
if (config.hideLastGroup && channelGroups.size() > 0) {
|
|
|
|
return channelGroups[channelGroups.size() - 1].StopChannel();
|
|
|
|
}
|
|
|
|
#if VDRVERSNUM >= 20301
|
|
|
|
LOCK_CHANNELS_READ;
|
|
|
|
return Channels->MaxNumber();
|
|
|
|
#else
|
|
|
|
return Channels.MaxNumber();
|
|
|
|
#endif
|
2013-12-23 09:12:19 +01:00
|
|
|
}
|
|
|
|
|
2013-05-31 13:58:22 +02:00
|
|
|
void cChannelGroups::DumpGroups(void) {
|
|
|
|
for (std::vector<cChannelGroup>::iterator group = channelGroups.begin(); group!=channelGroups.end(); ++group) {
|
|
|
|
group->Dump();
|
|
|
|
}
|
|
|
|
}
|