From 2d8e03d177d20f22c2776b77b2d704a5009ce0fa Mon Sep 17 00:00:00 2001 From: chriszero Date: Sat, 21 Feb 2015 16:43:14 +0100 Subject: Add feature: recovers menustate before playing --- Makefile | 2 +- Plexservice.cpp | 8 +++++--- Plexservice.h | 2 +- hlsPlayerControl.cpp | 4 ++++ plex.cpp | 35 ++++++++++++++++++++++++++++++++--- plex.h | 8 ++++++++ 6 files changed, 51 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 01c2f33..b902f3a 100644 --- a/Makefile +++ b/Makefile @@ -70,7 +70,7 @@ SOFILE = libvdr-$(PLUGIN).so INCLUDES += -DEFINES += -DPLUGIN_NAME_I18N='"$(PLUGIN)"' -D_GNU_SOURCE $(CONFIG) \ +DEFINES += -DPLUGIN_NAME_I18N='"$(PLUGIN)"' -DPLUGIN='"$(PLUGIN)"' -D_GNU_SOURCE $(CONFIG) \ $(if $(GIT_REV), -DGIT_REV='"$(GIT_REV)"') ### Make it standard diff --git a/Plexservice.cpp b/Plexservice.cpp index a61caec..d208882 100644 --- a/Plexservice.cpp +++ b/Plexservice.cpp @@ -145,11 +145,13 @@ std::shared_ptr Plexservice::GetSection(std::string section, boo } } -std::shared_ptr Plexservice::GetLastSection() +std::shared_ptr Plexservice::GetLastSection(bool current) { if(m_vUriStack.size() > 1) { - // discard last one - m_vUriStack.pop(); + if(!current) { + // discard last one + m_vUriStack.pop(); + } std::string uri = m_vUriStack.top(); return GetSection(uri, false); } diff --git a/Plexservice.h b/Plexservice.h index e2cab4b..4f81caf 100644 --- a/Plexservice.h +++ b/Plexservice.h @@ -44,7 +44,7 @@ public: void DisplaySections(); std::shared_ptr GetSection(std::string section, bool putOnStack = true); - std::shared_ptr GetLastSection(); + std::shared_ptr GetLastSection(bool current = false); void GetAuthDetails(); void Authenticate(); PlexServer* GetServer(); diff --git a/hlsPlayerControl.cpp b/hlsPlayerControl.cpp index 1f19336..73e2d6f 100644 --- a/hlsPlayerControl.cpp +++ b/hlsPlayerControl.cpp @@ -1,7 +1,9 @@ #include "hlsPlayerControl.h" #include +#include +#include "plex.h" #include "PlexServer.h" #include "Plexservice.h" #include "MediaContainer.h" @@ -125,6 +127,8 @@ eOSState cHlsPlayerControl::ProcessKey(eKeys Key) case kBlue: Hide(); Stop(); + cMyPlugin::CalledFromCode = true; + cRemote::CallPlugin(PLUGIN); return osEnd; default: { DoShowMode = false; diff --git a/plex.cpp b/plex.cpp index f9a1a84..89193af 100644 --- a/plex.cpp +++ b/plex.cpp @@ -11,16 +11,30 @@ static char ShowBrowser; ///< flag show browser static std::shared_ptr pPlexService; +std::shared_ptr cPlexBrowser::pLastService; +int cPlexBrowser::lastCurrentItem; + cPlexBrowser::cPlexBrowser(const char *title, std::shared_ptr Service) :cOsdMenu(title) { dsyslog("[plex]%s:\n", __FUNCTION__); pService = Service; pService->Authenticate(); - pCont = pService->GetSection(pService->StartUri); + if(pService == pLastService) { + pCont = pService->GetLastSection(true); + } + else { + pCont = pService->GetSection(pService->StartUri); + } SetMenuCategory(mcRecording); CreateMenu(); } +cPlexBrowser* cPlexBrowser::RecoverLastState() +{ + cPlexBrowser* pBrowser = new cPlexBrowser("", cPlexBrowser::pLastService); + return pBrowser; +} + void cPlexBrowser::CreateMenu() { // Clear Menu @@ -44,10 +58,16 @@ void cPlexBrowser::CreateMenu() if(Count() < 1) { Add(new cPlexOsdItem("Empty")); } + else if (pService == pLastService) { + // recover last selected item + cOsdItem* item = Get(lastCurrentItem); + SetCurrent(item); + pLastService = NULL; + } + Display(); } - eOSState cPlexBrowser::ProcessKey(eKeys key) { eOSState state; @@ -98,6 +118,8 @@ eOSState cPlexBrowser::ProcessSelected() if(item->IsVideo()) { + pLastService = pService; + lastCurrentItem = current; cMyPlugin::PlayFile(*item->GetAttachedVideo()); return osEnd; } @@ -230,6 +252,8 @@ eOSState cPlayMenu::ProcessKey(eKeys key) // cPlugin ////////////////////////////////////////////////////////////////////////////// +volatile bool cMyPlugin::CalledFromCode = false; + /** ** Initialize any member variables here. ** @@ -300,7 +324,12 @@ const char *cMyPlugin::MainMenuEntry(void) cOsdObject *cMyPlugin::MainMenuAction(void) { //dsyslog("[plex]%s:\n", __FUNCTION__); - + + if(CalledFromCode) { + CalledFromCode = false; + return cPlexBrowser::RecoverLastState(); + } + if (ShowBrowser) { return new cPlexBrowser("Browse Plex", pPlexService); } diff --git a/plex.h b/plex.h index 89075f5..c2570c8 100644 --- a/plex.h +++ b/plex.h @@ -56,10 +56,15 @@ private: eOSState LevelUp(void); /// Handle menu item selection eOSState ProcessSelected(); + + static std::shared_ptr pLastService; + static int lastCurrentItem; public: cPlexBrowser(const char *title, std::shared_ptr Service); virtual eOSState ProcessKey(eKeys); + + static cPlexBrowser* RecoverLastState(); }; @@ -98,6 +103,9 @@ public: virtual bool SetupParse(const char *, const char *); static void PlayFile(plexclient::Video Vid); + +public: + static volatile bool CalledFromCode; }; -- cgit v1.2.3