| 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 "GUIWindowSystemInfo.h" |
| 10 |
|
| 11 |
#include "GUIInfoManager.h" |
| 12 |
#include "ServiceBroker.h" |
| 13 |
#include "guilib/GUIComponent.h" |
| 14 |
#include "guilib/GUIMessage.h" |
| 15 |
#include "guilib/LocalizeStrings.h" |
| 16 |
#include "guilib/WindowIDs.h" |
| 17 |
#include "guilib/guiinfo/GUIInfoLabels.h" |
| 18 |
#include "pvr/PVRManager.h" |
| 19 |
#include "storage/MediaManager.h" |
| 20 |
#include "utils/CPUInfo.h" |
| 21 |
#include "utils/StringUtils.h" |
| 22 |
#include "utils/SystemInfo.h" |
| 23 |
|
| 24 |
constexpr int CONTROL_TEXT_START = 2; |
| 25 |
constexpr int CONTROL_TEXT_END = 13; // 12 lines |
| 26 |
|
| 27 |
#define CONTROL_TB_POLICY 30 |
| 28 |
#define CONTROL_BT_STORAGE 94 |
| 29 |
#define CONTROL_BT_DEFAULT 95 |
| 30 |
#define CONTROL_BT_NETWORK 96 |
| 31 |
#define CONTROL_BT_VIDEO 97 |
| 32 |
#define CONTROL_BT_HARDWARE 98 |
| 33 |
#define CONTROL_BT_PVR 99 |
| 34 |
#define CONTROL_BT_POLICY 100 |
| 35 |
|
| 36 |
constexpr int CONTROL_BT_DONATE = 101; |
| 37 |
constexpr int CONTROL_GROUP_DONATE = 102; |
| 38 |
constexpr int CONTROL_MULTI_IMAGE_DONATE = 103; |
| 39 |
|
| 40 |
constexpr int CONTROL_GROUP_SYSTEM_BAR = 104; |
| 41 |
|
| 42 |
constexpr int CONTROL_START = CONTROL_BT_STORAGE; |
| 43 |
constexpr int CONTROL_END = CONTROL_BT_DONATE; |
| 44 |
|
| 45 |
CGUIWindowSystemInfo::CGUIWindowSystemInfo(void) : |
| 46 |
CGUIWindow(WINDOW_SYSTEM_INFORMATION, "SettingsSystemInfo.xml") |
| 47 |
{ |
| 48 |
m_section = CONTROL_BT_DEFAULT; |
| 49 |
m_loadType = KEEP_IN_MEMORY; |
| 50 |
} |
| 51 |
|
| 52 |
CGUIWindowSystemInfo::~CGUIWindowSystemInfo(void) = default; |
| 53 |
|
| 54 |
bool CGUIWindowSystemInfo::OnMessage(CGUIMessage& message) |
| 55 |
{ |
| 56 |
switch (message.GetMessage()) |
| 57 |
{ |
| 58 |
case GUI_MSG_WINDOW_INIT: |
| 59 |
{ |
| 60 |
CGUIWindow::OnMessage(message); |
| 61 |
SET_CONTROL_LABEL(52, CSysInfo::GetAppName() + " " + CSysInfo::GetVersion()); |
| 62 |
SET_CONTROL_LABEL(53, CSysInfo::GetBuildDate()); |
| 63 |
CONTROL_ENABLE_ON_CONDITION(CONTROL_BT_PVR, CServiceBroker::GetPVRManager().IsStarted()); |
| 64 |
return true; |
| 65 |
} |
| 66 |
break; |
| 67 |
|
| 68 |
case GUI_MSG_WINDOW_DEINIT: |
| 69 |
{ |
| 70 |
CGUIWindow::OnMessage(message); |
| 71 |
m_diskUsage.clear(); |
| 72 |
m_privacyPolicyLoaded = false; |
| 73 |
return true; |
| 74 |
} |
| 75 |
break; |
| 76 |
|
| 77 |
case GUI_MSG_FOCUSED: |
| 78 |
{ |
| 79 |
CGUIWindow::OnMessage(message); |
| 80 |
int focusedControl = GetFocusedControlID(); |
| 81 |
if (m_section != focusedControl && focusedControl >= CONTROL_START && focusedControl <= CONTROL_END) |
| 82 |
{ |
| 83 |
ResetLabels(); |
| 84 |
m_section = focusedControl; |
| 85 |
} |
| 86 |
if (m_section >= CONTROL_BT_STORAGE && m_section <= CONTROL_BT_PVR) |
| 87 |
{ |
| 88 |
SET_CONTROL_HIDDEN(CONTROL_TB_POLICY); |
| 89 |
SET_CONTROL_HIDDEN(CONTROL_GROUP_DONATE); |
| 90 |
SET_CONTROL_VISIBLE(CONTROL_GROUP_SYSTEM_BAR); |
| 91 |
} |
| 92 |
else if (m_section == CONTROL_BT_POLICY) |
| 93 |
{ |
| 94 |
LoadPrivacyPolicy(); |
| 95 |
SET_CONTROL_VISIBLE(CONTROL_TB_POLICY); |
| 96 |
SET_CONTROL_HIDDEN(CONTROL_GROUP_DONATE); |
| 97 |
SET_CONTROL_VISIBLE(CONTROL_GROUP_SYSTEM_BAR); |
| 98 |
} |
| 99 |
else if (m_section == CONTROL_BT_DONATE) |
| 100 |
{ |
| 101 |
SET_CONTROL_HIDDEN(CONTROL_TB_POLICY); |
| 102 |
SET_CONTROL_VISIBLE(CONTROL_GROUP_DONATE); |
| 103 |
SET_CONTROL_HIDDEN(CONTROL_GROUP_SYSTEM_BAR); |
| 104 |
} |
| 105 |
return true; |
| 106 |
} |
| 107 |
break; |
| 108 |
} |
| 109 |
return CGUIWindow::OnMessage(message); |
| 110 |
} |
| 111 |
|
| 112 |
void CGUIWindowSystemInfo::FrameMove() |
| 113 |
{ |
| 114 |
int i = CONTROL_TEXT_START; |
| 115 |
if (m_section == CONTROL_BT_DEFAULT) |
| 116 |
{ |
| 117 |
SET_CONTROL_LABEL(40, g_localizeStrings.Get(20154)); |
| 118 |
SetControlLabel(i++, "{}: {}", 158, SYSTEM_FREE_MEMORY); |
| 119 |
SetControlLabel(i++, "{}: {}", 150, NETWORK_IP_ADDRESS); |
| 120 |
SetControlLabel(i++, "{} {}", 13287, SYSTEM_SCREEN_RESOLUTION); |
| 121 |
SetControlLabel(i++, "{} {}", 13283, SYSTEM_OS_VERSION_INFO); |
| 122 |
SetControlLabel(i++, "{}: {}", 12390, SYSTEM_UPTIME); |
| 123 |
SetControlLabel(i++, "{}: {}", 12394, SYSTEM_TOTALUPTIME); |
| 124 |
SetControlLabel(i++, "{}: {}", 12395, SYSTEM_BATTERY_LEVEL); |
| 125 |
} |
| 126 |
|
| 127 |
else if (m_section == CONTROL_BT_STORAGE) |
| 128 |
{ |
| 129 |
SET_CONTROL_LABEL(40, g_localizeStrings.Get(20155)); |
| 130 |
if (m_diskUsage.empty()) |
| 131 |
m_diskUsage = CServiceBroker::GetMediaManager().GetDiskUsage(); |
| 132 |
|
| 133 |
for (size_t d = 0; d < m_diskUsage.size() && d <= CONTROL_TEXT_END - CONTROL_TEXT_START; ++d) |
| 134 |
{ |
| 135 |
SET_CONTROL_LABEL(i++, m_diskUsage[d]); |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
else if (m_section == CONTROL_BT_NETWORK) |
| 140 |
{ |
| 141 |
SET_CONTROL_LABEL(40,g_localizeStrings.Get(20158)); |
| 142 |
SET_CONTROL_LABEL(i++, CServiceBroker::GetGUI()->GetInfoManager().GetLabel( |
| 143 |
NETWORK_LINK_STATE, INFO::DEFAULT_CONTEXT)); |
| 144 |
SetControlLabel(i++, "{}: {}", 149, NETWORK_MAC_ADDRESS); |
| 145 |
SetControlLabel(i++, "{}: {}", 150, NETWORK_IP_ADDRESS); |
| 146 |
SetControlLabel(i++, "{}: {}", 13159, NETWORK_SUBNET_MASK); |
| 147 |
SetControlLabel(i++, "{}: {}", 13160, NETWORK_GATEWAY_ADDRESS); |
| 148 |
SetControlLabel(i++, "{}: {}", 13161, NETWORK_DNS1_ADDRESS); |
| 149 |
SetControlLabel(i++, "{}: {}", 20307, NETWORK_DNS2_ADDRESS); |
| 150 |
SetControlLabel(i++, "{} {}", 13295, SYSTEM_INTERNET_STATE); |
| 151 |
} |
| 152 |
|
| 153 |
else if (m_section == CONTROL_BT_VIDEO) |
| 154 |
{ |
| 155 |
SET_CONTROL_LABEL(40,g_localizeStrings.Get(20159)); |
| 156 |
SET_CONTROL_LABEL(i++, CServiceBroker::GetGUI()->GetInfoManager().GetLabel( |
| 157 |
SYSTEM_VIDEO_ENCODER_INFO, INFO::DEFAULT_CONTEXT)); |
| 158 |
SetControlLabel(i++, "{} {}", 13287, SYSTEM_SCREEN_RESOLUTION); |
| 159 |
|
| 160 |
auto renderingSystem = CServiceBroker::GetRenderSystem(); |
| 161 |
if (renderingSystem) |
| 162 |
{ |
| 163 |
static std::string vendor = renderingSystem->GetRenderVendor(); |
| 164 |
if (!vendor.empty()) |
| 165 |
SET_CONTROL_LABEL(i++, StringUtils::Format("{} {}", g_localizeStrings.Get(22007), vendor)); |
| 166 |
|
| 167 |
#if defined(HAS_DX) |
| 168 |
int renderVersionLabel = 22024; |
| 169 |
#else |
| 170 |
int renderVersionLabel = 22009; |
| 171 |
#endif |
| 172 |
static std::string version = renderingSystem->GetRenderVersionString(); |
| 173 |
if (!version.empty()) |
| 174 |
SET_CONTROL_LABEL( |
| 175 |
i++, StringUtils::Format("{} {}", g_localizeStrings.Get(renderVersionLabel), version)); |
| 176 |
} |
| 177 |
|
| 178 |
auto windowSystem = CServiceBroker::GetWinSystem(); |
| 179 |
if (windowSystem) |
| 180 |
{ |
| 181 |
static std::string platform = windowSystem->GetName(); |
| 182 |
if (platform != "platform default") |
| 183 |
SET_CONTROL_LABEL(i++, |
| 184 |
StringUtils::Format("{} {}", g_localizeStrings.Get(39153), platform)); |
| 185 |
} |
| 186 |
|
| 187 |
SetControlLabel(i++, "{} {}", 22010, SYSTEM_GPU_TEMPERATURE); |
| 188 |
|
| 189 |
const std::string hdrTypes = CServiceBroker::GetGUI()->GetInfoManager().GetLabel( |
| 190 |
SYSTEM_SUPPORTED_HDR_TYPES, INFO::DEFAULT_CONTEXT); |
| 191 |
SET_CONTROL_LABEL( |
| 192 |
i++, StringUtils::Format("{}: {}", g_localizeStrings.Get(39174), |
| 193 |
hdrTypes.empty() ? g_localizeStrings.Get(231) : hdrTypes)); |
| 194 |
} |
| 195 |
|
| 196 |
else if (m_section == CONTROL_BT_HARDWARE) |
| 197 |
{ |
| 198 |
SET_CONTROL_LABEL(40,g_localizeStrings.Get(20160)); |
| 199 |
|
| 200 |
auto cpuInfo = CServiceBroker::GetCPUInfo(); |
| 201 |
if (cpuInfo) |
| 202 |
{ |
| 203 |
static std::string model = cpuInfo->GetCPUModel(); |
| 204 |
if (!model.empty()) |
| 205 |
SET_CONTROL_LABEL(i++, "CPU: " + model); |
| 206 |
|
| 207 |
static std::string mips = cpuInfo->GetCPUBogoMips(); |
| 208 |
if (!mips.empty()) |
| 209 |
SET_CONTROL_LABEL(i++, "BogoMips: " + mips); |
| 210 |
|
| 211 |
static std::string soc = cpuInfo->GetCPUSoC(); |
| 212 |
if (!soc.empty()) |
| 213 |
SET_CONTROL_LABEL(i++, "SoC: " + soc); |
| 214 |
|
| 215 |
static std::string hardware = cpuInfo->GetCPUHardware(); |
| 216 |
if (!hardware.empty()) |
| 217 |
SET_CONTROL_LABEL(i++, "Hardware: " + hardware); |
| 218 |
|
| 219 |
static std::string revision = cpuInfo->GetCPURevision(); |
| 220 |
if (!revision.empty()) |
| 221 |
SET_CONTROL_LABEL(i++, "Revision: " + revision); |
| 222 |
|
| 223 |
static std::string serial = cpuInfo->GetCPUSerial(); |
| 224 |
if (!serial.empty()) |
| 225 |
SET_CONTROL_LABEL(i++, "Serial: " + serial); |
| 226 |
|
| 227 |
// temperature can't really be conditional because of localization units |
| 228 |
SetControlLabel(i++, "{} {}", 22011, SYSTEM_CPU_TEMPERATURE); |
| 229 |
|
| 230 |
// we can check if the cpufrequency is not 0 (default if not implemented) |
| 231 |
// but we have to call through CGUIInfoManager -> CSystemGUIInfo -> CSysInfo |
| 232 |
// to limit the frequency of updates |
| 233 |
static float cpuFreq = cpuInfo->GetCPUFrequency(); |
| 234 |
if (cpuFreq > 0) |
| 235 |
SetControlLabel(i++, "{} {}", 13284, SYSTEM_CPUFREQUENCY); |
| 236 |
} |
| 237 |
} |
| 238 |
|
| 239 |
else if (m_section == CONTROL_BT_PVR) |
| 240 |
{ |
| 241 |
SET_CONTROL_LABEL(40, g_localizeStrings.Get(19166)); |
| 242 |
int i = CONTROL_TEXT_START; |
| 243 |
|
| 244 |
SetControlLabel(i++, "{}: {}", 19120, PVR_BACKEND_NUMBER); |
| 245 |
i++; // empty line |
| 246 |
SetControlLabel(i++, "{}: {}", 19012, PVR_BACKEND_NAME); |
| 247 |
SetControlLabel(i++, "{}: {}", 19114, PVR_BACKEND_VERSION); |
| 248 |
SetControlLabel(i++, "{}: {}", 19115, PVR_BACKEND_HOST); |
| 249 |
SetControlLabel(i++, "{}: {}", 19116, PVR_BACKEND_DISKSPACE); |
| 250 |
SetControlLabel(i++, "{}: {}", 19334, PVR_BACKEND_PROVIDERS); |
| 251 |
SetControlLabel(i++, "{}: {}", 19042, PVR_BACKEND_CHANNEL_GROUPS); |
| 252 |
SetControlLabel(i++, "{}: {}", 19019, PVR_BACKEND_CHANNELS); |
| 253 |
SetControlLabel(i++, "{}: {}", 19163, PVR_BACKEND_RECORDINGS); |
| 254 |
SetControlLabel(i++, "{}: {}", 19168, |
| 255 |
PVR_BACKEND_DELETED_RECORDINGS); // Deleted and recoverable recordings |
| 256 |
SetControlLabel(i++, "{}: {}", 19025, PVR_BACKEND_TIMERS); |
| 257 |
} |
| 258 |
|
| 259 |
else if (m_section == CONTROL_BT_POLICY) |
| 260 |
{ |
| 261 |
SET_CONTROL_LABEL(40, g_localizeStrings.Get(12389)); |
| 262 |
} |
| 263 |
CGUIWindow::FrameMove(); |
| 264 |
} |
| 265 |
|
| 266 |
void CGUIWindowSystemInfo::ResetLabels() |
| 267 |
{ |
| 268 |
for (int i = CONTROL_TEXT_START; i <= CONTROL_TEXT_END; ++i) |
| 269 |
{ |
| 270 |
SET_CONTROL_LABEL(i, ""); |
| 271 |
} |
| 272 |
|
| 273 |
// Reset the multiimage to the beginning |
| 274 |
CGUIMessage msg{GUI_MSG_RESET_MULTI_IMAGE, GetID(), CONTROL_MULTI_IMAGE_DONATE}; |
| 275 |
OnMessage(msg); |
| 276 |
} |
| 277 |
|
| 278 |
void CGUIWindowSystemInfo::SetControlLabel(int id, const char *format, int label, int info) |
| 279 |
{ |
| 280 |
std::string tmpStr = StringUtils::Format( |
| 281 |
format, g_localizeStrings.Get(label), |
| 282 |
CServiceBroker::GetGUI()->GetInfoManager().GetLabel(info, INFO::DEFAULT_CONTEXT)); |
| 283 |
SET_CONTROL_LABEL(id, tmpStr); |
| 284 |
} |
| 285 |
|
| 286 |
void CGUIWindowSystemInfo::LoadPrivacyPolicy() |
| 287 |
{ |
| 288 |
if (!m_privacyPolicyLoaded) |
| 289 |
{ |
| 290 |
m_privacyPolicyLoaded = true; |
| 291 |
SET_CONTROL_LABEL(CONTROL_TB_POLICY, CServiceBroker::GetGUI()->GetInfoManager().GetLabel( |
| 292 |
SYSTEM_PRIVACY_POLICY, INFO::DEFAULT_CONTEXT)); |
| 293 |
} |
| 294 |
} |