initial version
[enigma2-plugins.git] / vlcplayer / src / plugin.py
1 from datetime import datetime
2 from Plugins.Plugin import PluginDescriptor
3 from Components.ActionMap import ActionMap
4 from Components.Label import Label
5 from Components.Button import Button
6 from Screens.MessageBox import MessageBox
7 from Screens.Screen import Screen
8 from enigma import eServiceCenter
9 from VlcFileList import VlcFileList
10 from VlcConfig import VLCSettings, VLCServerConfig
11 from VlcPlayer import VlcPlayer
12
13 class VlcBrowser(Screen):
14         skin = """
15                 <screen position="80,100" size="560,400" title="VLC Video Player" >
16                         <widget name="currentdir" position="10,10" size="550,20" font="Regular;18"/>
17                         <widget name="filelist" position="10,35" size="550,310"  scrollbarMode="showOnDemand"/>
18                         <ePixmap name="red"    position="0,355"   zPosition="4" size="140,40" pixmap="Nemesis.SkinSuite.Shared/key-red.png" transparent="1" alphatest="on" />
19                         <ePixmap name="green"  position="140,355" zPosition="4" size="140,40" pixmap="Nemesis.SkinSuite.Shared/key-green.png" transparent="1" alphatest="on" />
20                         <ePixmap name="yellow" position="280,355" zPosition="4" size="140,40" pixmap="Nemesis.SkinSuite.Shared/key-yellow.png" transparent="1" alphatest="on" />
21                         <ePixmap name="blue"   position="420,355" zPosition="4" size="140,40" pixmap="Nemesis.SkinSuite.Shared/key-blue.png" transparent="1" alphatest="on" />
22                         <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" />
23                         <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" />
24                         <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" />
25                         <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" />
26                 </screen>"""
27
28         defaultFilter = "(?i)\.(avi|mpeg|mpg|divx|xvid|mov|ts|vob)$"
29         
30         def __init__(self, session):
31                 self.session = session
32                 self.serviceHandler = eServiceCenter.getInstance()
33                 self.oldService = self.session.nav.getCurrentlyPlayingServiceReference()
34                 self.session.nav.stopService()
35                 self.filelist = VlcFileList(self.defaultFilter)
36
37                 Screen.__init__(self, session)
38                 self["currentdir"] = Label("Loading Serverlist...")
39                 self["filelist"] = self.filelist
40                 self["key_red"] = Button("filter off")
41                 self["key_green"] = Button("serverlist")
42                 self["key_yellow"] = Button("edit server")
43                 self["key_blue"] = Button(_("settings"))
44                 self["actions"] = ActionMap(["WizardActions", "MenuActions", "ShortcutActions", "MoviePlayerActions"], 
45                         {
46                          "back":        self.close, 
47                          "red":         self.keyFilter, 
48                          "green":       self.keyServerlist, 
49                          "yellow":      self.keyEditServer, 
50                          "blue":        self.keySettings, 
51                          "up":          self.up, 
52                          "down":        self.down, 
53                          "left":        self.left, 
54                          "right":       self.right, 
55                          "ok":          self.ok, 
56                          }, -1)
57
58                 self.onLayoutFinish.append(self.keyServerlist)
59                 self.onClose.append(self.__onClose)
60
61         def keyServerlist(self):
62                 self.changeDir(None)
63
64         def keyFilter(self):
65                 if self.filelist.matchingPattern is None:
66                         self.filelist.matchingPattern = self.defaultFilter
67                         self["key_red"].setText("filter off")
68                 else:
69                         self.filelist.matchingPattern = None
70                         self["key_red"].setText("filter on")
71                 dir = self.filelist.getCurrentDirectory()
72                 self.changeDir(dir)
73
74         def keyEditServer(self):
75                 servernum = None
76                 if self.filelist.current_server is None:
77                         if self.filelist.getSelection() is not None:
78                                 path, isdir = self.filelist.getSelection()
79                                 if isdir:
80                                         servernum = int(path[0:path.find(":")])
81                 else:
82                         servernum = self.filelist.current_server
83                 self.session.openWithCallback(self.refresh, VLCServerConfig, servernum)
84
85         def keySettings(self):
86                 self.session.open(VLCSettings)
87
88         def up(self):
89                 self.filelist.up()
90
91         def down(self):
92                 self.filelist.down()
93
94         def left(self):
95                 self.filelist.pageUp()
96
97         def right(self):
98                 self.filelist.pageDown()
99         
100         def ok(self):
101                 if self.filelist.getSelection() is not None:
102                         path, isdir = self.filelist.getSelection()
103                         if path is None:
104                                 self.session.openWithCallback(self.refresh, VLCServerConfig, None)
105                         elif isdir:
106                                 self.changeDir(path)
107                         else:
108                                 servernum, path = path.split(":", 1)
109                                 servernum = int(servernum)
110                                 dlg = self.session.open(VlcPlayer)
111                                 dlg.playfile(servernum, path)
112
113         def __onClose(self):
114                 self.session.nav.playService(self.oldService)
115
116         def refresh(self):
117                 self.changeDir(None)
118         
119         def changeDir(self, dir):
120                 try:
121                         self.filelist.changeDir(dir, self.filelist.getCurrentDirectory())
122                 except Exception, e:
123                         self.session.open(
124                                 MessageBox, _("Error contacting server %s:\n%s" % (dir, e)), MessageBox.TYPE_ERROR)
125                         return
126                 dir = self.filelist.getCurrentDirectory()
127                 if dir is None:
128                         self["currentdir"].setText("Serverlist")
129                 else:
130                         dir = self.filelist.current_path
131                         if len(dir) >= 50:
132                                 dir = "..." + dir[-50:]
133                         self["currentdir"].setText(dir)
134
135 #
136 #-------------------------------------------------------------------------------------------
137 #
138 def main(session, **kwargs):
139         session.open(VlcBrowser)
140
141 def Plugins(**kwargs):
142         return PluginDescriptor(
143                 name="VLC Video Player", 
144                 description="VLC Video Player", 
145                 where = [ PluginDescriptor.WHERE_MOVIELIST, PluginDescriptor.WHERE_PLUGINMENU ],
146                 fnc = main)