| 1 |
/* |
| 2 |
* Copyright (C) 2010-2021 Team Kodi (https://kodi.tv) |
| 3 |
* Copyright (C) 2020 Alwin Esch (Team Kodi) |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSE.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "Settings.h" |
| 10 |
|
| 11 |
#include <kodi/General.h> |
| 12 |
|
| 13 |
namespace |
| 14 |
{ |
| 15 |
int prioVals[] = {0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, |
| 16 |
55, 60, 65, 70, 75, 80, 85, 90, 95, 99, 100}; |
| 17 |
} |
| 18 |
|
| 19 |
CVNSISettings& CVNSISettings::Get() |
| 20 |
{ |
| 21 |
static CVNSISettings settings; |
| 22 |
return settings; |
| 23 |
} |
| 24 |
|
| 25 |
bool CVNSISettings::Load() |
| 26 |
{ |
| 27 |
// Read setting "host" from settings.xml |
| 28 |
if (!kodi::addon::CheckSettingString("host", m_szHostname)) |
| 29 |
{ |
| 30 |
// If setting is unknown fallback to defaults |
| 31 |
kodi::Log(ADDON_LOG_ERROR, "Couldn't get 'host' setting, falling back to '%s' as default", |
| 32 |
DEFAULT_HOST); |
| 33 |
m_szHostname = DEFAULT_HOST; |
| 34 |
} |
| 35 |
|
| 36 |
// Read setting "wol_mac" from settings.xml |
| 37 |
if (!kodi::addon::CheckSettingString("wol_mac", m_szWolMac)) |
| 38 |
{ |
| 39 |
// If setting is unknown fallback to empty default |
| 40 |
kodi::Log(ADDON_LOG_ERROR, "Couldn't get 'wol_mac' setting, falling back to default"); |
| 41 |
m_szWolMac = ""; |
| 42 |
} |
| 43 |
|
| 44 |
// Read setting "port" from settings.xml |
| 45 |
if (!kodi::addon::CheckSettingInt("port", m_iPort)) |
| 46 |
{ |
| 47 |
// If setting is unknown fallback to defaults |
| 48 |
kodi::Log(ADDON_LOG_ERROR, "Couldn't get 'port' setting, falling back to '%i' as default", |
| 49 |
DEFAULT_PORT); |
| 50 |
m_iPort = DEFAULT_PORT; |
| 51 |
} |
| 52 |
|
| 53 |
// Read setting "priority" from settings.xml |
| 54 |
int prio = DEFAULT_PRIORITY; |
| 55 |
if (kodi::addon::CheckSettingInt("priority", prio)) |
| 56 |
{ |
| 57 |
m_iPriority = prioVals[prio]; |
| 58 |
} |
| 59 |
else |
| 60 |
{ |
| 61 |
// If setting is unknown fallback to defaults |
| 62 |
kodi::Log(ADDON_LOG_ERROR, "Couldn't get 'priority' setting, falling back to %i as default", |
| 63 |
-1); |
| 64 |
m_iPriority = DEFAULT_PRIORITY; |
| 65 |
} |
| 66 |
|
| 67 |
/* Read setting "timeshift" from settings.xml */ |
| 68 |
if (!kodi::addon::CheckSettingInt("timeshift", m_iTimeshift)) |
| 69 |
{ |
| 70 |
// If setting is unknown fallback to defaults |
| 71 |
kodi::Log(ADDON_LOG_ERROR, "Couldn't get 'timeshift' setting, falling back to %i as default", |
| 72 |
1); |
| 73 |
m_iTimeshift = 1; |
| 74 |
} |
| 75 |
|
| 76 |
// Read setting "convertchar" from settings.xml |
| 77 |
if (!kodi::addon::CheckSettingBoolean("convertchar", m_bCharsetConv)) |
| 78 |
{ |
| 79 |
/* If setting is unknown fallback to defaults */ |
| 80 |
kodi::Log(ADDON_LOG_ERROR, |
| 81 |
"Couldn't get 'convertchar' setting, falling back to 'false' as default"); |
| 82 |
m_bCharsetConv = DEFAULT_CHARCONV; |
| 83 |
} |
| 84 |
|
| 85 |
// Read setting "timeout" from settings.xml |
| 86 |
if (!kodi::addon::CheckSettingInt("timeout", m_iConnectTimeout)) |
| 87 |
{ |
| 88 |
/* If setting is unknown fallback to defaults */ |
| 89 |
kodi::Log(ADDON_LOG_ERROR, |
| 90 |
"Couldn't get 'timeout' setting, falling back to %i seconds as default", |
| 91 |
DEFAULT_TIMEOUT); |
| 92 |
m_iConnectTimeout = DEFAULT_TIMEOUT; |
| 93 |
} |
| 94 |
|
| 95 |
// Read setting "autochannelgroups" from settings.xml |
| 96 |
if (!kodi::addon::CheckSettingBoolean("autochannelgroups", m_bAutoChannelGroups)) |
| 97 |
{ |
| 98 |
// If setting is unknown fallback to defaults |
| 99 |
kodi::Log(ADDON_LOG_ERROR, |
| 100 |
"Couldn't get 'autochannelgroups' setting, falling back to 'false' as default"); |
| 101 |
m_bAutoChannelGroups = DEFAULT_AUTOGROUPS; |
| 102 |
} |
| 103 |
|
| 104 |
// Read setting "iconpath" from settings.xml |
| 105 |
if (!kodi::addon::CheckSettingString("iconpath", m_szIconPath)) |
| 106 |
{ |
| 107 |
// If setting is unknown fallback to defaults |
| 108 |
kodi::Log(ADDON_LOG_ERROR, "Couldn't get 'iconpath' setting"); |
| 109 |
m_szIconPath = ""; |
| 110 |
} |
| 111 |
|
| 112 |
// Read setting "chunksize" from settings.xml |
| 113 |
if (!kodi::addon::CheckSettingInt("chunksize", m_iChunkSize)) |
| 114 |
{ |
| 115 |
/* If setting is unknown fallback to defaults */ |
| 116 |
kodi::Log(ADDON_LOG_ERROR, "Couldn't get 'chunksize' setting, falling back to %i as default", |
| 117 |
DEFAULT_CHUNKSIZE); |
| 118 |
m_iChunkSize = DEFAULT_CHUNKSIZE; |
| 119 |
} |
| 120 |
|
| 121 |
return true; |
| 122 |
} |
| 123 |
|
| 124 |
ADDON_STATUS CVNSISettings::SetSetting(const std::string& settingName, |
| 125 |
const kodi::addon::CSettingValue& settingValue) |
| 126 |
{ |
| 127 |
if (settingName == "host") |
| 128 |
{ |
| 129 |
std::string tmp_sHostname; |
| 130 |
kodi::Log(ADDON_LOG_INFO, "Changed Setting 'host' from %s to %s", m_szHostname.c_str(), |
| 131 |
settingValue.GetString().c_str()); |
| 132 |
tmp_sHostname = m_szHostname; |
| 133 |
m_szHostname = settingValue.GetString(); |
| 134 |
if (tmp_sHostname != m_szHostname) |
| 135 |
return ADDON_STATUS_NEED_RESTART; |
| 136 |
} |
| 137 |
else if (settingName == "wol_mac") |
| 138 |
{ |
| 139 |
kodi::Log(ADDON_LOG_INFO, "Changed Setting 'wol_mac'"); |
| 140 |
std::string tmp_sWol_mac; |
| 141 |
kodi::Log(ADDON_LOG_INFO, "Changed Setting 'wol_mac' from %s to %s", m_szWolMac.c_str(), |
| 142 |
settingValue.GetString().c_str()); |
| 143 |
tmp_sWol_mac = m_szWolMac; |
| 144 |
m_szWolMac = settingValue.GetString(); |
| 145 |
if (tmp_sWol_mac != m_szWolMac) |
| 146 |
return ADDON_STATUS_NEED_RESTART; |
| 147 |
} |
| 148 |
else if (settingName == "port") |
| 149 |
{ |
| 150 |
kodi::Log(ADDON_LOG_INFO, "Changed Setting 'port' from %u to %u", m_iPort, |
| 151 |
settingValue.GetInt()); |
| 152 |
if (m_iPort != settingValue.GetInt()) |
| 153 |
{ |
| 154 |
m_iPort = settingValue.GetInt(); |
| 155 |
return ADDON_STATUS_NEED_RESTART; |
| 156 |
} |
| 157 |
} |
| 158 |
else if (settingName == "priority") |
| 159 |
{ |
| 160 |
int newPrio = prioVals[settingValue.GetInt()]; |
| 161 |
kodi::Log(ADDON_LOG_INFO, "Changed Setting 'priority' from %u to %u", m_iPriority, newPrio); |
| 162 |
m_iPriority = newPrio; |
| 163 |
} |
| 164 |
else if (settingName == "timeshift") |
| 165 |
{ |
| 166 |
kodi::Log(ADDON_LOG_INFO, "Changed Setting 'timeshift' from %u to %u", m_iTimeshift, |
| 167 |
settingValue.GetInt()); |
| 168 |
m_iTimeshift = settingValue.GetInt(); |
| 169 |
} |
| 170 |
else if (settingName == "convertchar") |
| 171 |
{ |
| 172 |
kodi::Log(ADDON_LOG_INFO, "Changed Setting 'convertchar' from %u to %u", m_bCharsetConv, |
| 173 |
settingValue.GetBoolean()); |
| 174 |
m_bCharsetConv = settingValue.GetBoolean(); |
| 175 |
} |
| 176 |
else if (settingName == "timeout") |
| 177 |
{ |
| 178 |
kodi::Log(ADDON_LOG_INFO, "Changed Setting 'timeout' from %u to %u", m_iConnectTimeout, |
| 179 |
settingValue.GetInt()); |
| 180 |
m_iConnectTimeout = settingValue.GetInt(); |
| 181 |
} |
| 182 |
else if (settingName == "autochannelgroups") |
| 183 |
{ |
| 184 |
kodi::Log(ADDON_LOG_INFO, "Changed Setting 'autochannelgroups' from %u to %u", |
| 185 |
m_bAutoChannelGroups, settingValue.GetBoolean()); |
| 186 |
if (m_bAutoChannelGroups != settingValue.GetBoolean()) |
| 187 |
{ |
| 188 |
m_bAutoChannelGroups = settingValue.GetBoolean(); |
| 189 |
return ADDON_STATUS_NEED_RESTART; |
| 190 |
} |
| 191 |
} |
| 192 |
else if (settingName == "chunksize") |
| 193 |
{ |
| 194 |
kodi::Log(ADDON_LOG_INFO, "Changed Setting 'chunksize' from %u to %u", m_iChunkSize, |
| 195 |
settingValue.GetInt()); |
| 196 |
m_iChunkSize = settingValue.GetInt(); |
| 197 |
} |
| 198 |
|
| 199 |
return ADDON_STATUS_OK; |
| 200 |
} |