Merge pull request #25614 from garbear/show-version
[xbmc.git] / xbmc / windows / GUIWindowScreensaver.cpp
blob37e42455ffcb83dd282246c3e00c1de3a0ece065
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "GUIWindowScreensaver.h"
11 #include "GUIPassword.h"
12 #include "GUIUserMessages.h"
13 #include "ServiceBroker.h"
14 #include "addons/AddonManager.h"
15 #include "addons/ScreenSaver.h"
16 #include "addons/addoninfo/AddonType.h"
17 #include "application/ApplicationComponents.h"
18 #include "application/ApplicationPowerHandling.h"
19 #include "guilib/GUIComponent.h"
20 #include "guilib/GUIWindowManager.h"
21 #include "settings/Settings.h"
22 #include "settings/SettingsComponent.h"
24 using namespace KODI;
26 CGUIWindowScreensaver::CGUIWindowScreensaver()
27 : CGUIDialog(WINDOW_SCREENSAVER, "", DialogModalityType::MODELESS)
29 m_renderOrder = RENDER_ORDER_WINDOW_SCREENSAVER;
32 void CGUIWindowScreensaver::Process(unsigned int currentTime, CDirtyRegionList& regions)
34 MarkDirtyRegion();
35 CGUIWindow::Process(currentTime, regions);
36 const auto& context = CServiceBroker::GetWinSystem()->GetGfxContext();
37 m_renderRegion.SetRect(0, 0, static_cast<float>(context.GetWidth()),
38 static_cast<float>(context.GetHeight()));
41 void CGUIWindowScreensaver::Render()
43 if (m_addon)
45 auto& context = CServiceBroker::GetWinSystem()->GetGfxContext();
47 context.CaptureStateBlock();
48 m_addon->Render();
49 context.ApplyStateBlock();
50 return;
53 CGUIDialog::Render();
56 void CGUIWindowScreensaver::OnInitWindow()
58 CGUIDialog::OnInitWindow();
59 m_visible = true;
62 void CGUIWindowScreensaver::UpdateVisibility()
64 auto& components = CServiceBroker::GetAppComponents();
65 const auto appPower = components.GetComponent<CApplicationPowerHandling>();
66 if (!appPower->IsInScreenSaver() && m_visible)
68 m_visible = false;
69 Close();
73 bool CGUIWindowScreensaver::OnMessage(CGUIMessage& message)
75 switch (message.GetMessage())
77 case GUI_MSG_WINDOW_DEINIT:
79 if (m_addon)
81 m_addon->Stop();
82 m_addon.reset();
85 CServiceBroker::GetWinSystem()->GetGfxContext().ApplyStateBlock();
87 break;
89 case GUI_MSG_WINDOW_INIT:
91 CGUIWindow::OnMessage(message);
93 CServiceBroker::GetWinSystem()->GetGfxContext().CaptureStateBlock();
95 const std::string addon = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(
96 CSettings::SETTING_SCREENSAVER_MODE);
97 const ADDON::AddonInfoPtr addonBase =
98 CServiceBroker::GetAddonMgr().GetAddonInfo(addon, ADDON::AddonType::SCREENSAVER);
99 if (!addonBase)
100 return false;
101 m_addon = std::make_unique<KODI::ADDONS::CScreenSaver>(addonBase);
102 return m_addon->Start();
105 case GUI_MSG_CHECK_LOCK:
107 auto& components = CServiceBroker::GetAppComponents();
108 const auto appPower = components.GetComponent<CApplicationPowerHandling>();
109 if (!g_passwordManager.IsProfileLockUnlocked())
111 appPower->SetScreenSaverLockFailed();
112 return false;
114 appPower->SetScreenSaverUnlocked();
115 return true;
119 return CGUIWindow::OnMessage(message);