forked from openlp/openlp
started work on converting old image settings
This commit is contained in:
parent
c1ba98ee0f
commit
25373944b2
@ -301,23 +301,10 @@ class Plugin(QtCore.QObject):
|
||||
# This is needed to load the list of images/media/presentation from the config saved
|
||||
# before the settings rewrite.
|
||||
if self.mediaItemClass is not None:
|
||||
# We need QSettings instead of Settings here to bypass our central settings dict.
|
||||
# Do NOT do this anywhere else!
|
||||
settings = QtCore.QSettings()
|
||||
settings.beginGroup(self.settingsSection)
|
||||
if settings.contains(u'%s count' % self.name):
|
||||
list_count = int(settings.value(u'%s count' % self.name, 0))
|
||||
loaded_list = []
|
||||
if list_count:
|
||||
for counter in range(list_count):
|
||||
item = settings.value(u'%s %d' % (self.name, counter), u'')
|
||||
if item:
|
||||
loaded_list.append(item)
|
||||
settings.remove(u'%s %d' % (self.name, counter))
|
||||
settings.remove(u'%s count' % self.name)
|
||||
# Now save the list to the config using our Settings class.
|
||||
Settings().setValue(u'%s/%s files' % (self.settingsSection, self.name), loaded_list)
|
||||
settings.endGroup()
|
||||
loaded_list = Settings().get_files_from_config(self)
|
||||
# Now save the list to the config using our Settings class.
|
||||
Settings().setValue(u'%s/%s files' % (self.settingsSection, self.name), loaded_list)
|
||||
# FIXME: make sure we do not do this for the images plugin.
|
||||
|
||||
def usesTheme(self, theme):
|
||||
"""
|
||||
|
@ -364,3 +364,32 @@ class Settings(QtCore.QSettings):
|
||||
if isinstance(default_value, int):
|
||||
return int(setting)
|
||||
return setting
|
||||
|
||||
def get_files_from_config(self, plugin):
|
||||
"""
|
||||
This removes the settings needed for old way we saved files (e. g. the image paths for the image plugin). A list
|
||||
of file paths are returned.
|
||||
|
||||
**Note**: Only a list of paths is returned; this does not convert anything!
|
||||
|
||||
``plugin``
|
||||
The Plugin object.The caller has to convert/save the list himself; o
|
||||
"""
|
||||
files_list = []
|
||||
# We need QSettings instead of Settings here to bypass our central settings dict.
|
||||
# Do NOT do this anywhere else!
|
||||
settings = QtCore.QSettings()
|
||||
settings.beginGroup(plugin.settingsSection)
|
||||
if settings.contains(u'%s count' % plugin.name):
|
||||
# Get the count.
|
||||
list_count = int(settings.value(u'%s count' % plugin.name, 0))
|
||||
if list_count:
|
||||
for counter in range(list_count):
|
||||
# The keys were named e. g.: "image 0"
|
||||
item = settings.value(u'%s %d' % (plugin.name, counter), u'')
|
||||
if item:
|
||||
files_list.append(item)
|
||||
settings.remove(u'%s %d' % (plugin.name, counter))
|
||||
settings.remove(u'%s count' % plugin.name)
|
||||
settings.endGroup()
|
||||
return files_list
|
||||
|
@ -835,19 +835,11 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
||||
return
|
||||
setting_sections = []
|
||||
# Add main sections.
|
||||
setting_sections.extend([self.generalSettingsSection])
|
||||
setting_sections.extend([self.advancedSettingsSection])
|
||||
setting_sections.extend([self.uiSettingsSection])
|
||||
setting_sections.extend([self.shortcutsSettingsSection])
|
||||
setting_sections.extend([self.serviceManagerSettingsSection])
|
||||
setting_sections.extend([self.themesSettingsSection])
|
||||
setting_sections.extend([self.playersSettingsSection])
|
||||
setting_sections.extend([self.displayTagsSection])
|
||||
setting_sections.extend([self.headerSection])
|
||||
setting_sections.extend([u'crashreport'])
|
||||
setting_sections.extend([self.generalSettingsSection, self.advancedSettingsSection, self.uiSettingsSection,
|
||||
self.shortcutsSettingsSection, self.serviceManagerSettingsSection, self.themesSettingsSection,
|
||||
self.playersSettingsSection, self.displayTagsSection, self.headerSection, u'crashreport'])
|
||||
# Add plugin sections.
|
||||
for plugin in self.plugin_manager.plugins:
|
||||
setting_sections.extend([plugin.name])
|
||||
setting_sections.extend([plugin.name for plugin in self.plugin_manager.plugins])
|
||||
# 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)
|
||||
@ -857,9 +849,10 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
||||
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
|
||||
# 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
|
||||
# FIXME: Convert image files
|
||||
|
||||
# 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 from it, and just silently ignore anything we don't recognise.
|
||||
if import_settings.value(u'SettingsImport/type') != u'OpenLP_settings_export':
|
||||
QtGui.QMessageBox.critical(self, translate('OpenLP.MainWindow', 'Import settings'),
|
||||
translate('OpenLP.MainWindow', 'The file you have selected does not appear to be a valid OpenLP '
|
||||
@ -894,9 +887,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
||||
settings.setValue(u'file_date_imported', now.strftime("%Y-%m-%d %H:%M"))
|
||||
settings.endGroup()
|
||||
settings.sync()
|
||||
# We must do an immediate restart or current configuration will
|
||||
# overwrite what was just imported when application terminates
|
||||
# normally. We need to exit without saving configuration.
|
||||
# We must do an immediate restart or current configuration will overwrite what was just imported when
|
||||
# application terminates normally. We need to exit without saving configuration.
|
||||
QtGui.QMessageBox.information(self, translate('OpenLP.MainWindow', 'Import settings'),
|
||||
translate('OpenLP.MainWindow', 'OpenLP will now close. Imported settings will '
|
||||
'be applied the next time you start OpenLP.'),
|
||||
|
@ -41,7 +41,6 @@ log = logging.getLogger(__name__)
|
||||
__default_settings__ = {
|
||||
u'images/db type': u'sqlite',
|
||||
u'images/background color': u'#000000',
|
||||
u'images/images files': []
|
||||
}
|
||||
|
||||
|
||||
|
@ -91,16 +91,12 @@ class ImageMediaItem(MediaManagerItem):
|
||||
self.servicePath = os.path.join(AppLocation.get_section_data_path(self.settingsSection), u'thumbnails')
|
||||
check_directory_exists(self.servicePath)
|
||||
# Import old images list
|
||||
images_old = Settings().value(self.settingsSection + u'/images files')
|
||||
if len(images_old) > 0:
|
||||
for imageFile in images_old:
|
||||
imagefilename = ImageFilenames()
|
||||
imagefilename.group_id = 0
|
||||
imagefilename.filename = imageFile
|
||||
success = self.manager.save_object(imagefilename)
|
||||
Settings().setValue(self.settingsSection + u'/images files', [])
|
||||
Settings().remove(self.settingsSection + u'/images files')
|
||||
Settings().remove(self.settingsSection + u'/images count')
|
||||
files_from_config = Settings().get_files_from_config(self.plugin)
|
||||
for old_file in files_from_config:
|
||||
imagefilename = ImageFilenames()
|
||||
imagefilename.group_id = 0
|
||||
imagefilename.filename = old_file
|
||||
success = self.manager.save_object(imagefilename)
|
||||
# Load images from the database
|
||||
self.loadFullList(self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename),
|
||||
initial_load=True)
|
||||
|
Loading…
Reference in New Issue
Block a user