Move settings load and save methods into Config

Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
This commit is contained in:
Juraj Oravec 2019-07-01 13:20:42 +02:00
parent 551bc468de
commit 97db403adc
No known key found for this signature in database
GPG Key ID: 63ACB65056BC8D07
2 changed files with 40 additions and 27 deletions

View File

@ -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 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

View File

@ -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_()