Skip to content

Commit

Permalink
Merge pull request xbmc#21936 from notspiff/app_comp_skin_handling
Browse files Browse the repository at this point in the history
Move ApplicationSkinHandling to ApplicationComponent
  • Loading branch information
notspiff committed Oct 12, 2022
2 parents 59b98c8 + aa856b4 commit 7a923e4
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 62 deletions.
33 changes: 15 additions & 18 deletions xbmc/application/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "application/ApplicationActionListeners.h"
#include "application/ApplicationPlayer.h"
#include "application/ApplicationPowerHandling.h"
#include "application/ApplicationSkinHandling.h"
#include "cores/AudioEngine/Engines/ActiveAE/ActiveAE.h"
#include "cores/IPlayer.h"
#include "cores/playercorefactory/PlayerCoreFactory.h"
Expand Down Expand Up @@ -219,7 +220,7 @@ using namespace std::chrono_literals;

CApplication::CApplication(void)
: CApplicationPlayerCallback(m_stackHelper),
CApplicationSettingsHandling(*this, *this)
CApplicationSettingsHandling(static_cast<CApplicationVolumeHandling&>(*this))
#ifdef HAS_DVD_DRIVE
,
m_Autorun(new CAutorun())
Expand All @@ -238,10 +239,12 @@ CApplication::CApplication(void)
RegisterComponent(std::make_shared<CApplicationActionListeners>(m_critSection));
RegisterComponent(std::make_shared<CApplicationPlayer>());
RegisterComponent(std::make_shared<CApplicationPowerHandling>());
RegisterComponent(std::make_shared<CApplicationSkinHandling>(this, this, m_bInitializing));
}

CApplication::~CApplication(void)
{
DeregisterComponent(typeid(CApplicationSkinHandling));
DeregisterComponent(typeid(CApplicationPowerHandling));
DeregisterComponent(typeid(CApplicationPlayer));
DeregisterComponent(typeid(CApplicationActionListeners));
Expand Down Expand Up @@ -675,15 +678,17 @@ bool CApplication::Initialize()
// GUI depends on seek handler
GetComponent<CApplicationPlayer>()->GetSeekHandler().Configure();

const auto skinHandling = GetComponent<CApplicationSkinHandling>();

bool uiInitializationFinished = false;

if (CServiceBroker::GetGUI()->GetWindowManager().Initialized())
{
const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
const auto settings = CServiceBroker::GetSettingsComponent()->GetSettings();

CServiceBroker::GetGUI()->GetWindowManager().CreateWindows();

m_confirmSkinChange = false;
skinHandling->m_confirmSkinChange = false;

std::vector<AddonInfoPtr> incompatibleAddons;
event.Reset();
Expand Down Expand Up @@ -725,7 +730,7 @@ bool CApplication::Initialize()

// Start splashscreen and load skin
CServiceBroker::GetRenderSystem()->ShowSplash("");
m_confirmSkinChange = true;
skinHandling->m_confirmSkinChange = true;

auto setting = settings->GetSetting(CSettings::SETTING_LOOKANDFEEL_SKIN);
if (!setting)
Expand All @@ -737,12 +742,12 @@ bool CApplication::Initialize()
CServiceBroker::RegisterTextureCache(std::make_shared<CTextureCache>());

std::string skinId = settings->GetString(CSettings::SETTING_LOOKANDFEEL_SKIN);
if (!CApplicationSkinHandling::LoadSkin(skinId, this, this))
if (!skinHandling->LoadSkin(skinId))
{
CLog::Log(LOGERROR, "Failed to load skin '{}'", skinId);
std::string defaultSkin =
std::static_pointer_cast<const CSettingString>(setting)->GetDefault();
if (!CApplicationSkinHandling::LoadSkin(defaultSkin, this, this))
if (!skinHandling->LoadSkin(defaultSkin))
{
CLog::Log(LOGFATAL, "Default skin '{}' could not be loaded! Terminating..", defaultSkin);
return false;
Expand Down Expand Up @@ -843,14 +848,6 @@ bool CApplication::OnSettingsSaving() const
return !m_bStop;
}

void CApplication::ReloadSkin(bool confirm/*=false*/)
{
if (!g_SkinInfo || m_bInitializing)
return; // Don't allow reload before skin is loaded by system

CApplicationSkinHandling::ReloadSkin(confirm, this, this);
}

void CApplication::Render()
{
// do not render if we are stopped or in background
Expand Down Expand Up @@ -1921,7 +1918,7 @@ bool CApplication::Cleanup()
CServiceBroker::UnregisterSpeechRecognition();

CLog::Log(LOGINFO, "unload skin");
UnloadSkin();
GetComponent<CApplicationSkinHandling>()->UnloadSkin();

CServiceBroker::UnregisterTextureCache();

Expand Down Expand Up @@ -2687,7 +2684,7 @@ bool CApplication::OnMessage(CGUIMessage& message)
m_bInitializing = false;

if (message.GetSenderId() == WINDOW_SETTINGS_PROFILES)
g_application.ReloadSkin(false);
GetComponent<CApplicationSkinHandling>()->ReloadSkin(false);
}
else if (message.GetParam1() == GUI_MSG_UPDATE_ITEM && message.GetItem())
{
Expand Down Expand Up @@ -3099,7 +3096,7 @@ void CApplication::Process()
void CApplication::ProcessSlow()
{
// process skin resources (skin timers)
ProcessSkin();
GetComponent<CApplicationSkinHandling>()->ProcessSkin();

CServiceBroker::GetPowerManager().ProcessEvents();

Expand Down Expand Up @@ -3531,7 +3528,7 @@ void CApplication::SetLoggingIn(bool switchingProfiles)
// because in that case we have already loaded the new profile and
// would therefore write the previous skin's settings into the new profile
// instead of into the previous one
m_saveSkinOnUnloading = !switchingProfiles;
GetComponent<CApplicationSkinHandling>()->m_saveSkinOnUnloading = !switchingProfiles;
}

void CApplication::PrintStartupLog()
Expand Down
3 changes: 0 additions & 3 deletions xbmc/application/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "application/ApplicationEnums.h"
#include "application/ApplicationPlayerCallback.h"
#include "application/ApplicationSettingsHandling.h"
#include "application/ApplicationSkinHandling.h"
#include "application/ApplicationStackHelper.h"
#include "application/ApplicationVolumeHandling.h"
#include "guilib/IMsgTargetCallback.h"
Expand Down Expand Up @@ -90,7 +89,6 @@ class CApplication : public IWindowManagerCallback,
public CApplicationComponents,
public CApplicationPlayerCallback,
public CApplicationSettingsHandling,
public CApplicationSkinHandling,
public CApplicationVolumeHandling
{
friend class CAppInboundProtocol;
Expand Down Expand Up @@ -119,7 +117,6 @@ friend class CAppInboundProtocol;
bool InitWindow(RESOLUTION res = RES_INVALID);

bool Stop(int exitCode);
void ReloadSkin(bool confirm = false);
const std::string& CurrentFile();
CFileItem& CurrentFileItem();
std::shared_ptr<CFileItem> CurrentFileItemPtr();
Expand Down
16 changes: 8 additions & 8 deletions xbmc/application/ApplicationSettingsHandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ bool IsPlaying(const std::string& condition,
} // namespace

CApplicationSettingsHandling::CApplicationSettingsHandling(
CApplicationSkinHandling& skinHandling, CApplicationVolumeHandling& volumeHandling)
: m_skinHandling(skinHandling), m_volumeHandling(volumeHandling)
CApplicationVolumeHandling& volumeHandling)
: m_volumeHandling(volumeHandling)
{
}

Expand Down Expand Up @@ -113,18 +113,18 @@ void CApplicationSettingsHandling::OnSettingChanged(const std::shared_ptr<const
if (!setting)
return;

if (m_skinHandling.OnSettingChanged(*setting))
return;

auto& components = CServiceBroker::GetAppComponents();
const auto appPower = components.GetComponent<CApplicationPowerHandling>();

if (appPower->OnSettingChanged(*setting))
const auto appSkin = components.GetComponent<CApplicationSkinHandling>();
if (appSkin->OnSettingChanged(*setting))
return;

if (m_volumeHandling.OnSettingChanged(*setting))
return;

const auto appPower = components.GetComponent<CApplicationPowerHandling>();
if (appPower->OnSettingChanged(*setting))
return;

const std::string& settingId = setting->GetId();

if (settingId == CSettings::SETTING_VIDEOSCREEN_FAKEFULLSCREEN)
Expand Down
5 changes: 1 addition & 4 deletions xbmc/application/ApplicationSettingsHandling.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "settings/lib/ISettingsHandler.h"

class CApplicationVolumeHandling;
class CApplicationSkinHandling;

/*!
* \brief Class handling application support for settings.
Expand All @@ -24,8 +23,7 @@ class CApplicationSettingsHandling : public ISettingCallback,
public ISubSettings
{
public:
CApplicationSettingsHandling(CApplicationSkinHandling& skinHandling,
CApplicationVolumeHandling& volumeHandling);
explicit CApplicationSettingsHandling(CApplicationVolumeHandling& volumeHandling);

protected:
void RegisterSettings();
Expand All @@ -39,6 +37,5 @@ class CApplicationSettingsHandling : public ISettingCallback,
const char* oldSettingId,
const TiXmlNode* oldSettingNode) override;

CApplicationSkinHandling& m_skinHandling;
CApplicationVolumeHandling& m_volumeHandling;
};
25 changes: 14 additions & 11 deletions xbmc/application/ApplicationSkinHandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@

using namespace KODI::MESSAGING;

bool CApplicationSkinHandling::LoadSkin(const std::string& skinID,
IMsgTargetCallback* msgCb,
IWindowManagerCallback* wCb)
CApplicationSkinHandling::CApplicationSkinHandling(IMsgTargetCallback* msgCb,
IWindowManagerCallback* wCb,
bool& bInitializing)
: m_msgCb(msgCb), m_wCb(wCb), m_bInitializing(bInitializing)
{
}

bool CApplicationSkinHandling::LoadSkin(const std::string& skinID)
{
ADDON::SkinPtr skin;
{
Expand Down Expand Up @@ -151,12 +156,12 @@ bool CApplicationSkinHandling::LoadSkin(const std::string& skinID,
CLog::Log(LOGDEBUG, "Load Skin XML: {:.2f} ms", duration.count());

CLog::Log(LOGINFO, " initialize new skin...");
CServiceBroker::GetGUI()->GetWindowManager().AddMsgTarget(msgCb);
CServiceBroker::GetGUI()->GetWindowManager().AddMsgTarget(m_msgCb);
CServiceBroker::GetGUI()->GetWindowManager().AddMsgTarget(&CServiceBroker::GetPlaylistPlayer());
CServiceBroker::GetGUI()->GetWindowManager().AddMsgTarget(&g_fontManager);
CServiceBroker::GetGUI()->GetWindowManager().AddMsgTarget(
&CServiceBroker::GetGUI()->GetStereoscopicsManager());
CServiceBroker::GetGUI()->GetWindowManager().SetCallback(*wCb);
CServiceBroker::GetGUI()->GetWindowManager().SetCallback(*m_wCb);

//@todo should be done by GUIComponents
CServiceBroker::GetGUI()->GetWindowManager().Initialize();
Expand Down Expand Up @@ -366,12 +371,10 @@ bool CApplicationSkinHandling::LoadCustomWindows()
return true;
}

void CApplicationSkinHandling::ReloadSkin(bool confirm,
IMsgTargetCallback* msgCb,
IWindowManagerCallback* wCb)
void CApplicationSkinHandling::ReloadSkin(bool confirm)
{
// if (!g_SkinInfo || m_bInitializing)
// return; // Don't allow reload before skin is loaded by system
if (!g_SkinInfo || m_bInitializing)
return; // Don't allow reload before skin is loaded by system

std::string oldSkin = g_SkinInfo->ID();

Expand All @@ -381,7 +384,7 @@ void CApplicationSkinHandling::ReloadSkin(bool confirm,

const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
std::string newSkin = settings->GetString(CSettings::SETTING_LOOKANDFEEL_SKIN);
if (LoadSkin(newSkin, msgCb, wCb))
if (LoadSkin(newSkin))
{
/* The Reset() or SetString() below will cause recursion, so the m_confirmSkinChange boolean is set so as to not prompt the
user as to whether they want to keep the current skin. */
Expand Down
21 changes: 17 additions & 4 deletions xbmc/application/ApplicationSkinHandling.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,46 @@

#pragma once

#include "application/IApplicationComponent.h"

#include <string>

class CApplication;
class CSetting;
class IMsgTargetCallback;
class IWindowManagerCallback;

/*!
* \brief Class handling application support for skin management.
*/
class CApplicationSkinHandling
class CApplicationSkinHandling : public IApplicationComponent
{
friend class CApplication;

public:
CApplicationSkinHandling(IMsgTargetCallback* msgCb,
IWindowManagerCallback* wCb,
bool& bInitializing);

void UnloadSkin();

bool OnSettingChanged(const CSetting& setting);
void ReloadSkin(bool confirm = false);

protected:
bool LoadSkin(const std::string& skinID, IMsgTargetCallback* msgCb, IWindowManagerCallback* wCb);
bool LoadSkin(const std::string& skinID);
bool LoadCustomWindows();
void ReloadSkin(bool confirm, IMsgTargetCallback* msgCb, IWindowManagerCallback* wCb);

/*!
* \brief Called by the application main/render thread for processing operations belonging to the skin
* \brief Called by the application main/render thread for processing
* operations belonging to the skin.
*/
void ProcessSkin() const;

bool m_saveSkinOnUnloading = true;
bool m_confirmSkinChange = true;
bool m_ignoreSkinSettingChanges = false;
IMsgTargetCallback* m_msgCb;
IWindowManagerCallback* m_wCb;
bool& m_bInitializing;
};
16 changes: 11 additions & 5 deletions xbmc/interfaces/builtins/SkinBuiltins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#include "Util.h"
#include "addons/addoninfo/AddonInfo.h"
#include "addons/gui/GUIWindowAddonBrowser.h"
#include "application/Application.h"
#include "application/ApplicationComponents.h"
#include "application/ApplicationSkinHandling.h"
#include "dialogs/GUIDialogColorPicker.h"
#include "dialogs/GUIDialogFileBrowser.h"
#include "dialogs/GUIDialogNumeric.h"
Expand All @@ -39,8 +40,9 @@ using namespace ADDON;
static int ReloadSkin(const std::vector<std::string>& params)
{
// Reload the skin
g_application.ReloadSkin(!params.empty() &&
StringUtils::EqualsNoCase(params[0], "confirm"));
auto& components = CServiceBroker::GetAppComponents();
const auto appSkin = components.GetComponent<CApplicationSkinHandling>();
appSkin->ReloadSkin(!params.empty() && StringUtils::EqualsNoCase(params[0], "confirm"));

return 0;
}
Expand All @@ -50,7 +52,9 @@ static int ReloadSkin(const std::vector<std::string>& params)
*/
static int UnloadSkin(const std::vector<std::string>& params)
{
g_application.UnloadSkin();
auto& components = CServiceBroker::GetAppComponents();
const auto appSkin = components.GetComponent<CApplicationSkinHandling>();
appSkin->UnloadSkin();

return 0;
}
Expand Down Expand Up @@ -421,7 +425,9 @@ static int SetTheme(const std::vector<std::string>& params)
if (StringUtils::EqualsNoCase(colorTheme, "Textures.xml"))
colorTheme = "defaults.xml";
settings->SetString(CSettings::SETTING_LOOKANDFEEL_SKINCOLORS, colorTheme);
g_application.ReloadSkin();
auto& components = CServiceBroker::GetAppComponents();
const auto appSkin = components.GetComponent<CApplicationSkinHandling>();
appSkin->ReloadSkin();

return 0;
}
Expand Down
Loading

0 comments on commit 7a923e4

Please sign in to comment.