- ordered settings

- fixed old 'songs/ccli number' setting
 - do not make changes to the settings file when importing
- move settings file to the tmp dir and clean it up there

bzr-revno: 2170
This commit is contained in:
Andreas Preikschat 2013-02-05 09:08:56 +01:00
commit 864909c753
3 changed files with 91 additions and 65 deletions

View File

@ -74,7 +74,8 @@ class Settings(QtCore.QSettings):
The first entry is the *old key*; it will be removed. The first entry is the *old key*; it will be removed.
The second entry is the *new key*; we will add it to the config. The second entry is the *new key*; we will add it to the config. If this is just an empty string, we just remove
the old key.
The last entry is a list containing two-pair tuples. If the list is empty, no conversion is made. Otherwise each The last entry is a list containing two-pair tuples. If the list is empty, no conversion is made. Otherwise each
pair describes how to convert the old setting's value:: pair describes how to convert the old setting's value::
@ -86,66 +87,67 @@ class Settings(QtCore.QSettings):
So, if the type of the old value is bool, then there must be two rules. So, if the type of the old value is bool, then there must be two rules.
""" """
__default_settings__ = { __default_settings__ = {
u'advanced/x11 bypass wm': X11_BYPASS_DEFAULT, u'advanced/add page break': False,
u'advanced/alternate rows': not sys.platform.startswith(u'win'), u'advanced/alternate rows': not sys.platform.startswith(u'win'),
u'advanced/default service enabled': True,
u'advanced/enable exit confirmation': True,
u'advanced/save current plugin': False,
u'advanced/single click preview': False,
# 7 stands for now, 0 to 6 is Monday to Sunday.
u'advanced/default service day': 7,
u'advanced/max recent files': 20,
u'advanced/is portable': False,
u'advanced/hide mouse': True,
u'advanced/current media plugin': -1, u'advanced/current media plugin': -1,
u'advanced/double click live': False,
u'advanced/data path': u'', u'advanced/data path': u'',
u'advanced/default service hour': 11,
u'advanced/default color': u'#ffffff', u'advanced/default color': u'#ffffff',
u'advanced/default image': u':/graphics/openlp-splash-screen.png', u'advanced/default image': u':/graphics/openlp-splash-screen.png',
u'advanced/expand service item': False, # 7 stands for now, 0 to 6 is Monday to Sunday.
u'advanced/recent file count': 4, u'advanced/default service day': 7,
u'advanced/default service name': UiStrings().DefaultServiceName, u'advanced/default service enabled': True,
u'advanced/default service hour': 11,
u'advanced/default service minute': 0, u'advanced/default service minute': 0,
u'advanced/slide limits': SlideLimits.End, u'advanced/default service name': UiStrings().DefaultServiceName,
u'advanced/print slide text': False, u'advanced/display size': 0,
u'advanced/add page break': False, u'advanced/double click live': False,
u'advanced/enable exit confirmation': True,
u'advanced/expand service item': False,
u'advanced/hide mouse': True,
u'advanced/is portable': False,
u'advanced/max recent files': 20,
u'advanced/print file meta data': False, u'advanced/print file meta data': False,
u'advanced/print notes': False, u'advanced/print notes': False,
u'advanced/display size': 0, u'advanced/print slide text': False,
u'advanced/recent file count': 4,
u'advanced/save current plugin': False,
u'advanced/slide limits': SlideLimits.End,
u'advanced/single click preview': False,
u'advanced/x11 bypass wm': X11_BYPASS_DEFAULT,
u'crashreport/last directory': u'', u'crashreport/last directory': u'',
u'displayTags/html_tags': u'', u'displayTags/html_tags': u'',
u'general/audio repeat list': False,
u'general/auto open': False,
u'general/auto preview': False,
u'general/audio start paused': True,
u'general/auto unblank': False,
u'general/blank warning': False,
u'general/ccli number': u'', u'general/ccli number': u'',
u'general/has run wizard': False, u'general/has run wizard': False,
u'general/update check': True,
u'general/language': u'[en]', u'general/language': u'[en]',
u'general/songselect password': u'',
u'general/recent files': [],
u'general/save prompt': False,
u'general/auto preview': False,
u'general/view mode': u'default',
u'general/auto open': False,
u'general/enable slide loop': True,
u'general/show splash': True,
u'general/screen blank': False,
# The other display settings (display position and dimensions) are defined in the ScreenList class due to a
# circular dependency.
u'general/override position': False,
u'general/loop delay': 5,
u'general/songselect username': u'',
u'general/audio repeat list': False,
u'general/auto unblank': False,
u'general/display on monitor': True,
u'general/audio start paused': True,
# This defaults to yesterday in order to force the update check to run when you've never run it before. # This defaults to yesterday in order to force the update check to run when you've never run it before.
u'general/last version test': datetime.datetime.now().date() - datetime.timedelta(days=1), u'general/last version test': datetime.datetime.now().date() - datetime.timedelta(days=1),
u'general/blank warning': False, u'general/loop delay': 5,
u'general/recent files': [],
u'general/save prompt': False,
u'general/screen blank': False,
u'general/show splash': True,
u'general/songselect password': u'',
u'general/songselect username': u'',
u'general/update check': True,
u'general/view mode': u'default',
# The other display settings (display position and dimensions) are defined in the ScreenList class due to a
# circular dependency.
u'general/display on monitor': True,
u'general/override position': False,
u'media/players': u'webkit',
u'media/override player': QtCore.Qt.Unchecked,
u'players/background color': u'#000000', u'players/background color': u'#000000',
u'servicemanager/service theme': u'',
u'servicemanager/last file': u'', u'servicemanager/last file': u'',
u'servicemanager/service theme': u'',
u'SettingsImport/file_date_created': datetime.datetime.now().strftime("%Y-%m-%d %H:%M"),
u'SettingsImport/Make_Changes': u'At_Own_RISK', u'SettingsImport/Make_Changes': u'At_Own_RISK',
u'SettingsImport/type': u'OpenLP_settings_export', u'SettingsImport/type': u'OpenLP_settings_export',
u'SettingsImport/file_date_created': datetime.datetime.now().strftime("%Y-%m-%d %H:%M"),
u'SettingsImport/version': u'', u'SettingsImport/version': u'',
u'shortcuts/aboutItem': [QtGui.QKeySequence(u'Ctrl+F1')], u'shortcuts/aboutItem': [QtGui.QKeySequence(u'Ctrl+F1')],
u'shortcuts/audioPauseItem': [], u'shortcuts/audioPauseItem': [],
@ -213,39 +215,38 @@ class Settings(QtCore.QSettings):
u'shortcuts/viewLivePanel': [QtGui.QKeySequence(u'F12')], u'shortcuts/viewLivePanel': [QtGui.QKeySequence(u'F12')],
u'shortcuts/viewServiceManagerItem': [QtGui.QKeySequence(u'F9')], u'shortcuts/viewServiceManagerItem': [QtGui.QKeySequence(u'F9')],
u'shortcuts/webSiteItem': [], u'shortcuts/webSiteItem': [],
u'themes/theme level': ThemeLevel.Song,
u'themes/global theme': u'', u'themes/global theme': u'',
u'themes/last directory': u'', u'themes/last directory': u'',
u'themes/last directory export': u'', u'themes/last directory export': u'',
u'themes/last directory import': u'', u'themes/last directory import': u'',
u'user interface/main window position': QtCore.QPoint(0, 0), u'themes/theme level': ThemeLevel.Song,
u'user interface/preview panel': True,
u'user interface/live panel': True, u'user interface/live panel': True,
u'user interface/main window geometry': QtCore.QByteArray(),
u'user interface/preview splitter geometry': QtCore.QByteArray(),
u'user interface/lock panel': False,
u'user interface/mainwindow splitter geometry': QtCore.QByteArray(),
u'user interface/live splitter geometry': QtCore.QByteArray(), u'user interface/live splitter geometry': QtCore.QByteArray(),
u'user interface/lock panel': False,
u'user interface/main window geometry': QtCore.QByteArray(),
u'user interface/main window position': QtCore.QPoint(0, 0),
u'user interface/main window splitter geometry': QtCore.QByteArray(),
u'user interface/main window state': QtCore.QByteArray(), u'user interface/main window state': QtCore.QByteArray(),
u'media/players': u'webkit', u'user interface/preview panel': True,
u'media/override player': QtCore.Qt.Unchecked, u'user interface/preview splitter geometry': QtCore.QByteArray()
# Old settings (not used anymore). Have to be here, so that old setting.config backups can be imported.
u'advanced/stylesheet fix': u'',
u'servicemanager/last directory': u''
} }
__file_path__ = u'' __file_path__ = u''
__obsolete_settings__ = [ __obsolete_settings__ = [
# Changed during 1.9.x development.
(u'bibles/bookname language', u'bibles/book name language', []), (u'bibles/bookname language', u'bibles/book name language', []),
(u'general/enable slide loop', u'advanced/slide limits', [(SlideLimits.Wrap, True), (SlideLimits.End, False)]), (u'general/enable slide loop', u'advanced/slide limits', [(SlideLimits.Wrap, True), (SlideLimits.End, False)]),
(u'songs/ccli number', u'general/ccli number', []),
# Changed during 2.1.x development.
(u'advanced/stylesheet fix', u'', []),
(u'bibles/last directory 1', u'bibles/last directory import', []),
(u'media/background color', u'players/background color', []),
(u'themes/last directory', u'themes/last directory import', []), (u'themes/last directory', u'themes/last directory import', []),
(u'themes/last directory 1', u'themes/last directory export', []), (u'themes/last directory 1', u'themes/last directory export', []),
(u'servicemanager/last directory', u'', []), (u'servicemanager/last directory', u'', []),
(u'songs/last directory 1', u'songs/last directory import', []), (u'songs/last directory 1', u'songs/last directory import', []),
(u'bibles/last directory 1', u'bibles/last directory import', []),
(u'songusage/last directory 1', u'songusage/last directory export', []), (u'songusage/last directory 1', u'songusage/last directory export', []),
(u'shortcuts/makeLive', u'shortcuts/make_live', []), (u'user interface/mainwindow splitter geometry', u'user interface/main window splitter geometry', []),
(u'advanced/stylesheet fix', u'', []), (u'shortcuts/makeLive', u'shortcuts/make_live', [])
(u'media/background color', u'players/background color', [])
] ]
@staticmethod @staticmethod
@ -296,6 +297,11 @@ class Settings(QtCore.QSettings):
if new_key: if new_key:
# Get the value of the old_key. # Get the value of the old_key.
old_value = super(Settings, self).value(old_key) old_value = super(Settings, self).value(old_key)
# When we want to convert the value, we have to figure out the default value (because we cannot get
# the default value from the central settings dict.
if rules:
default_value = rules[0][1]
old_value = self._convert_value(old_value, default_value)
# Iterate over our rules and check what the old_value should be "converted" to. # Iterate over our rules and check what the old_value should be "converted" to.
for new, old in rules: for new, old in rules:
# If the value matches with the condition (rule), then use the provided value. This is used to # If the value matches with the condition (rule), then use the provided value. This is used to
@ -311,8 +317,6 @@ class Settings(QtCore.QSettings):
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
*Settings.__default_settings__* dict. *Settings.__default_settings__* dict.
**Note**, this method only converts a few types and might need to be extended if a certain type is missing!
``key`` ``key``
The key to return the value from. The key to return the value from.
""" """
@ -322,6 +326,21 @@ class Settings(QtCore.QSettings):
else: else:
default_value = Settings.__default_settings__[key] default_value = Settings.__default_settings__[key]
setting = super(Settings, self).value(key, default_value) setting = super(Settings, self).value(key, default_value)
return self._convert_value(setting, default_value)
def _convert_value(self, setting, default_value):
"""
This converts the given ``setting`` to the type of the given ``default_value``.
``setting``
The setting to convert. This could be ``true`` for example.Settings()
``default_value``
Indication the type the setting should be converted to. For example ``True`` (type is boolean), meaning that
we convert the string ``true`` to a python boolean.
**Note**, this method only converts a few types and might need to be extended if a certain type is missing!
"""
# On OS X (and probably on other platforms too) empty value from QSettings is represented as type # On OS X (and probably on other platforms too) empty value from QSettings is represented as type
# PyQt4.QtCore.QPyNullVariant. This type has to be converted to proper 'None' Python type. # PyQt4.QtCore.QPyNullVariant. This type has to be converted to proper 'None' Python type.
if isinstance(setting, QtCore.QPyNullVariant) and setting.isNull(): if isinstance(setting, QtCore.QPyNullVariant) and setting.isNull():

View File

@ -42,7 +42,7 @@ from datetime import datetime
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.core.lib import Renderer, build_icon, OpenLPDockWidget, PluginManager, Receiver, translate, ImageManager, \ from openlp.core.lib import Renderer, build_icon, OpenLPDockWidget, PluginManager, Receiver, translate, ImageManager, \
PluginStatus, Registry, Settings, ScreenList PluginStatus, Registry, Settings, ScreenList, check_directory_exists
from openlp.core.lib.ui import UiStrings, create_action from openlp.core.lib.ui import UiStrings, create_action
from openlp.core.ui import AboutForm, SettingsForm, ServiceManager, ThemeManager, SlideController, PluginForm, \ from openlp.core.ui import AboutForm, SettingsForm, ServiceManager, ThemeManager, SlideController, PluginForm, \
MediaDockManager, ShortcutListForm, FormattingTagForm MediaDockManager, ShortcutListForm, FormattingTagForm
@ -842,8 +842,15 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
# Add plugin sections. # Add plugin sections.
for plugin in self.plugin_manager.plugins: for plugin in self.plugin_manager.plugins:
setting_sections.extend([plugin.name]) setting_sections.extend([plugin.name])
# Copy the settings file to the tmp dir, because we do not want to change the original one.
temp_directory = os.path.join(unicode(gettempdir()), u'openlp')
check_directory_exists(temp_directory)
temp_config = os.path.join(temp_directory, os.path.basename(import_file_name))
shutil.copyfile(import_file_name, temp_config)
settings = Settings() settings = Settings()
import_settings = Settings(import_file_name, Settings.IniFormat) import_settings = Settings(temp_config, Settings.IniFormat)
# Remove/rename old settings to prepare the import.
import_settings.remove_obsolete_settings()
# Lets do a basic sanity check. If it contains this string we can # Lets do a basic sanity check. If it contains this string we can
# assume it was created by OpenLP and so we'll load what we can # assume it was created by OpenLP and so we'll load what we can
# from it, and just silently ignore anything we don't recognise # from it, and just silently ignore anything we don't recognise
@ -1222,7 +1229,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self.restoreState(settings.value(u'main window state')) self.restoreState(settings.value(u'main window state'))
self.liveController.splitter.restoreState(settings.value(u'live splitter geometry')) self.liveController.splitter.restoreState(settings.value(u'live splitter geometry'))
self.previewController.splitter.restoreState(settings.value(u'preview splitter geometry')) self.previewController.splitter.restoreState(settings.value(u'preview splitter geometry'))
self.controlSplitter.restoreState(settings.value(u'mainwindow splitter geometry')) self.controlSplitter.restoreState(settings.value(u'main window splitter geometry'))
settings.endGroup() settings.endGroup()
def saveSettings(self): def saveSettings(self):
@ -1243,7 +1250,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
settings.setValue(u'main window geometry', self.saveGeometry()) settings.setValue(u'main window geometry', self.saveGeometry())
settings.setValue(u'live splitter geometry', self.liveController.splitter.saveState()) settings.setValue(u'live splitter geometry', self.liveController.splitter.saveState())
settings.setValue(u'preview splitter geometry', self.previewController.splitter.saveState()) settings.setValue(u'preview splitter geometry', self.previewController.splitter.saveState())
settings.setValue(u'mainwindow splitter geometry', self.controlSplitter.saveState()) settings.setValue(u'main window splitter geometry', self.controlSplitter.saveState())
settings.endGroup() settings.endGroup()
def updateRecentFilesMenu(self): def updateRecentFilesMenu(self):

View File

@ -230,7 +230,7 @@ class SlideController(DisplayController):
self.playSlidesOnce = create_action(self, u'playSlidesOnce', text=UiStrings().PlaySlidesToEnd, self.playSlidesOnce = create_action(self, u'playSlidesOnce', text=UiStrings().PlaySlidesToEnd,
icon=u':/media/media_time.png', checked=False, shortcuts=[], icon=u':/media/media_time.png', checked=False, shortcuts=[],
category=self.category, triggers=self.onPlaySlidesOnce) category=self.category, triggers=self.onPlaySlidesOnce)
if Settings().value(self.parent().generalSettingsSection + u'/enable slide loop'): if Settings().value(self.parent().advancedSettingsSection + u'/slide limits') == SlideLimits.Wrap:
self.playSlidesMenu.setDefaultAction(self.playSlidesLoop) self.playSlidesMenu.setDefaultAction(self.playSlidesLoop)
else: else:
self.playSlidesMenu.setDefaultAction(self.playSlidesOnce) self.playSlidesMenu.setDefaultAction(self.playSlidesOnce)