blob: 0ca3c72a400b5118dd9d331ec04585a2106c1193 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
#include <vector>
#include "config.h"
#include "channelgroups.h"
cChannelGroups::cChannelGroups(void) {
}
cChannelGroups::~cChannelGroups(void) {
}
void cChannelGroups::ReadChannelGroups(void) {
bool setStart = false;
int lastChannelNumber = 0;
#if VDRVERSNUM >= 20301
LOCK_CHANNELS_READ;
const cChannels *channels = Channels;
#else
const cChannels *channels = &Channels;
#endif
const cChannel *first = channels->First();
if (!first->GroupSep()) {
channelGroups.push_back(cChannelGroup(tr("Main Program")));
setStart = true;
}
for (const cChannel *channel = channels->First(); channel; channel = channels->Next(channel)) {
if (setStart && (channelGroups.size() > 0)) {
channelGroups[channelGroups.size() - 1].SetChannelStart(channel->Number());
setStart = false;
}
if (channel->GroupSep()) {
if (channelGroups.size() > 0) {
channelGroups[channelGroups.size() - 1].SetChannelStop(lastChannelNumber);
}
channelGroups.push_back(cChannelGroup(channel->Name()));
setStart = true;
} else {
lastChannelNumber = channel->Number();
}
}
if (channelGroups.size() > 0) {
channelGroups[channelGroups.size() - 1].SetChannelStop(lastChannelNumber);
if ((config.hideLastGroup) && (channelGroups.size() > 1)) {
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) {
if ((group+1) < (int)channelGroups.size())
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;
if ((currentGroup+1) < (int)channelGroups.size()) {
return channelGroups[currentGroup+1].StartChannel();
}
return 0;
}
bool cChannelGroups::IsInLastGroup(const cChannel *channel) {
if (!config.hideLastGroup)
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;
#if VDRVERSNUM >= 20301
LOCK_CHANNELS_READ;
for (const cChannel *channel = Channels->Next(start); channel; channel = Channels->Next(channel)) {
#else
for (const cChannel *channel = Channels.Next(start); channel; channel = Channels.Next(channel)) {
#endif
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) {
CreateGroupGrid(channelGroups[groupLast].GetName(), group+1, lineStart, line);
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);
}
int cChannelGroups::GetLastValidChannel(void) {
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
}
void cChannelGroups::DumpGroups(void) {
for (std::vector<cChannelGroup>::iterator group = channelGroups.begin(); group!=channelGroups.end(); ++group) {
group->Dump();
}
}
|