Unloader/unloader/Config.py
Juraj Oravec 1da3a86ba2 Port to PySide6
Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
2024-12-07 15:13:22 +01:00

126 lines
3.7 KiB
Python

# Unloader - plugin for Falkon
# Copyright (C) 2019 Juraj Oravec <sgd.orava@gmail.com>
#
# 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 <http://www.gnu.org/licenses/>.
import os
from PySide6.QtCore import QObject, Signal, QSettings
class Config(QObject):
updateIntervalChanged = Signal(int)
closeThresholdChanged = Signal(int)
thresholdChanged = Signal(int)
settingsFileChanged = Signal(str)
configLoaded = Signal()
configSaved = Signal()
def __init__(self, updateInterval=None, closeThreshold=None, threshold=None, settingsFile=None):
super().__init__()
self._updateInterval = updateInterval
self._closeThreshold = closeThreshold
self._threshold = threshold
self._settingsFile = settingsFile
def load(self):
if not self.settingsFile:
return
if os.path.exists(self.settingsFile):
pass
settings = QSettings(self.settingsFile, QSettings.IniFormat)
settings.beginGroup("Unloader")
self.threshold = int(settings.value("threshold", self.threshold))
self.closeThreshold = int(
settings.value("closeThreshold", self.closeThreshold)
)
self.updateInterval = int(
settings.value("defaultZoom", self.updateInterval)
)
settings.endGroup()
self.configLoaded.emit()
def save(self):
settings = QSettings(self.settingsFile, QSettings.IniFormat)
settings.beginGroup("Unloader")
settings.setValue("threshold", self.threshold)
settings.setValue("closeThreshold", self.closeThreshold)
settings.setValue("updateInterval", self.updateInterval)
settings.endGroup()
settings.sync()
self.configSaved.emit()
@property
def updateInterval(self):
return self._updateInterval
@updateInterval.setter
def updateInterval(self, updateInterval):
if updateInterval < 1:
return
if self._updateInterval == updateInterval:
return
self._updateInterval = updateInterval
self.updateIntervalChanged.emit(updateInterval)
@property
def closeThreshold(self):
return self._closeThreshold
@closeThreshold.setter
def closeThreshold(self, closeThreshold):
if closeThreshold < 0:
return
if self._closeThreshold == closeThreshold:
return
self._closeThreshold = closeThreshold
self.closeThresholdChanged.emit(closeThreshold)
@property
def threshold(self):
return self._threshold
@threshold.setter
def threshold(self, threshold):
if threshold < 1:
return
if self._threshold == threshold:
return
self._threshold = threshold
self.thresholdChanged.emit(threshold)
@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)