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