forked from openlp/openlp
Fixed manual import of configuration file with a list of images
This commit is contained in:
parent
a5e6cc358b
commit
2561f995ac
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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':
|
||||
|
@ -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
|
@ -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)
|
@ -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):
|
||||
"""
|
||||
|
@ -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):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user