Config: Add load and save methods

Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
This commit is contained in:
Juraj Oravec 2019-06-26 09:00:33 +02:00
parent 8502b8265e
commit 983572eb43
No known key found for this signature in database
GPG Key ID: 63ACB65056BC8D07
2 changed files with 46 additions and 1 deletions

View File

@ -14,7 +14,8 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from PySide2.QtCore import Signal, QObject import os
from PySide2.QtCore import Signal, QObject, QSettings
class Config(QObject): class Config(QObject):
@ -26,6 +27,9 @@ class Config(QObject):
separatorCountChanged = Signal(int) separatorCountChanged = Signal(int)
separatorWidthChanged = Signal(int) separatorWidthChanged = Signal(int)
configLoaded = Signal()
configSaved = Signal()
def __init__(self, parent=None): def __init__(self, parent=None):
super().__init__(parent) super().__init__(parent)
@ -37,6 +41,44 @@ class Config(QObject):
self._separatorCount = 2 self._separatorCount = 2
self._separatorWidth = 5 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 @property
def settingsFile(self): def settingsFile(self):
return self._settingsFile return self._settingsFile

View File

@ -33,6 +33,7 @@ class ToolbarTools(Falkon.PluginInterface, QtCore.QObject):
self.config = Config() self.config = Config()
self.config.settingsFile = os.path.join(settingsPath, "ToolbarTools", "settings.ini") self.config.settingsFile = os.path.join(settingsPath, "ToolbarTools", "settings.ini")
self.config.load()
plugins = Falkon.MainApplication.instance().plugins() plugins = Falkon.MainApplication.instance().plugins()
@ -44,6 +45,8 @@ class ToolbarTools(Falkon.PluginInterface, QtCore.QObject):
self.onMainWindowCreated(window) self.onMainWindowCreated(window)
def unload(self): def unload(self):
self.config.save()
for window in Falkon.MainApplication.instance().windows(): for window in Falkon.MainApplication.instance().windows():
self.mainWindowDeleted(window) self.mainWindowDeleted(window)