fixed up remove_obsolete_settings method

This commit is contained in:
Andreas Preikschat 2013-01-12 09:54:49 +01:00
parent cd343bd16c
commit fa6703f307
2 changed files with 13 additions and 15 deletions

View File

@ -229,25 +229,23 @@ class Settings(QtCore.QSettings):
""" """
Settings.__filePath__ = iniFile Settings.__filePath__ = iniFile
@staticmethod
def remove_obsolete_settings():
"""
This method is only called to clean up the config. It removes all changed keys, but before doing so, we copy
the value to the new key.
"""
for new_key, old_key in Settings.__obsolete_settings__.items():
settings = Settings()
if settings.contains(old_key):
# Copy the value from the old_key to the new_key.
settings.setValue(new_key. settings.value(key))
settings.remove(old_key)
def __init__(self, *args): def __init__(self, *args):
if not args and Settings.__filePath__ and Settings.defaultFormat() == Settings.IniFormat: if not args and Settings.__filePath__ and Settings.defaultFormat() == Settings.IniFormat:
QtCore.QSettings.__init__(self, Settings.__filePath__, Settings.IniFormat) QtCore.QSettings.__init__(self, Settings.__filePath__, Settings.IniFormat)
else: else:
QtCore.QSettings.__init__(self, *args) QtCore.QSettings.__init__(self, *args)
def remove_obsolete_settings(self):
"""
This method is only called to clean up the config. It removes all changed keys, but before doing so, we copy
the value to the new key.
"""
for old_key, new_key in Settings.__obsolete_settings__.items():
if self.contains(old_key):
# Copy the value from the old_key to the new_key.
self.setValue(new_key, super(Settings, self).value(old_key))
self.remove(old_key)
def value(self, key): def value(self, key):
""" """
Returns the value for the given ``key``. The returned ``value`` is of the same type as the default value in the Returns the value for the given ``key``. The returned ``value`` is of the same type as the default value in the
@ -259,7 +257,7 @@ class Settings(QtCore.QSettings):
The key to return the value from. The key to return the value from.
""" """
try: try:
# if group() is empty the group has been specified together with the key. # if group() is not empty the group has not been specified together with the key.
if self.group(): if self.group():
default_value = Settings.__default_settings__[self.group() + u'/' + key] default_value = Settings.__default_settings__[self.group() + u'/' + key]
else: else:

View File

@ -471,7 +471,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self.playersSettingsSection = u'players' self.playersSettingsSection = u'players'
self.displayTagsSection = u'displayTags' self.displayTagsSection = u'displayTags'
self.headerSection = u'SettingsImport' self.headerSection = u'SettingsImport'
Settings.remove_obsolete_settings() Settings().remove_obsolete_settings()
self.serviceNotSaved = False self.serviceNotSaved = False
self.aboutForm = AboutForm(self) self.aboutForm = AboutForm(self)
self.mediaController = MediaController(self) self.mediaController = MediaController(self)