From 6ba73d00c4d0a6b0af341e901e92cb561118bd10 Mon Sep 17 00:00:00 2001
From: sebastiii <sebastiii@team-mediaportal.com>
Date: Sun, 27 Dec 2015 15:48:17 +0100
Subject: [PATCH] TVE3 Patch @regeszter Part2 (Add another check to only reset
 protected items if we go outside of TV Window.)

---
 TvEngine3/TVLibrary/TvPlugin/TvPlugin/TVHome.cs      | 11 ++++++++++-
 TvEngine3/TVLibrary/TvPlugin/TvPlugin/TVScheduler.cs |  3 +++
 TvEngine3/TVLibrary/TvPlugin/TvPlugin/TvGuideBase.cs |  6 ++++++
 TvEngine3/TVLibrary/TvPlugin/TvPlugin/TvRecorded.cs  |  5 +++--
 4 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TVHome.cs b/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TVHome.cs
index 5176eca..3467910 100644
--- a/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TVHome.cs
+++ b/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TVHome.cs
@@ -554,7 +554,13 @@ namespace TvPlugin
       }
       else
       {
-        LoadSettings(true); // needs for PIN protection function avoid to start tvhome with a protected group
+        // needs for PIN protection function avoid to start tvhome with a protected group
+        var previousWindowId = GUIWindowManager.GetWindow(GUIWindowManager.ActiveWindow).PreviousWindowId;
+        if (previousWindowId == (int)Window.WINDOW_HOME ||
+            previousWindowId == (int)Window.WINDOW_SECOND_HOME)
+        {
+          LoadSettings(true);
+        }
       }
 
       if (m_navigator == null)
@@ -677,6 +683,9 @@ namespace TvPlugin
       // if we're switching to another plugin
       if (!GUIGraphicsContext.IsTvWindow(newWindowId))
       {
+        // needs for PIN protection function avoid to start tvhome with a protected group
+        TVHome._allowProtectedItem = false;
+        LoadSettings(true);
         //and we're not playing which means we dont timeshift tv
         //g_Player.Stop();
       }
diff --git a/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TVScheduler.cs b/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TVScheduler.cs
index d6fadf2..32e34ad 100644
--- a/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TVScheduler.cs
+++ b/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TVScheduler.cs
@@ -214,6 +214,9 @@ namespace TvPlugin
               TVHome.Card.StopTimeShifting();
             }
           }
+          // needs for PIN protection function avoid to start tvhome with a protected group
+          TVHome._allowProtectedItem = false;
+          TVHome.LoadSettings(true);
         }
       }
     }
diff --git a/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TvGuideBase.cs b/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TvGuideBase.cs
index 67d7974..7e81e8f 100644
--- a/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TvGuideBase.cs
+++ b/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TvGuideBase.cs
@@ -583,6 +583,12 @@ namespace TvPlugin
         case Action.ActionType.ACTION_TVGUIDE_PREV_GROUP:
           OnChangeChannelGroup(-1);
           break;
+
+        case Action.ActionType.ACTION_SWITCH_HOME:
+          // needs for PIN protection function avoid to start tvhome with a protected group
+          TVHome._allowProtectedItem = false;
+          TVHome.LoadSettings(true);
+          return;
       }
       base.OnAction(action);
     }
diff --git a/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TvRecorded.cs b/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TvRecorded.cs
index 35bc37e..de39e4c 100644
--- a/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TvRecorded.cs
+++ b/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TvRecorded.cs
@@ -271,8 +271,9 @@ namespace TvPlugin
       g_Player.PlayBackStarted -= new g_Player.StartedHandler(OnPlayRecordingBackStarted);
       g_Player.PlayBackChanged -= new g_Player.ChangedHandler(OnPlayRecordingBackChanged);*/
 
-      // Reset disallowed recorded items only we didn't start or stop the video.
-      if (newWindowId != (int)Window.WINDOW_FULLSCREEN_VIDEO)
+      // Reset disallowed recorded items only when we didn't start or stop the video.
+      // if we're switching to another plugin
+      if (!GUIGraphicsContext.IsTvWindow(newWindowId) && newWindowId != (int)Window.WINDOW_FULLSCREEN_VIDEO)
       {
         _showAllRecording = false;
         TVHome._allowProtectedItem = false;
-- 
2.6.3.windows.1

