summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitar Petrovski <dimeptr@gmail.com>2012-11-21 08:11:04 (GMT)
committerDimitar Petrovski <dimeptr@gmail.com>2012-11-21 08:11:04 (GMT)
commitc72251596c42864a959aedd7d916e834aac276e9 (patch)
tree19350436aea74c64936440d203d057f172806f81
parenta6207b35db9e524fef7243faab839c4d98e318f1 (diff)
downloadvdr-plugin-eepg-c72251596c42864a959aedd7d916e834aac276e9.tar.gz
vdr-plugin-eepg-c72251596c42864a959aedd7d916e834aac276e9.tar.bz2
Moved charset fixing code to a separate class
Added setup option to enable/dissable charset fixing
-rw-r--r--eepg.c6
-rw-r--r--epghandler.c70
-rw-r--r--epghandler.h7
-rw-r--r--po/mk_MK.po7
-rw-r--r--setupeepg.c1
-rw-r--r--setupeepg.h1
-rw-r--r--util.c77
-rw-r--r--util.h19
8 files changed, 117 insertions, 71 deletions
diff --git a/eepg.c b/eepg.c
index 8a65609..29bd4d4 100644
--- a/eepg.c
+++ b/eepg.c
@@ -134,7 +134,8 @@ cMenuSetupPremiereEpg::cMenuSetupPremiereEpg (void)
}
// AddCategory (tr ("General"));
Add (new cMenuEditBoolItem (tr ("Display summary message"), &data->DisplayMessage));
- Add (new cMenuEditBoolItem (tr ("Replace Empty Short Text with Category - Genre"), &data->ReplaceEmptyShText));
+ Add (new cMenuEditBoolItem (tr ("Replace empty Short Text with Category - Genre"), &data->ReplaceEmptyShText));
+ Add (new cMenuEditBoolItem (tr ("Try to fix CharSet for events"), &data->FixCharset));
#ifdef DEBUG
Add (new cMenuEditIntItem (tr ("Level of logging verbosity"), &data->LogLevel, 0, 5));
Add (new cMenuEditBoolItem (tr ("Process EIT info with EEPG"), &data->ProcessEIT));
@@ -150,6 +151,7 @@ void cMenuSetupPremiereEpg::Store (void)
SetupStore ("FixEpg", SetupPE->FixEpg);
SetupStore ("DisplayMessage", SetupPE->DisplayMessage);
SetupStore ("ReplaceEmptyShText", SetupPE->ReplaceEmptyShText);
+ SetupStore ("FixCharset", SetupPE->FixCharset);
#ifdef DEBUG
SetupStore ("LogLevel", SetupPE->LogLevel);
SetupStore ("ProcessEIT", SetupPE->ProcessEIT);
@@ -3594,6 +3596,8 @@ bool cPluginEEPG::SetupParse (const char *Name, const char *Value)
SetupPE->DisplayMessage = atoi (Value);
else if (!strcasecmp (Name, "ReplaceEmptyShText"))
SetupPE->ReplaceEmptyShText = atoi (Value);
+ else if (!strcasecmp (Name, "FixCharset"))
+ SetupPE->FixCharset = atoi (Value);
#ifdef DEBUG
else if (!strcasecmp (Name, "LogLevel"))
SetupPE->LogLevel = atoi (Value);
diff --git a/epghandler.c b/epghandler.c
index 01cccea..ca214c7 100644
--- a/epghandler.c
+++ b/epghandler.c
@@ -16,26 +16,18 @@
using namespace util;
-cCharSetConv* conv;//("UTF-8",CharsetOverride);
-cCharSetConv* conv2;//(fixCharset.c_str());
cEEpgHandler::cEEpgHandler() {
LogD(4, prep("cEEpgHandler()"));
equivHandler = new cEquivHandler();
modified = false;
-
- CharsetOverride = getenv("VDR_CHARSET_OVERRIDE");
- if (!CharsetOverride) CharsetOverride = "ISO6937";
+ charsetFixer = new cCharsetFixer();
}
cEEpgHandler::~cEEpgHandler() {
delete equivHandler;
equivHandler = NULL;
- delete conv;
- conv = NULL;
- delete conv2;
- conv2 = NULL;
}
@@ -98,30 +90,10 @@ bool cEEpgHandler::SetEventID(cEvent* Event, tEventID EventID) {
return true;
}
-const char* cEEpgHandler::FixCharset(const char* text)
-{
- if (!text) return text;
-
- //LogD(0, prep("FixCharset fixCharset:%s charsetOverride:%s text:%s"), fixCharset.c_str(), CharsetOverride, text);
- const char* fixed = NULL;
- if (!fixCharset.empty()) {
-
- if (fixCharset != CharsetOverride) {
- //LogD(0, prep("FixCharset2 fixCharset:%s charsetOverride:%s text:%s"), fixCharset.c_str(), CharsetOverride, text);
- fixed = conv->Convert(text);
- //LogD(0, prep("conv 1 fixed:%s"),fixed);
- fixed = conv2->Convert(fixed);
- //LogD(0, prep("Fixed text:%s"), fixed);
- }
- }
- if (!fixed) fixed = text;
- return fixed;
-}
-
bool cEEpgHandler::SetTitle(cEvent* Event, const char* Title) {
LogD(3, prep("Event id:%d title:%s new title:%s"), Event->EventID(), Event->Title(), Title);
- const char* title = FixCharset(Title);
+ const char* title = charsetFixer->FixCharset(Title);
//Sometimes same events overlap and have different EventID
if (origDescription.empty() && origShortText.empty()) {
@@ -167,7 +139,7 @@ bool cEEpgHandler::SetShortText(cEvent* Event, const char* ShortText) {
origShortText.clear();
}
- const char* shText = FixCharset(ShortText);
+ const char* shText = charsetFixer->FixCharset(ShortText);
//if (!Event->ShortText() || ShortText && (!strcmp(Event->ShortText(),"") || (strcmp(ShortText,"") && strcmp(Event->ShortText(),ShortText))))
Event->SetShortText(shText);
@@ -182,7 +154,7 @@ bool cEEpgHandler::SetDescription(cEvent* Event, const char* Description) {
else
origDescription.clear();
- const char* desc = FixCharset(Description);
+ const char* desc = charsetFixer->FixCharset(Description);
//Based on asumption that SetDescription is always called after SetTitle
if (!modified && desc && (!Event->Description() || strcmp(Event->Description(),desc) ))
@@ -287,39 +259,7 @@ bool cEEpgHandler::FixEpgBugs(cEvent* Event)
bool cEEpgHandler::IgnoreChannel(const cChannel* Channel)
{
-
- //TODO
- //return false;
-
- if (conv) {
- delete conv;
- conv = NULL;
- }
- if (conv2) {
- delete conv2;
- conv2 = NULL;
- }
- if (strcasecmp( Channel->Provider(), "Skylink") == 0 || strcasecmp( Channel->Provider(), "UPC Direct") == 0
- || strcasecmp( Channel->Provider(), "CYFRA +") == 0) {
- fixCharset = "ISO6937";
- } else if (strcasestr( Channel->Provider(), "Polsat") != 0) {
- fixCharset = "ISO-8859-2";
- } else if (Channel->Nid() == 0x01) {
- fixCharset = "ISO-8859-9";
- } else {
- fixCharset = "";
- }
-
-
- if (!fixCharset.empty()) {
- conv2 = new cCharSetConv(fixCharset.c_str());
- if (strcasecmp( Channel->Provider(), "CYFRA +") == 0) {
- conv = new cCharSetConv(NULL,"ISO-8859-5");
- }else {
- conv = new cCharSetConv(NULL,CharsetOverride);
- }
- }
-
+ charsetFixer->InitCharsets(Channel);
return false;
}
diff --git a/epghandler.h b/epghandler.h
index 23874b9..b37f7c2 100644
--- a/epghandler.h
+++ b/epghandler.h
@@ -13,6 +13,9 @@
#include <string>
class cEquivHandler;
+namespace util {
+class cCharsetFixer;
+}
class cEEpgHandler : public cEpgHandler {
public:
@@ -36,17 +39,15 @@ public:
// bool ParseEitEvent(cSchedule *Schedule, const SI::EIT::Event *EitEvent, uchar TableID, uchar Version);
private:
- const char* FixCharset(const char* text);
std::string ExtractAttribute(const char* attr);
private:
std::string origShortText;
std::string origDescription;
- std::string fixCharset;
cEquivHandler* equivHandler;
+ util::cCharsetFixer* charsetFixer;
static const int _LONG_EVENT_HOURS = 10;
bool modified;
- const char* CharsetOverride;
};
diff --git a/po/mk_MK.po b/po/mk_MK.po
index 5224001..69936f2 100644
--- a/po/mk_MK.po
+++ b/po/mk_MK.po
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: vdr-eepg 0.0.6pre\n"
"Report-Msgid-Bugs-To: <see README>\n"
-"POT-Creation-Date: 2012-10-29 13:42+0100\n"
+"POT-Creation-Date: 2012-11-20 23:13+0100\n"
"PO-Revision-Date: 2012-10-29 13:44+0100\n"
"Last-Translator: Dimitar Petrovski <dimeptr@gmail.com>\n"
"Language-Team: Macedonian <mk@li.org>\n"
@@ -43,9 +43,12 @@ msgstr "Општо"
msgid "Display summary message"
msgstr "Прикажи сумарна порака"
-msgid "Replace Empty Short Text with Category - Genre"
+msgid "Replace empty Short Text with Category - Genre"
msgstr "Замени празен Краток Текст со Категорија - Жанр"
+msgid "Try to fix CharSet for events"
+msgstr "Пробај да го поправиш сетот на карактери за настаните"
+
msgid "Level of logging verbosity"
msgstr "Ниво на логирање"
diff --git a/setupeepg.c b/setupeepg.c
index bfbb26f..c6056d8 100644
--- a/setupeepg.c
+++ b/setupeepg.c
@@ -23,6 +23,7 @@ cSetupEEPG::cSetupEEPG (void)
DisplayMessage = 1;
ProcessEIT = 0;
ReplaceEmptyShText = 0;
+ FixCharset = 0;
#ifdef DEBUG
LogLevel = 0;
diff --git a/setupeepg.h b/setupeepg.h
index 089eb82..ed0f04e 100644
--- a/setupeepg.h
+++ b/setupeepg.h
@@ -19,6 +19,7 @@ public:
int DisplayMessage;
int ProcessEIT;
int ReplaceEmptyShText;
+ int FixCharset;
#ifdef DEBUG
int LogLevel;
#endif
diff --git a/util.c b/util.c
index 7554319..49f863a 100644
--- a/util.c
+++ b/util.c
@@ -7,6 +7,7 @@
#include "util.h"
#include "log.h"
#include "equivhandler.h"
+#include "setupeepg.h"
#include <vdr/channels.h>
#include <vdr/thread.h>
#include <vdr/epg.h>
@@ -388,5 +389,81 @@ void sortSchedules(cSchedules * Schedules, tChannelID channelID){
EquivHandler->sortEquivalents(channelID, Schedules);
}
+cCharsetFixer::cCharsetFixer()
+{
+ charsetOverride = getenv("VDR_CHARSET_OVERRIDE");
+ if (!charsetOverride) charsetOverride = "ISO6937";
+ initialCharset = charsetOverride;
+ fixedCharset = "";
+ conv_revert = NULL;
+ conv_to = NULL;
+
+}
+
+cCharsetFixer::~cCharsetFixer()
+{
+}
+
+const char* cCharsetFixer::FixCharset(const char* text)
+{
+ if (!text || !conv_revert || !conv_to) return text;
+
+ //LogD(0, prep("FixCharset fixCharset:%s charsetOverride:%s text:%s"), fixCharset.c_str(), CharsetOverride, text);
+ const char* fixed = NULL;
+ if (!fixedCharset.empty()) {
+
+ if (fixedCharset != charsetOverride) {
+ //LogD(0, prep("FixCharset2 fixCharset:%s charsetOverride:%s text:%s"), fixCharset.c_str(), CharsetOverride, text);
+ fixed = conv_revert->Convert(text);
+ //LogD(0, prep("conv 1 fixed:%s"),fixed);
+ fixed = conv_to->Convert(fixed);
+ //LogD(0, prep("Fixed text:%s"), fixed);
+ }
+ }
+ if (!fixed) fixed = text;
+ return fixed;
+
+}
+
+void cCharsetFixer::InitCharsets(const cChannel* Channel)
+{
+ if (!cSetupEEPG::getInstance()->FixCharset) return;
+
+ if (strcasecmp( Channel->Provider(), "Skylink") == 0 || strcasecmp( Channel->Provider(), "UPC Direct") == 0
+ || strcasecmp( Channel->Provider(), "CYFRA +") == 0) {
+ fixedCharset = "ISO6937";
+ } else if (strcasestr( Channel->Provider(), "Polsat") != 0) {
+ fixedCharset = "ISO-8859-2";
+ } else if (Channel->Nid() == 0x01) {
+ fixedCharset = "ISO-8859-9";
+ } else {
+ fixedCharset = "";
+ }
+
+
+ if (!fixedCharset.empty()) {
+ delete conv_to;
+ conv_to = new cCharSetConv(fixedCharset.c_str());
+
+
+ const char* chrs;
+ if (strcasecmp( Channel->Provider(), "CYFRA +") == 0) {
+ chrs = "ISO-8859-5";
+ }else {
+ chrs = charsetOverride;
+ }
+
+ if (initialCharset != chrs) {
+ delete conv_revert;
+ conv_revert = NULL;
+ }
+ if (!conv_revert || initialCharset != chrs)
+ conv_revert = new cCharSetConv(NULL,chrs);
+
+ initialCharset = chrs;
+ }
+
+}
+
}
diff --git a/util.h b/util.h
index 4b3ce9b..bef2a3e 100644
--- a/util.h
+++ b/util.h
@@ -9,12 +9,14 @@
#define UTIL_H_
#include <time.h>
#include <stdlib.h>
+#include <string>
class cChannel;
struct tChannelID;
class cEvent;
class cEquivHandler;
class cSchedules;
+class cCharSetConv;
#define START '\0'
#define STOP '\0'
@@ -94,5 +96,22 @@ extern struct hufftab *tables[2][128];
extern int table_size[2][128];
//static sNodeH* sky_tables[2];
+class cCharsetFixer
+{
+public:
+ cCharsetFixer();
+ virtual ~cCharsetFixer();
+ const char* FixCharset(const char* text);
+ void InitCharsets(const cChannel* Channel);
+
+private:
+ cCharSetConv* conv_revert;//("UTF-8",CharsetOverride);
+ cCharSetConv* conv_to;//(fixCharset.c_str());
+ const char* charsetOverride;
+ std::string fixedCharset;
+ std::string initialCharset;
+
+};
+
}
#endif /* UTIL_H_ */