add "preview" type update_notification to notifications too instead of just displaying it
[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                 self.l.setFont(0, gFont("Regular", 22))
14                 self.l.setFont(1, gFont("Regular", 18))
15                 self.l.setItemHeight(itemheight)
16
17         def connectSelChanged(self, fnc):
18                 if not fnc in self.onSelectionChanged:
19                         self.onSelectionChanged.append(fnc)
20
21         def disconnectSelChanged(self, fnc):
22                 if fnc in self.onSelectionChanged:
23                         self.onSelectionChanged.remove(fnc)
24
25         def moveToEntry(self, identifier):
26                 pass
27
28         def invalidate(self):
29                 self.l.invalidate()
30
31 class RSSFeedList(RSSBaseList):
32         def __init__(self, entries):
33                 RSSBaseList.__init__(self, entries, 100)
34                 self.l.setBuildFunc(self.buildListboxEntry)
35
36         def moveToEntry(self, feed):
37                 if feed is None:
38                         return
39
40                 idx = 0
41                 for x in self.list:
42                         if feed.uri == x[0].uri:
43                                 self.instance.moveSelectionTo(idx)
44                                 break
45                         idx += 1
46
47         def buildListboxEntry(self, feed):
48                 res = [ None ]
49                 width = self.l.getItemSize().width()
50                 res.append(MultiContentEntryText(pos=(0, 0), size=(width, 75), font=0, flags = RT_HALIGN_LEFT|RT_WRAP, text = feed.title))
51                 res.append(MultiContentEntryText(pos=(0, 75), size=(width, 20), font=1, flags = RT_HALIGN_LEFT, text = feed.description))
52                 return res
53
54         def getCurrent(self):
55                 # We know that the list will never be empty...
56                 return self.l.getCurrentSelection()[0]
57
58 class RSSEntryList(RSSBaseList):
59         def __init__(self, entries):
60                 RSSBaseList.__init__(self, entries, 50)
61                 self.l.setBuildFunc(self.buildListboxEntry)
62
63         def moveToEntry(self, entry):
64                 if entry is None:
65                         return
66
67                 idx = 0
68                 for x in self.list:
69                         if entry[0] == x[0]:
70                                 self.instance.moveSelectionTo(idx)
71                                 break
72                         idx += 1
73
74         def buildListboxEntry(self, title, link, summary, enclosures):
75                 res = [ None ]
76                 width = self.l.getItemSize().width()
77                 res.append(MultiContentEntryText(pos=(0, 3), size=(width, 50), font=0, flags = RT_HALIGN_LEFT|RT_WRAP, text = title))
78                 return res