| 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/SystemGUIInfo.h" |
| 10 | |
| 11 | #include "FileItem.h" |
| 12 | #include "GUIPassword.h" |
| 13 | #include "LangInfo.h" |
| 14 | #include "ServiceBroker.h" |
| 15 | #include "addons/AddonManager.h" |
| 16 | #include "addons/addoninfo/AddonType.h" |
| 17 | #include "application/AppParams.h" |
| 18 | #include "application/ApplicationComponents.h" |
| 19 | #include "application/ApplicationPowerHandling.h" |
| 20 | #include "guilib/GUIComponent.h" |
| 21 | #include "guilib/GUIWindowManager.h" |
| 22 | #include "guilib/LocalizeStrings.h" |
| 23 | #include "guilib/guiinfo/GUIInfo.h" |
| 24 | #include "guilib/guiinfo/GUIInfoHelper.h" |
| 25 | #include "guilib/guiinfo/GUIInfoLabels.h" |
| 26 | #include "powermanagement/PowerManager.h" |
| 27 | #include "profiles/ProfileManager.h" |
| 28 | #include "settings/AdvancedSettings.h" |
| 29 | #include "settings/MediaSettings.h" |
| 30 | #include "settings/SettingUtils.h" |
| 31 | #include "settings/Settings.h" |
| 32 | #include "settings/SettingsComponent.h" |
| 33 | #include "storage/MediaManager.h" |
| 34 | #include "storage/discs/IDiscDriveHandler.h" |
| 35 | #include "utils/AlarmClock.h" |
| 36 | #include "utils/CPUInfo.h" |
| 37 | #include "utils/GpuInfo.h" |
| 38 | #include "utils/HDRCapabilities.h" |
| 39 | #include "utils/MemUtils.h" |
| 40 | #include "utils/StringUtils.h" |
| 41 | #include "utils/SystemInfo.h" |
| 42 | #include "utils/TimeUtils.h" |
| 43 | #include "windowing/WinSystem.h" |
| 44 | #include "windows/GUIMediaWindow.h" |
| 45 | |
| 46 | using namespace KODI::GUILIB; |
| 47 | using namespace KODI::GUILIB::GUIINFO; |
| 48 | |
| 49 | CSystemGUIInfo::CSystemGUIInfo() |
| 50 | : m_gpuInfo(CGPUInfo::GetGPUInfo()), m_lastSysHeatInfoTime(-SYSTEM_HEAT_UPDATE_INTERVAL) |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | std::string CSystemGUIInfo::GetSystemHeatInfo(int info) const |
| 55 | { |
| 56 | if (CTimeUtils::GetFrameTime() - m_lastSysHeatInfoTime >= SYSTEM_HEAT_UPDATE_INTERVAL) |
| 57 | { |
| 58 | m_lastSysHeatInfoTime = CTimeUtils::GetFrameTime(); |
| 59 | CServiceBroker::GetCPUInfo()->GetTemperature(m_cpuTemp); |
| 60 | if (m_gpuInfo) |
| 61 | { |
| 62 | m_gpuInfo->GetTemperature(m_gpuTemp); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | std::string text; |
| 67 | switch(info) |
| 68 | { |
| 69 | case SYSTEM_CPU_TEMPERATURE: |
| 70 | return m_cpuTemp.IsValid() ? g_langInfo.GetTemperatureAsString(m_cpuTemp) : g_localizeStrings.Get(10005); // Not available |
| 71 | case SYSTEM_GPU_TEMPERATURE: |
| 72 | return m_gpuTemp.IsValid() ? g_langInfo.GetTemperatureAsString(m_gpuTemp) : g_localizeStrings.Get(10005); |
| 73 | case SYSTEM_FAN_SPEED: |
| 74 | text = StringUtils::Format("{}%", m_fanSpeed * 2); |
| 75 | break; |
| 76 | case SYSTEM_CPU_USAGE: |
| 77 | if (CServiceBroker::GetCPUInfo()->SupportsCPUUsage()) |
| 78 | #if defined(TARGET_DARWIN) || defined(TARGET_WINDOWS) |
| 79 | text = StringUtils::Format("{}%", CServiceBroker::GetCPUInfo()->GetUsedPercentage()); |
| 80 | #else |
| 81 | text = CServiceBroker::GetCPUInfo()->GetCoresUsageString(); |
| 82 | #endif |
| 83 | else |
| 84 | text = g_localizeStrings.Get(10005); // Not available |
| 85 | break; |
| 86 | } |
| 87 | return text; |
| 88 | } |
| 89 | |
| 90 | void CSystemGUIInfo::UpdateFPS() |
| 91 | { |
| 92 | m_frameCounter++; |
| 93 | unsigned int curTime = CTimeUtils::GetFrameTime(); |
| 94 | |
| 95 | float fTimeSpan = static_cast<float>(curTime - m_lastFPSTime); |
| 96 | if (fTimeSpan >= 1000.0f) |
| 97 | { |
| 98 | fTimeSpan /= 1000.0f; |
| 99 | m_fps = m_frameCounter / fTimeSpan; |
| 100 | m_lastFPSTime = curTime; |
| 101 | m_frameCounter = 0; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | bool CSystemGUIInfo::InitCurrentItem(CFileItem *item) |
| 106 | { |
| 107 | return false; |
| 108 | } |
| 109 | |
| 110 | bool CSystemGUIInfo::GetLabel(std::string& value, const CFileItem *item, int contextWindow, const CGUIInfo &info, std::string *fallback) const |
| 111 | { |
| 112 | switch (info.m_info) |
| 113 | { |
| 114 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 115 | // SYSTEM_* |
| 116 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 117 | case SYSTEM_TIME: |
| 118 | value = CDateTime::GetCurrentDateTime().GetAsLocalizedTime(static_cast<TIME_FORMAT>(info.GetData1())); |
| 119 | return true; |
| 120 | case SYSTEM_DATE: |
| 121 | if (info.GetData3().empty()) |
| 122 | value = CDateTime::GetCurrentDateTime().GetAsLocalizedDate(true); |
| 123 | else |
| 124 | value = CDateTime::GetCurrentDateTime().GetAsLocalizedDate(info.GetData3()); |
| 125 | return true; |
| 126 | case SYSTEM_FREE_SPACE: |
| 127 | case SYSTEM_USED_SPACE: |
| 128 | case SYSTEM_TOTAL_SPACE: |
| 129 | case SYSTEM_FREE_SPACE_PERCENT: |
| 130 | case SYSTEM_USED_SPACE_PERCENT: |
| 131 | value = g_sysinfo.GetHddSpaceInfo(info.m_info); |
| 132 | return true; |
| 133 | case SYSTEM_CPU_TEMPERATURE: |
| 134 | case SYSTEM_GPU_TEMPERATURE: |
| 135 | case SYSTEM_FAN_SPEED: |
| 136 | case SYSTEM_CPU_USAGE: |
| 137 | value = GetSystemHeatInfo(info.m_info); |
| 138 | return true; |
| 139 | case SYSTEM_VIDEO_ENCODER_INFO: |
| 140 | case NETWORK_IP_ADDRESS: |
| 141 | case NETWORK_MAC_ADDRESS: |
| 142 | case NETWORK_SUBNET_MASK: |
| 143 | case NETWORK_GATEWAY_ADDRESS: |
| 144 | case NETWORK_DNS1_ADDRESS: |
| 145 | case NETWORK_DNS2_ADDRESS: |
| 146 | case NETWORK_LINK_STATE: |
| 147 | case SYSTEM_OS_VERSION_INFO: |
| 148 | case SYSTEM_CPUFREQUENCY: |
| 149 | case SYSTEM_INTERNET_STATE: |
| 150 | case SYSTEM_UPTIME: |
| 151 | case SYSTEM_TOTALUPTIME: |
| 152 | case SYSTEM_BATTERY_LEVEL: |
| 153 | value = g_sysinfo.GetInfo(info.m_info); |
| 154 | return true; |
| 155 | case SYSTEM_PRIVACY_POLICY: |
| 156 | value = g_sysinfo.GetPrivacyPolicy(); |
| 157 | return true; |
| 158 | case SYSTEM_SCREEN_RESOLUTION: |
| 159 | { |
| 160 | const auto winSystem = CServiceBroker::GetWinSystem(); |
| 161 | if (winSystem) |
| 162 | { |
| 163 | const RESOLUTION_INFO& resInfo = winSystem->GetGfxContext().GetResInfo(); |
| 164 | |
| 165 | if (winSystem->IsFullScreen()) |
| 166 | value = StringUtils::Format("{}x{} @ {:.2f} Hz - {}", resInfo.iScreenWidth, |
| 167 | resInfo.iScreenHeight, resInfo.fRefreshRate, |
| 168 | g_localizeStrings.Get(244)); |
| 169 | else |
| 170 | value = StringUtils::Format("{}x{} - {}", resInfo.iScreenWidth, resInfo.iScreenHeight, |
| 171 | g_localizeStrings.Get(242)); |
| 172 | } |
| 173 | else |
| 174 | { |
| 175 | value = ""; |
| 176 | } |
| 177 | return true; |
| 178 | } |
| 179 | case SYSTEM_BUILD_VERSION_SHORT: |
| 180 | value = CSysInfo::GetVersionShort(); |
| 181 | return true; |
| 182 | case SYSTEM_BUILD_VERSION: |
| 183 | value = CSysInfo::GetVersion(); |
| 184 | return true; |
| 185 | case SYSTEM_BUILD_DATE: |
| 186 | value = CSysInfo::GetBuildDate(); |
| 187 | return true; |
| 188 | case SYSTEM_BUILD_VERSION_CODE: |
| 189 | value = CSysInfo::GetVersionCode(); |
| 190 | return true; |
| 191 | case SYSTEM_BUILD_VERSION_GIT: |
| 192 | value = CSysInfo::GetVersionGit(); |
| 193 | return true; |
| 194 | case SYSTEM_FREE_MEMORY: |
| 195 | case SYSTEM_FREE_MEMORY_PERCENT: |
| 196 | case SYSTEM_USED_MEMORY: |
| 197 | case SYSTEM_USED_MEMORY_PERCENT: |
| 198 | case SYSTEM_TOTAL_MEMORY: |
| 199 | { |
| 200 | KODI::MEMORY::MemoryStatus stat; |
| 201 | KODI::MEMORY::GetMemoryStatus(&stat); |
| 202 | int iMemPercentFree = 100 - static_cast<int>(100.0f * (stat.totalPhys - stat.availPhys) / stat.totalPhys + 0.5f); |
| 203 | int iMemPercentUsed = 100 - iMemPercentFree; |
| 204 | |
| 205 | if (info.m_info == SYSTEM_FREE_MEMORY) |
| 206 | value = StringUtils::Format("{}MB", static_cast<unsigned int>(stat.availPhys / MB)); |
| 207 | else if (info.m_info == SYSTEM_FREE_MEMORY_PERCENT) |
| 208 | value = StringUtils::Format("{}%", iMemPercentFree); |
| 209 | else if (info.m_info == SYSTEM_USED_MEMORY) |
| 210 | value = StringUtils::Format( |
| 211 | "{}MB", static_cast<unsigned int>((stat.totalPhys - stat.availPhys) / MB)); |
| 212 | else if (info.m_info == SYSTEM_USED_MEMORY_PERCENT) |
| 213 | value = StringUtils::Format("{}%", iMemPercentUsed); |
| 214 | else if (info.m_info == SYSTEM_TOTAL_MEMORY) |
| 215 | value = StringUtils::Format("{}MB", static_cast<unsigned int>(stat.totalPhys / MB)); |
| 216 | return true; |
| 217 | } |
| 218 | case SYSTEM_SCREEN_MODE: |
| 219 | value = CServiceBroker::GetWinSystem()->GetGfxContext().GetResInfo().strMode; |
| 220 | return true; |
| 221 | case SYSTEM_SCREEN_WIDTH: |
| 222 | value = StringUtils::Format( |
| 223 | "{}", CServiceBroker::GetWinSystem()->GetGfxContext().GetResInfo().iScreenWidth); |
| 224 | return true; |
| 225 | case SYSTEM_SCREEN_HEIGHT: |
| 226 | value = StringUtils::Format( |
| 227 | "{}", CServiceBroker::GetWinSystem()->GetGfxContext().GetResInfo().iScreenHeight); |
| 228 | return true; |
| 229 | case SYSTEM_FPS: |
| 230 | value = StringUtils::Format("{:02.2f}", m_fps); |
| 231 | return true; |
| 232 | #ifdef HAS_OPTICAL_DRIVE |
| 233 | case SYSTEM_DVD_LABEL: |
| 234 | value = CServiceBroker::GetMediaManager().GetDiskLabel(); |
| 235 | return true; |
| 236 | #endif |
| 237 | case SYSTEM_ALARM_POS: |
| 238 | if (g_alarmClock.GetRemaining("shutdowntimer") == 0.0) |
| 239 | value.clear(); |
| 240 | else |
| 241 | { |
| 242 | double fTime = g_alarmClock.GetRemaining("shutdowntimer"); |
| 243 | if (fTime > 60.0) |
| 244 | value = StringUtils::Format(g_localizeStrings.Get(13213), |
| 245 | g_alarmClock.GetRemaining("shutdowntimer") / 60.0); |
| 246 | else |
| 247 | value = StringUtils::Format(g_localizeStrings.Get(13214), |
| 248 | g_alarmClock.GetRemaining("shutdowntimer")); |
| 249 | } |
| 250 | return true; |
| 251 | case SYSTEM_PROFILENAME: |
| 252 | value = CServiceBroker::GetSettingsComponent()->GetProfileManager()->GetCurrentProfile().getName(); |
| 253 | return true; |
| 254 | case SYSTEM_PROFILECOUNT: |
| 255 | value = StringUtils::Format("{0}", CServiceBroker::GetSettingsComponent()->GetProfileManager()->GetNumberOfProfiles()); |
| 256 | return true; |
| 257 | case SYSTEM_PROFILEAUTOLOGIN: |
| 258 | { |
| 259 | const std::shared_ptr<CProfileManager> profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager(); |
| 260 | int iProfileId = profileManager->GetAutoLoginProfileId(); |
| 261 | if ((iProfileId < 0) || !profileManager->GetProfileName(iProfileId, value)) |
| 262 | value = g_localizeStrings.Get(37014); // Last used profile |
| 263 | return true; |
| 264 | } |
| 265 | case SYSTEM_PROFILETHUMB: |
| 266 | { |
| 267 | const std::string& thumb = CServiceBroker::GetSettingsComponent()->GetProfileManager()->GetCurrentProfile().getThumb(); |
| 268 | value = thumb.empty() ? "DefaultUser.png" : thumb; |
| 269 | return true; |
| 270 | } |
| 271 | case SYSTEM_LANGUAGE: |
| 272 | value = g_langInfo.GetEnglishLanguageName(); |
| 273 | return true; |
| 274 | case SYSTEM_TEMPERATURE_UNITS: |
| 275 | value = g_langInfo.GetTemperatureUnitString(); |
| 276 | return true; |
| 277 | case SYSTEM_FRIENDLY_NAME: |
| 278 | value = CSysInfo::GetDeviceName(); |
| 279 | return true; |
| 280 | case SYSTEM_STEREOSCOPIC_MODE: |
| 281 | { |
| 282 | int iStereoMode = CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_VIDEOSCREEN_STEREOSCOPICMODE); |
| 283 | value = std::to_string(iStereoMode); |
| 284 | return true; |
| 285 | } |
| 286 | case SYSTEM_GET_CORE_USAGE: |
| 287 | value = StringUtils::Format( |
| 288 | "{:4.2f}", |
| 289 | CServiceBroker::GetCPUInfo()->GetCoreInfo(std::stoi(info.GetData3())).m_usagePercent); |
| 290 | return true; |
| 291 | case SYSTEM_RENDER_VENDOR: |
| 292 | value = CServiceBroker::GetRenderSystem()->GetRenderVendor(); |
| 293 | return true; |
| 294 | case SYSTEM_RENDER_RENDERER: |
| 295 | value = CServiceBroker::GetRenderSystem()->GetRenderRenderer(); |
| 296 | return true; |
| 297 | case SYSTEM_RENDER_VERSION: |
| 298 | value = CServiceBroker::GetRenderSystem()->GetRenderVersionString(); |
| 299 | return true; |
| 300 | case SYSTEM_ADDON_UPDATE_COUNT: |
| 301 | value = CServiceBroker::GetAddonMgr().GetLastAvailableUpdatesCountAsString(); |
| 302 | return true; |
| 303 | #if defined(TARGET_LINUX) |
| 304 | case SYSTEM_PLATFORM_WINDOWING: |
| 305 | value = CServiceBroker::GetWinSystem()->GetName(); |
| 306 | StringUtils::ToCapitalize(value); |
| 307 | return true; |
| 308 | #endif |
| 309 | case SYSTEM_SUPPORTED_HDR_TYPES: |
| 310 | { |
| 311 | if (CServiceBroker::GetWinSystem()->IsHDRDisplay()) |
| 312 | { |
| 313 | // Assumes HDR10 minimum requirement for HDR |
| 314 | std::string types = "HDR10"; |
| 315 | |
| 316 | const CHDRCapabilities caps = CServiceBroker::GetWinSystem()->GetDisplayHDRCapabilities(); |
| 317 | |
| 318 | if (caps.SupportsHLG()) |
| 319 | types += ", HLG"; |
| 320 | if (caps.SupportsHDR10Plus()) |
| 321 | types += ", HDR10+"; |
| 322 | if (caps.SupportsDolbyVision()) |
| 323 | types += ", Dolby Vision"; |
| 324 | |
| 325 | value = types; |
| 326 | } |
| 327 | |
| 328 | return true; |
| 329 | } |
| 330 | |
| 331 | case SYSTEM_LOCALE_TIMEZONECOUNTRY: |
| 332 | { |
| 333 | value = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString( |
| 334 | CSettings::SETTING_LOCALE_TIMEZONECOUNTRY); |
| 335 | return true; |
| 336 | } |
| 337 | |
| 338 | case SYSTEM_LOCALE_TIMEZONE: |
| 339 | { |
| 340 | value = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString( |
| 341 | CSettings::SETTING_LOCALE_TIMEZONE); |
| 342 | return true; |
| 343 | } |
| 344 | |
| 345 | case SYSTEM_LOCALE_REGION: |
| 346 | { |
| 347 | value = g_langInfo.GetCurrentRegion(); |
| 348 | return true; |
| 349 | } |
| 350 | |
| 351 | case SYSTEM_LOCALE: |
| 352 | { |
| 353 | value = g_langInfo.GetRegionLocale(); |
| 354 | return true; |
| 355 | } |
| 356 | } |
| 357 | return false; |
| 358 | } |
| 359 | |
| 360 | bool CSystemGUIInfo::GetInt(int& value, const CGUIListItem *gitem, int contextWindow, const CGUIInfo &info) const |
| 361 | { |
| 362 | switch (info.m_info) |
| 363 | { |
| 364 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 365 | // SYSTEM_* |
| 366 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 367 | case SYSTEM_FREE_MEMORY: |
| 368 | case SYSTEM_USED_MEMORY: |
| 369 | { |
| 370 | KODI::MEMORY::MemoryStatus stat; |
| 371 | KODI::MEMORY::GetMemoryStatus(&stat); |
| 372 | int memPercentUsed = static_cast<int>(100.0f * (stat.totalPhys - stat.availPhys) / stat.totalPhys + 0.5f); |
| 373 | if (info.m_info == SYSTEM_FREE_MEMORY) |
| 374 | value = 100 - memPercentUsed; |
| 375 | else |
| 376 | value = memPercentUsed; |
| 377 | return true; |
| 378 | } |
| 379 | case SYSTEM_FREE_SPACE: |
| 380 | case SYSTEM_USED_SPACE: |
| 381 | { |
| 382 | g_sysinfo.GetHddSpaceInfo(value, info.m_info, true); |
| 383 | return true; |
| 384 | } |
| 385 | case SYSTEM_CPU_USAGE: |
| 386 | value = CServiceBroker::GetCPUInfo()->GetUsedPercentage(); |
| 387 | return true; |
| 388 | case SYSTEM_BATTERY_LEVEL: |
| 389 | value = CServiceBroker::GetPowerManager().BatteryLevel(); |
| 390 | return true; |
| 391 | } |
| 392 | |
| 393 | return false; |
| 394 | } |
| 395 | |
| 396 | bool CSystemGUIInfo::GetBool(bool& value, const CGUIListItem *gitem, int contextWindow, const CGUIInfo &info) const |
| 397 | { |
| 398 | switch (info.m_info) |
| 399 | { |
| 400 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 401 | // SYSTEM_* |
| 402 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 403 | case SYSTEM_ALWAYS_TRUE: |
| 404 | value = true; |
| 405 | return true; |
| 406 | case SYSTEM_ALWAYS_FALSE: |
| 407 | value = false; |
| 408 | return true; |
| 409 | case SYSTEM_ETHERNET_LINK_ACTIVE: |
| 410 | // wtf: not implemented - always returns true?! |
| 411 | value = true; |
| 412 | return true; |
| 413 | case SYSTEM_PLATFORM_LINUX: |
| 414 | #if defined(TARGET_LINUX) || defined(TARGET_FREEBSD) |
| 415 | value = true; |
| 416 | #else |
| 417 | value = false; |
| 418 | #endif |
| 419 | return true; |
| 420 | case SYSTEM_PLATFORM_WINDOWS: |
| 421 | #ifdef TARGET_WINDOWS |
| 422 | value = true; |
| 423 | #else |
| 424 | value = false; |
| 425 | #endif |
| 426 | return true; |
| 427 | case SYSTEM_PLATFORM_UWP: |
| 428 | #ifdef TARGET_WINDOWS_STORE |
| 429 | value = true; |
| 430 | #else |
| 431 | value = false; |
| 432 | #endif |
| 433 | return true; |
| 434 | case SYSTEM_PLATFORM_DARWIN: |
| 435 | #ifdef TARGET_DARWIN |
| 436 | value = true; |
| 437 | #else |
| 438 | value = false; |
| 439 | #endif |
| 440 | return true; |
| 441 | case SYSTEM_PLATFORM_DARWIN_OSX: |
| 442 | #ifdef TARGET_DARWIN_OSX |
| 443 | value = true; |
| 444 | #else |
| 445 | value = false; |
| 446 | #endif |
| 447 | return true; |
| 448 | case SYSTEM_PLATFORM_DARWIN_IOS: |
| 449 | #ifdef TARGET_DARWIN_IOS |
| 450 | value = true; |
| 451 | #else |
| 452 | value = false; |
| 453 | #endif |
| 454 | return true; |
| 455 | case SYSTEM_PLATFORM_DARWIN_TVOS: |
| 456 | #ifdef TARGET_DARWIN_TVOS |
| 457 | value = true; |
| 458 | #else |
| 459 | value = false; |
| 460 | #endif |
| 461 | return true; |
| 462 | case SYSTEM_PLATFORM_ANDROID: |
| 463 | #if defined(TARGET_ANDROID) |
| 464 | value = true; |
| 465 | #else |
| 466 | value = false; |
| 467 | #endif |
| 468 | return true; |
| 469 | case SYSTEM_PLATFORM_WEBOS: |
| 470 | #if defined(TARGET_WEBOS) |
| 471 | value = true; |
| 472 | #else |
| 473 | value = false; |
| 474 | #endif |
| 475 | return true; |
| 476 | case SYSTEM_MEDIA_DVD: |
| 477 | value = CServiceBroker::GetMediaManager().IsDiscInDrive(); |
| 478 | return true; |
| 479 | case SYSTEM_MEDIA_AUDIO_CD: |
| 480 | #ifdef HAS_OPTICAL_DRIVE |
| 481 | if (CServiceBroker::GetMediaManager().IsDiscInDrive()) |
| 482 | { |
| 483 | MEDIA_DETECT::CCdInfo* pCdInfo = CServiceBroker::GetMediaManager().GetCdInfo(); |
| 484 | value = pCdInfo && (pCdInfo->IsAudio(1) || pCdInfo->IsCDExtra(1) || pCdInfo->IsMixedMode(1)); |
| 485 | } |
| 486 | else |
| 487 | #endif |
| 488 | { |
| 489 | value = false; |
| 490 | } |
| 491 | return true; |
| 492 | #ifdef HAS_OPTICAL_DRIVE |
| 493 | case SYSTEM_DVDREADY: |
| 494 | value = CServiceBroker::GetMediaManager().GetDriveStatus() != DriveState::NOT_READY; |
| 495 | return true; |
| 496 | case SYSTEM_TRAYOPEN: |
| 497 | value = CServiceBroker::GetMediaManager().GetDriveStatus() == DriveState::OPEN; |
| 498 | return true; |
| 499 | #endif |
| 500 | case SYSTEM_CAN_POWERDOWN: |
| 501 | value = CServiceBroker::GetPowerManager().CanPowerdown(); |
| 502 | return true; |
| 503 | case SYSTEM_CAN_SUSPEND: |
| 504 | value = CServiceBroker::GetPowerManager().CanSuspend(); |
| 505 | return true; |
| 506 | case SYSTEM_CAN_HIBERNATE: |
| 507 | value = CServiceBroker::GetPowerManager().CanHibernate(); |
| 508 | return true; |
| 509 | case SYSTEM_CAN_REBOOT: |
| 510 | value = CServiceBroker::GetPowerManager().CanReboot(); |
| 511 | return true; |
| 512 | case SYSTEM_SCREENSAVER_ACTIVE: |
| 513 | case SYSTEM_IS_SCREENSAVER_INHIBITED: |
| 514 | case SYSTEM_DPMS_ACTIVE: |
| 515 | case SYSTEM_IDLE_SHUTDOWN_INHIBITED: |
| 516 | case SYSTEM_IDLE_TIME: |
| 517 | { |
| 518 | auto& components = CServiceBroker::GetAppComponents(); |
| 519 | const auto appPower = components.GetComponent<CApplicationPowerHandling>(); |
| 520 | switch (info.m_info) |
| 521 | { |
| 522 | case SYSTEM_SCREENSAVER_ACTIVE: |
| 523 | value = appPower->IsInScreenSaver(); |
| 524 | return true; |
| 525 | case SYSTEM_IS_SCREENSAVER_INHIBITED: |
| 526 | value = appPower->IsScreenSaverInhibited(); |
| 527 | return true; |
| 528 | case SYSTEM_DPMS_ACTIVE: |
| 529 | value = appPower->IsDPMSActive(); |
| 530 | return true; |
| 531 | case SYSTEM_IDLE_SHUTDOWN_INHIBITED: |
| 532 | value = appPower->IsIdleShutdownInhibited(); |
| 533 | return true; |
| 534 | case SYSTEM_IDLE_TIME: |
| 535 | value = appPower->GlobalIdleTime() >= static_cast<int>(info.GetData1()); |
| 536 | return true; |
| 537 | default: |
| 538 | return false; |
| 539 | } |
| 540 | } |
| 541 | case SYSTEM_HASLOCKS: |
| 542 | value = CServiceBroker::GetSettingsComponent()->GetProfileManager()->GetMasterProfile().getLockMode() != LOCK_MODE_EVERYONE; |
| 543 | return true; |
| 544 | case SYSTEM_HAS_PVR: |
| 545 | value = true; |
| 546 | return true; |
| 547 | case SYSTEM_HAS_PVR_ADDON: |
| 548 | value = CServiceBroker::GetAddonMgr().HasAddons(ADDON::AddonType::PVRDLL); |
| 549 | return true; |
| 550 | case SYSTEM_HAS_CMS: |
| 551 | #if defined(HAS_GL) || defined(HAS_DX) |
| 552 | value = true; |
| 553 | #else |
| 554 | value = false; |
| 555 | #endif |
| 556 | return true; |
| 557 | case SYSTEM_ISMASTER: |
| 558 | value = CServiceBroker::GetSettingsComponent()->GetProfileManager()->GetMasterProfile().getLockMode() != LOCK_MODE_EVERYONE && g_passwordManager.bMasterUser; |
| 559 | return true; |
| 560 | case SYSTEM_ISFULLSCREEN: |
| 561 | value = CServiceBroker::GetWinSystem()->IsFullScreen(); |
| 562 | return true; |
| 563 | case SYSTEM_ISSTANDALONE: |
| 564 | value = CServiceBroker::GetAppParams()->IsStandAlone(); |
| 565 | return true; |
| 566 | case SYSTEM_HAS_SHUTDOWN: |
| 567 | value = (CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_POWERMANAGEMENT_SHUTDOWNTIME) > 0); |
| 568 | return true; |
| 569 | case SYSTEM_LOGGEDON: |
| 570 | value = !(CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow() == WINDOW_LOGIN_SCREEN); |
| 571 | return true; |
| 572 | case SYSTEM_SHOW_EXIT_BUTTON: |
| 573 | value = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_showExitButton; |
| 574 | return true; |
| 575 | case SYSTEM_HAS_LOGINSCREEN: |
| 576 | value = CServiceBroker::GetSettingsComponent()->GetProfileManager()->UsingLoginScreen(); |
| 577 | return true; |
| 578 | case SYSTEM_INTERNET_STATE: |
| 579 | { |
| 580 | g_sysinfo.GetInfo(info.m_info); |
| 581 | value = g_sysinfo.HasInternet(); |
| 582 | return true; |
| 583 | } |
| 584 | case SYSTEM_HAS_CORE_ID: |
| 585 | value = CServiceBroker::GetCPUInfo()->HasCoreId(info.GetData1()); |
| 586 | return true; |
| 587 | case SYSTEM_DATE: |
| 588 | { |
| 589 | if (info.GetData2() == -1) // info doesn't contain valid startDate |
| 590 | return false; |
| 591 | const CDateTime date = CDateTime::GetCurrentDateTime(); |
| 592 | int currentDate = date.GetMonth() * 100 + date.GetDay(); |
| 593 | int startDate = info.GetData1(); |
| 594 | int stopDate = info.GetData2(); |
| 595 | |
| 596 | if (stopDate < startDate) |
| 597 | value = currentDate >= startDate || currentDate < stopDate; |
| 598 | else |
| 599 | value = currentDate >= startDate && currentDate < stopDate; |
| 600 | return true; |
| 601 | } |
| 602 | case SYSTEM_TIME: |
| 603 | { |
| 604 | int currentTime = CDateTime::GetCurrentDateTime().GetMinuteOfDay(); |
| 605 | int startTime = info.GetData1(); |
| 606 | int stopTime = info.GetData2(); |
| 607 | |
| 608 | if (stopTime < startTime) |
| 609 | value = currentTime >= startTime || currentTime < stopTime; |
| 610 | else |
| 611 | value = currentTime >= startTime && currentTime < stopTime; |
| 612 | return true; |
| 613 | } |
| 614 | case SYSTEM_ALARM_LESS_OR_EQUAL: |
| 615 | { |
| 616 | int time = std::lrint(g_alarmClock.GetRemaining(info.GetData3())); |
| 617 | int timeCompare = info.GetData2(); |
| 618 | if (time > 0) |
| 619 | value = timeCompare >= time; |
| 620 | else |
| 621 | value = false; |
| 622 | return true; |
| 623 | } |
| 624 | case SYSTEM_HAS_ALARM: |
| 625 | value = g_alarmClock.HasAlarm(info.GetData3()); |
| 626 | return true; |
| 627 | case SYSTEM_SUPPORTS_CPU_USAGE: |
| 628 | value = CServiceBroker::GetCPUInfo()->SupportsCPUUsage(); |
| 629 | return true; |
| 630 | case SYSTEM_GET_BOOL: |
| 631 | value = CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(info.GetData3()); |
| 632 | return true; |
| 633 | case SYSTEM_SETTING: |
| 634 | { |
| 635 | if (StringUtils::EqualsNoCase(info.GetData3(), "hidewatched")) |
| 636 | { |
| 637 | CGUIMediaWindow* window = GUIINFO::GetMediaWindow(contextWindow); |
| 638 | if (window) |
| 639 | { |
| 640 | value = CMediaSettings::GetInstance().GetWatchedMode(window->CurrentDirectory().GetContent()) == WatchedModeUnwatched; |
| 641 | return true; |
| 642 | } |
| 643 | } |
| 644 | else if (StringUtils::EqualsNoCase(info.GetData3(), "hideunwatchedepisodethumbs")) |
| 645 | { |
| 646 | const std::shared_ptr<CSettingList> setting(std::dynamic_pointer_cast<CSettingList>( |
| 647 | CServiceBroker::GetSettingsComponent()->GetSettings()->GetSetting( |
| 648 | CSettings::SETTING_VIDEOLIBRARY_SHOWUNWATCHEDPLOTS))); |
| 649 | value = setting && !CSettingUtils::FindIntInList( |
| 650 | setting, CSettings::VIDEOLIBRARY_THUMB_SHOW_UNWATCHED_EPISODE); |
| 651 | return true; |
| 652 | } |
| 653 | break; |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | return false; |
| 658 | } |