1ad1694c424d4d1325614a7a7d8b18e1300a3bb2
[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
4 from Components.Element import cached
5 from ServiceReference import resolveAlternate
6
7 class ServiceName(Converter, object):
8         NAME = 0
9         PROVIDER = 1
10         REFERENCE = 2
11         EDITREFERENCE = 3
12
13         def __init__(self, type):
14                 Converter.__init__(self, type)
15                 if type == "Provider":
16                         self.type = self.PROVIDER
17                 elif type == "Reference":
18                         self.type = self.REFERENCE
19                 elif type == "EditReference":
20                         self.type = self.EDITREFERENCE
21                 else:
22                         self.type = self.NAME
23
24         @cached
25         def getText(self):
26                 service = self.source.service
27                 if isinstance(service, iPlayableServicePtr):
28                         info = service and service.info()
29                         ref = None
30                 else: # reference
31                         info = service and self.source.info
32                         ref = service
33                 if not info:
34                         return ""
35                 if self.type == self.NAME:
36                         name = ref and info.getName(ref)
37                         if name is None:
38                                 name = info.getName()
39                         return name.replace('\xc2\x86', '').replace('\xc2\x87', '')
40                 elif self.type == self.PROVIDER:
41                         return info.getInfoString(iServiceInformation.sProvider)
42                 elif self.type == self.REFERENCE or self.type == self.EDITREFERENCE and hasattr(self.source, "editmode") and self.source.editmode:
43                         if not ref:
44                                 return info.getInfoString(iServiceInformation.sServiceref)
45                         nref = resolveAlternate(ref)
46                         if nref:
47                                 ref = nref
48                         return ref.toString()
49
50         text = property(getText)
51
52         def changed(self, what):
53                 if what[0] != self.CHANGED_SPECIFIC or what[1] in (iPlayableService.evStart,):
54                         Converter.changed(self, what)