PDC - possible display with pixmap, added posibility display running status for nex...
[openblackhole/openblackhole-enigma2.git] / lib / python / Components / Converter / EventName.py
1 from Components.Converter.Converter import Converter
2 from Components.Element import cached
3 from Components.Converter.genre import getGenreStringLong, getGenreStringSub
4
5 class EventName(Converter, object):
6         NAME = 0
7         SHORT_DESCRIPTION = 1
8         EXTENDED_DESCRIPTION = 2
9         FULL_DESCRIPTION = 3
10         ID = 4
11         NAME_NOW = 5
12         NAME_NEXT = 6
13         GENRE = 7
14         RATING = 8
15         SRATING = 9
16         PDC = 10
17         PDCTIME = 11
18         ISRUNNINGSTATUS = 12
19
20         def __init__(self, type):
21                 Converter.__init__(self, type)
22                 if type == "Description":
23                         self.type = self.SHORT_DESCRIPTION
24                 elif type == "ExtendedDescription":
25                         self.type = self.EXTENDED_DESCRIPTION
26                 elif type == "FullDescription":
27                         self.type = self.FULL_DESCRIPTION
28                 elif type == "ID":
29                         self.type = self.ID
30                 elif type == "NameNow":
31                         self.type = self.NAME_NOW
32                 elif type == "NameNext":
33                         self.type = self.NAME_NEXT
34                 elif type == "Genre":
35                         self.type = self.GENRE
36                 elif type == "Rating":
37                         self.type = self.RATING
38                 elif type == "SmallRating":
39                         self.type = self.SRATING
40                 elif type == "Pdc":
41                         self.type = self.PDC
42                 elif type == "PdcTime":
43                         self.type = self.PDCTIME
44                 elif type == "IsRunningStatus":
45                         self.type = self.ISRUNNINGSTATUS
46                 else:
47                         self.type = self.NAME
48
49         @cached
50         def getBoolean(self):
51                 event = self.source.event
52                 if event is None:
53                         return False
54                 if self.type == self.PDC:
55                         if event.getPdcPil():
56                                 return True
57                 return False
58
59         boolean = property(getBoolean)
60
61         @cached
62         def getText(self):
63                 event = self.source.event
64                 if event is None:
65                         return ""
66
67                 if self.type == self.NAME:
68                         return event.getEventName()
69                 elif self.type == self.SRATING:
70                         rating = event.getParentalData()
71                         if rating is None:
72                                 return ""
73                         else:
74                                 country = rating.getCountryCode()
75                                 age = rating.getRating()
76                                 if age == 0:
77                                         return _("All ages")
78                                 elif age > 15:
79                                         return _("bc%s") % age
80                                 else:
81                                         age += 3
82                                         return " %d+" % age
83                 elif self.type == self.RATING:
84                         rating = event.getParentalData()
85                         if rating is None:
86                                 return ""
87                         else:
88                                 country = rating.getCountryCode()
89                                 age = rating.getRating()
90                                 if age == 0:
91                                         return _("Rating undefined")
92                                 elif age > 15:
93                                         return _("Rating defined by broadcaster - %d") % age
94                                 else:
95                                         age += 3
96                                         return _("Minimum age %d years") % age
97                 elif self.type == self.GENRE:
98                         genre = event.getGenreData()
99                         if genre is None:
100                                 return ""
101                         else:
102                                 return getGenreStringSub(genre.getLevel1(), genre.getLevel2())
103                 elif self.type == self.NAME_NOW:
104                         return pgettext("now/next: 'now' event label", "Now") + ": " + event.getEventName()
105                 elif self.type == self.NAME_NEXT:
106                         return pgettext("now/next: 'next' event label", "Next") + ": " + event.getEventName()
107                 elif self.type == self.SHORT_DESCRIPTION:
108                         return event.getShortDescription()
109                 elif self.type == self.EXTENDED_DESCRIPTION:
110                         return event.getExtendedDescription() or event.getShortDescription()
111                 elif self.type == self.FULL_DESCRIPTION:
112                         description = event.getShortDescription()
113                         extended = event.getExtendedDescription()
114                         if description and extended:
115                                 description += '\n'
116                         return description + extended
117                 elif self.type == self.ID:
118                         return str(event.getEventId())
119                 elif self.type == self.PDC:
120                         if event.getPdcPil():
121                                 return _("PDC")
122                         return ""
123                 elif self.type == self.PDCTIME:
124                         pil = event.getPdcPil()
125                         if pil:
126                                 return _("%d.%02d. %d:%02d") % ((pil & 0xF8000) >> 15, (pil & 0x7800) >> 11, (pil & 0x7C0) >> 6, (pil & 0x3F))
127                         return ""
128                 elif self.type == self.ISRUNNINGSTATUS:
129                         if event.getPdcPil():
130                                 running_status = event.getRunningStatus()
131                                 if running_status == 1:
132                                         return "not running"
133                                 if running_status == 2:
134                                         return "starts in a few seconds"
135                                 if running_status == 3:
136                                         return "pausing"
137                                 if running_status == 4:
138                                         return "running"
139                                 if running_status == 5:
140                                         return "service off-air"
141                                 if running_status in (6,7):
142                                         return "reserved for future use"
143                                 return "undefined"
144                         return ""
145
146         text = property(getText)