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:
|
if self.mediaItemClass:
|
||||||
self.mediaItem = self.mediaItemClass(self.main_window.mediaDockManager.media_dock, self, self.icon)
|
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):
|
def addImportMenuItem(self, importMenu):
|
||||||
"""
|
"""
|
||||||
Create a menu item and add it to the "Import" menu.
|
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:
|
if plugin.status is not PluginStatus.Disabled:
|
||||||
plugin.addToolsMenuItem(tools_menu)
|
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):
|
def initialise_plugins(self):
|
||||||
"""
|
"""
|
||||||
Loop through all the plugins and give them an opportunity to
|
Loop through all the plugins and give them an opportunity to
|
||||||
|
@ -453,7 +453,7 @@ class Settings(QtCore.QSettings):
|
|||||||
files_list = []
|
files_list = []
|
||||||
# We need QSettings instead of Settings here to bypass our central settings dict.
|
# We need QSettings instead of Settings here to bypass our central settings dict.
|
||||||
# Do NOT do this anywhere else!
|
# Do NOT do this anywhere else!
|
||||||
settings = QtCore.QSettings()
|
settings = QtCore.QSettings(self.fileName(), Settings.IniFormat)
|
||||||
settings.beginGroup(plugin.settingsSection)
|
settings.beginGroup(plugin.settingsSection)
|
||||||
if settings.contains(u'%s count' % plugin.name):
|
if settings.contains(u'%s count' % plugin.name):
|
||||||
# Get the count.
|
# Get the count.
|
||||||
|
@ -51,7 +51,6 @@ from openlp.core.utils import AppLocation, LanguageManager, add_actions, get_app
|
|||||||
get_filesystem_encoding
|
get_filesystem_encoding
|
||||||
from openlp.core.utils.actions import ActionList, CategoryOrder
|
from openlp.core.utils.actions import ActionList, CategoryOrder
|
||||||
from openlp.core.ui.firsttimeform import FirstTimeForm
|
from openlp.core.ui.firsttimeform import FirstTimeForm
|
||||||
from openlp.plugins.images.converter import ImagesListSaver
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -850,11 +849,11 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||||||
shutil.copyfile(import_file_name, temp_config)
|
shutil.copyfile(import_file_name, temp_config)
|
||||||
settings = Settings()
|
settings = Settings()
|
||||||
import_settings = Settings(temp_config, Settings.IniFormat)
|
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.
|
# Remove/rename old settings to prepare the import.
|
||||||
import_settings.remove_obsolete_settings()
|
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
|
# 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.
|
# 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':
|
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)
|
files_from_config = Settings().get_files_from_config(self)
|
||||||
if len(files_from_config) > 0:
|
if len(files_from_config) > 0:
|
||||||
log.debug(u'Importing images list from old config: %s' % files_from_config)
|
log.debug(u'Importing images list from old config: %s' % files_from_config)
|
||||||
for filename in files_from_config:
|
self.mediaItem.save_new_images_list(files_from_config)
|
||||||
imageFile = ImageFilenames()
|
|
||||||
imageFile.group_id = 0
|
def upgrade_settings(self, settings):
|
||||||
imageFile.filename = unicode(filename)
|
"""
|
||||||
self.manager.save_object(imageFile)
|
Upgrade the settings of this plugin.
|
||||||
self.mediaItem.loadFullList(self.manager.get_all_objects(ImageFilenames,
|
"""
|
||||||
order_by_ref=ImageFilenames.filename))
|
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):
|
def setPluginTextStrings(self):
|
||||||
"""
|
"""
|
||||||
|
@ -374,16 +374,21 @@ class ImageMediaItem(MediaManagerItem):
|
|||||||
if not isinstance(parent_group, ImageGroups):
|
if not isinstance(parent_group, ImageGroups):
|
||||||
return
|
return
|
||||||
# Save the new images in the database
|
# 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:
|
if type(filename) is not str and type(filename) is not unicode:
|
||||||
continue
|
continue
|
||||||
log.debug(u'Adding new image: %s', filename)
|
log.debug(u'Adding new image: %s', filename)
|
||||||
imageFile = ImageFilenames()
|
imageFile = ImageFilenames()
|
||||||
imageFile.group_id = parent_group.id
|
imageFile.group_id = group_id
|
||||||
imageFile.filename = unicode(filename)
|
imageFile.filename = unicode(filename)
|
||||||
self.manager.save_object(imageFile)
|
self.manager.save_object(imageFile)
|
||||||
self.loadFullList(self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename),
|
if reload_list:
|
||||||
initial_load=initial_load, open_group=parent_group)
|
self.loadFullList(self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename))
|
||||||
|
|
||||||
def dnd_move_internal(self, target):
|
def dnd_move_internal(self, target):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user