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
|
#include <time.h>
#include <glcdskin/type.h>
#include <vdr/plugin.h>
#if APIVERSNUM < 10503
#include <locale.h>
static char* locID[] = {
"en_US", //" English",
"de_DE", // "Deutsch",
"sl_SI", // "Slovenski",
"it_IT", // "Italiano",
"nl_NL", // "Nederlands",
"pt_PT", // "Português",
"fr_FR", // "Français",
"no_NO", // "Norsk",
"fi_FI", // "suomi", Finnish (this is not a typo - it's really lowercase!)
"pl_PL", // "Polski",
"es_ES", // "Español",
"el_GR", // "ÅëëçíéêÜ", Greek
"sv_SE", // "Svenska",
"ro_RO", // "Românã",
"hu_HU", // "Magyar",
"ca_ES", // "Català",
"ru_RU", // "ÀãááÚØÙ", Russian
"hr_HR", // "Hrvatski",
"et_EE", // "Eesti",
"da_DK", // "Dansk",
"cs_CZ" // "Èesky", Czech
};
#endif
GLCD::cType TimeType(time_t Time, const std::string &Format)
{
static char result[1000];
struct tm tm_r, *tm;
tm = localtime_r(&Time, &tm_r);
if (Time > 0)
{
if (Format.length() > 0)
{
// for vdr < 1.5.x: force locale for correct language output. for >= 1.5.x: system locale should be fine
#if APIVERSNUM < 10503
setlocale(LC_TIME, ( Setup.OSDLanguage < (int)(sizeof(locID)/sizeof(char*)) ) ? locID[Setup.OSDLanguage] : "en_US" );
#endif
strftime(result, sizeof(result), Format.c_str(), tm);
GLCD::cType r = result;
return r;
} else
return Time;
}
return false;
}
GLCD::cType DurationType(int Index, const std::string &Format)
{
static char result[1000];
if (Index > 0)
{
if (Format.length() > 0)
{
uint update = 0;
const char *ptr = Format.c_str();
char *res = result;
enum { normal, format } state = normal;
int n = 0;
#if VDRVERSNUM >= 10701
int f = (Index % DEFAULTFRAMESPERSECOND) + 1;
int s = (Index / DEFAULTFRAMESPERSECOND);
#else
int f = (Index % FRAMESPERSEC) + 1;
int s = (Index / FRAMESPERSEC);
#endif
int m = s / 60 % 60;
int h = s / 3600;
s %= 60;
while (*ptr && res < result + sizeof(result))
{
switch (state)
{
case normal:
if (*ptr == '%')
state = format;
else
*(res++) = *ptr;
break;
case format:
switch (*ptr)
{
case 'H':
n = snprintf(res, sizeof(result) - (res - result), "%02d", h);
break;
case 'k':
n = snprintf(res, sizeof(result) - (res - result), "% 2d", h);
break;
case 'M':
n = snprintf(res, sizeof(result) - (res - result), "%02d", m);
update = 1000*60;
break;
case 'm':
n = snprintf(res, sizeof(result) - (res - result), "%d", m + (h * 60));
update = 1000*60;
break;
case 'S':
n = snprintf(res, sizeof(result) - (res - result), "%02d", s);
update = 1000;
break;
case 'f':
n = snprintf(res, sizeof(result) - (res - result), "%d", f);
update = 1000;
break;
case '%':
n = 1;
*res = '%';
break;
}
res += n;
state = normal;
break;
}
++ptr;
}
GLCD::cType r = result;
r.SetUpdate(update);
return r;
} else
return (int)Index;
}
return false;
}
|