| 1 |
/* |
| 2 |
* Copyright (C) 2005-2018 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "GUIWindowScreensaver.h" |
| 10 |
|
| 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/GUITexture.h" |
| 21 |
#include "guilib/GUIWindowManager.h" |
| 22 |
#include "settings/Settings.h" |
| 23 |
#include "settings/SettingsComponent.h" |
| 24 |
|
| 25 |
using namespace KODI; |
| 26 |
|
| 27 |
CGUIWindowScreensaver::CGUIWindowScreensaver() |
| 28 |
: CGUIDialog(WINDOW_SCREENSAVER, "", DialogModalityType::MODELESS) |
| 29 |
{ |
| 30 |
m_renderOrder = RENDER_ORDER_WINDOW_SCREENSAVER; |
| 31 |
} |
| 32 |
|
| 33 |
void CGUIWindowScreensaver::Process(unsigned int currentTime, CDirtyRegionList& regions) |
| 34 |
{ |
| 35 |
MarkDirtyRegion(); |
| 36 |
CGUIWindow::Process(currentTime, regions); |
| 37 |
const auto& context = CServiceBroker::GetWinSystem()->GetGfxContext(); |
| 38 |
m_renderRegion.SetRect(0, 0, static_cast<float>(context.GetWidth()), |
| 39 |
static_cast<float>(context.GetHeight())); |
| 40 |
} |
| 41 |
|
| 42 |
void CGUIWindowScreensaver::Render() |
| 43 |
{ |
| 44 |
// FIXME/TODO: Screensaver addons should make the screen black instead |
| 45 |
// keeping this just for compatibility reasons since it's now a dialog. |
| 46 |
CGUITexture::DrawQuad(m_renderRegion, UTILS::COLOR::BLACK); |
| 47 |
|
| 48 |
if (m_addon) |
| 49 |
{ |
| 50 |
auto& context = CServiceBroker::GetWinSystem()->GetGfxContext(); |
| 51 |
|
| 52 |
context.CaptureStateBlock(); |
| 53 |
m_addon->Render(); |
| 54 |
context.ApplyStateBlock(); |
| 55 |
return; |
| 56 |
} |
| 57 |
|
| 58 |
CGUIDialog::Render(); |
| 59 |
} |
| 60 |
|
| 61 |
void CGUIWindowScreensaver::OnInitWindow() |
| 62 |
{ |
| 63 |
CGUIDialog::OnInitWindow(); |
| 64 |
m_visible = true; |
| 65 |
} |
| 66 |
|
| 67 |
void CGUIWindowScreensaver::UpdateVisibility() |
| 68 |
{ |
| 69 |
auto& components = CServiceBroker::GetAppComponents(); |
| 70 |
const auto appPower = components.GetComponent<CApplicationPowerHandling>(); |
| 71 |
if (!appPower->IsInScreenSaver() && m_visible) |
| 72 |
{ |
| 73 |
m_visible = false; |
| 74 |
Close(); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
bool CGUIWindowScreensaver::OnMessage(CGUIMessage& message) |
| 79 |
{ |
| 80 |
switch (message.GetMessage()) |
| 81 |
{ |
| 82 |
case GUI_MSG_WINDOW_DEINIT: |
| 83 |
{ |
| 84 |
if (m_addon) |
| 85 |
{ |
| 86 |
m_addon->Stop(); |
| 87 |
m_addon.reset(); |
| 88 |
} |
| 89 |
|
| 90 |
CServiceBroker::GetWinSystem()->GetGfxContext().ApplyStateBlock(); |
| 91 |
} |
| 92 |
break; |
| 93 |
|
| 94 |
case GUI_MSG_WINDOW_INIT: |
| 95 |
{ |
| 96 |
CGUIWindow::OnMessage(message); |
| 97 |
|
| 98 |
CServiceBroker::GetWinSystem()->GetGfxContext().CaptureStateBlock(); |
| 99 |
|
| 100 |
const std::string addon = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString( |
| 101 |
CSettings::SETTING_SCREENSAVER_MODE); |
| 102 |
const ADDON::AddonInfoPtr addonBase = |
| 103 |
CServiceBroker::GetAddonMgr().GetAddonInfo(addon, ADDON::AddonType::SCREENSAVER); |
| 104 |
if (!addonBase) |
| 105 |
return false; |
| 106 |
m_addon = std::make_unique<KODI::ADDONS::CScreenSaver>(addonBase); |
| 107 |
return m_addon->Start(); |
| 108 |
} |
| 109 |
|
| 110 |
case GUI_MSG_CHECK_LOCK: |
| 111 |
{ |
| 112 |
auto& components = CServiceBroker::GetAppComponents(); |
| 113 |
const auto appPower = components.GetComponent<CApplicationPowerHandling>(); |
| 114 |
if (!g_passwordManager.IsProfileLockUnlocked()) |
| 115 |
{ |
| 116 |
appPower->SetScreenSaverLockFailed(); |
| 117 |
return false; |
| 118 |
} |
| 119 |
appPower->SetScreenSaverUnlocked(); |
| 120 |
return true; |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
return CGUIWindow::OnMessage(message); |
| 125 |
} |