| 1 | /* |
| 2 | * Copyright (C) 2012-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 "guilib/guiinfo/SkinGUIInfo.h" |
| 10 | |
| 11 | #include "ServiceBroker.h" |
| 12 | #include "addons/Skin.h" |
| 13 | #include "guilib/LocalizeStrings.h" |
| 14 | #include "guilib/guiinfo/GUIInfo.h" |
| 15 | #include "guilib/guiinfo/GUIInfoLabels.h" |
| 16 | #include "settings/Settings.h" |
| 17 | #include "settings/SettingsComponent.h" |
| 18 | #include "settings/SkinSettings.h" |
| 19 | #include "utils/StringUtils.h" |
| 20 | #include "utils/URIUtils.h" |
| 21 | |
| 22 | using namespace KODI::GUILIB::GUIINFO; |
| 23 | |
| 24 | bool CSkinGUIInfo::InitCurrentItem(CFileItem *item) |
| 25 | { |
| 26 | return false; |
| 27 | } |
| 28 | |
| 29 | bool CSkinGUIInfo::GetLabel(std::string& value, const CFileItem *item, int contextWindow, const CGUIInfo &info, std::string *fallback) const |
| 30 | { |
| 31 | switch (info.m_info) |
| 32 | { |
| 33 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 34 | // SKIN_* |
| 35 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 36 | case SKIN_BOOL: |
| 37 | { |
| 38 | bool bInfo = CSkinSettings::GetInstance().GetBool(info.GetData1()); |
| 39 | if (bInfo) |
| 40 | { |
| 41 | value = g_localizeStrings.Get(20122); // True |
| 42 | return true; |
| 43 | } |
| 44 | break; |
| 45 | } |
| 46 | case SKIN_STRING: |
| 47 | { |
| 48 | value = CSkinSettings::GetInstance().GetString(info.GetData1()); |
| 49 | return true; |
| 50 | } |
| 51 | case SKIN_THEME: |
| 52 | { |
| 53 | value = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(CSettings::SETTING_LOOKANDFEEL_SKINTHEME); |
| 54 | return true; |
| 55 | } |
| 56 | case SKIN_COLOUR_THEME: |
| 57 | { |
| 58 | value = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(CSettings::SETTING_LOOKANDFEEL_SKINCOLORS); |
| 59 | return true; |
| 60 | } |
| 61 | case SKIN_ASPECT_RATIO: |
| 62 | { |
| 63 | if (g_SkinInfo) |
| 64 | { |
| 65 | value = g_SkinInfo->GetCurrentAspect(); |
| 66 | return true; |
| 67 | } |
| 68 | break; |
| 69 | } |
| 70 | case SKIN_FONT: |
| 71 | { |
| 72 | value = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(CSettings::SETTING_LOOKANDFEEL_FONT); |
| 73 | return true; |
| 74 | } |
| 75 | case SKIN_TIMER_ELAPSEDSECS: |
| 76 | { |
| 77 | value = std::to_string(g_SkinInfo->GetTimerElapsedSeconds(info.GetData3())); |
| 78 | return true; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | return false; |
| 83 | } |
| 84 | |
| 85 | bool CSkinGUIInfo::GetInt(int& value, const CGUIListItem *gitem, int contextWindow, const CGUIInfo &info) const |
| 86 | { |
| 87 | switch (info.m_info) |
| 88 | { |
| 89 | case SKIN_INTEGER: |
| 90 | { |
| 91 | value = CSkinSettings::GetInstance().GetInt(info.GetData1()); |
| 92 | return true; |
| 93 | } |
| 94 | case SKIN_TIMER_ELAPSEDSECS: |
| 95 | { |
| 96 | value = g_SkinInfo->GetTimerElapsedSeconds(info.GetData3()); |
| 97 | return true; |
| 98 | } |
| 99 | } |
| 100 | return false; |
| 101 | } |
| 102 | |
| 103 | bool CSkinGUIInfo::GetBool(bool& value, const CGUIListItem *gitem, int contextWindow, const CGUIInfo &info) const |
| 104 | { |
| 105 | switch (info.m_info) |
| 106 | { |
| 107 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 108 | // SKIN_* |
| 109 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 110 | case SKIN_BOOL: |
| 111 | { |
| 112 | value = CSkinSettings::GetInstance().GetBool(info.GetData1()); |
| 113 | return true; |
| 114 | } |
| 115 | case SKIN_STRING_IS_EQUAL: |
| 116 | { |
| 117 | value = StringUtils::EqualsNoCase(CSkinSettings::GetInstance().GetString(info.GetData1()), info.GetData3()); |
| 118 | return true; |
| 119 | } |
| 120 | case SKIN_STRING: |
| 121 | { |
| 122 | value = !CSkinSettings::GetInstance().GetString(info.GetData1()).empty(); |
| 123 | return true; |
| 124 | } |
| 125 | case SKIN_HAS_THEME: |
| 126 | { |
| 127 | std::string theme = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(CSettings::SETTING_LOOKANDFEEL_SKINTHEME); |
| 128 | URIUtils::RemoveExtension(theme); |
| 129 | value = StringUtils::EqualsNoCase(theme, info.GetData3()); |
| 130 | return true; |
| 131 | } |
| 132 | case SKIN_TIMER_IS_RUNNING: |
| 133 | { |
| 134 | value = g_SkinInfo->TimerIsRunning(info.GetData3()); |
| 135 | return true; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | return false; |
| 140 | } |