From Kodiâs source, we see:
/// \table_row3{ <b>`System.FriendlyName`</b>,
/// \anchor System_FriendlyName
/// _string_,
/// @return The Kodi instance name.
/// @note It will auto append (%hostname%) in case
/// the device name was not changed. eg. "Kodi (htpc)"
/// <p>
SYSTEM_FRIENDLY_NAME only seems to be found in:
xbmc/GUIInfoManager.cpp
xbmc/guilib/guiinfo/SystemGUIInfo.cpp
xbmc/guilib/guiinfo/GUIInfoLabels.h
We have this patch for OSMC, to keep the Kodi device name in sync with the hostname:
From 7e0c2d40b6a24418740dab9f06bf39c6ba595f9f Mon Sep 17 00:00:00 2001
From: Sam Nazarko <email@samnazarko.co.uk>
Date: Sun, 20 Sep 2015 14:40:24 +0100
Subject: [PATCH] Ensure that Kodi's 'services.devicename' reflects
/etc/hostname:
* Set the device name from the hostname at startup
* Ensure callback handles changes to this and updates /etc/hostname if changed in GUI
Do not worry about /etc/hosts as libnss-myhostname should handle this.
Signed-off-by: Sam Nazarko <email@samnazarko.co.uk>
---
xbmc/Application.cpp | 1 +
xbmc/guilib/guiinfo/SystemGUIInfo.cpp | 9 +++++++--
xbmc/network/NetworkServices.cpp | 20 +++++++++++++++++++-
3 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/xbmc/Application.cpp b/xbmc/Application.cpp
index 3bd24ef..ac1f4f5 100644
--- a/xbmc/Application.cpp
+++ b/xbmc/Application.cpp
@@ -542,6 +542,7 @@ bool CApplication::Create(const CAppParamParser ¶ms)
return false;
CLog::Log(LOGINFO, "creating subdirectories");
+ CServiceBroker::GetSettingsComponent()->GetSettings()->SetString(CSettings::SETTING_SERVICES_DEVICENAME, hostname);
const std::shared_ptr<CProfileManager> profileManager = m_pSettingsComponent->GetProfileManager();
const std::shared_ptr<CSettings> settings = m_pSettingsComponent->GetSettings();
CLog::Log(LOGINFO, "userdata folder: %s", CURL::GetRedacted(profileManager->GetProfileUserDataFolder()).c_str());
diff --git a/xbmc/guilib/guiinfo/SystemGUIInfo.cpp b/xbmc/guilib/guiinfo/SystemGUIInfo.cpp
index a27bda4..e76ed82 100644
--- a/xbmc/guilib/guiinfo/SystemGUIInfo.cpp
+++ b/xbmc/guilib/guiinfo/SystemGUIInfo.cpp
@@ -137,6 +137,7 @@ bool CSystemGUIInfo::InitCurrentItem(CFileItem *item)
bool CSystemGUIInfo::GetLabel(std::string& value, const CFileItem *item, int contextWindow, const CGUIInfo &info, std::string *fallback) const
{
+ std::string strLabel;
switch (info.m_info)
{
///////////////////////////////////////////////////////////////////////////////////////////////
@@ -277,8 +278,12 @@ bool CSystemGUIInfo::GetLabel(std::string& value, const CFileItem *item, int con
value = g_langInfo.GetTemperatureUnitString();
return true;
case SYSTEM_FRIENDLY_NAME:
- value = CSysInfo::GetDeviceName();
- return true;
+ {
+ std::string hostname("osmc");
+ CServiceBroker::GetNetwork().GetHostName(hostname);
+ strLabel = hostname.c_str();
+ return true;
+ }
case SYSTEM_STEREOSCOPIC_MODE:
{
int iStereoMode = CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_VIDEOSCREEN_STEREOSCOPICMODE);
diff --git a/xbmc/network/NetworkServices.cpp b/xbmc/network/NetworkServices.cpp
index cbbac07..18faef5 100644
--- a/xbmc/network/NetworkServices.cpp
+++ b/xbmc/network/NetworkServices.cpp
@@ -131,7 +131,8 @@ CNetworkServices::CNetworkServices()
CSettings::SETTING_SMB_WORKGROUP,
CSettings::SETTING_SMB_MINPROTOCOL,
CSettings::SETTING_SMB_MAXPROTOCOL,
- CSettings::SETTING_SMB_LEGACYSECURITY
+ CSettings::SETTING_SMB_LEGACYSECURITY,
+ CSettings::SETTING_SERVICES_DEVICENAME
};
m_settings = CServiceBroker::GetSettingsComponent()->GetSettings();
m_settings->GetSettingsManager()->RegisterCallback(this, settingSet);
@@ -448,6 +449,23 @@ void CNetworkServices::OnSettingChanged(std::shared_ptr<const CSetting> setting)
CApplicationMessenger::GetInstance().PostMsg(TMSG_RESTARTAPP);
}
}
+
+ if (settingId == "services.devicename")
+ {
+ std::string newHostName = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString("services.devicename");
+ FILE *fp;
+ fp = fopen("/tmp/hostname", "w");
+ if (fp)
+ {
+ fprintf(fp, "%s", newHostName.c_str());
+ fclose(fp);
+ }
+ else
+ return;
+ system("/usr/bin/sudo /bin/mv /tmp/hostname /etc/hostname");
+ system("/usr/bin/sudo /bin/hostname -F /etc/hostname");
+ }
+
}
bool CNetworkServices::OnSettingUpdate(std::shared_ptr<CSetting> setting, const char *oldSettingId, const TiXmlNode *oldSettingNode)
--
2.7.4
Sam