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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
|
/*
* setup_menu.c: Setup Menu
*
* See the README file for copyright information and how to reach the author.
*
*/
#include "setup_menu.h"
#include <vdr/config.h>
#include <vdr/i18n.h>
#include "blacklist.h"
#include "charset.h"
#include "epgclone.h"
#include "regexp.h"
#include "tools.h"
//--- cMenuSetupConfigEditor ------------------------------------------------------
#define MAXREGEXPLENGTH 512
const char *RegexpChars =
trNOOP("RegexpChars$ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789%~\\/?!()[]{}<>$^*.,:;-=#");
template<class LISTITEM, class PARAMETER> class cMenuSetupConfigEditor : public cMenuSetupPage
{
private:
cEpgfixerList<LISTITEM, PARAMETER> *list;
const char *fileName;
char **lines;
char **numlines;
virtual void LoadListToArray(void)
{
lines = (char **)malloc(sizeof(char *)*(list->Count()));
int i = 0;
LISTITEM *item = (LISTITEM *)list->First();
while (item) {
lines[i] = (char *)malloc(sizeof(char)*MAXREGEXPLENGTH);
snprintf(lines[i], MAXREGEXPLENGTH, "%s", item->GetString());
item = (LISTITEM *)item->Next();
++i;
}
}
void FreeArray()
{
int i = 0;
while (i < list->Count()) {
free(lines[i]);
++i;
}
FREE(lines);
}
void Save()
{
// Store regular expressions to config file
if (fileName && access(fileName, F_OK) == 0) {
FILE *f = fopen(fileName, "w");
if (f) {
LISTITEM *item = (LISTITEM *)list->First();
while (item) {
item->PrintConfigLineToFile(f);
item = (LISTITEM *)item->Next();
}
fclose(f);
}
}
}
protected:
virtual void Store(void)
{
// Store regular expressions back to list
int i = 0;
LISTITEM *item = (LISTITEM *)list->First();
while (i < list->Count()) {
item->SetFromString(lines[i], item->Enabled());
item = (LISTITEM *)item->Next();
++i;
}
}
void Set(void)
{
Clear();
int i = 0;
LISTITEM *item = (LISTITEM *)list->First();
while (i < list->Count()) {
Add(new cMenuEditStrItem(item->Enabled() ? "+" : "-", lines[i], MAXREGEXPLENGTH, tr(RegexpChars)));
item = (LISTITEM *)item->Next();
++i;
}
SetHelp(trVDR("Button$On/Off"), trVDR("Button$New"), trVDR("Button$Delete"), tr("Button$Cancel"));
Display();
}
public:
cMenuSetupConfigEditor(cEpgfixerList<LISTITEM, PARAMETER> *l)
{
list = l;
cEitFilter::SetDisableUntil(time(NULL) + 1000);
SetCols(2);
fileName = list->GetConfigFile();
LoadListToArray();
Set();
}
~cMenuSetupConfigEditor(void)
{
FreeArray();
cEitFilter::SetDisableUntil(time(NULL) + 5);
}
virtual eOSState ProcessKey(eKeys Key)
{
eOSState state = cOsdMenu::ProcessKey(Key);
if (state == osUnknown) {
switch (Key) {
case kRed:
list->Get(Current())->ToggleEnabled();
Set();
Display();
state = osContinue;
break;
case kGreen:
Store();
FreeArray();
list->Add(new LISTITEM());
LoadListToArray();
Set();
Display();
state = osContinue;
break;
case kYellow:
Store();
FreeArray();
list->Del(list->Get(Current()),true);
LoadListToArray();
Set();
Display();
state = osContinue;
break;
case kBlue:
list->ReloadConfigFile();
state = osBack;
break;
case kOk:
Store();
Save();
list->ReloadConfigFile();
state = osBack;
break;
default:
break;
}
}
return state;
}
};
//--- cMenuSetupEpgfixer ------------------------------------------------------
cMenuSetupEpgfixer::cMenuSetupEpgfixer(void)
{
memcpy(&newconfig, &EpgfixerSetup, sizeof(cEpgfixerSetup));
Set();
}
void cMenuSetupEpgfixer::Set(void)
{
Clear();
help.Clear();
Add(new cOsdItem(tr("Regular expressions"), osUser1));
help.Append(tr("Edit regular expressions."));
Add(new cOsdItem(tr("Character set conversions"), osUser2));
help.Append(tr("Edit character set conversions."));
Add(new cOsdItem(tr("EPG blacklists"), osUser3));
help.Append(tr("Edit EPG blacklists."));
Add(new cOsdItem(tr("EPG cloning"), osUser4));
help.Append(tr("Edit EPG data cloning."));
Add(new cOsdItem(tr("--- EPG bugfixes ---"), osUnknown, false));
help.Append("");
Add(new cMenuEditBoolItem(tr("Remove quotes from ShortText"),
&newconfig.quotedshorttext));
help.Append(tr("EPG bugfix level >= 1: Some channels put the ShortText in quotes and use either the ShortText or the Description field, depending on how long the string is:\n\nTitle\n\"ShortText\". Description"));
Add(new cMenuEditBoolItem(tr("Move Description from ShortText"),
&newconfig.blankbeforedescription));
help.Append(tr("EPG bugfix level >= 1: Some channels put the Description into the ShortText (preceded by a blank) if there is no actual ShortText and the Description is short enough:\n\nTitle\n Description"));
Add(new cMenuEditBoolItem(tr("Remove repeated title from ShortText"),
&newconfig.repeatedtitle));
help.Append(tr("EPG bugfix level >= 1: Sometimes they repeat the Title in the ShortText:\n\nTitle\nTitle"));
Add(new cMenuEditBoolItem(tr("Remove double quotes from ShortText"),
&newconfig.doublequotedshorttext));
help.Append(tr("EPG bugfix level >= 1: Some channels put the ShortText between double quotes, which is nothing but annoying (some even put a '.' after the closing '\"'):\n\nTitle\n\"ShortText\"[.]"));
Add(new cMenuEditBoolItem(tr("Remove useless formatting"),
&newconfig.removeformatting));
help.Append(tr("EPG bugfix level >= 2: Some channels apparently try to do some formatting in the texts, which is a bad idea because they have no way of knowing the width of the window that will actually display the text. Remove excess whitespace."));
Add(new cMenuEditBoolItem(tr("Move long ShortText to Description"),
&newconfig.longshorttext));
help.Append(tr("EPG bugfix level >= 2: Some channels put a whole lot of information in the ShortText and leave the Description totally empty. So if the ShortText length exceeds 40, let's put this into the Description instead."));
Add(new cMenuEditBoolItem(tr("Prevent equal ShortText and Description"),
&newconfig.equalshorttextanddescription));
help.Append(tr("EPG bugfix level >= 2: Some channels put the same information into ShortText and Description. In that case we delete one of them."));
Add(new cMenuEditBoolItem(tr("Replace backticks with single quotes"),
&newconfig.nobackticks));
help.Append(tr("EPG bugfix level >= 2: Some channels use the ` (\"backtick\") character, where a ' (single quote) would be normally used. Actually, \"backticks\" in normal text don't make much sense, so let's replace them."));
Add(new cMenuEditBoolItem(tr("Fix stream component descriptions"),
&newconfig.components));
help.Append(tr("EPG bugfix level = 3: The stream components have a \"description\" field which some channels apparently have no idea of how to set correctly."));
Add(new cMenuEditBoolItem(tr("Strip HTML entities"),
&newconfig.striphtml));
help.Append(tr("Convert HTML entities from all fields to matching regular characters."));
SetHelp(tr("Button$Load"),NULL,NULL, tr("Button$Clear EPG"));
Display();
}
void cMenuSetupEpgfixer::Store(void)
{
memcpy(&EpgfixerSetup, &newconfig, sizeof(cEpgfixerSetup));
SetupStore("RemoveQuotesFromShortText", EpgfixerSetup.quotedshorttext);
SetupStore("MoveDescriptionFromShortText", EpgfixerSetup.blankbeforedescription);
SetupStore("RemoveRepeatedTitleFromShortText", EpgfixerSetup.repeatedtitle);
SetupStore("RemoveDoubleQuotesFromShortText", EpgfixerSetup.doublequotedshorttext);
SetupStore("RemoveUselessFormatting", EpgfixerSetup.removeformatting);
SetupStore("MoveLongShortTextToDescription", EpgfixerSetup.longshorttext);
SetupStore("PreventEqualShortTextAndDescription", EpgfixerSetup.equalshorttextanddescription);
SetupStore("ReplaceBackticksWithSingleQuotes", EpgfixerSetup.nobackticks);
SetupStore("FixStreamComponentDescriptions", EpgfixerSetup.components);
SetupStore("StripHTMLentities", EpgfixerSetup.striphtml);
Setup.Save();
}
eOSState cMenuSetupEpgfixer::ProcessKey(eKeys Key)
{
eOSState state = cMenuSetupPage::ProcessKey(Key);
if (state == osUnknown) {
switch (Key) {
case kRed:
Skins.Message(mtInfo, tr("Loading configuration files..."));
EpgfixerRegexps.ReloadConfigFile();
EpgfixerCharSets.ReloadConfigFile();
EpgfixerBlacklists.ReloadConfigFile();
EpgfixerEpgClones.ReloadConfigFile();
Skins.Message(mtInfo, NULL);
state = osContinue;
break;
case kBlue:
Skins.Message(mtInfo, tr("Clearing EPG data..."));
cEitFilter::SetDisableUntil(time(NULL) + 10);
if (cSchedules::ClearAll())
cEitFilter::SetDisableUntil(time(NULL) + 10);
Skins.Message(mtInfo, NULL);
state = osContinue;
break;
case kInfo:
if (Current() < help.Size())
return AddSubMenu(new cMenuText(cString::sprintf("%s - %s '%s'", tr("Help"), trVDR("Plugin"), PLUGIN_NAME_I18N), help[Current()]));
break;
default:
break;
}
}
else if (state == osUser1)
return AddSubMenu(new cMenuSetupConfigEditor<cRegexp, cEvent>(&EpgfixerRegexps));
else if (state == osUser2)
return AddSubMenu(new cMenuSetupConfigEditor<cCharSet, cEvent>(&EpgfixerCharSets));
else if (state == osUser3)
return AddSubMenu(new cMenuSetupConfigEditor<cBlacklist, cChannel>(&EpgfixerBlacklists));
else if (state == osUser4)
return AddSubMenu(new cMenuSetupConfigEditor<cEpgClone, cEvent>(&EpgfixerEpgClones));
return state;
}
|