1 ############################################################################
2 # Copyright (C) 2008 by Volker Christian #
3 # Volker.Christian@fh-hagenberg.at #
5 # This program is free software; you can redistribute it and#or modify #
6 # it under the terms of the GNU General Public License as published by #
7 # the Free Software Foundation; either version 2 of the License, or #
8 # (at your option) any later version. #
10 # This program is distributed in the hope that it will be useful, #
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
13 # GNU General Public License for more details. #
15 # You should have received a copy of the GNU General Public License #
16 # along with this program; if not, write to the #
17 # Free Software Foundation, Inc., #
18 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
19 ############################################################################
21 from YouTubeInterface import interface
22 from YouTubeAddPlayList import YouTubeAddPlaylistDialog
23 from Components.ActionMap import ActionMap
24 from Components.MenuList import MenuList
25 from Components.Label import Label
26 from Components.MultiContent import MultiContentEntryText
27 from Screens.MessageBox import MessageBox
28 from Screens.Screen import Screen
29 from enigma import eListboxPythonMultiContent, gFont, RT_HALIGN_LEFT, RT_VALIGN_TOP, RT_WRAP
34 def YouTubePlaylistEntryComponent(entry):
37 res.append(MultiContentEntryText(pos = (5, 5), size = (550, 18), font = 0, flags = RT_HALIGN_LEFT | RT_VALIGN_TOP| RT_WRAP, text = entry.getTitle()))
38 res.append(MultiContentEntryText(pos = (5, 23), size = (550, 14), font = 1, color = 0xFFA323, color_sel = 0xFFA323, flags = RT_HALIGN_LEFT | RT_VALIGN_TOP| RT_WRAP, text = entry.getDescription()))
43 class YouTubePlaylistList(MenuList):
44 def __init__(self, list, enableWrapAround = False):
45 MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
46 self.l.setFont(0, gFont("Regular", 18))
47 self.l.setFont(1, gFont("Regular", 14))
48 self.l.setItemHeight(41)
51 class YouTubePlaylistScreen(Screen):
52 def __init__(self, session):
53 Screen.__init__(self, session)
55 self.session = session
57 self["red"] = Label(_("Delete Playlist"))
58 self["green"] = Label(_("Add new Playlist"))
61 self["list"] = YouTubePlaylistList(self.list)
63 self["actions"] = ActionMap(["YouTubePlaylistScreenActions"],
65 "ok" : self.choosePlaylist,
66 "delete" : self.deletePlaylist,
67 "add" : self.addPlaylist,
72 def loadPlaylist(self):
74 feed = interface.getPlaylistFeed()
75 for entry in feed.getEntries():
76 self.list.append(YouTubePlaylistEntryComponent(entry))
77 self["list"].setList(self.list)
80 def choosePlaylist(self):
81 Screen.close(self, self["list"].getCurrent()[0])
84 def deletePlaylist(self):
85 playList = self["list"].getCurrent()[0]
86 if playList is not None:
87 self.session.openWithCallback(self.deleteCallback, MessageBox, _("Really delete %(playlist)s?") % {"playlist" : playList.getTitle()})
90 def deleteCallback(self, result):
92 if interface.deletePlaylist(self["list"].getCurrent()[0]):
93 self.list.remove(self["list"].getCurrent())
94 self["list"].setList(self.list)
97 def addPlaylist(self):
98 self.session.openWithCallback(self.addCallback, YouTubeAddPlaylistDialog)
101 def addCallback(self, result, playlistContext):
103 entry = interface.addPlaylist(playlistContext.name.value, playlistContext.description.value, playlistContext.private.value)
104 self.list.append(YouTubePlaylistEntryComponent(entry))
105 self["list"].setList(self.list)
109 Screen.close(self, None)