2014-10-31 17:40:47 +01:00
|
|
|
import json
|
2019-11-25 22:48:42 +01:00
|
|
|
import xbmc
|
2019-08-27 21:55:22 +02:00
|
|
|
from . import utils as utils
|
2014-10-31 17:40:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
class GuiSettingsManager:
|
2020-12-03 21:08:25 +01:00
|
|
|
filename = 'kodi_settings.json'
|
|
|
|
systemSettings = None
|
2019-11-25 22:33:34 +01:00
|
|
|
|
2019-09-11 17:01:49 +02:00
|
|
|
def __init__(self):
|
2020-12-03 21:08:25 +01:00
|
|
|
# get all of the current Kodi settings
|
|
|
|
json_response = json.loads(xbmc.executeJSONRPC('{"jsonrpc":"2.0", "id":1, "method":"Settings.GetSettings","params":{"level":"expert"}}'))
|
2019-11-25 22:33:34 +01:00
|
|
|
|
2020-12-03 21:08:25 +01:00
|
|
|
self.systemSettings = json_response['result']['settings']
|
2019-11-25 22:33:34 +01:00
|
|
|
|
2020-12-03 21:08:25 +01:00
|
|
|
def backup(self):
|
|
|
|
utils.log('Backing up Kodi settings')
|
2019-11-25 22:33:34 +01:00
|
|
|
|
2020-12-03 21:08:25 +01:00
|
|
|
# return all current settings
|
|
|
|
return self.systemSettings
|
2019-11-25 22:33:34 +01:00
|
|
|
|
2020-12-03 21:08:25 +01:00
|
|
|
def restore(self, restoreSettings):
|
|
|
|
utils.log('Restoring Kodi settings')
|
2019-11-25 22:33:34 +01:00
|
|
|
|
2020-12-03 21:08:25 +01:00
|
|
|
updateJson = {"jsonrpc": "2.0", "id": 1, "method": "Settings.SetSettingValue", "params": {"setting": "", "value": ""}}
|
2019-11-25 22:33:34 +01:00
|
|
|
|
2020-12-03 21:08:25 +01:00
|
|
|
# create a setting=value dict of the current settings
|
|
|
|
settingsDict = {}
|
|
|
|
for aSetting in self.systemSettings:
|
|
|
|
# ignore action types, no value
|
|
|
|
if(aSetting['type'] != 'action'):
|
|
|
|
settingsDict[aSetting['id']] = aSetting['value']
|
2019-11-25 22:33:34 +01:00
|
|
|
|
2020-12-03 21:08:25 +01:00
|
|
|
restoreCount = 0
|
|
|
|
for aSetting in restoreSettings:
|
2022-06-14 16:14:23 +02:00
|
|
|
# Ensure key exists before referencing
|
|
|
|
if(aSetting['id'] in settingsDict.values()):
|
2020-12-03 21:08:25 +01:00
|
|
|
# only update a setting if its different than the current (action types have no value)
|
2022-06-14 16:14:23 +02:00
|
|
|
if(aSetting['type'] != 'action' and settingsDict[aSetting['id']] != aSetting['value']):
|
|
|
|
if(utils.getSettingBool('verbose_logging')):
|
|
|
|
utils.log('%s different than current: %s' % (aSetting['id'], str(aSetting['value'])))
|
2019-11-25 22:33:34 +01:00
|
|
|
|
2020-12-03 21:08:25 +01:00
|
|
|
updateJson['params']['setting'] = aSetting['id']
|
|
|
|
updateJson['params']['value'] = aSetting['value']
|
2019-11-25 22:33:34 +01:00
|
|
|
|
2020-12-03 21:08:25 +01:00
|
|
|
xbmc.executeJSONRPC(json.dumps(updateJson))
|
|
|
|
restoreCount = restoreCount + 1
|
2019-11-25 22:33:34 +01:00
|
|
|
|
2020-12-03 21:08:25 +01:00
|
|
|
utils.log('Update %d settings' % restoreCount)
|