diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index 203f30e6e..58384c15d 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -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): """ diff --git a/openlp/core/lib/settings.py b/openlp/core/lib/settings.py index 56821f1d1..94afa275c 100644 --- a/openlp/core/lib/settings.py +++ b/openlp/core/lib/settings.py @@ -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 diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index e86f068a8..07649a6b3 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -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.'), diff --git a/openlp/plugins/images/imageplugin.py b/openlp/plugins/images/imageplugin.py index e474a088b..28f611863 100644 --- a/openlp/plugins/images/imageplugin.py +++ b/openlp/plugins/images/imageplugin.py @@ -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': [] } diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index d2cd48b97..3871fec5d 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -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)