Config: Add load and save methods
Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
This commit is contained in:
parent
8502b8265e
commit
983572eb43
@ -14,7 +14,8 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# 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):
|
||||
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user