diff options
-rw-r--r-- | vdr-vdrmanager/helpers.cpp | 56 | ||||
-rw-r--r-- | vdr-vdrmanager/helpers.h | 5 |
2 files changed, 60 insertions, 1 deletions
diff --git a/vdr-vdrmanager/helpers.cpp b/vdr-vdrmanager/helpers.cpp index 2d1aec2..5d6dd42 100644 --- a/vdr-vdrmanager/helpers.cpp +++ b/vdr-vdrmanager/helpers.cpp @@ -578,7 +578,7 @@ string cHelpers::ToText(cTimer * timer) { result += ":"; - result += timer->WeekDays(); + result += ConvertWeekdays(timer->WeekDays()); result += "\r\n"; @@ -926,6 +926,60 @@ string cHelpers::decompress_string(const string& str) return outstring; } +//These three methodes were stolen from vdr-restfulapi project. Thanks! +std::stack<int> cHelpers::ConvertToBinary(int v) +{ + int b; + std::stack <int> res; + + while ( v != 0) { + b = v % 2; + res.push(b); + v = (v-b) / 2; + } + return res; +} + +std::string cHelpers::ConvertWeekdays(int v) +{ + std::stack<int> b = cHelpers::ConvertToBinary(v); + int counter = 0; + std::ostringstream res; + while ( !b.empty() && counter < 7 ) { + int val = b.top(); + switch(counter) { + case 0: res << (val == 1 ? 'M' : '-'); break; + case 1: res << (val == 1 ? 'T' : '-'); break; + case 2: res << (val == 1 ? 'W' : '-'); break; + case 3: res << (val == 1 ? 'T' : '-'); break; + case 4: res << (val == 1 ? 'F' : '-'); break; + case 5: res << (val == 1 ? 'S' : '-'); break; + case 6: res << (val == 1 ? 'S' : '-'); break; + } + b.pop(); + counter++; + } + while ( counter < 7 ) { + res << '-'; + counter++; + } + return res.str(); +} + +int cHelpers::ConvertWeekdays(std::string v) +{ + const char* str = v.c_str(); + int res = 0; + if ( str[0] == 'M' ) res += 64; + if ( str[1] == 'T' ) res += 32; + if ( str[2] == 'W' ) res += 16; + if ( str[3] == 'T' ) res += 8; + if ( str[4] == 'F' ) res += 4; + if ( str[5] == 'S' ) res += 2; + if ( str[6] == 'S' ) res += 1; + return res; +} + diff --git a/vdr-vdrmanager/helpers.h b/vdr-vdrmanager/helpers.h index ad6d17b..d610084 100644 --- a/vdr-vdrmanager/helpers.h +++ b/vdr-vdrmanager/helpers.h @@ -11,6 +11,7 @@ #include <iostream> #include <iomanip> #include <sstream> +#include <stack> using namespace std; @@ -57,4 +58,8 @@ private: static string Error(const string &error); static string SetTimerIntern(char c, string params); static int RecordingLengthInSeconds(cRecording* recording); + static std::string cHelpers::ConvertWeekdays(int v); + static int cHelpers::ConvertWeekdays(std::string v); + static std::stack<int> cHelpers::ConvertToBinary(int v); + }; |