enigma2: 4.3.1r16
[enigma2.git] / usr / lib / enigma2 / python / Plugins / Extensions / MediaRenderer / MediaGUI.py
1 # -*- coding: UTF-8 -*-
2 from enigma import eTimer
3 from Components.ActionMap import ActionMap
4 from Plugins.SystemPlugins.UPnP.UPnPCore import Statics
5 from Screens.Screen import Screen
6 from Screens.ChoiceBox import ChoiceBox
7
8 from Tools.Log import Log
9 from LCDScreen import MediaRendererLCDScreen
10
11 class MediaGUI(Screen):
12         ENABLE_RESUME_SUPPORT = True
13         ALLOW_SUSPEND = True
14
15         def __init__(self, session, master):
16                 Screen.__init__(self, session)
17
18                 self._master = master
19                 self._getInfo = self._master.getInfo
20                 self._play = self._master.play
21                 self._stop = self._master.stop
22                 self._playpause = self._master.playpause
23                 self._screen_timeout = 5000
24                 self._is_closing = False
25                 self._getMetadata = self._master.getMetadata
26
27                 self.__delayed_close_timer = eTimer()
28                 self.__delayed_close_timer_conn = self.__delayed_close_timer.timeout.connect(self.close)
29
30                 self["actions"] = ActionMap(["OkCancelActions", "InfobarSeekActions", "MediaPlayerActions", "MovieSelectionActions"],
31                 {
32                                 "ok": self._actionOk,
33                                 "cancel": self._actionCancel,
34                                 "stop": self._actionStop,
35                                 "playpauseService": self._actionPlaypause,
36                                 "showEventInfo": self._actionShowInfo,
37                         }, -2)
38
39                 self.returning = False
40                 self.onClose.append(self.__onClose)
41
42         def __onClose(self):
43                 self.stopCurrent()
44
45         def _actionOk(self):
46                 Log.i("Nothing to do for OK")
47
48         def _actionCancel(self):
49                 self.leavePlayer()
50
51         def _actionStop(self):
52                 self.leavePlayer()
53
54         def _actionPlaypause(self):
55                 self.playpause()
56
57         def _actionShowInfo(self):
58                 self.showInfo()
59
60         def createSummary(self):
61                 return MediaRendererLCDScreen
62
63         def delayedClose(self):
64                 Log.i()
65                 self.__delayed_close_timer.stop()
66                 self.__delayed_close_timer.startLongTimer(4)
67
68         def playAgain(self):
69                 Log.i()
70                 self.stopCurrent()
71                 self.play()
72
73         def play(self):
74                 Log.i()
75                 self.setSeekState(self.SEEK_STATE_PLAY, onlyGUI=True)
76                 self.__delayed_close_timer.stop()
77                 self.setMetadata()
78                 if self.shown:
79                         self.checkSkipShowHideLock()
80
81         def pause(self):
82                 Log.i()
83                 self.setSeekState(self.SEEK_STATE_PAUSE, onlyGUI=True)
84
85         def unpause(self):
86                 Log.i()
87                 self.setSeekState(self.SEEK_STATE_PLAY, onlyGUI=True)
88
89         def setMetadata(self):
90                 Log.i()
91                 metadata = self._getMetadata()
92                 if metadata is not None:
93                         title = metadata.get(Statics.META_TITLE, None)
94                         artist = metadata.get(Statics.META_ARTIST, None)
95                         album = metadata.get(Statics.META_ALBUM, None)
96                         if title:
97                                 self.summaries.setText(title, 1)
98                                 if artist:
99                                         self.summaries.setText(artist, 2)
100                                 if album:
101                                         self.summaries.setText(album, 3)
102                                 return
103
104         def playpause(self):
105                 if self._playpause(self.seekstate == self.SEEK_STATE_PLAY):
106                         self.setSeekState(self.SEEK_STATE_PAUSE, onlyGUI=True)
107                 else:
108                         self.setSeekState(self.SEEK_STATE_PLAY, onlyGUI=True)
109
110         def stopCurrent(self):
111                 Log.i()
112                 self.summaries.clear()
113                 if self.seekstate != self.SEEK_STATE_EOF:
114                         self._stop()
115
116         def showInfo(self):
117                 if self._getInfo != None:
118                         self._getInfo()
119
120         def handleLeave(self, ask=True, error=False):
121                 self._is_closing = True
122                 if ask:
123                         lst = [(_("Yes"), "quit"),
124                                         (_("No, but play again"), "playAgain")]
125
126                         if error is False:
127                                 self.session.openWithCallback(self.leavePlayerConfirmed, ChoiceBox, title=_("Stop playing this movie?"), list=lst)
128                         else:
129                                 self.session.openWithCallback(self.leavePlayerConfirmed, ChoiceBox, title=_("No playable video found! Stop playing this movie?"), list=lst)
130                 else:
131                         self.leavePlayerConfirmed([True, "quit"])
132
133         def leavePlayer(self):
134                 self.handleLeave(ask=False)
135
136         def leavePlayerConfirmed(self, answer):
137                 answer = answer and answer[1]
138                 if answer == "quit":
139                         self.close()
140                 elif answer == "playAgain":
141                         self.playAgain()