remove unused import
[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 VlcServerConfig import vlcServerConfig
22 from VlcServerConfig import VlcServerConfigScreen
23 from enigma import eListboxPythonMultiContent, RT_HALIGN_LEFT, gFont
24 from . import _
25
26 def VlcServerListEntry(vlcServer, defaultServer):
27         res = [ vlcServer ]
28         res.append((eListboxPythonMultiContent.TYPE_TEXT, 35, 1, 470, 20, 0, RT_HALIGN_LEFT, vlcServer.getName()))
29
30         if defaultServer is not None and defaultServer.getName() == vlcServer.getName():
31                 png = LoadPixmap(resolveFilename(SCOPE_PLUGINS, "Extensions/VlcPlayer/vlc_default.png"))
32         else:
33                 png = LoadPixmap(resolveFilename(SCOPE_PLUGINS, "Extensions/VlcPlayer/vlc.png"))
34         if png is not None:
35                 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 10, 2, 20, 20, png))
36
37         return res
38
39
40 class VlcServerList(MenuList):
41         def __init__(self):
42                 MenuList.__init__(self, list, False, eListboxPythonMultiContent)
43                 self.l.setFont(0, gFont("Regular", 18))
44                 self.l.setItemHeight(23)
45
46         def update(self, serverList, defaultServer):
47                 self.list = []
48                 for server in serverList:
49                         self.list.append(VlcServerListEntry(server, defaultServer))
50                 self.l.setList(self.list)
51                 self.moveToIndex(0)
52
53         def getSelection(self):
54                 if self.l.getCurrentSelection() is None:
55                         return None
56                 return self.l.getCurrentSelection()[0]
57
58
59 class VlcServerListScreen(Screen):
60         skin = """
61                 <screen position="80,100" size="560,400" title="VLC Video Player V2.5 - Select a VLC-Server Profile" >
62                         <widget name="serverlabel" position="10,10" size="550,20" font="Regular;18"/>
63                         <widget name="serverlist" position="10,35" size="550,310"  scrollbarMode="showOnDemand"/>
64                         <ePixmap name="red"    position="0,355"   zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
65                         <ePixmap name="green"  position="140,355" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
66                         <ePixmap name="yellow" position="280,355" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
67                         <ePixmap name="blue"   position="420,355" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
68                         <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" />
69                         <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" />
70                         <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" />
71                         <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" />
72                 </screen>"""
73
74         def __init__(self, session, defaultServer):
75                 Screen.__init__(self, session)
76                 self.session = session
77                 self.serverlist = VlcServerList()
78                 self.defaultServer = defaultServer
79
80                 self["serverlabel"] = Label(_("List of known VLC-Server Profiles"))
81                 self["serverlist"] = self.serverlist
82                 self["key_red"] = Button(_("delete server"))
83                 self["key_green"] = Button(_("add server"))
84                 self["key_yellow"] = Button(_("edit server"))
85                 self["key_blue"] = Button(_("set default"))
86
87                 self["actions"] = ActionMap(["WizardActions", "ColorActions"],
88                         {
89                          "back":        self.close,
90                          "red":         self.keyDelete,
91                          "green":       self.keyAddServer,
92                          "yellow":      self.keyEditServer,
93                          "blue":        self.keySetAsDefault,
94                          "up":          self.up,
95                          "down":        self.down,
96                          "left":        self.left,
97                          "right":       self.right,
98                          "ok":          self.ok,
99             }, -1)
100                         
101                 self.onLayoutFinish.append(self.initialServerlistUpdate)
102
103         def initialServerlistUpdate(self):
104                 self.updateServerlist()
105                 if self.defaultServer is not None:
106                         defaultIndex = vlcServerConfig.getServerlist().index(self.defaultServer)
107                         self.serverlist.moveToIndex(defaultIndex)
108
109         def updateServerlist(self):
110                 self.serverlist.update(vlcServerConfig.getServerlist(), self.defaultServer)
111
112         def keyAddServer(self):
113                 newServer = vlcServerConfig.new()
114                 self.session.openWithCallback(self.addCallback, VlcServerConfigScreen, newServer)
115
116         def addCallback(self, result, server):
117                 if result:
118                         vlcServerConfig.save(server)
119                         self.updateServerlist()
120                 else:
121                         vlcServerConfig.delete(server)
122
123         def keyDelete(self):
124                 server = self.serverlist.getSelection()
125                 if server is not None:
126                         self.session.openWithCallback(self.deleteCallback, MessageBox, _("Really delete this Server?"))
127
128         def deleteCallback(self, result):
129                 if result:
130                         vlcServerConfig.delete(self.serverlist.getSelection())
131                         self.updateServerlist()
132
133         def keyEditServer(self):
134                 server = self.serverlist.getSelection()
135                 if server is not None:
136                         self.session.openWithCallback(self.editCallback, VlcServerConfigScreen, server)
137
138         def editCallback(self, result, server):
139                 if result:
140                         vlcServerConfig.save(server)
141                         index = self.serverlist.getSelectedIndex()
142                         self.updateServerlist()
143                         self.serverlist.moveToIndex(index)
144                 else:
145                         vlcServerConfig.cancel(server)
146
147         def keySetAsDefault(self):
148                 self.defaultServer = self.serverlist.getSelection()
149                 index = self.serverlist.getSelectedIndex()
150                 self.updateServerlist()
151                 self.serverlist.moveToIndex(index)
152
153         def up(self):
154                 self.serverlist.up()
155
156         def down(self):
157                 self.serverlist.down()
158
159         def left(self):
160                 self.serverlist.pageUp()
161
162         def right(self):
163                 self.serverlist.pageDown()
164
165         def close(self, server = None):
166                 Screen.close(self, server, self.defaultServer)
167
168         def ok(self):
169                 self.close(self.serverlist.getSelection())