tabCounter/tabcounter/config.py
Juraj Oravec 3e95e04610
Add Config class, ability to display different data
Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
2020-02-29 21:18:13 +01:00

94 lines
2.7 KiB
Python

# ============================================================
# Tab Counter - plugin for Falkon
# Copyright (C) 2020 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 PySide2.QtCore import QObject, Signal, QSettings
class Config(QObject):
displayTypeChanged = Signal(int)
settingsFileChanged = Signal(str)
configLoaded = Signal()
configSaved = Signal()
def __init__(self, displayType=None, settingsFile=None):
super().__init__()
self._displayType = displayType
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("Config")
self.displayType = int(settings.value("displayType", self.displayType))
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("Config")
settings.setValue("displayType", self.displayType)
settings.endGroup()
settings.sync()
self.configSaved.emit()
@property
def displayType(self):
return self._displayType
@displayType.setter
def displayType(self, displayType):
if not displayType:
return
if self._displayType == displayType:
return
self._displayType = displayType
self.displayTypeChanged.emit(displayType)
@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)