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