# ============================================================ # Tab Counter - plugin for Falkon # Copyright (C) 2020 Juraj Oravec # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # ============================================================ import os from PySide2.QtCore import QObject, Signal, QSettings class Config(QObject): displayTypeChanged = Signal(int) enableTooltipChanged = Signal(bool) settingsFileChanged = Signal(str) configLoaded = Signal() configSaved = Signal() def __init__(self, displayType=None, settingsFile=None, enableTooltip=None): super().__init__() self._displayType = displayType self._settingsFile = settingsFile self._enableTooltip = enableTooltip def load(self): if not self.settingsFile: return if os.path.exists(self.settingsFile): pass settings = QSettings(self.settingsFile, QSettings.IniFormat) settings.beginGroup("Config") self.displayType = int(settings.value("displayType", self.displayType)) self.enableTooltip = settings.value("enableTooltip", self.enableTooltip) == "true" settings.endGroup() self.configLoaded.emit() def save(self): if not self.settingsFile: return if os.path.exists(self.settingsFile): pass settings = QSettings(self.settingsFile, QSettings.IniFormat) settings.beginGroup("Config") settings.setValue("displayType", self.displayType) settings.setValue("enableTooltip", self.enableTooltip) settings.endGroup() settings.sync() self.configSaved.emit() @property def displayType(self): return self._displayType @displayType.setter def displayType(self, displayType): if not displayType: return if self._displayType == displayType: return self._displayType = displayType self.displayTypeChanged.emit(displayType) @property def enableTooltip(self): return self._enableTooltip @enableTooltip.setter def enableTooltip(self, enableTooltip): if not isinstance(enableTooltip, bool): return if self._enableTooltip == enableTooltip: return self._enableTooltip = enableTooltip self.enableTooltipChanged.emit(enableTooltip) @property def settingsFile(self): return self._settingsFile @settingsFile.setter def settingsFile(self, settingsFile): if not settingsFile: return if self._settingsFile == settingsFile: return self._settingsFile = settingsFile self.settingsFileChanged.emit(settingsFile)