# Toolbar Tools - Falkon plugin # Copyright (C) 2019 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 PySide6.QtCore import Signal, QObject, QSettings class Config(QObject): settingsFileChanged = Signal(str) spacerCountChanged = Signal(int) spacerMaxWidthChanged = Signal(int) separatorCountChanged = Signal(int) separatorWidthChanged = Signal(int) configLoaded = Signal() configSaved = Signal() def __init__(self, parent=None): super().__init__(parent) self._settingsFile = "" self._spacerCount = 2 self._spacerMaxWidth = 150 self._separatorCount = 2 self._separatorWidth = 5 def load(self): if not self.settingsFile: return if os.path.exists(self.settingsFile): pass settings = QSettings(self.settingsFile, QSettings.IniFormat) settings.beginGroup("ToolbarTools") self.spacerCount = int(settings.value("spacerCount", self.spacerCount)) self.spacerMaxWidth = int(settings.value("spacerMaxWidth", self.spacerMaxWidth)) self.separatorCount = int(settings.value("separatorCount", self.separatorCount)) self.separatorWidth = int(settings.value("separatorWidth", self.separatorWidth)) 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("ToolbarTools") settings.setValue("spacerCount", self.spacerCount) settings.setValue("spacerMaxWidth", self.spacerMaxWidth) settings.setValue("separatorCount", self.separatorCount) settings.setValue("separatorWidth", self.separatorWidth) settings.endGroup() settings.sync() self.configSaved.emit() @property def settingsFile(self): return self._settingsFile @settingsFile.setter def settingsFile(self, filePath): if not filePath: return if self._settingsFile == filePath: return self._settingsFile = filePath self.settingsFileChanged.emit(filePath) @property def spacerCount(self): return self._spacerCount @spacerCount.setter def spacerCount(self, count): if count < 0: return if self._spacerCount == count: return self._spacerCount = count self.spacerCountChanged.emit(count) @property def spacerMaxWidth(self): return self._spacerMaxWidth @spacerMaxWidth.setter def spacerMaxWidth(self, maxWidth): if maxWidth < 0: return if self._spacerMaxWidth == maxWidth: return self._spacerMaxWidth = maxWidth self.spacerMaxWidthChanged.emit(maxWidth) @property def separatorCount(self): return self._separatorCount @separatorCount.setter def separatorCount(self, count): if count < 0: return if self._separatorCount == count: return self._separatorCount = count self.separatorCountChanged.emit(count) @property def separatorWidth(self): return self._separatorWidth @separatorWidth.setter def separatorWidth(self, width): if width < 0: return if self._separatorWidth == width: return self._separatorWidth = width self.separatorWidthChanged.emit(width)