Permalink
Browse files

Merge pull request #4603 from jmarshallnz/skin_load_cleanup

Skin load cleanup
  • Loading branch information...
2 parents 8bae9fe + 3618081 commit 6046397008d9a5051696b216a49509b2c1d6782e @jmarshallnz jmarshallnz committed Apr 28, 2014
Showing with 43 additions and 54 deletions.
  1. +42 −52 xbmc/Application.cpp
  2. +1 −2 xbmc/Application.h
View
@@ -402,7 +402,6 @@ CApplication::CApplication(void)
m_nextPlaylistItem = -1;
m_bPlaybackStarting = false;
m_ePlayState = PLAY_STATE_NONE;
- m_skinReloading = false;
m_skinReverting = false;
m_loggingIn = false;
@@ -1810,44 +1809,40 @@ bool CApplication::OnSettingsSaving() const
void CApplication::ReloadSkin(bool confirm/*=false*/)
{
- m_skinReloading = false;
std::string oldSkin = g_SkinInfo ? g_SkinInfo->ID() : "";
CGUIMessage msg(GUI_MSG_LOAD_SKIN, -1, g_windowManager.GetActiveWindow());
g_windowManager.SendMessage(msg);
-
- // Reload the skin, restoring the previously focused control. We need this as
- // the window unload will reset all control states.
- int iCtrlID = -1;
- CGUIWindow* pWindow = g_windowManager.GetWindow(g_windowManager.GetActiveWindow());
- if (pWindow)
- iCtrlID = pWindow->GetFocusedControlID();
-
- g_application.LoadSkin(CSettings::Get().GetString("lookandfeel.skin"));
-
- if (iCtrlID != -1)
+
+ string newSkin = CSettings::Get().GetString("lookandfeel.skin");
+ if (LoadSkin(newSkin))
{
- pWindow = g_windowManager.GetWindow(g_windowManager.GetActiveWindow());
- if (pWindow && pWindow->HasSaveLastControl())
+ /* The Reset() or SetString() below will cause recursion, so the m_skinReverting boolean is set so as to not prompt the
+ user as to whether they want to keep the current skin. */
+ if (confirm && !m_skinReverting)
{
- CGUIMessage msg3(GUI_MSG_SETFOCUS, g_windowManager.GetActiveWindow(), iCtrlID, 0);
- pWindow->OnMessage(msg3);
+ bool cancelled;
+ if (!CGUIDialogYesNo::ShowAndGetInput(13123, 13111, -1, -1, -1, -1, cancelled, 10000))
+ {
+ m_skinReverting = true;
+ if (oldSkin.empty())
+ CSettings::Get().GetSetting("lookandfeel.skin")->Reset();
+ else
+ CSettings::Get().SetString("lookandfeel.skin", oldSkin);
+ }
}
}
-
- if (!m_skinReverting && confirm)
+ else
{
- bool cancelled;
- if (!CGUIDialogYesNo::ShowAndGetInput(13123, 13111, -1, -1, -1, -1, cancelled, 10000))
+ // skin failed to load - we revert to the default only if we didn't fail loading the default
+ string defaultSkin = ((CSettingString*)CSettings::Get().GetSetting("lookandfeel.skin"))->GetDefault();
+ if (newSkin != defaultSkin)
{
m_skinReverting = true;
- if (oldSkin.empty())
- CSettings::Get().GetSetting("lookandfeel.skin")->Reset();
- else
- CSettings::Get().SetString("lookandfeel.skin", oldSkin);
+ CSettings::Get().GetSetting("lookandfeel.skin")->Reset();
+ CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Error, g_localizeStrings.Get(24102), g_localizeStrings.Get(24103));
}
}
-
m_skinReverting = false;
}
@@ -1885,41 +1880,24 @@ bool CApplication::Save(TiXmlNode *settings) const
bool CApplication::LoadSkin(const CStdString& skinID)
{
- if (m_skinReloading)
- return false;
-
AddonPtr addon;
if (CAddonMgr::Get().GetAddon(skinID, addon, ADDON_SKIN))
{
- LoadSkin(boost::dynamic_pointer_cast<ADDON::CSkinInfo>(addon));
- return true;
+ if (LoadSkin(boost::dynamic_pointer_cast<ADDON::CSkinInfo>(addon)))
+ return true;
}
+ CLog::Log(LOGERROR, "failed to load requested skin '%s'", skinID.c_str());
return false;
}
-void CApplication::LoadSkin(const SkinPtr& skin)
+bool CApplication::LoadSkin(const SkinPtr& skin)
{
- string defaultSkin = ((const CSettingString*)CSettings::Get().GetSetting("lookandfeel.skin"))->GetDefault();
if (!skin)
- {
- CLog::Log(LOGERROR, "failed to load requested skin, fallback to \"%s\" skin", defaultSkin.c_str());
- CSettings::Get().GetSetting("lookandfeel.skin")->Reset();
- return ;
- }
+ return false;
skin->Start();
if (!skin->HasSkinFile("Home.xml"))
- {
- // failed to find home.xml
- // fallback to default skin
- if (strcmpi(skin->ID().c_str(), defaultSkin.c_str()) != 0)
- {
- CLog::Log(LOGERROR, "home.xml doesn't exist in skin: %s, fallback to \"%s\" skin", skin->ID().c_str(), defaultSkin.c_str());
- CSettings::Get().GetSetting("lookandfeel.skin")->Reset();
- CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Error, g_localizeStrings.Get(24102), g_localizeStrings.Get(24103));
- return ;
- }
- }
+ return false;
bool bPreviousPlayingState=false;
bool bPreviousRenderingState=false;
@@ -1939,8 +1917,12 @@ void CApplication::LoadSkin(const SkinPtr& skin)
// close the music and video overlays (they're re-opened automatically later)
CSingleLock lock(g_graphicsContext);
- // save the current window details
+ // save the current window details and focused control
int currentWindow = g_windowManager.GetActiveWindow();
+ int iCtrlID = -1;
+ CGUIWindow* pWindow = g_windowManager.GetWindow(currentWindow);
+ if (pWindow)
+ iCtrlID = pWindow->GetFocusedControlID();
vector<int> currentModelessWindows;
g_windowManager.GetActiveModelessWindows(currentModelessWindows);
@@ -2027,6 +2009,15 @@ void CApplication::LoadSkin(const SkinPtr& skin)
CGUIDialog *dialog = (CGUIDialog *)g_windowManager.GetWindow(currentModelessWindows[i]);
if (dialog) dialog->Show();
}
+ if (iCtrlID != -1)
+ {
+ pWindow = g_windowManager.GetWindow(currentWindow);
+ if (pWindow && pWindow->HasSaveLastControl())
+ {
+ CGUIMessage msg(GUI_MSG_SETFOCUS, currentWindow, iCtrlID, 0);
+ pWindow->OnMessage(msg);
+ }
+ }
}
if (g_application.m_pPlayer->IsPlayingVideo())
@@ -2036,12 +2027,11 @@ void CApplication::LoadSkin(const SkinPtr& skin)
if (bPreviousRenderingState)
g_windowManager.ActivateWindow(WINDOW_FULLSCREEN_VIDEO);
}
+ return true;
}
void CApplication::UnloadSkin(bool forReload /* = false */)
{
- m_skinReloading = forReload;
-
CLog::Log(LOGINFO, "Unloading old skin %s...", forReload ? "for reload " : "");
g_audioManager.Enable(false);
View
@@ -365,9 +365,8 @@ class CApplication : public CXBApplicationEx, public IPlayerCallback, public IMs
virtual bool OnSettingUpdate(CSetting* &setting, const char *oldSettingId, const TiXmlNode *oldSettingNode);
bool LoadSkin(const CStdString& skinID);
- void LoadSkin(const boost::shared_ptr<ADDON::CSkinInfo>& skin);
+ bool LoadSkin(const boost::shared_ptr<ADDON::CSkinInfo>& skin);
- bool m_skinReloading; // if true we disallow LoadSkin until ReloadSkin is called
bool m_skinReverting;
bool m_loggingIn;

0 comments on commit 6046397

Please sign in to comment.