/// <summary> /// /// </summary> /// <param name="action"></param> private void OnAction(Action action) { try { // hack/fix for lastactivemodulefullscreen // when recovering from hibernation/standby after closing with remote control somehow a F9 (keycode 120) onkeydown event is thrown from outside // we are currently filtering it away. // sometimes more than one F9 keydown event fired. // if these events are not filtered away the F9 context menu is shown on the restored/shown module. if ((action.wID == Action.ActionType.ACTION_CONTEXT_MENU || _suspended) && (_showLastActiveModule)) { if (_ignoreContextMenuAction) { _ignoreContextMenuAction = false; _lastContextMenuAction = DateTime.Now; return; } if (_lastContextMenuAction != DateTime.MaxValue) { TimeSpan ts = _lastContextMenuAction - DateTime.Now; if (ts.TotalMilliseconds > -100) { _ignoreContextMenuAction = false; _lastContextMenuAction = DateTime.Now; return; } } _lastContextMenuAction = DateTime.Now; } GUIWindow window; if (action.IsUserAction()) { GUIGraphicsContext.ResetLastActivity(); } switch (action.wID) { // record current tv program case Action.ActionType.ACTION_RECORD: if ((GUIGraphicsContext.IsTvWindow(GUIWindowManager.ActiveWindowEx) && GUIWindowManager.ActiveWindowEx != (int)GUIWindow.Window.WINDOW_TVGUIDE) && (GUIWindowManager.ActiveWindowEx != (int)GUIWindow.Window.WINDOW_DIALOG_TVGUIDE)) { GUIWindow tvHome = GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_TV); if (tvHome != null && tvHome.GetID != GUIWindowManager.ActiveWindow) { tvHome.OnAction(action); return; } } break; // TV: zap to previous channel case Action.ActionType.ACTION_PREV_CHANNEL: if (!GUIWindowManager.IsRouted) { window = GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_TV); window.OnAction(action); return; } break; // TV: zap to next channel case Action.ActionType.ACTION_NEXT_CHANNEL: if (!GUIWindowManager.IsRouted) { window = GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_TV); window.OnAction(action); return; } break; // TV: zap to last channel viewed case Action.ActionType.ACTION_LAST_VIEWED_CHANNEL: // mPod if (!GUIWindowManager.IsRouted) { window = GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_TV); window.OnAction(action); return; } break; // toggle between windowed and fullscreen mode case Action.ActionType.ACTION_TOGGLE_WINDOWED_FULLSCREEN: ToggleFullscreen(); return; // mute or unmute audio case Action.ActionType.ACTION_VOLUME_MUTE: VolumeHandler.Instance.IsMuted = !VolumeHandler.Instance.IsMuted; break; // decrease volume case Action.ActionType.ACTION_VOLUME_DOWN: VolumeHandler.Instance.Volume = VolumeHandler.Instance.Previous; break; // increase volume case Action.ActionType.ACTION_VOLUME_UP: VolumeHandler.Instance.Volume = VolumeHandler.Instance.Next; break; // toggle live tv in background case Action.ActionType.ACTION_BACKGROUND_TOGGLE: // show livetv or video as background instead of the static GUI background // toggle livetv/video in background on/off if (GUIGraphicsContext.ShowBackground) { Log.Info("Main: Using live TV as background"); // if on, but we're not playing any video or watching tv if (GUIGraphicsContext.Vmr9Active) { GUIGraphicsContext.ShowBackground = false; } else { // show warning message var msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_SHOW_WARNING, 0, 0, 0, 0, 0, 0) {Param1 = 727, Param2 = 728, Param3 = 729}; GUIWindowManager.SendMessage(msg); return; } } else { Log.Info("Main: Using GUI as background"); GUIGraphicsContext.ShowBackground = true; } break; // switch between several home windows case Action.ActionType.ACTION_SWITCH_HOME: GUIWindow.Window newHome = _startWithBasicHome ? GUIWindow.Window.WINDOW_SECOND_HOME : GUIWindow.Window.WINDOW_HOME; // do we prefer to use only one home screen? if (_useOnlyOneHome) { // skip if we are already in there if (GUIWindowManager.ActiveWindow == (int)newHome) { break; } } // we like both else { // if already in one home switch to the other switch (GUIWindowManager.ActiveWindow) { case (int)GUIWindow.Window.WINDOW_HOME: newHome = GUIWindow.Window.WINDOW_SECOND_HOME; break; case (int)GUIWindow.Window.WINDOW_SECOND_HOME: newHome = GUIWindow.Window.WINDOW_HOME; break; } } var homeMsg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, (int)newHome, 0, null); GUIWindowManager.SendThreadMessage(homeMsg); // Stop Video for MyPictures when going to home if (g_Player.IsPicture) { GUISlideShow._slideDirection = 0; g_Player.Stop(); } break; case Action.ActionType.ACTION_MPRESTORE: Log.Info("Main: Restore MP by action"); RestoreFromTray(); if ((g_Player.IsVideo || g_Player.IsTV || g_Player.IsDVD) && Volume > 0) { g_Player.Volume = Volume; g_Player.ContinueGraph(); if (g_Player.Paused && !GUIGraphicsContext.IsVMR9Exclusive) { g_Player.Pause(); } } break; // reboot pc case Action.ActionType.ACTION_POWER_OFF: case Action.ActionType.ACTION_SUSPEND: case Action.ActionType.ACTION_HIBERNATE: case Action.ActionType.ACTION_REBOOT: // reboot Log.Info("Main: Reboot requested"); bool okToChangePowermode = (Math.Abs(action.fAmount1 - 1) < float.Epsilon); if (!okToChangePowermode) { okToChangePowermode = PromptUserBeforeChangingPowermode(action); } if (okToChangePowermode) { switch (action.wID) { case Action.ActionType.ACTION_REBOOT: _restartOptions = RestartOptions.Reboot; _useRestartOptions = true; GUIGraphicsContext.CurrentState = GUIGraphicsContext.State.STOPPING; break; case Action.ActionType.ACTION_POWER_OFF: _restartOptions = RestartOptions.PowerOff; _useRestartOptions = true; GUIGraphicsContext.CurrentState = GUIGraphicsContext.State.STOPPING; ShuttingDown = true; break; case Action.ActionType.ACTION_SUSPEND: if (IsSuspendOrHibernationAllowed()) { _restartOptions = RestartOptions.Suspend; Utils.SuspendSystem(false); } else { Log.Info("Main: SUSPEND ignored since suspend graceperiod of {0} sec. is violated.", _suspendGracePeriodSec); } break; case Action.ActionType.ACTION_HIBERNATE: if (IsSuspendOrHibernationAllowed()) { _restartOptions = RestartOptions.Hibernate; Utils.HibernateSystem(false); } else { Log.Info("Main: HIBERNATE ignored since hibernate graceperiod of {0} sec. is violated.", _suspendGracePeriodSec); } break; } } break; // eject cd case Action.ActionType.ACTION_EJECTCD: Utils.EjectCDROM(); break; // shutdown pc case Action.ActionType.ACTION_SHUTDOWN: Log.Info("Main: Shutdown dialog"); var dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); if (dlg != null) { dlg.Reset(); dlg.SetHeading(GUILocalizeStrings.Get(498)); //Menu dlg.AddLocalizedString(1057); //Exit MediaPortal dlg.AddLocalizedString(1058); //Restart MediaPortal dlg.AddLocalizedString(1032); //Suspend dlg.AddLocalizedString(1049); //Hibernate dlg.AddLocalizedString(1031); //Reboot dlg.AddLocalizedString(1030); //PowerOff dlg.DoModal(GUIWindowManager.ActiveWindow); if (dlg.SelectedId >= 0) { switch (dlg.SelectedId) { case 1057: ExitMP(); return; case 1058: GUIGraphicsContext.CurrentState = GUIGraphicsContext.State.STOPPING; Utils.RestartMePo(); break; case 1030: _restartOptions = RestartOptions.PowerOff; _useRestartOptions = true; GUIGraphicsContext.CurrentState = GUIGraphicsContext.State.STOPPING; ShuttingDown = true; break; case 1031: _restartOptions = RestartOptions.Reboot; _useRestartOptions = true; GUIGraphicsContext.CurrentState = GUIGraphicsContext.State.STOPPING; ShuttingDown = true; break; case 1032: _restartOptions = RestartOptions.Suspend; Utils.SuspendSystem(false); break; case 1049: _restartOptions = RestartOptions.Hibernate; Utils.HibernateSystem(false); break; } } else { GUIWindow win = GUIWindowManager.GetWindow((int) GUIWindow.Window.WINDOW_HOME); if (win != null) { win.OnAction(new Action(Action.ActionType.ACTION_MOVE_LEFT, 0, 0)); } } } break; // exit Mediaportal case Action.ActionType.ACTION_EXIT: ExitMP(); break; // stop radio case Action.ActionType.ACTION_STOP: break; // Take Screen shot case Action.ActionType.ACTION_TAKE_SCREENSHOT: try { string directory = string.Format("{0}\\MediaPortal Screenshots\\{1:0000}-{2:00}-{3:00}", Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); if (!Directory.Exists(directory)) { Log.Info("Main: Taking screenshot - Creating directory: {0}", directory); Directory.CreateDirectory(directory); } string fileName = string.Format("{0}\\{1:00}-{2:00}-{3:00}", directory, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); Log.Info("Main: Taking screenshot - Target: {0}.png", fileName); Surface backbuffer = GUIGraphicsContext.DX9Device.GetBackBuffer(0, 0, BackBufferType.Mono); SurfaceLoader.Save(fileName + ".png", ImageFileFormat.Png, backbuffer); backbuffer.Dispose(); Log.Info("Main: Taking screenshot done"); } catch (Exception ex) { Log.Info("Main: Error taking screenshot: {0}", ex.Message); } break; case Action.ActionType.ACTION_SHOW_GUI: // can we handle the switch to fullscreen? if (!GUIGraphicsContext.IsFullScreenVideo && g_Player.ShowFullScreenWindow()) { return; } break; } if (g_Player.Playing) { string activeWindowName; GUIWindow.Window activeWindow; switch (action.wID) { // show DVD menu case Action.ActionType.ACTION_DVD_MENU: if (g_Player.IsDVD) { g_Player.OnAction(action); return; } break; // DVD: goto previous chapter // play previous item from playlist; case Action.ActionType.ACTION_PREV_ITEM: case Action.ActionType.ACTION_PREV_CHAPTER: if (g_Player.IsDVD || g_Player.HasChapters) { action = new Action(Action.ActionType.ACTION_PREV_CHAPTER, 0, 0); g_Player.OnAction(action); break; } // When MyPictures Plugin shows the pictures/videos we don't want to change music track activeWindowName = GUIWindowManager.ActiveWindow.ToString(CultureInfo.InvariantCulture); activeWindow = (GUIWindow.Window) Enum.Parse(typeof(GUIWindow.Window), activeWindowName); if (!ActionTranslator.HasKeyMapped(GUIWindowManager.ActiveWindowEx, action.m_key) && (activeWindow != GUIWindow.Window.WINDOW_SLIDESHOW && !g_Player.IsPicture)) { PlaylistPlayer.PlayPrevious(); } break; // play next item from playlist; // DVD: goto next chapter case Action.ActionType.ACTION_NEXT_CHAPTER: case Action.ActionType.ACTION_NEXT_ITEM: if (g_Player.IsDVD || g_Player.HasChapters) { action = new Action(Action.ActionType.ACTION_NEXT_CHAPTER, 0, 0); g_Player.OnAction(action); break; } // When MyPictures Plugin shows the pictures/videos we don't want to change music track activeWindowName = GUIWindowManager.ActiveWindow.ToString(CultureInfo.InvariantCulture); activeWindow = (GUIWindow.Window) Enum.Parse(typeof(GUIWindow.Window), activeWindowName); if (!ActionTranslator.HasKeyMapped(GUIWindowManager.ActiveWindowEx, action.m_key) && (activeWindow != GUIWindow.Window.WINDOW_SLIDESHOW && !g_Player.IsPicture)) { PlaylistPlayer.PlayNext(); } break; // stop playback case Action.ActionType.ACTION_STOP: // When MyPictures Plugin shows the pictures we want to stop the slide show only, not the player activeWindowName = GUIWindowManager.ActiveWindow.ToString(CultureInfo.InvariantCulture); activeWindow = (GUIWindow.Window)Enum.Parse(typeof(GUIWindow.Window), activeWindowName); if ((activeWindow == GUIWindow.Window.WINDOW_SLIDESHOW) || (activeWindow == GUIWindow.Window.WINDOW_FULLSCREEN_VIDEO && g_Player.IsPicture) && g_Player.Playing) { break; } if (!g_Player.IsTV || !GUIGraphicsContext.IsFullScreenVideo) { Log.Info("Main: Stopping media"); if (g_Player.IsPicture) { GUISlideShow._slideDirection = 0; } g_Player.Stop(); } break; // Jump to Music Now Playing case Action.ActionType.ACTION_JUMP_MUSIC_NOW_PLAYING: if (g_Player.IsMusic) { if (GUIWindowManager.ActiveWindow == (int)GUIWindow.Window.WINDOW_MUSIC_PLAYING_NOW) { GUIWindowManager.ShowPreviousWindow(); } else { GUIWindowManager.ActivateWindow((int) GUIWindow.Window.WINDOW_MUSIC_PLAYING_NOW); } } break; // play music // resume playback case Action.ActionType.ACTION_PLAY: case Action.ActionType.ACTION_MUSIC_PLAY: // Don't start playing from the beginning if we press play to return to normal speed if (g_Player.IsMusic && g_Player.Speed != 1 && (GUIWindowManager.ActiveWindow != (int) GUIWindow.Window.WINDOW_MUSIC_FILES && GUIWindowManager.ActiveWindow != (int) GUIWindow.Window.WINDOW_MUSIC_GENRE)) { g_Player.Speed = 1; break; } g_Player.StepNow(); g_Player.Speed = 1; if (g_Player.Paused) { g_Player.Pause(); } break; // pause (or resume playback) case Action.ActionType.ACTION_PAUSE: // When MyPictures Plugin shows the pictures we want to pause the slide show only, not the player activeWindowName = GUIWindowManager.ActiveWindow.ToString(CultureInfo.InvariantCulture); activeWindow = (GUIWindow.Window)Enum.Parse(typeof(GUIWindow.Window), activeWindowName); if ((activeWindow == GUIWindow.Window.WINDOW_SLIDESHOW) || (activeWindow == GUIWindow.Window.WINDOW_FULLSCREEN_VIDEO && g_Player.IsPicture) && g_Player.Playing && !g_Player.IsVideo) { break; } g_Player.Pause(); break; // fast forward... case Action.ActionType.ACTION_FORWARD: { if (g_Player.Paused) { g_Player.Pause(); } g_Player.Speed = Utils.GetNextForwardSpeed(g_Player.Speed); break; } // Decide if we want to have CD style of FF or Skip steps case Action.ActionType.ACTION_MUSIC_FORWARD: // When MyPictures Plugin shows the pictures/videos we don't want to change music track activeWindowName = GUIWindowManager.ActiveWindow.ToString(CultureInfo.InvariantCulture); activeWindow = (GUIWindow.Window) Enum.Parse(typeof(GUIWindow.Window), activeWindowName); if (!ActionTranslator.HasKeyMapped(GUIWindowManager.ActiveWindowEx, action.m_key) && (activeWindow != GUIWindow.Window.WINDOW_SLIDESHOW && !g_Player.IsPicture || g_Player.IsVideo)) { if (g_Player.Paused) { g_Player.Pause(); } if (!MediaPortal.MusicPlayer.BASS.Config.UseSkipSteps) { g_Player.Speed = Utils.GetNextForwardSpeed(g_Player.Speed); } } break; // fast rewind... case Action.ActionType.ACTION_REWIND: { if (g_Player.Paused) { g_Player.Pause(); } g_Player.Speed = Utils.GetNextRewindSpeed(g_Player.Speed); break; } // Decide if we want to have CD style of Rew or Skip steps case Action.ActionType.ACTION_MUSIC_REWIND: // When MyPictures Plugin shows the pictures/videos we don't want to change music track activeWindowName = GUIWindowManager.ActiveWindow.ToString(CultureInfo.InvariantCulture); activeWindow = (GUIWindow.Window) Enum.Parse(typeof(GUIWindow.Window), activeWindowName); if (!ActionTranslator.HasKeyMapped(GUIWindowManager.ActiveWindowEx, action.m_key) && (activeWindow != GUIWindow.Window.WINDOW_SLIDESHOW && !g_Player.IsPicture || g_Player.IsVideo)) { if (g_Player.Paused) { g_Player.Pause(); } if (!MediaPortal.MusicPlayer.BASS.Config.UseSkipSteps) { g_Player.Speed = Utils.GetNextRewindSpeed(g_Player.Speed); } } break; } } GUIWindowManager.OnAction(action); } catch (FileNotFoundException ex) { Log.Error(ex); // ReSharper disable LocalizableElement MessageBox.Show("File not found:" + ex.FileName, "MediaPortal", MessageBoxButtons.OK, MessageBoxIcon.Error); // ReSharper restore LocalizableElement Close(); } catch (Exception ex) { Log.Error(ex); Log.Error("Exception: {0} {1} {2}", ex.Message, ex.Source, ex.StackTrace); #if !DEBUG throw new Exception("exception occurred", ex); #endif } }
private void OnAction(Action action) { try { // hack/fix for lastactivemodulefullscreen // when recovering from hibernation/standby after closing with remote control somehow a F9 (keycode 120) onkeydown event is thrown from outside // we are currently filtering it away. // sometimes more than one F9 keydown event fired. // if these events are not filtered away the F9 context menu is shown on the restored/shown module. if ((action.wID == Action.ActionType.ACTION_CONTEXT_MENU || _suspended) && (showLastActiveModule)) { //Log.Info("ACTION_CONTEXT_MENU, ignored = {0}, suspended = {1}", ignoreContextMenuAction, _suspended); if (ignoreContextMenuAction) { ignoreContextMenuAction = false; lastContextMenuAction = DateTime.Now; return; } else if (lastContextMenuAction != DateTime.MaxValue) { TimeSpan ts = lastContextMenuAction - DateTime.Now; if (ts.TotalMilliseconds > -100) { ignoreContextMenuAction = false; lastContextMenuAction = DateTime.Now; return; } } lastContextMenuAction = DateTime.Now; } GUIWindow window; if (action.IsUserAction()) { GUIGraphicsContext.ResetLastActivity(); } switch (action.wID) { // record current tv program case Action.ActionType.ACTION_RECORD: if ((GUIGraphicsContext.IsTvWindow(GUIWindowManager.ActiveWindowEx) && GUIWindowManager.ActiveWindowEx != (int)GUIWindow.Window.WINDOW_TVGUIDE) && (GUIWindowManager.ActiveWindowEx != (int)GUIWindow.Window.WINDOW_DIALOG_TVGUIDE)) { GUIWindow tvHome = GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_TV); if (tvHome != null) { if (tvHome.GetID != GUIWindowManager.ActiveWindow) { tvHome.OnAction(action); return; } } } break; //TV: zap to previous channel case Action.ActionType.ACTION_PREV_CHANNEL: if (!GUIWindowManager.IsRouted) { window = GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_TV); window.OnAction(action); return; } break; //TV: zap to next channel case Action.ActionType.ACTION_NEXT_CHANNEL: if (!GUIWindowManager.IsRouted) { window = GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_TV); window.OnAction(action); return; } break; //TV: zap to last channel viewed case Action.ActionType.ACTION_LAST_VIEWED_CHANNEL: // mPod if (!GUIWindowManager.IsRouted) { window = GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_TV); window.OnAction(action); return; } break; //toggle between directx windowed and exclusive mode case Action.ActionType.ACTION_TOGGLE_WINDOWED_FULLSCREEN: ToggleFullWindowed(); return; //break; //mute or unmute audio case Action.ActionType.ACTION_VOLUME_MUTE: VolumeHandler.Instance.IsMuted = !VolumeHandler.Instance.IsMuted; break; //decrease volume case Action.ActionType.ACTION_VOLUME_DOWN: VolumeHandler.Instance.Volume = VolumeHandler.Instance.Previous; break; //increase volume case Action.ActionType.ACTION_VOLUME_UP: VolumeHandler.Instance.Volume = VolumeHandler.Instance.Next; break; //toggle live tv in background case Action.ActionType.ACTION_BACKGROUND_TOGGLE: //show livetv or video as background instead of the static GUI background // toggle livetv/video in background on/pff if (GUIGraphicsContext.ShowBackground) { Log.Info("Main: Using live TV as background"); // if on, but we're not playing any video or watching tv if (GUIGraphicsContext.Vmr9Active) { GUIGraphicsContext.ShowBackground = false; //GUIGraphicsContext.Overlay = false; } else { //show warning message GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_SHOW_WARNING, 0, 0, 0, 0, 0, 0); msg.Param1 = 727; //Live tv in background msg.Param2 = 728; //No Video/TV playing msg.Param3 = 729; //Make sure that something is playing GUIWindowManager.SendMessage(msg); return; } } else { Log.Info("Main: Using GUI as background"); GUIGraphicsContext.ShowBackground = true; //GUIGraphicsContext.Overlay = true; } return; //switch between several home windows case Action.ActionType.ACTION_SWITCH_HOME: GUIMessage homeMsg; GUIWindow.Window newHome = _startWithBasicHome ? GUIWindow.Window.WINDOW_SECOND_HOME : GUIWindow.Window.WINDOW_HOME; // do we prefer to use only one home screen? if (_useOnlyOneHome) { // skip if we are already in there if (GUIWindowManager.ActiveWindow == (int)newHome) { return; } } // we like both else { // if already in one home switch to the other if (GUIWindowManager.ActiveWindow == (int)GUIWindow.Window.WINDOW_HOME) { newHome = GUIWindow.Window.WINDOW_SECOND_HOME; } else if (GUIWindowManager.ActiveWindow == (int)GUIWindow.Window.WINDOW_SECOND_HOME) { newHome = GUIWindow.Window.WINDOW_HOME; } } homeMsg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, (int)newHome, 0, null); GUIWindowManager.SendThreadMessage(homeMsg); return; //exit mediaportal case Action.ActionType.ACTION_EXIT: Log.Info("Main: Exit requested"); // is the minimize on gui option set? If so, minimize to tray... if (_minimizeOnGuiExit && !_shuttingDown) { if (WindowState != FormWindowState.Minimized) { Log.Info("Main: Minimizing to tray on GUI exit and restoring taskbar"); } WindowState = FormWindowState.Minimized; Hide(); if (autoHideTaskbar) { // only re-show the startbar if MP is the one that has hidden it. Win32API.EnableStartBar(true); Win32API.ShowStartBar(true); } if (g_Player.IsVideo || g_Player.IsTV || g_Player.IsDVD) { if (g_Player.Volume > 0) { m_iVolume = g_Player.Volume; g_Player.Volume = 0; } if (g_Player.Paused == false && !GUIGraphicsContext.IsVMR9Exclusive) { g_Player.Pause(); } } return; } GUIGraphicsContext.CurrentState = GUIGraphicsContext.State.STOPPING; return; case Action.ActionType.ACTION_MPRESTORE: { Log.Info("Main: Restore MP by action"); Restore(); if ((g_Player.IsVideo || g_Player.IsTV || g_Player.IsDVD) && m_iVolume > 0) { g_Player.Volume = m_iVolume; g_Player.ContinueGraph(); if (g_Player.Paused && !GUIGraphicsContext.IsVMR9Exclusive) { g_Player.Pause(); } } } return; //reboot pc case Action.ActionType.ACTION_POWER_OFF: case Action.ActionType.ACTION_SUSPEND: case Action.ActionType.ACTION_HIBERNATE: case Action.ActionType.ACTION_REBOOT: { //reboot Log.Info("Main: Reboot requested"); bool okToChangePowermode = (action.fAmount1 == 1); if (!okToChangePowermode) { okToChangePowermode = PromptUserBeforeChangingPowermode(action); } if (okToChangePowermode) { switch (action.wID) { case Action.ActionType.ACTION_REBOOT: restartOptions = RestartOptions.Reboot; useRestartOptions = true; GUIGraphicsContext.CurrentState = GUIGraphicsContext.State.STOPPING; break; case Action.ActionType.ACTION_POWER_OFF: restartOptions = RestartOptions.PowerOff; useRestartOptions = true; GUIGraphicsContext.CurrentState = GUIGraphicsContext.State.STOPPING; base._shuttingDown = true; break; case Action.ActionType.ACTION_SUSPEND: if (IsSuspendOrHibernationAllowed()) { restartOptions = RestartOptions.Suspend; Utils.SuspendSystem(false); } else { Log.Info("Main: SUSPEND ignored since suspend graceperiod of {0} sec. is violated.", _suspendGracePeriodSec); } break; case Action.ActionType.ACTION_HIBERNATE: if (IsSuspendOrHibernationAllowed()) { restartOptions = RestartOptions.Hibernate; Utils.HibernateSystem(false); } else { Log.Info("Main: HIBERNATE ignored since hibernate graceperiod of {0} sec. is violated.", _suspendGracePeriodSec); } break; } } } return; //eject cd case Action.ActionType.ACTION_EJECTCD: Utils.EjectCDROM(); return; //shutdown pc case Action.ActionType.ACTION_SHUTDOWN: { Log.Info("Main: Shutdown dialog"); GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); if (dlg != null) { dlg.Reset(); dlg.SetHeading(GUILocalizeStrings.Get(498)); //Menu dlg.AddLocalizedString(1030); //PowerOff dlg.AddLocalizedString(1031); //Reboot dlg.AddLocalizedString(1032); //Suspend dlg.AddLocalizedString(1049); //Hibernate dlg.DoModal(GUIWindowManager.ActiveWindow); //RestartOptions option = RestartOptions.Suspend; if (dlg.SelectedId < 0) { GUIWindow win = GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_HOME); if (win != null) { win.OnAction(new Action(Action.ActionType.ACTION_MOVE_LEFT, 0, 0)); } return; } switch (dlg.SelectedId) { case 1030: restartOptions = RestartOptions.PowerOff; useRestartOptions = true; GUIGraphicsContext.CurrentState = GUIGraphicsContext.State.STOPPING; base._shuttingDown = true; break; case 1031: restartOptions = RestartOptions.Reboot; useRestartOptions = true; GUIGraphicsContext.CurrentState = GUIGraphicsContext.State.STOPPING; base._shuttingDown = true; break; case 1032: restartOptions = RestartOptions.Suspend; Utils.SuspendSystem(false); break; case 1049: restartOptions = RestartOptions.Hibernate; Utils.HibernateSystem(false); break; } } break; } //stop radio case Action.ActionType.ACTION_STOP: break; // Take Screenshot case Action.ActionType.ACTION_TAKE_SCREENSHOT: { try { string directory = string.Format("{0}\\MediaPortal Screenshots\\{1:0000}-{2:00}-{3:00}", Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); if (!Directory.Exists(directory)) { Log.Info("Main: Taking screenshot - Creating directory: {0}", directory); Directory.CreateDirectory(directory); } string fileName = string.Format("{0}\\{1:00}-{2:00}-{3:00}", directory, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); Log.Info("Main: Taking screenshot - Target: {0}.png", fileName); Surface backbuffer = GUIGraphicsContext.DX9Device.GetBackBuffer(0, 0, BackBufferType.Mono); SurfaceLoader.Save(fileName + ".png", ImageFileFormat.Png, backbuffer); backbuffer.Dispose(); Log.Info("Main: Taking screenshot done"); } catch (Exception ex) { Log.Info("Main: Error taking screenshot: {0}", ex.Message); } } break; case Action.ActionType.ACTION_SHOW_GUI: { // can we handle the switch to fullscreen? if (!GUIGraphicsContext.IsFullScreenVideo && g_Player.ShowFullScreenWindow()) { return; } } break; } if (g_Player.Playing) { switch (action.wID) { //show DVD menu case Action.ActionType.ACTION_DVD_MENU: if (g_Player.IsDVD) { g_Player.OnAction(action); return; } break; //DVD: goto previous chapter //play previous item from playlist; case Action.ActionType.ACTION_PREV_ITEM: case Action.ActionType.ACTION_PREV_CHAPTER: if (g_Player.IsDVD || g_Player.HasChapters) { action = new Action(Action.ActionType.ACTION_PREV_CHAPTER, 0, 0); g_Player.OnAction(action); return; } if (!ActionTranslator.HasKeyMapped(GUIWindowManager.ActiveWindowEx, action.m_key)) { playlistPlayer.PlayPrevious(); } break; //play next item from playlist; //DVD: goto next chapter case Action.ActionType.ACTION_NEXT_CHAPTER: case Action.ActionType.ACTION_NEXT_ITEM: if (g_Player.IsDVD || g_Player.HasChapters) { action = new Action(Action.ActionType.ACTION_NEXT_CHAPTER, 0, 0); g_Player.OnAction(action); return; } if (!ActionTranslator.HasKeyMapped(GUIWindowManager.ActiveWindowEx, action.m_key)) { playlistPlayer.PlayNext(); } break; //stop playback case Action.ActionType.ACTION_STOP: //When MyPictures Plugin shows the pictures we want to stop the slide show only, not the player if ( (GUIWindow.Window)(Enum.Parse(typeof (GUIWindow.Window), GUIWindowManager.ActiveWindow.ToString())) == GUIWindow.Window.WINDOW_SLIDESHOW) { break; } if (!g_Player.IsTV || !GUIGraphicsContext.IsFullScreenVideo) { Log.Info("Main: Stopping media"); g_Player.Stop(); return; } break; //Jump to Music Now Playing case Action.ActionType.ACTION_JUMP_MUSIC_NOW_PLAYING: if (g_Player.IsMusic && GUIWindowManager.ActiveWindow != (int)GUIWindow.Window.WINDOW_MUSIC_PLAYING_NOW) { GUIWindowManager.ActivateWindow((int)GUIWindow.Window.WINDOW_MUSIC_PLAYING_NOW); } break; //play music //resume playback case Action.ActionType.ACTION_PLAY: case Action.ActionType.ACTION_MUSIC_PLAY: // Don't start playing from the beginning if we press play to return to normal speed if (g_Player.IsMusic && g_Player.Speed != 1) { // Attention: GUIMusicGenre / GUIMusicFiles need to be handled differently. we reset the speed there if (GUIWindowManager.ActiveWindow == (int)GUIWindow.Window.WINDOW_MUSIC_FILES || GUIWindowManager.ActiveWindow == (int)GUIWindow.Window.WINDOW_MUSIC_GENRE) { return; } g_Player.Speed = 1; return; } g_Player.StepNow(); g_Player.Speed = 1; if (g_Player.Paused) { g_Player.Pause(); } break; //pause (or resume playback) case Action.ActionType.ACTION_PAUSE: g_Player.Pause(); break; //fast forward... case Action.ActionType.ACTION_FORWARD: case Action.ActionType.ACTION_MUSIC_FORWARD: { if (g_Player.Paused) { g_Player.Pause(); } g_Player.Speed = Utils.GetNextForwardSpeed(g_Player.Speed); break; } //fast rewind... case Action.ActionType.ACTION_REWIND: case Action.ActionType.ACTION_MUSIC_REWIND: { if (g_Player.Paused) { g_Player.Pause(); } g_Player.Speed = Utils.GetNextRewindSpeed(g_Player.Speed); break; } } } GUIWindowManager.OnAction(action); } catch (FileNotFoundException ex) { Log.Error(ex); MessageBox.Show("File not found:" + ex.FileName, "MediaPortal", MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); } catch (Exception ex) { Log.Error(ex); Log.Error(" exception: {0} {1} {2}", ex.Message, ex.Source, ex.StackTrace); #if !DEBUG throw new Exception("exception occured", ex); #endif } }