initial version
[enigma2-plugins.git] / vlcplayer / src / VlcConfig.py
1 from Screens.Screen import Screen\r
2 from Components.config import config\r
3 from Components.config import getConfigListEntry\r
4 from Components.ConfigList import ConfigListScreen\r
5 from Components.ActionMap import ActionMap\r
6 from Components.config import configfile\r
7 from Components.Button import Button\r
8 from Plugins.Extensions.VlcPlayer import addVlcServerConfig\r
9 from Screens.MessageBox import MessageBox\r
10 \r
11 class VLCSettings(Screen, ConfigListScreen):\r
12         skin = """\r
13                 <screen name="VLCSettings" position="80,140" size="560,320" title="VLC Settings">\r
14                         <widget name="config" position="10,10" size="520,240" scrollbarMode="showOnDemand" />\r
15                         <ePixmap name="red"    position="0,270"   zPosition="4" size="140,40" pixmap="Nemesis.SkinSuite.Shared/key-red.png" transparent="1" alphatest="on" />\r
16                         <ePixmap name="green"  position="140,270" zPosition="4" size="140,40" pixmap="Nemesis.SkinSuite.Shared/key-green.png" transparent="1" alphatest="on" />\r
17                         <ePixmap name="yellow" position="280,270" zPosition="4" size="140,40" pixmap="Nemesis.SkinSuite.Shared/key-yellow.png" transparent="1" alphatest="on" />\r
18                         <ePixmap name="blue"   position="420,270" zPosition="4" size="140,40" pixmap="Nemesis.SkinSuite.Shared/key-blue.png" transparent="1" alphatest="on" />\r
19                         <widget name="key_red" position="0,270" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />\r
20                         <widget name="key_green" position="140,270" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />\r
21                         <widget name="key_yellow" position="280,270" zPosition="5" size="140,40" valign="center" halign="center"  font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />\r
22                         <widget name="key_blue" position="420,270" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />\r
23                 </screen>"""\r
24         \r
25         def __init__(self, session):\r
26                 Screen.__init__(self, session)\r
27                 self["actions"] = ActionMap(["SetupActions", "ColorActions"],\r
28                 {\r
29                         "green": self.keySave,\r
30                         "red": self.keyCancel,\r
31                         "cancel": self.keyCancel\r
32                 }, -2)\r
33 \r
34                 self["key_red"] = Button(_("Cancel"))\r
35                 self["key_green"] = Button(_("OK"))\r
36                 self["key_yellow"] = Button("")\r
37                 self["key_blue"] = Button("")\r
38 \r
39                 cfglist = []\r
40                 cfglist.append(getConfigListEntry(_("Video Codec"), config.plugins.vlcplayer.vcodec))\r
41                 cfglist.append(getConfigListEntry(_("Video Bitrate"), config.plugins.vlcplayer.vb))\r
42                 cfglist.append(getConfigListEntry(_("Video Width"), config.plugins.vlcplayer.width))\r
43                 cfglist.append(getConfigListEntry(_("Video Height"), config.plugins.vlcplayer.height))\r
44                 cfglist.append(getConfigListEntry(_("Frames per Second"), config.plugins.vlcplayer.fps))\r
45                 cfglist.append(getConfigListEntry(_("Scale"), config.plugins.vlcplayer.scale))\r
46                 cfglist.append(getConfigListEntry(_("Audio Codec"), config.plugins.vlcplayer.acodec))\r
47                 cfglist.append(getConfigListEntry(_("Audio Bitrate"), config.plugins.vlcplayer.ab))\r
48                 cfglist.append(getConfigListEntry(_("Audio Channels"), config.plugins.vlcplayer.channels))\r
49                 ConfigListScreen.__init__(self, cfglist, session)\r
50 \r
51         def keySave(self):\r
52                 ConfigListScreen.keySave(self)\r
53                 configfile.save()\r
54 \r
55 \r
56 class VLCServerConfig(Screen, ConfigListScreen):\r
57         skin = """\r
58                 <screen name="VLCServerConfig" position="80,148" size="560,280" title="Edit VLC Server">\r
59                         <widget name="config" position="10,10" size="520,210" scrollbarMode="showOnDemand" />\r
60                         <ePixmap name="red"    position="0,240"   zPosition="4" size="140,40" pixmap="Nemesis.SkinSuite.Shared/key-red.png" transparent="1" alphatest="on" />\r
61                         <ePixmap name="green"  position="140,240" zPosition="4" size="140,40" pixmap="Nemesis.SkinSuite.Shared/key-green.png" transparent="1" alphatest="on" />\r
62                         <ePixmap name="yellow" position="280,240" zPosition="4" size="140,40" pixmap="Nemesis.SkinSuite.Shared/key-yellow.png" transparent="1" alphatest="on" />\r
63                         <ePixmap name="blue"   position="420,240" zPosition="4" size="140,40" pixmap="Nemesis.SkinSuite.Shared/key-blue.png" transparent="1" alphatest="on" />\r
64                         <widget name="key_red" position="0,240" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />\r
65                         <widget name="key_green" position="140,240" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />\r
66                         <widget name="key_yellow" position="280,240" zPosition="5" size="140,40" valign="center" halign="center"  font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />\r
67                         <widget name="key_blue" position="420,240" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />\r
68                 </screen>"""\r
69         \r
70         def __init__(self, session, servernum):\r
71                 Screen.__init__(self, session)\r
72                 self["actions"] = ActionMap(["SetupActions", "ColorActions"],\r
73                 {\r
74                         "green": self.keySave,\r
75                         "red": self.keyCancel,\r
76                         "blue": self.keyDelete,\r
77                         "cancel": self.keyCancel\r
78                 }, -2)\r
79 \r
80                 self["key_red"] = Button(_("Cancel"))\r
81                 self["key_green"] = Button(_("OK"))\r
82                 self["key_yellow"] = Button("")\r
83                 self["key_blue"] = Button(_("Delete"))\r
84 \r
85                 if servernum is None:\r
86                         i = addVlcServerConfig()\r
87                 else:\r
88                         i = servernum\r
89                 cfglist = []\r
90                 cfglist.append(getConfigListEntry(_("Hostname or IP"), config.plugins.vlcplayer.servers[i].host))\r
91                 cfglist.append(getConfigListEntry(_("HTTP Port"), config.plugins.vlcplayer.servers[i].httpport))\r
92                 cfglist.append(getConfigListEntry(_("Movie Directory"), config.plugins.vlcplayer.servers[i].basedir))\r
93                 cfglist.append(getConfigListEntry(_("Method"), config.plugins.vlcplayer.servers[i].method))\r
94                 cfglist.append(getConfigListEntry(_("Admin (telnet) Port"), config.plugins.vlcplayer.servers[i].adminport))\r
95                 cfglist.append(getConfigListEntry(_("Admin Password"), config.plugins.vlcplayer.servers[i].adminpwd))\r
96                 ConfigListScreen.__init__(self, cfglist, session)\r
97                 self.servernum = i\r
98 \r
99         def keySave(self):\r
100                 config.plugins.vlcplayer.servercount.save()\r
101                 for x in self["config"].list:\r
102                         if isinstance(x[1].value, str):\r
103                                 x[1].value = x[1].value.strip()\r
104                         x[1].save()\r
105                 self.close()\r
106                 configfile.save()\r
107 \r
108         def cancelConfirm(self, result):\r
109                 if result:\r
110                         config.plugins.vlcplayer.servercount.cancel()\r
111                 self.callback = None\r
112                 ConfigListScreen.cancelConfirm(self, result)\r
113 \r
114         def keyDelete(self):\r
115                 self.session.openWithCallback(self.deleteConfirm, MessageBox, _("Really delete this Server config?"))\r
116 \r
117         def deleteConfirm(self, result):\r
118                 if not result:\r
119                         return\r
120                 del(config.plugins.vlcplayer.servers[self.servernum])\r
121                 config.plugins.vlcplayer.servers.save()\r
122                 config.plugins.vlcplayer.servercount.value = config.plugins.vlcplayer.servercount.value - 1;\r
123                 config.plugins.vlcplayer.servercount.save()\r
124                 configfile.save()\r
125                 self.close()\r