Converter/ServiceName.py: add type service number
[openblackhole/openblackhole-enigma2.git] / lib / python / Components / Converter / ServiceName.py
1 # -*- coding: utf-8 -*-
2 from Components.Converter.Converter import Converter
3 from enigma import iServiceInformation, iPlayableService, iPlayableServicePtr, eServiceReference
4 from ServiceReference import resolveAlternate
5 from Components.Element import cached
6
7 class ServiceName(Converter, object):
8         NAME = 0
9         PROVIDER = 1
10         REFERENCE = 2
11         EDITREFERENCE = 3
12         NUMBER = 4
13
14         def __init__(self, type):
15                 Converter.__init__(self, type)
16
17                 if type == "Provider":
18                         self.type = self.PROVIDER
19                 elif type == "Reference":
20                         self.type = self.REFERENCE
21                 elif type == "EditReference":
22                         self.type = self.EDITREFERENCE
23                 elif type == "Number":
24                         self.type = self.NUMBER
25                 else:
26                         self.type = self.NAME
27
28         @cached
29         def getText(self):
30                 service = self.source.service
31                 if isinstance(service, iPlayableServicePtr):
32                         info = service and service.info()
33                         ref = None
34                 else: # reference
35                         info = service and self.source.info
36                         ref = service
37                 if not info:
38                         return ""
39                 if self.type == self.NAME:
40                         name = ref and info.getName(ref)
41                         if name is None:
42                                 name = info.getName()
43                         return name.replace('\xc2\x86', '').replace('\xc2\x87', '')
44                 elif self.type == self.PROVIDER:
45                         return info.getInfoString(iServiceInformation.sProvider)
46                 elif self.type == self.REFERENCE or self.type == self.EDITREFERENCE and hasattr(self.source, "editmode") and self.source.editmode:
47                         if not ref:
48                                 return info.getInfoString(iServiceInformation.sServiceref)
49                         nref = resolveAlternate(ref)
50                         if nref:
51                                 ref = nref
52                         return ref.toString()
53                 elif self.type == self.NUMBER:
54                         if not ref:
55                                 ref = eServiceReference(info.getInfoString(iServiceInformation.sServiceref))
56                         num = ref and ref.getChannelNum() or None
57                         if num is None:
58                                 num = '---'
59                         else:
60                                 num = str(num)
61                         return num
62
63         text = property(getText)
64
65         def changed(self, what):
66                 if what[0] != self.CHANGED_SPECIFIC or what[1] in (iPlayableService.evStart,):
67                         Converter.changed(self, what)