From 2561f995ac0716940c064cd28a7756d153f82a0a Mon Sep 17 00:00:00 2001 From: Arjan Schrijver Date: Mon, 4 Mar 2013 14:37:19 +0100 Subject: [PATCH] Fixed manual import of configuration file with a list of images --- openlp/core/lib/plugin.py | 6 +++ openlp/core/lib/pluginmanager.py | 11 ++++ openlp/core/lib/settings.py | 2 +- openlp/core/ui/mainwindow.py | 7 ++- openlp/plugins/images/converter/__init__.py | 30 ----------- .../images/converter/imageslistsaver.py | 51 ------------------- openlp/plugins/images/imageplugin.py | 17 ++++--- openlp/plugins/images/lib/mediaitem.py | 13 +++-- 8 files changed, 40 insertions(+), 97 deletions(-) delete mode 100644 openlp/plugins/images/converter/__init__.py delete mode 100644 openlp/plugins/images/converter/imageslistsaver.py diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index a82651275..e8f14bbc5 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -216,6 +216,12 @@ class Plugin(QtCore.QObject): if self.mediaItemClass: self.mediaItem = self.mediaItemClass(self.main_window.mediaDockManager.media_dock, self, self.icon) + def upgrade_settings(self, settings): + """ + Upgrade the settings of this plugin. + """ + pass + def addImportMenuItem(self, importMenu): """ Create a menu item and add it to the "Import" menu. diff --git a/openlp/core/lib/pluginmanager.py b/openlp/core/lib/pluginmanager.py index 43410b4a7..b39eabdde 100644 --- a/openlp/core/lib/pluginmanager.py +++ b/openlp/core/lib/pluginmanager.py @@ -169,6 +169,17 @@ class PluginManager(object): if plugin.status is not PluginStatus.Disabled: plugin.addToolsMenuItem(tools_menu) + def hook_upgrade_plugin_settings(self, settings): + """ + Loop through all the plugins and give them an opportunity to upgrade their settings. + + ``settings`` + The Settings object containing the old settings. + """ + for plugin in self.plugins: + if plugin.status is not PluginStatus.Disabled: + plugin.upgrade_settings(settings) + def initialise_plugins(self): """ Loop through all the plugins and give them an opportunity to diff --git a/openlp/core/lib/settings.py b/openlp/core/lib/settings.py index 5165cc0b5..42d4e7161 100644 --- a/openlp/core/lib/settings.py +++ b/openlp/core/lib/settings.py @@ -453,7 +453,7 @@ class Settings(QtCore.QSettings): 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 = QtCore.QSettings(self.fileName(), Settings.IniFormat) settings.beginGroup(plugin.settingsSection) if settings.contains(u'%s count' % plugin.name): # Get the count. diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 27f298ed2..d21b9a198 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -51,7 +51,6 @@ from openlp.core.utils import AppLocation, LanguageManager, add_actions, get_app get_filesystem_encoding from openlp.core.utils.actions import ActionList, CategoryOrder from openlp.core.ui.firsttimeform import FirstTimeForm -from openlp.plugins.images.converter import ImagesListSaver log = logging.getLogger(__name__) @@ -850,11 +849,11 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): shutil.copyfile(import_file_name, temp_config) settings = Settings() import_settings = Settings(temp_config, Settings.IniFormat) + # Convert image files + log.info(u'hook upgrade_plugin_settings') + self.plugin_manager.hook_upgrade_plugin_settings(import_settings) # Remove/rename old settings to prepare the import. import_settings.remove_obsolete_settings() - # Convert image files - loaded_list = import_settings.get_files_from_config(ImagePlugin) - ImagesListSaver.save_converted_images_list(loaded_list) # 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': diff --git a/openlp/plugins/images/converter/__init__.py b/openlp/plugins/images/converter/__init__.py deleted file mode 100644 index ec3c1ac15..000000000 --- a/openlp/plugins/images/converter/__init__.py +++ /dev/null @@ -1,30 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 - -############################################################################### -# OpenLP - Open Source Lyrics Projection # -# --------------------------------------------------------------------------- # -# Copyright (c) 2008-2013 Raoul Snyman # -# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan # -# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # -# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # -# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # -# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # -# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # -# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # -# --------------------------------------------------------------------------- # -# This program is free software; you can redistribute it and/or modify it # -# under the terms of the GNU General Public License as published by the Free # -# Software Foundation; version 2 of the License. # -# # -# This program is distributed in the hope that it will be useful, but WITHOUT # -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # -# more details. # -# # -# You should have received a copy of the GNU General Public License along # -# with this program; if not, write to the Free Software Foundation, Inc., 59 # -# Temple Place, Suite 330, Boston, MA 02111-1307 USA # -############################################################################### - -from imageslistsaver import ImagesListSaver diff --git a/openlp/plugins/images/converter/imageslistsaver.py b/openlp/plugins/images/converter/imageslistsaver.py deleted file mode 100644 index aa70f952c..000000000 --- a/openlp/plugins/images/converter/imageslistsaver.py +++ /dev/null @@ -1,51 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 - -############################################################################### -# OpenLP - Open Source Lyrics Projection # -# --------------------------------------------------------------------------- # -# Copyright (c) 2008-2013 Raoul Snyman # -# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan # -# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # -# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # -# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # -# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # -# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # -# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # -# --------------------------------------------------------------------------- # -# This program is free software; you can redistribute it and/or modify it # -# under the terms of the GNU General Public License as published by the Free # -# Software Foundation; version 2 of the License. # -# # -# This program is distributed in the hope that it will be useful, but WITHOUT # -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # -# more details. # -# # -# You should have received a copy of the GNU General Public License along # -# with this program; if not, write to the Free Software Foundation, Inc., 59 # -# Temple Place, Suite 330, Boston, MA 02111-1307 USA # -############################################################################### - -import logging - -from openlp.plugins.images.lib.db import ImageFilenames - -log = logging.getLogger(__name__) - - -class ImagesListSaver(object): - """ - This class is used to save a list of images into the database. - """ - @staticmethod - def save_converted_images_list(images_list): - """ - Save the list of images into the database. - """ - for filename in images_list: - log.debug(u'Adding new image: %s', filename) - imageFile = ImageFilenames() - imageFile.group_id = 0 - imageFile.filename = unicode(filename) - self.manager.save_object(imageFile) diff --git a/openlp/plugins/images/imageplugin.py b/openlp/plugins/images/imageplugin.py index 44146d4ae..250fd485a 100644 --- a/openlp/plugins/images/imageplugin.py +++ b/openlp/plugins/images/imageplugin.py @@ -78,13 +78,16 @@ class ImagePlugin(Plugin): files_from_config = Settings().get_files_from_config(self) if len(files_from_config) > 0: log.debug(u'Importing images list from old config: %s' % files_from_config) - for filename in files_from_config: - imageFile = ImageFilenames() - imageFile.group_id = 0 - imageFile.filename = unicode(filename) - self.manager.save_object(imageFile) - self.mediaItem.loadFullList(self.manager.get_all_objects(ImageFilenames, - order_by_ref=ImageFilenames.filename)) + self.mediaItem.save_new_images_list(files_from_config) + + def upgrade_settings(self, settings): + """ + Upgrade the settings of this plugin. + """ + files_from_config = settings.get_files_from_config(self) + if len(files_from_config) > 0: + log.debug(u'Importing images list from old config: %s' % files_from_config) + self.mediaItem.save_new_images_list(files_from_config) def setPluginTextStrings(self): """ diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index aa7ac7e69..977bc1ca8 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -374,16 +374,21 @@ class ImageMediaItem(MediaManagerItem): if not isinstance(parent_group, ImageGroups): return # Save the new images in the database - for filename in images: + self.save_new_images_list(images, group_id=parent_group.id, reload_list=False) + self.loadFullList(self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename), + initial_load=initial_load, open_group=parent_group) + + def save_new_images_list(self, images_list, group_id=0, reload_list=True): + for filename in images_list: if type(filename) is not str and type(filename) is not unicode: continue log.debug(u'Adding new image: %s', filename) imageFile = ImageFilenames() - imageFile.group_id = parent_group.id + imageFile.group_id = group_id imageFile.filename = unicode(filename) self.manager.save_object(imageFile) - self.loadFullList(self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename), - initial_load=initial_load, open_group=parent_group) + if reload_list: + self.loadFullList(self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename)) def dnd_move_internal(self, target): """