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