# Path: resources/lib/model/settings/category.py
# class Category(object):
#     def __init__(self, cat_id, cat_label, priority):
#         self.cat_id = cat_id
#         self.cat_label = cat_label
#         self.priority = priority
#         self.settings = {}
# 
# Path: resources/lib/model/settings/setting.py
# class Setting(object):
#     def __init__(self, setting_id, setting_label, priority, *args, **kwargs):
#         self.setting_id = setting_id
#         self.setting_label = setting_label
#         self.priority = priority
# 
#         if 'type' in kwargs.keys():
#             self.type = kwargs['type']
#         else:
#             self.type = None  # TODO: This should never happen
# 
#         if 'default' in kwargs.keys():
#             self.default = kwargs['default']
#         else:
#             self.default = None
# 
#         if 'visible' in kwargs.keys():
#             self.visible = kwargs['visible']
#         else:
#             self.visible = None
# 
#         if 'enable' in kwargs.keys():
#             self.enable = kwargs['enable']
#         else:
#             self.enable = None
# 
#         if 'values' in kwargs.keys():
#             self.values = kwargs['values']  # TODO: Parse into list
#         else:
#             self.values = None
# 
#         if 'range' in kwargs.keys():
#             self.range = kwargs['range']  # TODO: Parse into list
#         else:
#             self.range = None
# 
#         if 'option' in kwargs.keys():
#             self.option = kwargs['option']
#         else:
#             self.option = None
# 
#         if 'subsetting' in kwargs.keys():
#             self.subsetting = kwargs['subsetting']
#         else:
#             self.subsetting = None
# 
#         if 'current_value' in kwargs.keys():
#             self.current_value = kwargs['current_value']
#         else:
#             self.current_value = self.default
# 
#         if 'action' in kwargs.keys():
#             self.route = kwargs['action']
#         else:
#             self.route = None
# 
#         if 'file_mask' in kwargs.keys():
#             self.file_mask = kwargs['file_mask']
#         else:
#             self.file_mask = ""


import hashlib
import os
import xml.etree.ElementTree as ET
from resources.lib.model.settings.category import Category
from resources.lib.model.settings.setting import Setting
        self.settings_hash = self._get_settings_hash()
        self.settings_dict = {}

    def _get_settings_hash(self):
        settings_file = open(self.settings_path, 'rb')
        hasher = hashlib.sha256()
        blocksize = 65536
        buf = settings_file.read(blocksize)
        while len(buf) > 0:
            hasher.update(buf)
            buf = settings_file.read(blocksize)
        return hasher.hexdigest()

    def _reload_settings(self):
        if self._get_settings_hash() != self.settings_hash:
            etree = ET.ElementTree(file=self.settings_path)
            self.settings_tree = etree.getroot()

    def get_settings(self):
        if self.settings_hash == self._get_settings_hash() and len(self.settings_dict) > 0:
            self.update_values()
            return self.settings_dict
        else:
            self._reload_settings()

            cat_prio = 1

            for category in self.settings_tree.findall('category'):
                cat_label_id = category.get('label')
                cat_label = self.core.string(int(cat_label_id))

# Path: resources/lib/model/settings/category.py
# class Category(object):
#     def __init__(self, cat_id, cat_label, priority):
#         self.cat_id = cat_id
#         self.cat_label = cat_label
#         self.priority = priority
#         self.settings = {}
# 
# Path: resources/lib/model/settings/setting.py
# class Setting(object):
#     def __init__(self, setting_id, setting_label, priority, *args, **kwargs):
#         self.setting_id = setting_id
#         self.setting_label = setting_label
#         self.priority = priority
# 
#         if 'type' in kwargs.keys():
#             self.type = kwargs['type']
#         else:
#             self.type = None  # TODO: This should never happen
# 
#         if 'default' in kwargs.keys():
#             self.default = kwargs['default']
#         else:
#             self.default = None
# 
#         if 'visible' in kwargs.keys():
#             self.visible = kwargs['visible']
#         else:
#             self.visible = None
# 
#         if 'enable' in kwargs.keys():
#             self.enable = kwargs['enable']
#         else:
#             self.enable = None
# 
#         if 'values' in kwargs.keys():
#             self.values = kwargs['values']  # TODO: Parse into list
#         else:
#             self.values = None
# 
#         if 'range' in kwargs.keys():
#             self.range = kwargs['range']  # TODO: Parse into list
#         else:
#             self.range = None
# 
#         if 'option' in kwargs.keys():
#             self.option = kwargs['option']
#         else:
#             self.option = None
# 
#         if 'subsetting' in kwargs.keys():
#             self.subsetting = kwargs['subsetting']
#         else:
#             self.subsetting = None
# 
#         if 'current_value' in kwargs.keys():
#             self.current_value = kwargs['current_value']
#         else:
#             self.current_value = self.default
# 
#         if 'action' in kwargs.keys():
#             self.route = kwargs['action']
#         else:
#             self.route = None
# 
#         if 'file_mask' in kwargs.keys():
#             self.file_mask = kwargs['file_mask']
#         else:
#             self.file_mask = ""


# Path: resources/lib/util/settingsparser.py
import hashlib
import os
import xml.etree.ElementTree as ET
from resources.lib.model.settings.category import Category
from resources.lib.model.settings.setting import Setting

        self.settings_hash = self._get_settings_hash()
        self.settings_dict = {}

    def _get_settings_hash(self):
        settings_file = open(self.settings_path, 'rb')
        hasher = hashlib.sha256()
        blocksize = 65536
        buf = settings_file.read(blocksize)
        while len(buf) > 0:
            hasher.update(buf)
            buf = settings_file.read(blocksize)
        return hasher.hexdigest()

    def _reload_settings(self):
        if self._get_settings_hash() != self.settings_hash:
            etree = ET.ElementTree(file=self.settings_path)
            self.settings_tree = etree.getroot()

    def get_settings(self):
        if self.settings_hash == self._get_settings_hash() and len(self.settings_dict) > 0:
            self.update_values()
            return self.settings_dict
        else:
            self._reload_settings()

            cat_prio = 1

            for category in self.settings_tree.findall('category'):
                cat_label_id = category.get('label')
                cat_label = self.core.string(int(cat_label_id))

                cat = Category(cat_label_id, cat_label, cat_prio)