Skip to content

Commit

Permalink
Merge pull request xbmc#24291 from enen92/slideshow_delegator_design_…
Browse files Browse the repository at this point in the history
…pattern

[Pictures] Implement Slideshow delegator design pattern
  • Loading branch information
enen92 authored Dec 23, 2023
2 parents d9bc400 + da480e5 commit 7eebcfa
Show file tree
Hide file tree
Showing 17 changed files with 530 additions and 234 deletions.
5 changes: 5 additions & 0 deletions xbmc/ServiceBroker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ CDatabaseManager& CServiceBroker::GetDatabaseManager()
return g_application.m_ServiceManager->GetDatabaseManager();
}

CSlideShowDelegator& CServiceBroker::GetSlideShowDelegator()
{
return g_application.m_ServiceManager->GetSlideShowDelegator();
}

CEventLog* CServiceBroker::GetEventLog()
{
if (!g_serviceBroker.m_pSettingsComponent)
Expand Down
3 changes: 3 additions & 0 deletions xbmc/ServiceBroker.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class CPlatform;
class CTextureCache;
class CJobManager;
class CKeyboardLayoutManager;
class CSlideShowDelegator;

namespace WSDiscovery
{
Expand Down Expand Up @@ -148,6 +149,7 @@ class CServiceBroker
static CDataCacheCore& GetDataCacheCore();
static CPlatform& GetPlatform();
static PLAYLIST::CPlayListPlayer& GetPlaylistPlayer();
static CSlideShowDelegator& GetSlideShowDelegator();
static KODI::GAME::CControllerManager& GetGameControllerManager();
static KODI::GAME::CGameServices& GetGameServices();
static KODI::RETRO::CGUIGameRenderManager& GetGameRenderManager();
Expand Down Expand Up @@ -235,6 +237,7 @@ class CServiceBroker
std::shared_ptr<KODI::MESSAGING::CApplicationMessenger> m_appMessenger;
std::shared_ptr<CKeyboardLayoutManager> m_keyboardLayoutManager;
std::shared_ptr<speech::ISpeechRecognition> m_speechRecognition;
std::shared_ptr<CSlideShowDelegator> m_slideshowDelegator;
};

XBMC_GLOBAL_REF(CServiceBroker, g_serviceBroker);
Expand Down
8 changes: 8 additions & 0 deletions xbmc/ServiceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#if !defined(TARGET_WINDOWS) && defined(HAS_OPTICAL_DRIVE)
#include "storage/DetectDVDType.h"
#endif
#include "pictures/SlideShowDelegator.h"
#include "storage/MediaManager.h"
#include "utils/FileExtensionProvider.h"
#include "utils/log.h"
Expand Down Expand Up @@ -109,6 +110,7 @@ bool CServiceManager::InitStageOne()
#endif

m_playlistPlayer = std::make_unique<PLAYLIST::CPlayListPlayer>();
m_slideShowDelegator = std::make_unique<CSlideShowDelegator>();

m_network = CNetworkBase::GetNetwork();

Expand Down Expand Up @@ -273,6 +275,7 @@ void CServiceManager::DeinitStageOne()

m_network.reset();
m_playlistPlayer.reset();
m_slideShowDelegator.reset();
#ifdef HAS_PYTHON
CScriptInvocationManager::GetInstance().UnregisterLanguageInvocationHandler(m_XBPython.get());
m_XBPython.reset();
Expand Down Expand Up @@ -427,3 +430,8 @@ CMediaManager& CServiceManager::GetMediaManager()
{
return *m_mediaManager;
}

CSlideShowDelegator& CServiceManager::GetSlideShowDelegator()
{
return *m_slideShowDelegator;
}
3 changes: 3 additions & 0 deletions xbmc/ServiceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class CNetworkBase;
class CWinSystemBase;
class CPowerManager;
class CWeatherManager;
class CSlideShowDelegator;

namespace KODI
{
Expand Down Expand Up @@ -127,6 +128,7 @@ class CServiceManager
PERIPHERALS::CPeripherals& GetPeripherals();

PLAYLIST::CPlayListPlayer& GetPlaylistPlayer();
CSlideShowDelegator& GetSlideShowDelegator();
int init_level = 0;

CFavouritesService& GetFavouritesService();
Expand Down Expand Up @@ -182,4 +184,5 @@ class CServiceManager
#if !defined(TARGET_WINDOWS) && defined(HAS_OPTICAL_DRIVE)
std::unique_ptr<MEDIA_DETECT::CDetectDVDMedia> m_DetectDVDType;
#endif
std::unique_ptr<CSlideShowDelegator> m_slideShowDelegator;
};
31 changes: 14 additions & 17 deletions xbmc/application/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
#include "network/upnp/UPnP.h"
#endif
#include "peripherals/Peripherals.h"
#include "pictures/GUIWindowSlideShow.h"
#include "pictures/SlideShowDelegator.h"
#include "platform/Environment.h"
#include "playlists/PlayList.h"
#include "playlists/PlayListFactory.h"
Expand Down Expand Up @@ -962,10 +962,9 @@ bool CApplication::OnAction(const CAction &action)
// playing or ACTION_PLAYER_PLAY if we are seeking (FF/RW) or not playing.
if (action.GetID() == ACTION_PLAYER_PLAYPAUSE)
{
CGUIWindowSlideShow* pSlideShow = CServiceBroker::GetGUI()->
GetWindowManager().GetWindow<CGUIWindowSlideShow>(WINDOW_SLIDESHOW);
CSlideShowDelegator& slideShow = CServiceBroker::GetSlideShowDelegator();
if ((appPlayer->IsPlaying() && appPlayer->GetPlaySpeed() == 1) ||
(pSlideShow && pSlideShow->InSlideShow() && !pSlideShow->IsPaused()))
(slideShow.InSlideShow() && !slideShow.IsPaused()))
return OnAction(CAction(ACTION_PAUSE));
else
return OnAction(CAction(ACTION_PLAYER_PLAY));
Expand Down Expand Up @@ -1636,8 +1635,7 @@ void CApplication::OnApplicationMessage(ThreadMessage* pMsg)

case TMSG_PICTURE_SHOW:
{
CGUIWindowSlideShow *pSlideShow = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIWindowSlideShow>(WINDOW_SLIDESHOW);
if (!pSlideShow) return;
CSlideShowDelegator& slideShow = CServiceBroker::GetSlideShowDelegator();

// stop playing file
if (appPlayer->IsPlayingVideo())
Expand All @@ -1664,33 +1662,32 @@ void CApplication::OnApplicationMessage(ThreadMessage* pMsg)
CUtil::GetRecursiveListing(pathToUrl.Get(), items, CServiceBroker::GetFileExtensionProvider().GetPictureExtensions(), XFILE::DIR_FLAG_NO_FILE_DIRS);
if (items.Size() > 0)
{
pSlideShow->Reset();
slideShow.Reset();
for (int i = 0; i<items.Size(); ++i)
{
pSlideShow->Add(items[i].get());
slideShow.Add(items[i].get());
}
pSlideShow->Select(items[0]->GetPath());
slideShow.Select(items[0]->GetPath());
}
}
else
{
CFileItem item(pMsg->strParam, false);
pSlideShow->Reset();
pSlideShow->Add(&item);
pSlideShow->Select(pMsg->strParam);
slideShow.Reset();
slideShow.Add(&item);
slideShow.Select(pMsg->strParam);
}
}
break;

case TMSG_PICTURE_SLIDESHOW:
{
CGUIWindowSlideShow *pSlideShow = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIWindowSlideShow>(WINDOW_SLIDESHOW);
if (!pSlideShow) return;
CSlideShowDelegator& slideShow = CServiceBroker::GetSlideShowDelegator();

if (appPlayer->IsPlayingVideo())
StopPlaying();

pSlideShow->Reset();
slideShow.Reset();

CFileItemList items;
std::string strPath = pMsg->strParam;
Expand All @@ -1702,8 +1699,8 @@ void CApplication::OnApplicationMessage(ThreadMessage* pMsg)
if (items.Size() > 0)
{
for (int i = 0; i<items.Size(); ++i)
pSlideShow->Add(items[i].get());
pSlideShow->StartSlideShow(); //Start the slideshow!
slideShow.Add(items[i].get());
slideShow.StartSlideShow(); //Start the slideshow!
}

if (CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow() != WINDOW_SLIDESHOW)
Expand Down
24 changes: 12 additions & 12 deletions xbmc/guilib/guiinfo/PicturesGUIInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include "guilib/GUIWindowManager.h"
#include "guilib/guiinfo/GUIInfo.h"
#include "guilib/guiinfo/GUIInfoLabels.h"
#include "pictures/GUIWindowSlideShow.h"
#include "pictures/PictureInfoTag.h"
#include "pictures/SlideShowDelegator.h"
#include "utils/StringUtils.h"
#include "utils/URIUtils.h"
#include "utils/log.h"
Expand Down Expand Up @@ -180,10 +180,10 @@ bool CPicturesGUIInfo::GetLabel(std::string& value, const CFileItem *item, int c
}
case SLIDESHOW_INDEX:
{
CGUIWindowSlideShow *slideshow = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIWindowSlideShow>(WINDOW_SLIDESHOW);
if (slideshow && slideshow->NumSlides())
CSlideShowDelegator& slideshow = CServiceBroker::GetSlideShowDelegator();
if (slideshow.NumSlides() > 0)
{
value = StringUtils::Format("{}/{}", slideshow->CurrentSlide(), slideshow->NumSlides());
value = StringUtils::Format("{}/{}", slideshow.CurrentSlide(), slideshow.NumSlides());
return true;
}
break;
Expand Down Expand Up @@ -232,26 +232,26 @@ bool CPicturesGUIInfo::GetBool(bool& value, const CGUIListItem *gitem, int conte
///////////////////////////////////////////////////////////////////////////////////////////////
case SLIDESHOW_ISPAUSED:
{
CGUIWindowSlideShow *slideShow = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIWindowSlideShow>(WINDOW_SLIDESHOW);
value = (slideShow && slideShow->IsPaused());
CSlideShowDelegator& slideShow = CServiceBroker::GetSlideShowDelegator();
value = slideShow.IsPaused();
return true;
}
case SLIDESHOW_ISRANDOM:
{
CGUIWindowSlideShow *slideShow = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIWindowSlideShow>(WINDOW_SLIDESHOW);
value = (slideShow && slideShow->IsShuffled());
CSlideShowDelegator& slideShow = CServiceBroker::GetSlideShowDelegator();
value = slideShow.IsShuffled();
return true;
}
case SLIDESHOW_ISACTIVE:
{
CGUIWindowSlideShow *slideShow = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIWindowSlideShow>(WINDOW_SLIDESHOW);
value = (slideShow && slideShow->InSlideShow());
CSlideShowDelegator& slideShow = CServiceBroker::GetSlideShowDelegator();
value = slideShow.InSlideShow();
return true;
}
case SLIDESHOW_ISVIDEO:
{
CGUIWindowSlideShow *slideShow = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIWindowSlideShow>(WINDOW_SLIDESHOW);
value = (slideShow && slideShow->GetCurrentSlide() && slideShow->GetCurrentSlide()->IsVideo());
CSlideShowDelegator& slideShow = CServiceBroker::GetSlideShowDelegator();
value = slideShow.GetCurrentSlide() && slideShow.GetCurrentSlide()->IsVideo();
return true;
}
}
Expand Down
Loading

0 comments on commit 7eebcfa

Please sign in to comment.