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.
9 #include "GUIWindowSystemInfo.h"
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"
24 #define CONTROL_TB_POLICY 30
25 #define CONTROL_BT_STORAGE 94
26 #define CONTROL_BT_DEFAULT 95
27 #define CONTROL_BT_NETWORK 96
28 #define CONTROL_BT_VIDEO 97
29 #define CONTROL_BT_HARDWARE 98
30 #define CONTROL_BT_PVR 99
31 #define CONTROL_BT_POLICY 100
33 #define CONTROL_START CONTROL_BT_STORAGE
34 #define CONTROL_END CONTROL_BT_POLICY
36 CGUIWindowSystemInfo::CGUIWindowSystemInfo(void) :
37 CGUIWindow(WINDOW_SYSTEM_INFORMATION
, "SettingsSystemInfo.xml")
39 m_section
= CONTROL_BT_DEFAULT
;
40 m_loadType
= KEEP_IN_MEMORY
;
43 CGUIWindowSystemInfo::~CGUIWindowSystemInfo(void) = default;
45 bool CGUIWindowSystemInfo::OnMessage(CGUIMessage
& message
)
47 switch (message
.GetMessage())
49 case GUI_MSG_WINDOW_INIT
:
51 CGUIWindow::OnMessage(message
);
52 SET_CONTROL_LABEL(52, CSysInfo::GetAppName() + " " + CSysInfo::GetVersion());
53 SET_CONTROL_LABEL(53, CSysInfo::GetBuildDate());
54 CONTROL_ENABLE_ON_CONDITION(CONTROL_BT_PVR
, CServiceBroker::GetPVRManager().IsStarted());
59 case GUI_MSG_WINDOW_DEINIT
:
61 CGUIWindow::OnMessage(message
);
69 CGUIWindow::OnMessage(message
);
70 int focusedControl
= GetFocusedControlID();
71 if (m_section
!= focusedControl
&& focusedControl
>= CONTROL_START
&& focusedControl
<= CONTROL_END
)
74 m_section
= focusedControl
;
76 if (m_section
>= CONTROL_BT_STORAGE
&& m_section
<= CONTROL_BT_PVR
)
77 SET_CONTROL_HIDDEN(CONTROL_TB_POLICY
);
78 else if (m_section
== CONTROL_BT_POLICY
)
80 SET_CONTROL_LABEL(CONTROL_TB_POLICY
, CServiceBroker::GetGUI()->GetInfoManager().GetLabel(
81 SYSTEM_PRIVACY_POLICY
, INFO::DEFAULT_CONTEXT
));
82 SET_CONTROL_VISIBLE(CONTROL_TB_POLICY
);
88 return CGUIWindow::OnMessage(message
);
91 void CGUIWindowSystemInfo::FrameMove()
94 if (m_section
== CONTROL_BT_DEFAULT
)
96 SET_CONTROL_LABEL(40, g_localizeStrings
.Get(20154));
97 SetControlLabel(i
++, "{}: {}", 158, SYSTEM_FREE_MEMORY
);
98 SetControlLabel(i
++, "{}: {}", 150, NETWORK_IP_ADDRESS
);
99 SetControlLabel(i
++, "{} {}", 13287, SYSTEM_SCREEN_RESOLUTION
);
100 SetControlLabel(i
++, "{} {}", 13283, SYSTEM_OS_VERSION_INFO
);
101 SetControlLabel(i
++, "{}: {}", 12390, SYSTEM_UPTIME
);
102 SetControlLabel(i
++, "{}: {}", 12394, SYSTEM_TOTALUPTIME
);
103 SetControlLabel(i
++, "{}: {}", 12395, SYSTEM_BATTERY_LEVEL
);
106 else if (m_section
== CONTROL_BT_STORAGE
)
108 SET_CONTROL_LABEL(40, g_localizeStrings
.Get(20155));
109 if (m_diskUsage
.empty())
110 m_diskUsage
= CServiceBroker::GetMediaManager().GetDiskUsage();
112 for (size_t d
= 0; d
< m_diskUsage
.size(); d
++)
114 SET_CONTROL_LABEL(i
++, m_diskUsage
[d
]);
118 else if (m_section
== CONTROL_BT_NETWORK
)
120 SET_CONTROL_LABEL(40,g_localizeStrings
.Get(20158));
121 SET_CONTROL_LABEL(i
++, CServiceBroker::GetGUI()->GetInfoManager().GetLabel(
122 NETWORK_LINK_STATE
, INFO::DEFAULT_CONTEXT
));
123 SetControlLabel(i
++, "{}: {}", 149, NETWORK_MAC_ADDRESS
);
124 SetControlLabel(i
++, "{}: {}", 150, NETWORK_IP_ADDRESS
);
125 SetControlLabel(i
++, "{}: {}", 13159, NETWORK_SUBNET_MASK
);
126 SetControlLabel(i
++, "{}: {}", 13160, NETWORK_GATEWAY_ADDRESS
);
127 SetControlLabel(i
++, "{}: {}", 13161, NETWORK_DNS1_ADDRESS
);
128 SetControlLabel(i
++, "{}: {}", 20307, NETWORK_DNS2_ADDRESS
);
129 SetControlLabel(i
++, "{} {}", 13295, SYSTEM_INTERNET_STATE
);
132 else if (m_section
== CONTROL_BT_VIDEO
)
134 SET_CONTROL_LABEL(40,g_localizeStrings
.Get(20159));
135 SET_CONTROL_LABEL(i
++, CServiceBroker::GetGUI()->GetInfoManager().GetLabel(
136 SYSTEM_VIDEO_ENCODER_INFO
, INFO::DEFAULT_CONTEXT
));
137 SetControlLabel(i
++, "{} {}", 13287, SYSTEM_SCREEN_RESOLUTION
);
139 auto renderingSystem
= CServiceBroker::GetRenderSystem();
142 static std::string vendor
= renderingSystem
->GetRenderVendor();
144 SET_CONTROL_LABEL(i
++, StringUtils::Format("{} {}", g_localizeStrings
.Get(22007), vendor
));
147 int renderVersionLabel
= 22024;
149 int renderVersionLabel
= 22009;
151 static std::string version
= renderingSystem
->GetRenderVersionString();
152 if (!version
.empty())
154 i
++, StringUtils::Format("{} {}", g_localizeStrings
.Get(renderVersionLabel
), version
));
157 auto windowSystem
= CServiceBroker::GetWinSystem();
160 static std::string platform
= windowSystem
->GetName();
161 if (platform
!= "platform default")
162 SET_CONTROL_LABEL(i
++,
163 StringUtils::Format("{} {}", g_localizeStrings
.Get(39153), platform
));
166 SetControlLabel(i
++, "{} {}", 22010, SYSTEM_GPU_TEMPERATURE
);
168 const std::string hdrTypes
= CServiceBroker::GetGUI()->GetInfoManager().GetLabel(
169 SYSTEM_SUPPORTED_HDR_TYPES
, INFO::DEFAULT_CONTEXT
);
171 i
++, StringUtils::Format("{}: {}", g_localizeStrings
.Get(39174),
172 hdrTypes
.empty() ? g_localizeStrings
.Get(231) : hdrTypes
));
175 else if (m_section
== CONTROL_BT_HARDWARE
)
177 SET_CONTROL_LABEL(40,g_localizeStrings
.Get(20160));
179 auto cpuInfo
= CServiceBroker::GetCPUInfo();
182 static std::string model
= cpuInfo
->GetCPUModel();
184 SET_CONTROL_LABEL(i
++, "CPU: " + model
);
186 static std::string mips
= cpuInfo
->GetCPUBogoMips();
188 SET_CONTROL_LABEL(i
++, "BogoMips: " + mips
);
190 static std::string soc
= cpuInfo
->GetCPUSoC();
192 SET_CONTROL_LABEL(i
++, "SoC: " + soc
);
194 static std::string hardware
= cpuInfo
->GetCPUHardware();
195 if (!hardware
.empty())
196 SET_CONTROL_LABEL(i
++, "Hardware: " + hardware
);
198 static std::string revision
= cpuInfo
->GetCPURevision();
199 if (!revision
.empty())
200 SET_CONTROL_LABEL(i
++, "Revision: " + revision
);
202 static std::string serial
= cpuInfo
->GetCPUSerial();
204 SET_CONTROL_LABEL(i
++, "Serial: " + serial
);
206 // temperature can't really be conditional because of localization units
207 SetControlLabel(i
++, "{} {}", 22011, SYSTEM_CPU_TEMPERATURE
);
209 // we can check if the cpufrequency is not 0 (default if not implemented)
210 // but we have to call through CGUIInfoManager -> CSystemGUIInfo -> CSysInfo
211 // to limit the frequency of updates
212 static float cpuFreq
= cpuInfo
->GetCPUFrequency();
214 SetControlLabel(i
++, "{} {}", 13284, SYSTEM_CPUFREQUENCY
);
218 else if (m_section
== CONTROL_BT_PVR
)
220 SET_CONTROL_LABEL(40, g_localizeStrings
.Get(19166));
223 SetControlLabel(i
++, "{}: {}", 19120, PVR_BACKEND_NUMBER
);
225 SetControlLabel(i
++, "{}: {}", 19012, PVR_BACKEND_NAME
);
226 SetControlLabel(i
++, "{}: {}", 19114, PVR_BACKEND_VERSION
);
227 SetControlLabel(i
++, "{}: {}", 19115, PVR_BACKEND_HOST
);
228 SetControlLabel(i
++, "{}: {}", 19116, PVR_BACKEND_DISKSPACE
);
229 SetControlLabel(i
++, "{}: {}", 19334, PVR_BACKEND_PROVIDERS
);
230 SetControlLabel(i
++, "{}: {}", 19042, PVR_BACKEND_CHANNEL_GROUPS
);
231 SetControlLabel(i
++, "{}: {}", 19019, PVR_BACKEND_CHANNELS
);
232 SetControlLabel(i
++, "{}: {}", 19163, PVR_BACKEND_RECORDINGS
);
233 SetControlLabel(i
++, "{}: {}", 19168,
234 PVR_BACKEND_DELETED_RECORDINGS
); // Deleted and recoverable recordings
235 SetControlLabel(i
++, "{}: {}", 19025, PVR_BACKEND_TIMERS
);
238 else if (m_section
== CONTROL_BT_POLICY
)
240 SET_CONTROL_LABEL(40, g_localizeStrings
.Get(12389));
242 CGUIWindow::FrameMove();
245 void CGUIWindowSystemInfo::ResetLabels()
247 for (int i
= 2; i
< 13; i
++)
249 SET_CONTROL_LABEL(i
, "");
251 SET_CONTROL_LABEL(CONTROL_TB_POLICY
, "");
254 void CGUIWindowSystemInfo::SetControlLabel(int id
, const char *format
, int label
, int info
)
256 std::string tmpStr
= StringUtils::Format(
257 format
, g_localizeStrings
.Get(label
),
258 CServiceBroker::GetGUI()->GetInfoManager().GetLabel(info
, INFO::DEFAULT_CONTEXT
));
259 SET_CONTROL_LABEL(id
, tmpStr
);