- "Default-Server" is implemented: If a default server was choosen, the plugin starts...
[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, showDefaultServer):
27         res = [ vlcServer ]
28         res.append((eListboxPythonMultiContent.TYPE_TEXT, 35, 1, 470, 20, 0, RT_HALIGN_LEFT, vlcServer.getName()))
29
30         if vlcServerConfig.getDefaultServer().getName() == vlcServer.getName() and showDefaultServer:
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, showDefaultServer):
47                 self.list = []
48                 for server in serverList:
49                         self.list.append(VlcServerListEntry(server, showDefaultServer))
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, showDefaultServer = True):
75                 Screen.__init__(self, session)
76                 self.session = session
77                 self.serverlist = VlcServerList()
78                 self.showDefaultServer = showDefaultServer
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                 if self.showDefaultServer:
86                         self["key_blue"] = Button(_("set default"))
87                 else:
88                         self["key_blue"] = Button("")
89
90                 self["actions"] = ActionMap(["WizardActions", "ColorActions"],
91                         {
92                          "back":        self.close,
93                          "red":         self.keyDelete,
94                          "green":       self.keyAddServer,
95                          "yellow":      self.keyEditServer,
96                          "blue":        self.keySetAsDefault,
97                          "up":          self.up,
98                          "down":        self.down,
99                          "left":        self.left,
100                          "right":       self.right,
101                          "ok":          self.ok,
102             }, -1)
103                         
104                 self.onLayoutFinish.append(self.updateServerlist)
105
106         def updateServerlist(self):
107                 self.serverlist.update(vlcServerConfig.getServerlist(), self.showDefaultServer)
108
109         def keyAddServer(self):
110                 newServer = vlcServerConfig.new()
111                 self.session.openWithCallback(self.addCallback, VlcServerConfigScreen, newServer)
112
113         def addCallback(self, result, server):
114                 if result:
115                         vlcServerConfig.save(server)
116                         self.updateServerlist()
117                 else:
118                         vlcServerConfig.delete(server)
119
120         def keyDelete(self):
121                 self.session.openWithCallback(self.deleteCallback, MessageBox, _("Really delete this Server?"))
122
123         def deleteCallback(self, result):
124                 if result:
125                         vlcServerConfig.delete(self.serverlist.getSelection())
126                         self.updateServerlist()
127
128         def keyEditServer(self):
129                 server = self.serverlist.getSelection()
130                 if server is not None:
131                         self.session.openWithCallback(self.editCallback, VlcServerConfigScreen, server)
132
133         def editCallback(self, result, server):
134                 if result:
135                         vlcServerConfig.save(server)
136                         index = self.serverlist.getSelectedIndex()
137                         self.updateServerlist()
138                         self.serverlist.moveToIndex(index)
139                 else:
140                         vlcServerConfig.cancel(server)
141
142         def keySetAsDefault(self):
143                 if showDefaultServer:
144                         vlcServerConfig.setAsDefault(self.serverlist.getSelection())
145                         index = self.serverlist.getSelectedIndex()
146                         self.updateServerlist()
147                         self.serverlist.moveToIndex(index)
148
149         def up(self):
150                 self.serverlist.up()
151
152         def down(self):
153                 self.serverlist.down()
154
155         def left(self):
156                 self.serverlist.pageUp()
157
158         def right(self):
159                 self.serverlist.pageDown()
160
161         def close(self, server = None):
162                 Screen.close(self, server)
163
164         def ok(self):
165                 self.close(self.serverlist.getSelection())