diff --git a/unloader/Config.py b/unloader/Config.py index 4001f57..f4cfca7 100644 --- a/unloader/Config.py +++ b/unloader/Config.py @@ -14,7 +14,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from PySide2.QtCore import QObject, Signal +import os +from PySide2.QtCore import QObject, Signal, QSettings class Config(QObject): @@ -23,6 +24,9 @@ class Config(QObject): thresholdChanged = Signal(int) settingsFileChanged = Signal(str) + configLoaded = Signal() + configSaved = Signal() + def __init__(self, updateInterval=None, closeThreshold=None, threshold=None, settingsFile=None): super().__init__() @@ -31,6 +35,39 @@ class Config(QObject): 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 diff --git a/unloader/manager.py b/unloader/manager.py index 5dcd923..320ee5a 100644 --- a/unloader/manager.py +++ b/unloader/manager.py @@ -41,7 +41,7 @@ class UnloaderManager(QtCore.QObject): closeThreshold=0, updateInterval=5 ) - self.loadSettings() + self.config.load() self.tabs = {} @@ -125,33 +125,9 @@ class UnloaderManager(QtCore.QObject): lambda r: self.onTabRestoredChanged(tab, r) ) - def loadSettings(self): - settings = QtCore.QSettings(self.config.settingsFile, QtCore.QSettings.IniFormat) - - settings.beginGroup("Unloader") - self.config.threshold = int(settings.value("threshold", self.config.threshold)) - self.config.closeThreshold = int( - settings.value("closeThreshold", self.config.closeThreshold) - ) - self.config.updateInterval = int( - settings.value("defaultZoom", self.config.updateInterval) - ) - settings.endGroup() - - def saveSettings(self): - settings = QtCore.QSettings(self.config.settingsFile, QtCore.QSettings.IniFormat) - - settings.beginGroup("Unloader") - settings.setValue("threshold", self.config.threshold) - settings.setValue("closeThreshold", self.config.closeThreshold) - settings.setValue("updateInterval", self.config.updateInterval) - settings.endGroup() - - settings.sync() - def showSettings(self, parent=None): settings = SettingsDialog(self.config, parent) - settings.accepted.connect(self.saveSettings) + settings.accepted.connect(self.config.save) settings.accepted.connect(self.configChanged) settings.exec_()