# Path: resources/lib/jsonrpc.py
# class JsonRpc(object):
# 
#     id_ = 1
#     jsonrpc = "2.0"
#     params = None
# 
#     def __init__(self, method, **kwargs):
#         
#         self.method = method
# 
#         for arg in kwargs:  # id_(int), jsonrpc(str)
#             self.arg = arg
# 
#     def _query(self):
# 
#         query = {
#             
#             'jsonrpc': self.jsonrpc,
#             'id': self.id_,
#             'method': self.method,
#         }
#         if self.params is not None:
#             query['params'] = self.params
# 
#         return json.dumps(query)
# 
#     def execute(self, params=None):
# 
#         self.params = params
#         return json.loads(xbmc.executeJSONRPC(self._query()))
# 
# def get_value(name):
#     result = JsonRpc('Settings.getSettingValue').execute({'setting': name})
#     return result['result']['value']
# 
# def set_value(name, value):
#     params = {
#         'setting': name,
#         'value': value
#     }
#     result = JsonRpc('Settings.setSettingValue').execute(params)
#     return result
# 
# Path: resources/lib/simple_logging.py
# class SimpleLogging:
#     name = ""
#     enable_logging = False
# 
#     def __init__(self, name):
#         settings = xbmcaddon.Addon()
#         prefix = settings.getAddonInfo('name')
#         self.name = prefix + '.' + name
#         self.enable_logging = settings.getSetting('log_debug') == "true"
# 
#         # params = {"setting": "debug.showloginfo"}
#         # setting_result = json_rpc('Settings.getSettingValue').execute(params)
#         # current_value = setting_result.get("result", None)
#         # if current_value is not None:
#         #     self.enable_logging = current_value.get("value", False)
#         # xbmc.log("LOGGING_ENABLED %s : %s" % (self.name, str(self.enable_logging)), level=xbmc.LOGDEBUG)
# 
#     def __str__(self):
#         return "LoggingEnabled: " + str(self.enable_logging)
# 
#     def info(self, fmt, *args, **kwargs):
#         log_line = self.name + "|INFO|" + self.log_line(fmt, *args)
#         xbmc.log(log_line, level=xbmc.LOGNOTICE)
# 
#     def error(self, fmt, *args, **kwargs):
#         log_line = self.name + "|ERROR|" + self.log_line(fmt, *args)
#         xbmc.log(log_line, level=xbmc.LOGERROR)
# 
#     def debug(self, fmt, *args, **kwargs):
#         if self.enable_logging:
#             log_line = self.name + "|DEBUG|" + self.log_line(fmt, *args)
#             xbmc.log(log_line, level=xbmc.LOGNOTICE)
# 
#     @staticmethod
#     def log_line(fmt, *args):
#         new_args = []
#         # convert any unicode to utf-8 strings
#         for arg in args:
#             if isinstance(arg, unicode):
#                 new_args.append(arg.encode("utf-8"))
#             else:
#                 new_args.append(arg)
#         log_line = fmt.format(*new_args)
#         return log_line


import os
import xbmc
import xbmcgui
import xbmcvfs
from .jsonrpc import JsonRpc, get_value, set_value
from .simple_logging import SimpleLogging
    file_list = ["Home.xml",
                 "Includes_Home.xml",
                 "DialogVideoInfo.xml",
                 "DialogSeekBar.xml",
                 "VideoOSD.xml"]

    for file_name in file_list:
        source = os.path.join(embycon_path, "resources", "skins", "skin.estuary", ver, "xml", file_name)
        destination = os.path.join(kodi_skin_destination, "xml", file_name)
        xbmcvfs.copy(source, destination)

    xbmc.executebuiltin("UpdateLocalAddons")

    pdialog.close()
    del pdialog

    response = xbmcgui.Dialog().yesno("EmbyCon Skin Cloner", "Do you want to switch to the new cloned skin?")
    if not response:
        return

    params = {
        'addonid': "skin.estuary_embycon",
        'enabled': True
    }
    result = JsonRpc('Addons.SetAddonEnabled').execute(params)
    log.debug("Addons.SetAddonEnabled : {0}", result)

    log.debug("SkinCloner : Current Skin : " + get_value("lookandfeel.skin"))
    set_result = set_value("lookandfeel.skin", "skin.estuary_embycon")
    log.debug("Save Setting : lookandfeel.skin : {0}", set_result)

# Path: resources/lib/jsonrpc.py
# class JsonRpc(object):
# 
#     id_ = 1
#     jsonrpc = "2.0"
#     params = None
# 
#     def __init__(self, method, **kwargs):
#         
#         self.method = method
# 
#         for arg in kwargs:  # id_(int), jsonrpc(str)
#             self.arg = arg
# 
#     def _query(self):
# 
#         query = {
#             
#             'jsonrpc': self.jsonrpc,
#             'id': self.id_,
#             'method': self.method,
#         }
#         if self.params is not None:
#             query['params'] = self.params
# 
#         return json.dumps(query)
# 
#     def execute(self, params=None):
# 
#         self.params = params
#         return json.loads(xbmc.executeJSONRPC(self._query()))
# 
# def get_value(name):
#     result = JsonRpc('Settings.getSettingValue').execute({'setting': name})
#     return result['result']['value']
# 
# def set_value(name, value):
#     params = {
#         'setting': name,
#         'value': value
#     }
#     result = JsonRpc('Settings.setSettingValue').execute(params)
#     return result
# 
# Path: resources/lib/simple_logging.py
# class SimpleLogging:
#     name = ""
#     enable_logging = False
# 
#     def __init__(self, name):
#         settings = xbmcaddon.Addon()
#         prefix = settings.getAddonInfo('name')
#         self.name = prefix + '.' + name
#         self.enable_logging = settings.getSetting('log_debug') == "true"
# 
#         # params = {"setting": "debug.showloginfo"}
#         # setting_result = json_rpc('Settings.getSettingValue').execute(params)
#         # current_value = setting_result.get("result", None)
#         # if current_value is not None:
#         #     self.enable_logging = current_value.get("value", False)
#         # xbmc.log("LOGGING_ENABLED %s : %s" % (self.name, str(self.enable_logging)), level=xbmc.LOGDEBUG)
# 
#     def __str__(self):
#         return "LoggingEnabled: " + str(self.enable_logging)
# 
#     def info(self, fmt, *args, **kwargs):
#         log_line = self.name + "|INFO|" + self.log_line(fmt, *args)
#         xbmc.log(log_line, level=xbmc.LOGNOTICE)
# 
#     def error(self, fmt, *args, **kwargs):
#         log_line = self.name + "|ERROR|" + self.log_line(fmt, *args)
#         xbmc.log(log_line, level=xbmc.LOGERROR)
# 
#     def debug(self, fmt, *args, **kwargs):
#         if self.enable_logging:
#             log_line = self.name + "|DEBUG|" + self.log_line(fmt, *args)
#             xbmc.log(log_line, level=xbmc.LOGNOTICE)
# 
#     @staticmethod
#     def log_line(fmt, *args):
#         new_args = []
#         # convert any unicode to utf-8 strings
#         for arg in args:
#             if isinstance(arg, unicode):
#                 new_args.append(arg.encode("utf-8"))
#             else:
#                 new_args.append(arg)
#         log_line = fmt.format(*new_args)
#         return log_line


# Path: resources/lib/skin_cloner.py
import os
import xbmc
import xbmcgui
import xbmcvfs
from .jsonrpc import JsonRpc, get_value, set_value
from .simple_logging import SimpleLogging

    file_list = ["Home.xml",
                 "Includes_Home.xml",
                 "DialogVideoInfo.xml",
                 "DialogSeekBar.xml",
                 "VideoOSD.xml"]

    for file_name in file_list:
        source = os.path.join(embycon_path, "resources", "skins", "skin.estuary", ver, "xml", file_name)
        destination = os.path.join(kodi_skin_destination, "xml", file_name)
        xbmcvfs.copy(source, destination)

    xbmc.executebuiltin("UpdateLocalAddons")

    pdialog.close()
    del pdialog

    response = xbmcgui.Dialog().yesno("EmbyCon Skin Cloner", "Do you want to switch to the new cloned skin?")
    if not response:
        return

    params = {
        'addonid': "skin.estuary_embycon",
        'enabled': True
    }
    result = JsonRpc('Addons.SetAddonEnabled').execute(params)
    log.debug("Addons.SetAddonEnabled : {0}", result)

    log.debug("SkinCloner : Current Skin : " + get_value("lookandfeel.skin"))
    set_result = set_value("lookandfeel.skin", "skin.estuary_embycon")
    log.debug("Save Setting : lookandfeel.skin : {0}", set_result)

    log.debug("SkinCloner : Current Skin : " + get_value("lookandfeel.skin"))