2014-10-31 17:40:47 +01:00
|
|
|
import json
|
|
|
|
import xbmc,xbmcvfs
|
2019-09-30 21:06:50 +02:00
|
|
|
from . import utils as utils
|
2014-10-31 17:40:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
class GuiSettingsManager:
|
2020-12-03 20:59:15 +01:00
|
|
|
systemSettings = None
|
|
|
|
|
2019-09-11 17:01:49 +02:00
|
|
|
def __init__(self):
|
2020-12-03 20:59:15 +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"}}').decode('utf-8', errors="ignore"))
|
|
|
|
|
|
|
|
self.systemSettings = json_response['result']['settings']
|
|
|
|
|
|
|
|
def backup(self):
|
|
|
|
utils.log('Backing up Kodi settings')
|
|
|
|
|
|
|
|
# return all current settings
|
|
|
|
return self.systemSettings
|
|
|
|
|
|
|
|
def restore(self, restoreSettings):
|
|
|
|
utils.log('Restoring Kodi settings')
|
|
|
|
|
|
|
|
updateJson = {"jsonrpc": "2.0", "id": 1, "method": "Settings.SetSettingValue", "params": {"setting": "", "value": ""}}
|
|
|
|
|
|
|
|
# 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']
|
|
|
|
|
|
|
|
restoreCount = 0
|
|
|
|
for aSetting in restoreSettings:
|
|
|
|
# only update a setting if its different than the current (action types have no value)
|
|
|
|
if(aSetting['type'] != 'action' and settingsDict[aSetting['id']] != aSetting['value']):
|
|
|
|
utils.log('%s different than current: %s' % (aSetting['id'], str(aSetting['value'])), xbmc.LOGDEBUG)
|
|
|
|
|
|
|
|
updateJson['params']['setting'] = aSetting['id']
|
|
|
|
updateJson['params']['value'] = aSetting['value']
|
|
|
|
|
|
|
|
xbmc.executeJSONRPC(json.dumps(updateJson))
|
|
|
|
restoreCount = restoreCount + 1
|
2014-10-31 17:40:47 +01:00
|
|
|
|
2020-12-03 20:59:15 +01:00
|
|
|
utils.log('Update %d settings' % restoreCount)
|