Patch by Stephan Reicholf: Display time as unix timestamp, remaining time in seconds
[enigma2.git] / lib / python / Components / Converter / RemainingToText.py
1 from Components.Converter.Converter import Converter
2 from Components.Element import cached
3
4 class RemainingToText(Converter, object):
5         DEFAULT = 0
6         WITH_SECONDS = 1
7         NO_SECONDS = 2
8         IN_SECONDS = 3
9
10         def __init__(self, type):
11                 Converter.__init__(self, type)
12                 if type == "WithSeconds":
13                         self.type = self.WITH_SECONDS
14                 elif type == "NoSeconds":
15                         self.type = self.NO_SECONDS
16                 elif type == "InSeconds":
17                         self.type = self.IN_SECONDS     
18                 else:
19                         self.type = self.DEFAULT
20
21         @cached
22         def getText(self):
23                 time = self.source.time
24                 if time is None:
25                         return ""
26
27                 (duration, remaining) = self.source.time
28
29                 if self.type == self.WITH_SECONDS:
30                         if remaining is not None:
31                                 return "%d:%02d:%02d" % (remaining / 3600, (remaining / 60) - ((remaining / 3600) * 60), remaining % 60)
32                         else:
33                                 return "%02d:%02d:%02d" % (duration / 3600, (duration / 60) - ((duration / 3600) * 60), duration % 60)
34                 elif self.type == self.NO_SECONDS:
35                         if remaining is not None:
36                                 return "+%d:%02d" % (remaining / 3600, (remaining / 60) - ((remaining / 3600) * 60))
37                         else:
38                                 return "%02d:%02d" % (duration / 3600, (duration / 60) - ((duration / 3600) * 60))
39                 elif self.type == self.IN_SECONDS:
40                         if remaining is not None:
41                                 return str(remaining)
42                         else:
43                                 return str(duration)
44                 elif self.type == self.DEFAULT:
45                         if remaining is not None:
46                                 return "+%d min" % (remaining / 60)
47                         else:
48                                 return "%d min" % (duration / 60)
49                 else:
50                         return "???"
51
52         text = property(getText)