smaller optimizations
[enigma2-plugins.git] / simplerss / src / RSSList.py
1 from Components.MenuList import MenuList
2 from Components.MultiContent import MultiContentEntryText
3
4 from enigma import eListboxPythonMultiContent, gFont, RT_HALIGN_LEFT, \
5         RT_WRAP
6
7 class RSSBaseList(MenuList):
8         """Base List Component for RSSFeeds."""
9
10         def __init__(self, entries, itemheight):
11                 MenuList.__init__(self, entries, False, content = eListboxPythonMultiContent)
12
13                 l = self.l
14                 l.setFont(0, gFont("Regular", 22))
15                 l.setFont(1, gFont("Regular", 18))
16                 l.setItemHeight(itemheight)
17
18         def connectSelChanged(self, fnc):
19                 if not fnc in self.onSelectionChanged:
20                         self.onSelectionChanged.append(fnc)
21
22         def disconnectSelChanged(self, fnc):
23                 if fnc in self.onSelectionChanged:
24                         self.onSelectionChanged.remove(fnc)
25
26         def moveToEntry(self, identifier):
27                 pass
28
29         def invalidate(self):
30                 self.l.invalidate()
31
32 class RSSFeedList(RSSBaseList):
33         def __init__(self, entries):
34                 RSSBaseList.__init__(self, entries, 100)
35                 self.l.setBuildFunc(self.buildListboxEntry)
36
37         def moveToEntry(self, feed):
38                 if feed is None:
39                         return
40
41                 idx = 0
42                 for x in self.list:
43                         if feed.uri == x[0].uri:
44                                 self.instance.moveSelectionTo(idx)
45                                 break
46                         idx += 1
47
48         def buildListboxEntry(self, feed):
49                 width = self.l.getItemSize().width()
50                 return [
51                         None,
52                         MultiContentEntryText(pos=(0, 0), size=(width, 75), font=0, flags = RT_HALIGN_LEFT|RT_WRAP, text = feed.title),
53                         MultiContentEntryText(pos=(0, 75), size=(width, 20), font=1, flags = RT_HALIGN_LEFT, text = feed.description)
54                 ]
55
56         def getCurrent(self):
57                 # We know that the list will never be empty...
58                 return self.l.getCurrentSelection()[0]
59
60 class RSSEntryList(RSSBaseList):
61         def __init__(self, entries):
62                 RSSBaseList.__init__(self, entries, 50)
63                 self.l.setBuildFunc(self.buildListboxEntry)
64
65         def moveToEntry(self, entry):
66                 if entry is None:
67                         return
68
69                 idx = 0
70                 for x in self.list:
71                         if entry[0] == x[0]:
72                                 self.instance.moveSelectionTo(idx)
73                                 break
74                         idx += 1
75
76         def buildListboxEntry(self, title, link, summary, enclosures):
77                 width = self.l.getItemSize().width()
78                 return [
79                         None,
80                         MultiContentEntryText(pos=(0, 3), size=(width, 50), font=0, flags = RT_HALIGN_LEFT|RT_WRAP, text = title)
81                 ]
82