[MerlinSkinThemes] - add support for globals
[enigma2-plugins.git] / serienfilm / src / plugin.py
1 # -*- coding: utf-8 -*-
2 from Plugins.Plugin import PluginDescriptor
3 from SerienFilm import SerienFilmVersion, SerienFilmCfg
4 from traceback import print_exc
5 from sys import stdout, exc_info
6 from Screens.InfoBar import MoviePlayer
7 from MovieSelection import MovieSelection
8
9
10 def pluginConfig(session, **kwargs):
11         print "[SF-Plugin] Config\n"
12         try:
13                 session.open(SerienFilmCfg)
14         except Exception, e:
15                 print "[SF-Plugin] pluginConfig Config exception:\n" + str(e)
16
17
18 gLeavePlayerConfirmed = None
19
20 def showMoviesSF(self):
21         try:
22 #               print "[SF-Plugin] showMoviesSF.InfoBar"
23                 self.session.openWithCallback(self.movieSelected, MovieSelection)
24         except Exception, e:
25                 print "[SF-Plugin] showMoviesSF exception:\n" + str(e)
26
27 def showMoviesMP(self):
28         ref = self.session.nav.getCurrentlyPlayingServiceReference()
29 #       print "[SF-Plugin] SF:MoviePlayer.showMoviesMP"
30 #       print "[SF-Plugin] SF:MoviePlayer.showMoviesMP, ref=" + str(ref)
31         self.session.openWithCallback(self.movieSelected, MovieSelection, ref)
32
33 def leavePlayerConfirmedMP(self, answer):
34         answer1 = answer and answer[1]
35
36         if answer1 == "movielist":
37                 ref = self.session.nav.getCurrentlyPlayingServiceReference()
38                 self.returning = True
39                 self.session.openWithCallback(self.movieSelected, MovieSelection, ref)
40                 self.session.nav.stopService()
41         else:
42                 gLeavePlayerConfirmed(self, answer)
43
44 RUNPLUGIN = 1
45
46 def autostart(reason, **kwargs):
47         if RUNPLUGIN != 1: return
48         if reason == 0: # start
49                 if kwargs.has_key("session"):
50                         global gLeavePlayerConfirmed
51                         Session = kwargs["session"]
52                         print "[SF-Plugin] autostart, Session = " +  str(Session) + "\n"
53                         try:
54                                 from Screens.InfoBar import InfoBar
55                                 InfoBar.showMovies = showMoviesSF
56                                 MoviePlayer.showMovies = showMoviesMP
57                                 if gLeavePlayerConfirmed is None:
58                                         gLeavePlayerConfirmed = MoviePlayer.leavePlayerConfirmed
59                                 MoviePlayer.leavePlayerConfirmed = leavePlayerConfirmedMP
60
61                         except Exception, e:
62                                 print "[SF-Plugin] autostart MovieList launch override exception:\n" + str(e)
63
64                 else:
65                         print "[SF-Plugin] autostart without session\n"
66
67
68 def Plugins(**kwargs):
69         descriptors = [PluginDescriptor(where = PluginDescriptor.WHERE_SESSIONSTART, fnc = autostart)]
70         descriptors.append( PluginDescriptor(
71                 name = "SerienFilm "+SerienFilmVersion,
72                 description = _("group movies of a series to virtual directories"),
73                 icon = "SerienFilm.png",
74                 where = PluginDescriptor.WHERE_PLUGINMENU,
75                 fnc = pluginConfig) )
76         print "[SF-Plugin] autostart descriptors = " + str(descriptors)
77         return descriptors