add possibility to remove old_keys from the config

This commit is contained in:
Andreas Preikschat 2013-01-11 21:44:30 +01:00
parent f1a8bad78e
commit 095066cf19
3 changed files with 22 additions and 9 deletions

View File

@ -65,6 +65,11 @@ class Settings(QtCore.QSettings):
object for accessing settings stored in that Ini file.
"""
__filePath__ = u''
__obsolete_settings__ = {
u'bibles/bookname language': u'bibles/book name language'
}
__default_settings__ = {
u'advanced/x11 bypass wm': X11_BYPASS_DEFAULT,
u'advanced/default service enabled': True,
@ -224,6 +229,19 @@ class Settings(QtCore.QSettings):
"""
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):
if not args and Settings.__filePath__ and Settings.defaultFormat() == Settings.IniFormat:
QtCore.QSettings.__init__(self, Settings.__filePath__, Settings.IniFormat)

View File

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

View File

@ -41,6 +41,7 @@ from openlp.plugins.bibles.forms import BibleUpgradeForm
log = logging.getLogger(__name__)
__default_settings__ = {
u'bibles/db type': u'sqlite',
u'bibles/status': PluginStatus.Inactive,
@ -50,8 +51,8 @@ __default_settings__ = {
u'bibles/display brackets': DisplayStyle.NoBrackets,
u'bibles/display new chapter': False,
u'bibles/second bibles': True,
u'bibles/advanced bible': u'', # FIXME: check
u'bibles/quick bible': u'', # FIXME: check
u'bibles/advanced bible': u'',
u'bibles/quick bible': u'',
u'bibles/proxy name': u'',
u'bibles/proxy address': u'',
u'bibles/proxy username': u'',
@ -113,13 +114,6 @@ class BiblePlugin(Plugin):
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)) == \
QtGui.QMessageBox.Yes:
self.onToolsUpgradeItemTriggered()
settings = Settings()
settings.beginGroup(self.settingsSection)
if settings.contains(u'bookname language'):
# FIXME: Will that cause crashes?
settings.setValue(u'book name language', settings.value(u'bookname language'))
settings.remove(u'bookname language')
settings.endGroup()
def addImportMenuItem(self, import_menu):
self.importBibleItem = create_action(import_menu, u'importBibleItem',