Set ff=unix for some files

This commit is contained in:
kamel5 2019-03-22 13:17:22 +01:00
parent 68af1b2086
commit a8ca6f19da
5 changed files with 779 additions and 779 deletions

View File

@ -82,4 +82,4 @@ class cMenuSetupImageCache : public cMenuSetupSubMenu {
cMenuSetupImageCache(cTvguideConfig *data); cMenuSetupImageCache(cTvguideConfig *data);
}; };
#endif //__TVGUIDE_SETUP_H #endif //__TVGUIDE_SETUP_H

View File

@ -1,187 +1,187 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <vdr/timers.h> #include <vdr/timers.h>
#include "tools.h" #include "tools.h"
#include "timer.h" #include "timer.h"
#include "timerconflict.h" #include "timerconflict.h"
cTVGuideTimerConflict::cTVGuideTimerConflict(void) { cTVGuideTimerConflict::cTVGuideTimerConflict(void) {
time = 0; time = 0;
timeStart = 0; timeStart = 0;
timeStop = 0; timeStop = 0;
overlapStart = 0; overlapStart = 0;
overlapStop = 0; overlapStop = 0;
percentPossible = 0; percentPossible = 0;
timerID = 0; timerID = 0;
} }
cTVGuideTimerConflict::~cTVGuideTimerConflict(void) { cTVGuideTimerConflict::~cTVGuideTimerConflict(void) {
} }
bool cTVGuideTimerConflict::timerInvolved(int involvedID) { bool cTVGuideTimerConflict::timerInvolved(int involvedID) {
int numConflicts = timerIDs.size(); int numConflicts = timerIDs.size();
for (int i=0; i<numConflicts; i++) { for (int i=0; i<numConflicts; i++) {
if (timerIDs[i] == involvedID) if (timerIDs[i] == involvedID)
return true; return true;
} }
return false; return false;
} }
// --- cTVGuideTimerConflicts------------------------------------ // --- cTVGuideTimerConflicts------------------------------------
cTVGuideTimerConflicts::cTVGuideTimerConflicts(void) { cTVGuideTimerConflicts::cTVGuideTimerConflicts(void) {
numConflicts = 0; numConflicts = 0;
currentConflict = -1; currentConflict = -1;
} }
cTVGuideTimerConflicts::~cTVGuideTimerConflicts(void) { cTVGuideTimerConflicts::~cTVGuideTimerConflicts(void) {
for(std::vector<cTVGuideTimerConflict*>::const_iterator it = conflicts.begin(); it != conflicts.end(); it++) { for(std::vector<cTVGuideTimerConflict*>::const_iterator it = conflicts.begin(); it != conflicts.end(); it++) {
cTVGuideTimerConflict *conf = *it; cTVGuideTimerConflict *conf = *it;
delete conf; delete conf;
} }
conflicts.clear(); conflicts.clear();
} }
void cTVGuideTimerConflicts::AddConflict(std::string epgSearchConflictLine) { void cTVGuideTimerConflicts::AddConflict(std::string epgSearchConflictLine) {
/* TIMERCONFLICT FORMAT: /* TIMERCONFLICT FORMAT:
The result list looks like this for example when we have 2 timer conflicts at one time: The result list looks like this for example when we have 2 timer conflicts at one time:
1190232780:152|30|50#152#45:45|10|50#152#45 1190232780:152|30|50#152#45:45|10|50#152#45
'1190232780' is the time of the conflict in seconds since 1970-01-01. '1190232780' is the time of the conflict in seconds since 1970-01-01.
It's followed by list of timers that have a conflict at this time: It's followed by list of timers that have a conflict at this time:
'152|30|50#1 int editTimer(cTimer *timer, bool active, int prio, int start, int stop); '152|30|50#1 int editTimer(cTimer *timer, bool active, int prio, int start, int stop);
52#45' is the description of the first conflicting timer. Here: 52#45' is the description of the first conflicting timer. Here:
'152' is VDR's timer id of this timer as returned from VDR's LSTT command '152' is VDR's timer id of this timer as returned from VDR's LSTT command
'30' is the percentage of recording that would be done (0...100) '30' is the percentage of recording that would be done (0...100)
'50#152#45' is the list of concurrent timers at this conflict '50#152#45' is the list of concurrent timers at this conflict
'45|10|50#152#45' describes the next conflict '45|10|50#152#45' describes the next conflict
*/ */
cTVGuideTimerConflict *conflict = new cTVGuideTimerConflict(); cTVGuideTimerConflict *conflict = new cTVGuideTimerConflict();
splitstring s(epgSearchConflictLine.c_str()); splitstring s(epgSearchConflictLine.c_str());
std::vector<std::string> flds = s.split(':'); std::vector<std::string> flds = s.split(':');
if (flds.size() < 2) if (flds.size() < 2)
return; return;
conflict->time = atoi(flds[0].c_str()); conflict->time = atoi(flds[0].c_str());
splitstring s2(flds[1].c_str()); splitstring s2(flds[1].c_str());
std::vector<std::string> flds2 = s2.split('|'); std::vector<std::string> flds2 = s2.split('|');
if (flds2.size() < 3) if (flds2.size() < 3)
return; return;
conflict->timerID = atoi(flds2[0].c_str()); conflict->timerID = atoi(flds2[0].c_str());
conflict->percentPossible = atoi(flds2[1].c_str()); conflict->percentPossible = atoi(flds2[1].c_str());
splitstring s3(flds2[2].c_str()); splitstring s3(flds2[2].c_str());
std::vector<std::string> flds3 = s3.split('#'); std::vector<std::string> flds3 = s3.split('#');
std::vector<int> timerIDs; std::vector<int> timerIDs;
for (int k = 0; k < flds3.size(); k++) { for (int k = 0; k < flds3.size(); k++) {
timerIDs.push_back(atoi(flds3[k].c_str()) - 1); timerIDs.push_back(atoi(flds3[k].c_str()) - 1);
} }
conflict->timerIDs = timerIDs; conflict->timerIDs = timerIDs;
conflicts.push_back(conflict); conflicts.push_back(conflict);
} }
void cTVGuideTimerConflicts::CalculateConflicts(void) { void cTVGuideTimerConflicts::CalculateConflicts(void) {
numConflicts = conflicts.size(); numConflicts = conflicts.size();
// time_t startTime = 0; // time_t startTime = 0;
// time_t endTime = 0; // time_t endTime = 0;
for (int i=0; i < numConflicts; i++) { for (int i=0; i < numConflicts; i++) {
cTimeInterval *unionSet = NULL; cTimeInterval *unionSet = NULL;
int numTimers = conflicts[i]->timerIDs.size(); int numTimers = conflicts[i]->timerIDs.size();
for (int j=0; j < numTimers; j++) { for (int j=0; j < numTimers; j++) {
#if VDRVERSNUM >= 20301 #if VDRVERSNUM >= 20301
LOCK_TIMERS_READ; LOCK_TIMERS_READ;
const cTimer *timer = Timers->Get(conflicts[i]->timerIDs[j]); const cTimer *timer = Timers->Get(conflicts[i]->timerIDs[j]);
#else #else
const cTimer *timer = Timers.Get(conflicts[i]->timerIDs[j]); const cTimer *timer = Timers.Get(conflicts[i]->timerIDs[j]);
#endif #endif
if (timer) { if (timer) {
if (!unionSet) { if (!unionSet) {
unionSet = new cTimeInterval(timer->StartTime(), timer->StopTime()); unionSet = new cTimeInterval(timer->StartTime(), timer->StopTime());
} else { } else {
cTimeInterval *timerInterval = new cTimeInterval(timer->StartTime(), timer->StopTime()); cTimeInterval *timerInterval = new cTimeInterval(timer->StartTime(), timer->StopTime());
cTimeInterval *newUnion = unionSet->Union(timerInterval); cTimeInterval *newUnion = unionSet->Union(timerInterval);
delete unionSet; delete unionSet;
delete timerInterval; delete timerInterval;
unionSet = newUnion; unionSet = newUnion;
} }
} }
} }
conflicts[i]->timeStart = unionSet->Start(); conflicts[i]->timeStart = unionSet->Start();
conflicts[i]->timeStop = unionSet->Stop(); conflicts[i]->timeStop = unionSet->Stop();
delete unionSet; delete unionSet;
cTimeInterval *intersect = NULL; cTimeInterval *intersect = NULL;
for (int j=0; j < numTimers; j++) { for (int j=0; j < numTimers; j++) {
#if VDRVERSNUM >= 20301 #if VDRVERSNUM >= 20301
LOCK_TIMERS_READ; LOCK_TIMERS_READ;
const cTimer *timer = Timers->Get(conflicts[i]->timerIDs[j]); const cTimer *timer = Timers->Get(conflicts[i]->timerIDs[j]);
#else #else
const cTimer *timer = Timers.Get(conflicts[i]->timerIDs[j]); const cTimer *timer = Timers.Get(conflicts[i]->timerIDs[j]);
#endif #endif
if (timer) { if (timer) {
if (!intersect) { if (!intersect) {
intersect = new cTimeInterval(timer->StartTime(), timer->StopTime()); intersect = new cTimeInterval(timer->StartTime(), timer->StopTime());
} else { } else {
cTimeInterval *timerInterval = new cTimeInterval(timer->StartTime(), timer->StopTime()); cTimeInterval *timerInterval = new cTimeInterval(timer->StartTime(), timer->StopTime());
cTimeInterval *newIntersect = intersect->Intersect(timerInterval); cTimeInterval *newIntersect = intersect->Intersect(timerInterval);
if (newIntersect) { if (newIntersect) {
delete intersect; delete intersect;
intersect = newIntersect; intersect = newIntersect;
} }
delete timerInterval; delete timerInterval;
} }
} }
} }
conflicts[i]->overlapStart = intersect->Start(); conflicts[i]->overlapStart = intersect->Start();
conflicts[i]->overlapStop = intersect->Stop(); conflicts[i]->overlapStop = intersect->Stop();
delete intersect; delete intersect;
} }
} }
cTVGuideTimerConflict *cTVGuideTimerConflicts::GetCurrentConflict(void) { cTVGuideTimerConflict *cTVGuideTimerConflicts::GetCurrentConflict(void) {
if (currentConflict < 0) if (currentConflict < 0)
return NULL; return NULL;
if (currentConflict > (numConflicts-1)) if (currentConflict > (numConflicts-1))
return NULL; return NULL;
return conflicts[currentConflict]; return conflicts[currentConflict];
} }
int cTVGuideTimerConflicts::GetCurrentConflictTimerID(int timerIndex) { int cTVGuideTimerConflicts::GetCurrentConflictTimerID(int timerIndex) {
if (currentConflict < 0) if (currentConflict < 0)
return -1; return -1;
if (currentConflict > (numConflicts-1)) if (currentConflict > (numConflicts-1))
return -1; return -1;
int numTimersInConflict = conflicts[currentConflict]->timerIDs.size(); int numTimersInConflict = conflicts[currentConflict]->timerIDs.size();
if (timerIndex > (numTimersInConflict - 1)) if (timerIndex > (numTimersInConflict - 1))
return -1; return -1;
return conflicts[currentConflict]->timerIDs[timerIndex]; return conflicts[currentConflict]->timerIDs[timerIndex];
} }
int cTVGuideTimerConflicts::GetCorrespondingConflict(int timerID) { int cTVGuideTimerConflicts::GetCorrespondingConflict(int timerID) {
int conflictIndex = -1; int conflictIndex = -1;
if (numConflicts > 0) { if (numConflicts > 0) {
for (int i=0; i<numConflicts; i++) { for (int i=0; i<numConflicts; i++) {
if (conflicts[i]->timerInvolved(timerID)) { if (conflicts[i]->timerInvolved(timerID)) {
conflictIndex = i; conflictIndex = i;
break; break;
} }
} }
} }
return conflictIndex; return conflictIndex;
} }
cTVGuideTimerConflict *cTVGuideTimerConflicts::GetConflict(int conflictIndex) { cTVGuideTimerConflict *cTVGuideTimerConflicts::GetConflict(int conflictIndex) {
if (conflictIndex < 0) if (conflictIndex < 0)
return NULL; return NULL;
if (conflictIndex > (numConflicts-1)) if (conflictIndex > (numConflicts-1))
return NULL; return NULL;
return conflicts[conflictIndex]; return conflicts[conflictIndex];
} }
std::vector<cTVGuideTimerConflict*> cTVGuideTimerConflicts::GetConflictsBetween(time_t start, time_t stop) { std::vector<cTVGuideTimerConflict*> cTVGuideTimerConflicts::GetConflictsBetween(time_t start, time_t stop) {
std::vector<cTVGuideTimerConflict*> conflictsFound; std::vector<cTVGuideTimerConflict*> conflictsFound;
for (int i=0; i < numConflicts; i++) { for (int i=0; i < numConflicts; i++) {
if ((conflicts[i]->timeStart > start) && (conflicts[i]->timeStart < stop)|| if ((conflicts[i]->timeStart > start) && (conflicts[i]->timeStart < stop)||
(conflicts[i]->timeStop > start) && (conflicts[i]->timeStop < stop)) (conflicts[i]->timeStop > start) && (conflicts[i]->timeStop < stop))
conflictsFound.push_back(conflicts[i]); conflictsFound.push_back(conflicts[i]);
} }
return conflictsFound; return conflictsFound;
} }

View File

@ -1,38 +1,38 @@
#ifndef __TVGUIDE_TIMERCONFLICT_H #ifndef __TVGUIDE_TIMERCONFLICT_H
#define __TVGUIDE_TIMERCONFLICT_H #define __TVGUIDE_TIMERCONFLICT_H
class cTVGuideTimerConflict { class cTVGuideTimerConflict {
public: public:
cTVGuideTimerConflict(void); cTVGuideTimerConflict(void);
virtual ~cTVGuideTimerConflict(void); virtual ~cTVGuideTimerConflict(void);
time_t time; time_t time;
time_t timeStart; time_t timeStart;
time_t timeStop; time_t timeStop;
time_t overlapStart; time_t overlapStart;
time_t overlapStop; time_t overlapStop;
int percentPossible; int percentPossible;
int timerID; int timerID;
std::vector<int> timerIDs; std::vector<int> timerIDs;
bool timerInvolved(int involvedID); bool timerInvolved(int involvedID);
}; };
class cTVGuideTimerConflicts { class cTVGuideTimerConflicts {
private: private:
std::vector<cTVGuideTimerConflict*> conflicts; std::vector<cTVGuideTimerConflict*> conflicts;
int numConflicts; int numConflicts;
int currentConflict; int currentConflict;
public: public:
cTVGuideTimerConflicts(void); cTVGuideTimerConflicts(void);
virtual ~cTVGuideTimerConflicts(void); virtual ~cTVGuideTimerConflicts(void);
void AddConflict(std::string epgSearchConflictLine); void AddConflict(std::string epgSearchConflictLine);
void CalculateConflicts(void); void CalculateConflicts(void);
int NumConflicts(void) {return numConflicts; }; int NumConflicts(void) {return numConflicts; };
void SetCurrentConflict(int current) { currentConflict = current; }; void SetCurrentConflict(int current) { currentConflict = current; };
cTVGuideTimerConflict *GetCurrentConflict(void); cTVGuideTimerConflict *GetCurrentConflict(void);
int GetCurrentConflictTimerID(int timerIndex); int GetCurrentConflictTimerID(int timerIndex);
int GetCorrespondingConflict(int timerID); int GetCorrespondingConflict(int timerID);
cTVGuideTimerConflict *GetConflict(int conflictIndex); cTVGuideTimerConflict *GetConflict(int conflictIndex);
std::vector<cTVGuideTimerConflict*> GetConflictsBetween(time_t start, time_t stop); std::vector<cTVGuideTimerConflict*> GetConflictsBetween(time_t start, time_t stop);
}; };
#endif //__TVGUIDE_RECMMANAGER_H #endif //__TVGUIDE_RECMMANAGER_H

964
tools.c
View File

@ -1,482 +1,482 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <sstream> #include <sstream>
#include <algorithm> #include <algorithm>
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <vdr/osd.h> #include <vdr/osd.h>
#include <vdr/plugin.h> #include <vdr/plugin.h>
#include <vdr/skins.h> #include <vdr/skins.h>
#include "services/epgsearch.h" #include "services/epgsearch.h"
#include "tools.h" #include "tools.h"
cPlugin *GetScraperPlugin(void) { cPlugin *GetScraperPlugin(void) {
static cPlugin *pScraper = cPluginManager::GetPlugin("scraper2vdr"); static cPlugin *pScraper = cPluginManager::GetPlugin("scraper2vdr");
if( !pScraper ) // if it doesn't exit, try tvscraper if( !pScraper ) // if it doesn't exit, try tvscraper
pScraper = cPluginManager::GetPlugin("tvscraper"); pScraper = cPluginManager::GetPlugin("tvscraper");
return pScraper; return pScraper;
} }
/**************************************************************************************** /****************************************************************************************
* CUTTEXT * CUTTEXT
****************************************************************************************/ ****************************************************************************************/
std::string CutText(std::string text, int width, const cFont *font) { std::string CutText(std::string text, int width, const cFont *font) {
if (width <= font->Size()) if (width <= font->Size())
return text.c_str(); return text.c_str();
if (font->Width(text.c_str()) < width) if (font->Width(text.c_str()) < width)
return text.c_str(); return text.c_str();
cTextWrapper twText; cTextWrapper twText;
twText.Set(text.c_str(), font, width); twText.Set(text.c_str(), font, width);
std::string cuttedTextNative = twText.GetLine(0); std::string cuttedTextNative = twText.GetLine(0);
std::stringstream sstrText; std::stringstream sstrText;
sstrText << cuttedTextNative << "..."; sstrText << cuttedTextNative << "...";
std::string cuttedText = sstrText.str(); std::string cuttedText = sstrText.str();
int actWidth = font->Width(cuttedText.c_str()); int actWidth = font->Width(cuttedText.c_str());
if (actWidth > width) { if (actWidth > width) {
int overlap = actWidth - width; int overlap = actWidth - width;
int charWidth = font->Width("."); int charWidth = font->Width(".");
if (charWidth == 0) if (charWidth == 0)
charWidth = 1; charWidth = 1;
int cutChars = overlap / charWidth; int cutChars = overlap / charWidth;
if (cutChars > 0) { if (cutChars > 0) {
cuttedTextNative = cuttedTextNative.substr(0, cuttedTextNative.length() - cutChars); cuttedTextNative = cuttedTextNative.substr(0, cuttedTextNative.length() - cutChars);
std::stringstream sstrText2; std::stringstream sstrText2;
sstrText2 << cuttedTextNative << "..."; sstrText2 << cuttedTextNative << "...";
cuttedText = sstrText2.str(); cuttedText = sstrText2.str();
} }
} }
return cuttedText; return cuttedText;
} }
/**************************************************************************************** /****************************************************************************************
* StrToLowerCase * StrToLowerCase
****************************************************************************************/ ****************************************************************************************/
std::string StrToLowerCase(std::string str) { std::string StrToLowerCase(std::string str) {
std::string lowerCase = str; std::string lowerCase = str;
const int length = lowerCase.length(); const int length = lowerCase.length();
for(int i=0; i < length; ++i) { for(int i=0; i < length; ++i) {
lowerCase[i] = std::tolower(lowerCase[i]); lowerCase[i] = std::tolower(lowerCase[i]);
} }
return lowerCase; return lowerCase;
} }
/**************************************************************************************** /****************************************************************************************
* GetDirectoryFromTimer * GetDirectoryFromTimer
****************************************************************************************/ ****************************************************************************************/
std::string GetDirectoryFromTimer(std::string file) { std::string GetDirectoryFromTimer(std::string file) {
std::string dir = ""; std::string dir = "";
size_t found = file.find_last_of('~'); size_t found = file.find_last_of('~');
if (found != std::string::npos) { if (found != std::string::npos) {
dir = file.substr(0, found); dir = file.substr(0, found);
} }
return dir; return dir;
} }
/**************************************************************************************** /****************************************************************************************
* GetDirectoryFromTimer * GetDirectoryFromTimer
****************************************************************************************/ ****************************************************************************************/
void ReadRecordingDirectories(std::vector<std::string> *folders, cList<cNestedItem> *rootFolders, cString path) { void ReadRecordingDirectories(std::vector<std::string> *folders, cList<cNestedItem> *rootFolders, cString path) {
cPlugin *epgSearchPlugin = NULL; cPlugin *epgSearchPlugin = NULL;
epgSearchPlugin = cPluginManager::GetPlugin("epgsearch"); epgSearchPlugin = cPluginManager::GetPlugin("epgsearch");
if (epgSearchPlugin) { if (epgSearchPlugin) {
Epgsearch_services_v1_0 *epgSearch = new Epgsearch_services_v1_0; Epgsearch_services_v1_0 *epgSearch = new Epgsearch_services_v1_0;
if (epgSearchPlugin->Service("Epgsearch-services-v1.0", epgSearch)) { if (epgSearchPlugin->Service("Epgsearch-services-v1.0", epgSearch)) {
std::set<std::string> epgSearchDirs = epgSearch->handler->DirectoryList(); std::set<std::string> epgSearchDirs = epgSearch->handler->DirectoryList();
std::set<std::string>::iterator it; std::set<std::string>::iterator it;
for (it = epgSearchDirs.begin(); it != epgSearchDirs.end(); it++) { for (it = epgSearchDirs.begin(); it != epgSearchDirs.end(); it++) {
std::string newFolder = *it; std::string newFolder = *it;
std::replace(newFolder.begin(), newFolder.end(), '/', '~'); std::replace(newFolder.begin(), newFolder.end(), '/', '~');
folders->push_back(newFolder); folders->push_back(newFolder);
} }
} }
} else { } else {
cList<cNestedItem> *foldersLevel = NULL; cList<cNestedItem> *foldersLevel = NULL;
if (rootFolders) { if (rootFolders) {
foldersLevel = rootFolders; foldersLevel = rootFolders;
} else { } else {
foldersLevel = &Folders; foldersLevel = &Folders;
} }
for (cNestedItem *folder = foldersLevel->First(); folder; folder = foldersLevel->Next(folder)) { for (cNestedItem *folder = foldersLevel->First(); folder; folder = foldersLevel->Next(folder)) {
std::string strFolder = *cString::sprintf("%s%s", *path, folder->Text()); std::string strFolder = *cString::sprintf("%s%s", *path, folder->Text());
std::replace(strFolder.begin(), strFolder.end(), '/', '~'); std::replace(strFolder.begin(), strFolder.end(), '/', '~');
folders->push_back(strFolder); folders->push_back(strFolder);
cList<cNestedItem> *subItems = folder->SubItems(); cList<cNestedItem> *subItems = folder->SubItems();
if (subItems) { if (subItems) {
std::string strFolder2 = *cString::sprintf("%s%s", *path, folder->Text()); std::string strFolder2 = *cString::sprintf("%s%s", *path, folder->Text());
std::replace(strFolder2.begin(), strFolder2.end(), '/', '~'); std::replace(strFolder2.begin(), strFolder2.end(), '/', '~');
ReadRecordingDirectories(folders, subItems, strFolder2.c_str()); ReadRecordingDirectories(folders, subItems, strFolder2.c_str());
} }
} }
} }
} }
/**************************************************************************************** /****************************************************************************************
* DrawRoundedCorners * DrawRoundedCorners
****************************************************************************************/ ****************************************************************************************/
void DrawRoundedCorners(cPixmap *p, int posX, int posY, int width, int height, int radius, int borderWidth, tColor borderColor) { void DrawRoundedCorners(cPixmap *p, int posX, int posY, int width, int height, int radius, int borderWidth, tColor borderColor) {
if( height > 2*radius) { if( height > 2*radius) {
p->DrawEllipse(cRect(posX, posY, radius, radius), borderColor, -2); p->DrawEllipse(cRect(posX, posY, radius, radius), borderColor, -2);
p->DrawEllipse(cRect(posX - borderWidth, posY - borderWidth, radius, radius), clrTransparent, -2); p->DrawEllipse(cRect(posX - borderWidth, posY - borderWidth, radius, radius), clrTransparent, -2);
p->DrawEllipse(cRect(posX+width - radius, posY, radius, radius), borderColor, -1); p->DrawEllipse(cRect(posX+width - radius, posY, radius, radius), borderColor, -1);
p->DrawEllipse(cRect(posX+width - radius + borderWidth, posY - borderWidth, radius, radius), clrTransparent, -1); p->DrawEllipse(cRect(posX+width - radius + borderWidth, posY - borderWidth, radius, radius), clrTransparent, -1);
p->DrawEllipse(cRect(posX, posY + height - radius, radius, radius), borderColor, -3); p->DrawEllipse(cRect(posX, posY + height - radius, radius, radius), borderColor, -3);
p->DrawEllipse(cRect(posX - borderWidth, posY + height - radius + borderWidth, radius, radius), clrTransparent, -3); p->DrawEllipse(cRect(posX - borderWidth, posY + height - radius + borderWidth, radius, radius), clrTransparent, -3);
p->DrawEllipse(cRect(posX + width - radius, posY + height - radius, radius, radius), borderColor, -4); p->DrawEllipse(cRect(posX + width - radius, posY + height - radius, radius, radius), borderColor, -4);
p->DrawEllipse(cRect(posX + width - radius + borderWidth, posY + height - radius + borderWidth, radius, radius), clrTransparent, -4); p->DrawEllipse(cRect(posX + width - radius + borderWidth, posY + height - radius + borderWidth, radius, radius), clrTransparent, -4);
} }
} }
/**************************************************************************************** /****************************************************************************************
* SPLTSTRING * SPLTSTRING
****************************************************************************************/ ****************************************************************************************/
// split: receives a char delimiter; returns a vector of strings // split: receives a char delimiter; returns a vector of strings
// By default ignores repeated delimiters, unless argument rep == 1. // By default ignores repeated delimiters, unless argument rep == 1.
std::vector<std::string>& splitstring::split(char delim, int rep) { std::vector<std::string>& splitstring::split(char delim, int rep) {
if (!flds.empty()) flds.clear(); // empty vector if necessary if (!flds.empty()) flds.clear(); // empty vector if necessary
std::string work = data(); std::string work = data();
std::string buf = ""; std::string buf = "";
int i = 0; int i = 0;
while (i < work.length()) { while (i < work.length()) {
if (work[i] != delim) if (work[i] != delim)
buf += work[i]; buf += work[i];
else if (rep == 1) { else if (rep == 1) {
flds.push_back(buf); flds.push_back(buf);
buf = ""; buf = "";
} else if (buf.length() > 0) { } else if (buf.length() > 0) {
flds.push_back(buf); flds.push_back(buf);
buf = ""; buf = "";
} }
i++; i++;
} }
if (!buf.empty()) if (!buf.empty())
flds.push_back(buf); flds.push_back(buf);
return flds; return flds;
} }
/**************************************************************************************** /****************************************************************************************
* FINDIGNORECASE * FINDIGNORECASE
****************************************************************************************/ ****************************************************************************************/
int FindIgnoreCase(const std::string& expr, const std::string& query) int FindIgnoreCase(const std::string& expr, const std::string& query)
{ {
const char *p = expr.c_str(); const char *p = expr.c_str();
const char *r = strcasestr(p, query.c_str()); const char *r = strcasestr(p, query.c_str());
if (!r) if (!r)
return -1; return -1;
return r - p; return r - p;
} }
/**************************************************************************************** /****************************************************************************************
* GetAuxValue * GetAuxValue
****************************************************************************************/ ****************************************************************************************/
char* GetAuxValue(const char* aux, const char* name) { char* GetAuxValue(const char* aux, const char* name) {
if (isempty(aux)) if (isempty(aux))
return NULL; return NULL;
char* descr = strdup(aux); char* descr = strdup(aux);
char* beginaux = strstr(descr, "<epgsearch>"); char* beginaux = strstr(descr, "<epgsearch>");
char* endaux = strstr(descr, "</epgsearch>"); char* endaux = strstr(descr, "</epgsearch>");
if (!beginaux || !endaux) { if (!beginaux || !endaux) {
free(descr); free(descr);
return NULL; return NULL;
} }
beginaux += 11; // strlen("<epgsearch>"); beginaux += 11; // strlen("<epgsearch>");
endaux[0] = 0; endaux[0] = 0;
memmove(descr, beginaux, endaux - beginaux + 1); memmove(descr, beginaux, endaux - beginaux + 1);
if (strcmp(name, "epgsearch") == 0) if (strcmp(name, "epgsearch") == 0)
return descr; // full aux return descr; // full aux
int namelen = strlen(name); int namelen = strlen(name);
char catname[100] = ""; char catname[100] = "";
catname[0] = '<'; catname[0] = '<';
memcpy(catname + 1, name, namelen); memcpy(catname + 1, name, namelen);
catname[1 + namelen] = '>'; catname[1 + namelen] = '>';
catname[2 + namelen] = 0; catname[2 + namelen] = 0;
char* cat = strcasestr(descr, catname); char* cat = strcasestr(descr, catname);
if (!cat) { if (!cat) {
free(descr); free(descr);
return NULL; return NULL;
} }
cat += namelen + 2; cat += namelen + 2;
char* end = strstr(cat, "</"); char* end = strstr(cat, "</");
if (!end) { if (!end) {
free(descr); free(descr);
return NULL; return NULL;
} }
end[0] = 0; end[0] = 0;
int catlen = end - cat + 1; int catlen = end - cat + 1;
char* value = (char *) malloc(catlen); char* value = (char *) malloc(catlen);
memcpy(value, cat, catlen); memcpy(value, cat, catlen);
free(descr); free(descr);
return value; return value;
} }
char* GetAuxValue(const cRecording *recording, const char* name) { char* GetAuxValue(const cRecording *recording, const char* name) {
if (!recording || !recording->Info()) if (!recording || !recording->Info())
return NULL; return NULL;
return GetAuxValue(recording->Info()->Aux(), name); return GetAuxValue(recording->Info()->Aux(), name);
} }
char* GetAuxValue(const cTimer *timer, const char* name) { char* GetAuxValue(const cTimer *timer, const char* name) {
if (!timer || !timer->Aux()) if (!timer || !timer->Aux())
return NULL; return NULL;
return GetAuxValue(timer->Aux(), name); return GetAuxValue(timer->Aux(), name);
} }
/**************************************************************************************** /****************************************************************************************
* FUZZYSEARCH * FUZZYSEARCH
****************************************************************************************/ ****************************************************************************************/
/****************************************************************************** /******************************************************************************
FUNCTION afuzzy_init() FUNCTION afuzzy_init()
Initialization of the fuzzy search routine. This applies to the consequent Initialization of the fuzzy search routine. This applies to the consequent
calls of the afuzzy_CheckRTR (whole string matching) and afuzzy_CheckSUB calls of the afuzzy_CheckRTR (whole string matching) and afuzzy_CheckSUB
(substring match) routines. afuzzy_init() should be called for each (substring match) routines. afuzzy_init() should be called for each
new pattern or error length. The search is case sensitive new pattern or error length. The search is case sensitive
ARGUMENTS: ARGUMENTS:
p Pattern p Pattern
kerr Number of possible errors. Shouldn't exceed pattern length kerr Number of possible errors. Shouldn't exceed pattern length
UseFilter Use agrep filter algorithm that speeds up search. UseFilter Use agrep filter algorithm that speeds up search.
fuzzy pointer to the structure that will be later passes to Check* fuzzy pointer to the structure that will be later passes to Check*
(the first 6 elements should be NULLs for the first call) (the first 6 elements should be NULLs for the first call)
RETURN VALUE: RETURN VALUE:
none none
ALGORITHM ALGORITHM
see. the article on agrep algorithms. see. the article on agrep algorithms.
The only change is accounting transpositions as one edit operation . The only change is accounting transpositions as one edit operation .
******************************************************************************/ ******************************************************************************/
void afuzzy_init(const char *p, int kerr, int UseFilter, AFUZZY *fuzzy) void afuzzy_init(const char *p, int kerr, int UseFilter, AFUZZY *fuzzy)
{ {
int cnt, p_len, i, j, l, d, m, dd; int cnt, p_len, i, j, l, d, m, dd;
char PatFilter[sizeof(Uint)*8 + 1]; char PatFilter[sizeof(Uint)*8 + 1];
fuzzy->k = kerr; fuzzy->k = kerr;
m = strlen(p); m = strlen(p);
fuzzy->FilterSet = 0; fuzzy->FilterSet = 0;
memset(fuzzy->Map, 0 , sizeof(fuzzy->Map) ); memset(fuzzy->Map, 0 , sizeof(fuzzy->Map) );
if (fuzzy->S) if (fuzzy->S)
free(fuzzy->S); free(fuzzy->S);
if (fuzzy->R) if (fuzzy->R)
free(fuzzy->R); free(fuzzy->R);
if (fuzzy->R1) if (fuzzy->R1)
free(fuzzy->R1); free(fuzzy->R1);
if (fuzzy->RP) if (fuzzy->RP)
free(fuzzy->RP); free(fuzzy->RP);
if (fuzzy->RI) if (fuzzy->RI)
free(fuzzy->RI); free(fuzzy->RI);
if (fuzzy->FilterS) if (fuzzy->FilterS)
free(fuzzy->FilterS); free(fuzzy->FilterS);
fuzzy->FilterS = NULL; fuzzy->FilterS = NULL;
fuzzy->S = (Uint *)calloc(m + 1, sizeof(Uint)); fuzzy->S = (Uint *)calloc(m + 1, sizeof(Uint));
fuzzy->R = (Uint *)calloc(fuzzy->k + 1, sizeof(Uint)); fuzzy->R = (Uint *)calloc(fuzzy->k + 1, sizeof(Uint));
fuzzy->R1 = (Uint *)calloc(fuzzy->k + 1, sizeof(Uint)); fuzzy->R1 = (Uint *)calloc(fuzzy->k + 1, sizeof(Uint));
fuzzy->RI = (Uint *)calloc(fuzzy->k + 1, sizeof(Uint)); fuzzy->RI = (Uint *)calloc(fuzzy->k + 1, sizeof(Uint));
fuzzy->RP = (Uint *)calloc(fuzzy->k + 1, sizeof(Uint)); fuzzy->RP = (Uint *)calloc(fuzzy->k + 1, sizeof(Uint));
for (i = 0, cnt = 0; i < m; i++) for (i = 0, cnt = 0; i < m; i++)
{ {
l = fuzzy->Map[(unsigned char)p[i]]; l = fuzzy->Map[(unsigned char)p[i]];
if (!l) if (!l)
{ {
l = fuzzy->Map[(unsigned char)p[i]] = ++cnt; l = fuzzy->Map[(unsigned char)p[i]] = ++cnt;
fuzzy->S[l] = 0; fuzzy->S[l] = 0;
} }
fuzzy->S[l] |= 1 << i; fuzzy->S[l] |= 1 << i;
} }
for (d = 0; d <= fuzzy->k; d++) for (d = 0; d <= fuzzy->k; d++)
fuzzy->RI[d] = (1 << d) - 1; fuzzy->RI[d] = (1 << d) - 1;
fuzzy->mask_ok = (1 << (m - 1)); fuzzy->mask_ok = (1 << (m - 1));
fuzzy->r_size = sizeof(Uint) * (fuzzy->k + 1); fuzzy->r_size = sizeof(Uint) * (fuzzy->k + 1);
p_len = m; p_len = m;
if (p_len > (int) sizeof(Uint)*8) if (p_len > (int) sizeof(Uint)*8)
p_len = (int) sizeof(Uint)*8; p_len = (int) sizeof(Uint)*8;
/* If k is zero then no filter is needed! */ /* If k is zero then no filter is needed! */
if (fuzzy->k && (p_len >= 2*(fuzzy->k + 1)) ) if (fuzzy->k && (p_len >= 2*(fuzzy->k + 1)) )
{ {
if (UseFilter) if (UseFilter)
{ {
fuzzy->FilterSet = 1; fuzzy->FilterSet = 1;
memset(fuzzy->FilterMap, 0 , sizeof(fuzzy->FilterMap) ); memset(fuzzy->FilterMap, 0 , sizeof(fuzzy->FilterMap) );
fuzzy->FilterS = (Uint *)calloc(m + 1, sizeof(Uint)); fuzzy->FilterS = (Uint *)calloc(m + 1, sizeof(Uint));
/* Not let's fill the interleaved pattern */ /* Not let's fill the interleaved pattern */
dd = p_len / (fuzzy->k + 1); dd = p_len / (fuzzy->k + 1);
p_len = dd * (fuzzy->k + 1); p_len = dd * (fuzzy->k + 1);
for (i = 0, cnt = 0; i < dd; i++) for (i = 0, cnt = 0; i < dd; i++)
for (j = 0; j < fuzzy->k + 1; j++, cnt++) for (j = 0; j < fuzzy->k + 1; j++, cnt++)
PatFilter[cnt] = (unsigned char)p[j*dd + i]; PatFilter[cnt] = (unsigned char)p[j*dd + i];
PatFilter[p_len] = 0; PatFilter[p_len] = 0;
for (i = 0, cnt = 0; i < p_len; i++) for (i = 0, cnt = 0; i < p_len; i++)
{ {
l = fuzzy->FilterMap[(unsigned char)PatFilter[i]]; l = fuzzy->FilterMap[(unsigned char)PatFilter[i]];
if (!l) if (!l)
{ {
l = fuzzy->FilterMap[(unsigned char)PatFilter[i]] = ++cnt; l = fuzzy->FilterMap[(unsigned char)PatFilter[i]] = ++cnt;
fuzzy->FilterS[l] = 0; fuzzy->FilterS[l] = 0;
} }
fuzzy->FilterS[l] |= 1 << i; fuzzy->FilterS[l] |= 1 << i;
} }
fuzzy->filter_ok = 0; fuzzy->filter_ok = 0;
for (i = p_len - fuzzy->k - 1; i <= p_len - 1; i++) /* k+1 times */ for (i = p_len - fuzzy->k - 1; i <= p_len - 1; i++) /* k+1 times */
fuzzy->filter_ok |= 1 << i; fuzzy->filter_ok |= 1 << i;
/* k+1 first bits set to 1 */ /* k+1 first bits set to 1 */
fuzzy->filter_shift = (1 << (fuzzy->k + 2)) - 1; fuzzy->filter_shift = (1 << (fuzzy->k + 2)) - 1;
} }
} }
} }
/****************************************************************************** /******************************************************************************
FUNCTION afuzzy_free() FUNCTION afuzzy_free()
Cleaning up after previous afuzzy_init() call. Cleaning up after previous afuzzy_init() call.
ARGUMENTS: ARGUMENTS:
fuzzy pointer to the afuzzy parameters structure fuzzy pointer to the afuzzy parameters structure
RETURN VALUE: RETURN VALUE:
none none
******************************************************************************/ ******************************************************************************/
void afuzzy_free(AFUZZY *fuzzy) void afuzzy_free(AFUZZY *fuzzy)
{ {
if (fuzzy->S) if (fuzzy->S)
{ {
free(fuzzy->S); free(fuzzy->S);
fuzzy->S = NULL; fuzzy->S = NULL;
} }
if (fuzzy->R) if (fuzzy->R)
{ {
free(fuzzy->R); free(fuzzy->R);
fuzzy->R = NULL; fuzzy->R = NULL;
} }
if (fuzzy->R1) if (fuzzy->R1)
{ {
free(fuzzy->R1); free(fuzzy->R1);
fuzzy->R1 = NULL; fuzzy->R1 = NULL;
} }
if (fuzzy->RP) if (fuzzy->RP)
{ {
free(fuzzy->RP); free(fuzzy->RP);
fuzzy->RP = NULL; fuzzy->RP = NULL;
} }
if (fuzzy->RI) if (fuzzy->RI)
{ {
free(fuzzy->RI); free(fuzzy->RI);
fuzzy->RI = NULL; fuzzy->RI = NULL;
} }
if (fuzzy->FilterS) if (fuzzy->FilterS)
{ {
free(fuzzy->FilterS); free(fuzzy->FilterS);
fuzzy->FilterS = NULL; fuzzy->FilterS = NULL;
} }
} }
/****************************************************************************** /******************************************************************************
FUNCTION afuzzy_CheckSUB() FUNCTION afuzzy_CheckSUB()
Perform a fuzzy pattern substring matching. afuzzy_init() should be Perform a fuzzy pattern substring matching. afuzzy_init() should be
called previously to initialize the pattern and error length. called previously to initialize the pattern and error length.
Positive result means that some part of the string given matches the Positive result means that some part of the string given matches the
pattern with no more than afuzzy->k errors (1 error = 1 letter pattern with no more than afuzzy->k errors (1 error = 1 letter
replacement or transposition) replacement or transposition)
ARGUMENTS: ARGUMENTS:
t the string to test t the string to test
fuzzy pointer to the afuzzy parameters structure fuzzy pointer to the afuzzy parameters structure
RETURN VALUE: RETURN VALUE:
0 - no match 0 - no match
> 0 - strings match > 0 - strings match
ALGORITHM ALGORITHM
???????????????? ????????????????
******************************************************************************/ ******************************************************************************/
int afuzzy_checkSUB(const char *t, AFUZZY *fuzzy) int afuzzy_checkSUB(const char *t, AFUZZY *fuzzy)
{ {
register char c; register char c;
register int j, d; register int j, d;
/* For eficciency this case should be little bit optimized */ /* For eficciency this case should be little bit optimized */
if (!fuzzy->k) if (!fuzzy->k)
{ {
Uint R = 0, R1; Uint R = 0, R1;
for (j = 0; (c = t[j]) != '\0'; j++) for (j = 0; (c = t[j]) != '\0'; j++)
{ {
R1 = ( ((R<<1) | 1) & fuzzy->S[fuzzy->Map[(unsigned char)c]]); R1 = ( ((R<<1) | 1) & fuzzy->S[fuzzy->Map[(unsigned char)c]]);
R = R1; R = R1;
if (R1 & fuzzy->mask_ok) if (R1 & fuzzy->mask_ok)
return 1; return 1;
} /* end for (register int j = 0 ... */ } /* end for (register int j = 0 ... */
return 0; return 0;
} }
if (fuzzy->FilterSet && !afuzzy_checkFLT(t, fuzzy)) if (fuzzy->FilterSet && !afuzzy_checkFLT(t, fuzzy))
return 0; return 0;
memcpy(fuzzy->R, fuzzy->RI, fuzzy->r_size); /* R = RI */ memcpy(fuzzy->R, fuzzy->RI, fuzzy->r_size); /* R = RI */
for (j = 0; (c = t[j]); j++) for (j = 0; (c = t[j]); j++)
{ {
for (d = 0; d <= fuzzy->k; d++) for (d = 0; d <= fuzzy->k; d++)
{ {
fuzzy->R1[d] = (((fuzzy->R[d]<<1) | 1) & fuzzy->R1[d] = (((fuzzy->R[d]<<1) | 1) &
fuzzy->S[fuzzy->Map[(unsigned char)c]]); fuzzy->S[fuzzy->Map[(unsigned char)c]]);
if (d > 0) if (d > 0)
fuzzy->R1[d] |= ((fuzzy->R[d-1] | fuzzy->R1[d-1])<<1) | 1 | fuzzy->R1[d] |= ((fuzzy->R[d-1] | fuzzy->R1[d-1])<<1) | 1 |
fuzzy->R[d-1]; fuzzy->R[d-1];
} }
if (fuzzy->R1[fuzzy->k] & fuzzy->mask_ok) if (fuzzy->R1[fuzzy->k] & fuzzy->mask_ok)
return j; return j;
memcpy(fuzzy->R, fuzzy->R1, fuzzy->r_size); memcpy(fuzzy->R, fuzzy->R1, fuzzy->r_size);
} /* end for (register int j = 0 ... */ } /* end for (register int j = 0 ... */
return 0; return 0;
} }
int afuzzy_checkFLT(const char *t, AFUZZY *fuzzy) int afuzzy_checkFLT(const char *t, AFUZZY *fuzzy)
{ {
register Uint FilterR = 0; register Uint FilterR = 0;
register Uint FilterR1; register Uint FilterR1;
register int j; register int j;
for (j = 0; t[j] != '\0'; j++) for (j = 0; t[j] != '\0'; j++)
{ {
FilterR1 = ( ((FilterR<<(fuzzy->k+1)) | fuzzy->filter_shift) & FilterR1 = ( ((FilterR<<(fuzzy->k+1)) | fuzzy->filter_shift) &
fuzzy->FilterS[fuzzy->FilterMap[(unsigned char)t[j]]]); fuzzy->FilterS[fuzzy->FilterMap[(unsigned char)t[j]]]);
if (FilterR1 & fuzzy->filter_ok) if (FilterR1 & fuzzy->filter_ok)
return 1; return 1;
FilterR = FilterR1; FilterR = FilterR1;
} /* end for (register int j = 0 ... */ } /* end for (register int j = 0 ... */
return 0; return 0;
} }

142
tools.h
View File

@ -1,71 +1,71 @@
#ifndef __TVGUIDETOOLS_H #ifndef __TVGUIDETOOLS_H
#define __TVGUIDETOOLS_H #define __TVGUIDETOOLS_H
#include <string> #include <string>
#include <vector> #include <vector>
#include <vdr/font.h> #include <vdr/font.h>
#include <vdr/recording.h> #include <vdr/recording.h>
#include <vdr/plugin.h> #include <vdr/plugin.h>
cPlugin *GetScraperPlugin(void); cPlugin *GetScraperPlugin(void);
std::string CutText(std::string text, int width, const cFont *font); std::string CutText(std::string text, int width, const cFont *font);
std::string StrToLowerCase(std::string str); std::string StrToLowerCase(std::string str);
std::string GetDirectoryFromTimer(std::string file); std::string GetDirectoryFromTimer(std::string file);
void ReadRecordingDirectories(std::vector<std::string> *folders, cList<cNestedItem> *rootFolders, cString path); void ReadRecordingDirectories(std::vector<std::string> *folders, cList<cNestedItem> *rootFolders, cString path);
void DrawRoundedCorners(cPixmap *p, int posX, int posY, int width, int height, int radius, int borderWidth, tColor borderColor); void DrawRoundedCorners(cPixmap *p, int posX, int posY, int width, int height, int radius, int borderWidth, tColor borderColor);
class splitstring : public std::string { class splitstring : public std::string {
std::vector<std::string> flds; std::vector<std::string> flds;
public: public:
splitstring(const char *s) : std::string(s) { }; splitstring(const char *s) : std::string(s) { };
std::vector<std::string>& split(char delim, int rep=0); std::vector<std::string>& split(char delim, int rep=0);
}; };
int FindIgnoreCase(const std::string& expr, const std::string& query); int FindIgnoreCase(const std::string& expr, const std::string& query);
char* GetAuxValue(const char* aux, const char* name); char* GetAuxValue(const char* aux, const char* name);
char* GetAuxValue(const cRecording *recording, const char* name); char* GetAuxValue(const cRecording *recording, const char* name);
char* GetAuxValue(const cTimer* timer, const char* name); char* GetAuxValue(const cTimer* timer, const char* name);
#ifndef _AFUZZY_H #ifndef _AFUZZY_H
#define _AFUZZY_H #define _AFUZZY_H
// source from: // source from:
/* /*
Leonid Boitsov 2002. (itman@narod.ru) Leonid Boitsov 2002. (itman@narod.ru)
C version of Stas Namin. C version of Stas Namin.
This code is a GPL software and is distributed under GNU This code is a GPL software and is distributed under GNU
public licence without any warranty. public licence without any warranty.
*/ */
typedef unsigned int Uint; typedef unsigned int Uint;
#define MaxPatSize (sizeof(Uint) * 8) #define MaxPatSize (sizeof(Uint) * 8)
typedef struct typedef struct
{ {
Uint *R, Uint *R,
*R1, *R1,
*RP, *RP,
*S, *S,
*RI; *RI;
Uint *FilterS; Uint *FilterS;
int Map[256]; int Map[256];
int FilterMap[256]; int FilterMap[256];
int k; int k;
Uint mask_ok; Uint mask_ok;
Uint filter_ok; Uint filter_ok;
Uint filter_shift; Uint filter_shift;
int r_size; int r_size;
int FilterSet; int FilterSet;
} AFUZZY; } AFUZZY;
void afuzzy_init(const char *p, int kerr, int UseFilter, AFUZZY *fuzzy); void afuzzy_init(const char *p, int kerr, int UseFilter, AFUZZY *fuzzy);
void afuzzy_free(AFUZZY *fuzzy); void afuzzy_free(AFUZZY *fuzzy);
int afuzzy_checkSUB(const char *t, AFUZZY *fuzzy); int afuzzy_checkSUB(const char *t, AFUZZY *fuzzy);
int afuzzy_checkFLT(const char *t, AFUZZY *fuzzy); int afuzzy_checkFLT(const char *t, AFUZZY *fuzzy);
#endif #endif
#endif // __TVGUIDETOOLS_H #endif // __TVGUIDETOOLS_H