[InternetRadio] initial commit of InternetRadio plugin (with music-visualization...
[enigma2-plugins.git] / internetradio / src / InternetRadioList.py
1 #
2 # InternetRadio E2
3 #
4 # Coded by Dr.Best (c) 2012
5 # Support: www.dreambox-tools.info
6 # E-Mail: dr.best@dreambox-tools.info
7 #
8 # This plugin is open source but it is NOT free software.
9 #
10 # This plugin may only be distributed to and executed on hardware which
11 # is licensed by Dream Multimedia GmbH.
12 # In other words:
13 # It's NOT allowed to distribute any parts of this plugin or its source code in ANY way
14 # to hardware which is NOT licensed by Dream Multimedia GmbH.
15 # It's NOT allowed to execute this plugin and its source code or even parts of it in ANY way
16 # on hardware which is NOT licensed by Dream Multimedia GmbH.
17 #
18 # If you want to use or modify the code or parts of it,
19 # you have to keep MY license and inform me about the modifications by mail.
20 #
21
22 from enigma import eListboxPythonMultiContent, eListbox, gFont, \
23         RT_HALIGN_LEFT, RT_VALIGN_CENTER
24 from Components.GUIComponent import GUIComponent
25         
26         
27 class InternetRadioList(GUIComponent, object):
28         def buildEntry(self, item):
29                 width = self.l.getItemSize().width()
30                 res = [ None ]
31                 if self.mode == 0: # GENRELIST
32                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 3, width, 23, 0, RT_HALIGN_LEFT|RT_VALIGN_CENTER, item.name))
33                 elif self.mode == 1: # STATIONLIST
34                         if len(item.country) != 0:
35                                 display = "%s (%s)" % (item.name, item.country)
36                         else:
37                                 display = item.name
38                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 3, width, 23, 0, RT_HALIGN_LEFT|RT_VALIGN_CENTER, display))
39                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 27, width, 23, 0, RT_HALIGN_LEFT|RT_VALIGN_CENTER, item.genre))
40                 elif self.mode == 2: # FAVORITELIST
41                         if len(item.configItem.country.value) != 0:
42                                 display = "%s (%s)" % (item.configItem.name.value, item.configItem.country.value)
43                         else:
44                                 display = item.configItem.name.value
45                                 
46                         if item.configItem.type.value > 0:
47                                 if item.configItem.type.value == 1:
48                                         filtername = _("Genres")
49                                 else:
50                                         filtername = _("Countries")
51                                 display2 = "%s %s" % (_("Filter:"),filtername)
52                         else:
53                                 display2 = item.configItem.tags.value
54                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 3, width, 23, 0, RT_HALIGN_LEFT|RT_VALIGN_CENTER, display))
55                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 27, width, 23, 0, RT_HALIGN_LEFT|RT_VALIGN_CENTER, display2))
56                 return res
57
58         def __init__(self):
59                 GUIComponent.__init__(self)
60                 self.l = eListboxPythonMultiContent()
61                 self.l.setFont(0, gFont("Regular", 22))
62                 self.l.setFont(1, gFont("Regular", 18))
63                 self.l.setBuildFunc(self.buildEntry)
64                 self.l.setItemHeight(29)
65                 self.onSelectionChanged = [ ]
66                 self.mode = 0
67                 self.list = []
68
69         def setMode(self, mode):
70                 self.mode = mode
71                 if mode == 0: # GENRELIST
72                         self.l.setItemHeight(29)
73                 elif mode == 1 or mode == 2: # STATIONLIST OR FAVORITELIST
74                         self.l.setItemHeight(53)
75
76         def connectSelChanged(self, fnc):
77                 if not fnc in self.onSelectionChanged:
78                         self.onSelectionChanged.append(fnc)
79
80         def disconnectSelChanged(self, fnc):
81                 if fnc in self.onSelectionChanged:
82                         self.onSelectionChanged.remove(fnc)
83
84         def selectionChanged(self):
85                 for x in self.onSelectionChanged:
86                         x()
87         
88         def getCurrent(self):
89                 cur = self.l.getCurrentSelection()
90                 return cur and cur[0]
91         
92         GUI_WIDGET = eListbox
93         
94         def postWidgetCreate(self, instance):
95                 instance.setContent(self.l)
96                 instance.selectionChanged.get().append(self.selectionChanged)
97
98         def preWidgetRemove(self, instance):
99                 instance.setContent(None)
100                 instance.selectionChanged.get().remove(self.selectionChanged)
101
102         def moveToIndex(self, index):
103                 self.instance.moveSelectionTo(index)
104
105         def getCurrentIndex(self):
106                 return self.instance.getCurrentIndex()
107
108         currentIndex = property(getCurrentIndex, moveToIndex)
109         currentSelection = property(getCurrent)
110
111         def setList(self, list):
112                 self.list = list
113                 self.l.setList(list)
114
115         def moveToFavorite(self, name, text):
116                 if self.mode == 2: # FAVORITELIST
117                         i = 0
118                         for favs in self.list:
119                                 if favs[0].configItem.name.value == name and favs[0].configItem.text.value == text:
120                                         self.moveToIndex(i)
121                                         break
122                                 i += 1