diff --git a/toolbartools/Config.py b/toolbartools/Config.py index 7d685fa..f55bc18 100644 --- a/toolbartools/Config.py +++ b/toolbartools/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 Signal, QObject +import os +from PySide2.QtCore import Signal, QObject, QSettings class Config(QObject): @@ -26,6 +27,9 @@ class Config(QObject): separatorCountChanged = Signal(int) separatorWidthChanged = Signal(int) + configLoaded = Signal() + configSaved = Signal() + def __init__(self, parent=None): super().__init__(parent) @@ -37,6 +41,44 @@ class Config(QObject): 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 diff --git a/toolbartools/__init__.py b/toolbartools/__init__.py index ecd6064..1d57034 100644 --- a/toolbartools/__init__.py +++ b/toolbartools/__init__.py @@ -33,6 +33,7 @@ class ToolbarTools(Falkon.PluginInterface, QtCore.QObject): self.config = Config() self.config.settingsFile = os.path.join(settingsPath, "ToolbarTools", "settings.ini") + self.config.load() plugins = Falkon.MainApplication.instance().plugins() @@ -44,6 +45,8 @@ class ToolbarTools(Falkon.PluginInterface, QtCore.QObject): self.onMainWindowCreated(window) def unload(self): + self.config.save() + for window in Falkon.MainApplication.instance().windows(): self.mainWindowDeleted(window)