- Some minor problems fixed
[enigma2-plugins.git] / vlcplayer / src / VlcServerList.py
1 # -*- coding: ISO-8859-1 -*-
2 #===============================================================================
3 # VLC Player Plugin by A. Lätsch 2007
4 #                   modified by Volker Christian 2008
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the terms of the GNU General Public License as published by the Free
8 # Software Foundation; either version 2, or (at your option) any later
9 # version.
10 #===============================================================================
11
12
13 from Components.ActionMap import ActionMap
14 from Components.Button import Button
15 from Components.Label import Label
16 from Components.MenuList import MenuList
17 from Screens.MessageBox import MessageBox
18 from Screens.Screen import Screen
19 from Tools.Directories import resolveFilename, SCOPE_PLUGINS
20 from Tools.LoadPixmap import LoadPixmap
21 from VlcMediaList import VlcMediaListScreen
22 from VlcServerConfig import vlcServerConfig
23 from VlcServerConfig import VlcServerConfigScreen
24 from enigma import eListboxPythonMultiContent, RT_HALIGN_LEFT, gFont
25 from . import _
26
27 def VlcServerListEntry(vlcServer):
28         res = [ vlcServer ]
29         res.append((eListboxPythonMultiContent.TYPE_TEXT, 35, 1, 470, 20, 0, RT_HALIGN_LEFT, vlcServer.getName()))
30
31         png = LoadPixmap(resolveFilename(SCOPE_PLUGINS, "Extensions/VlcPlayer/vlc.png"))
32         if png is not None:
33                 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 10, 2, 20, 20, png))
34
35         return res
36
37
38 class VlcServerList(MenuList):
39         def __init__(self):
40                 MenuList.__init__(self, list, False, eListboxPythonMultiContent)
41                 self.l.setFont(0, gFont("Regular", 18))
42                 self.l.setItemHeight(23)
43
44         def update(self, serverList):
45                 self.list = []
46                 for server in serverList:
47                         self.list.append(VlcServerListEntry(server))
48                 self.l.setList(self.list)
49                 self.moveToIndex(0)
50
51         def getSelection(self):
52                 if self.l.getCurrentSelection() is None:
53                         return None
54                 return self.l.getCurrentSelection()[0]
55
56
57 class VlcServerListScreen(Screen):
58         skin = """
59                 <screen position="80,100" size="560,400" title="VLC Video Player V2.5 - Select a VLC-Server Profile" >
60                         <widget name="serverlabel" position="10,10" size="550,20" font="Regular;18"/>
61                         <widget name="serverlist" position="10,35" size="550,310"  scrollbarMode="showOnDemand"/>
62                         <ePixmap name="red"    position="0,355"   zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
63                         <ePixmap name="green"  position="140,355" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
64                         <ePixmap name="yellow" position="280,355" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
65                         <ePixmap name="blue"   position="420,355" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
66                         <widget name="key_red" position="0,355" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
67                         <widget name="key_green" position="140,355" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
68                         <widget name="key_yellow" position="280,355" zPosition="5" size="140,40" valign="center" halign="center"  font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
69                         <widget name="key_blue" position="420,355" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
70                 </screen>"""
71
72         def __init__(self, session, asConfigDialog = False):
73                 Screen.__init__(self, session)
74                 self.session = session
75                 self.asConfigDialog = asConfigDialog
76                 self.serverlist = VlcServerList()
77
78                 self["serverlabel"] = Label(_("List of known VLC-Server Profiles"))
79                 self["serverlist"] = self.serverlist
80                 self["key_red"] = Button(_("delete server"))
81                 self["key_green"] = Button(_("add server"))
82                 self["key_yellow"] = Button(_("edit server"))
83                 self["key_blue"] = Button("")
84
85                 self["actions"] = ActionMap(["WizardActions", "ColorActions"],
86                         {
87                          "back":        self.doRealClose,
88                          "red":         self.keyDelete,
89                          "green":       self.keyAddServer,
90                          "yellow":      self.keyEditServer,
91                          "up":          self.up,
92                          "down":        self.down,
93                          "left":        self.left,
94                          "right":       self.right,
95                          "ok":          self.ok,
96             }, -1)
97
98                 self.onLayoutFinish.append(self.updateServerlist)
99
100         def updateServerlist(self):
101                 self.serverlist.update(vlcServerConfig.getServerlist())
102
103         def keyAddServer(self):
104                 newServer = vlcServerConfig.new()
105                 self.session.openWithCallback(self.addCallback, VlcServerConfigScreen, newServer)
106
107         def addCallback(self, result, server):
108                 if result:
109                         vlcServerConfig.save(server)
110                         self.updateServerlist()
111                 else:
112                         vlcServerConfig.delete(server)
113
114         def keyDelete(self):
115                 self.session.openWithCallback(self.deleteCallback, MessageBox, _("Really delete this Server?"))
116
117         def deleteCallback(self, result):
118                 if result:
119                         vlcServerConfig.delete(self.serverlist.getSelection())
120                         self.updateServerlist()
121
122         def keyEditServer(self):
123                 server = self.serverlist.getSelection()
124                 if server is not None:
125                         self.session.openWithCallback(self.editCallback, VlcServerConfigScreen, server)
126
127         def editCallback(self, result, server):
128                 if result:
129                         vlcServerConfig.save(server)
130                         index = self.serverlist.getSelectedIndex()
131                         self.updateServerlist()
132                         self.serverlist.moveToIndex(index)
133                 else:
134                         vlcServerConfig.cancel(server)
135
136         def up(self):
137                 self.serverlist.up()
138
139         def down(self):
140                 self.serverlist.down()
141
142         def left(self):
143                 self.serverlist.pageUp()
144
145         def right(self):
146                 self.serverlist.pageDown()
147
148         def doRealClose(self):
149                 self.close(None)
150
151         def ok(self):
152                 if self.asConfigDialog:
153                         self.close(self.serverlist.getSelection())
154                 else:
155                         if self.serverlist.getSelection() is not None:
156                                 self.session.open(VlcMediaListScreen, self.serverlist.getSelection()).update()