2010-09-10 19:21:14 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2019-04-13 13:00:22 +00:00
|
|
|
##########################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# ---------------------------------------------------------------------- #
|
2024-01-05 17:18:59 +00:00
|
|
|
# Copyright (c) 2008-2024 OpenLP Developers #
|
2019-04-13 13:00:22 +00:00
|
|
|
# ---------------------------------------------------------------------- #
|
|
|
|
# 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, either version 3 of the License, or #
|
|
|
|
# (at your option) any later version. #
|
|
|
|
# #
|
|
|
|
# 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, see <https://www.gnu.org/licenses/>. #
|
|
|
|
##########################################################################
|
2013-01-17 21:58:38 +00:00
|
|
|
"""
|
|
|
|
The :mod:`~openlp.plugins.custom.customplugin` module contains the Plugin class
|
|
|
|
for the Custom Slides plugin.
|
|
|
|
"""
|
2010-09-10 19:21:14 +00:00
|
|
|
|
|
|
|
import logging
|
|
|
|
|
2018-10-20 14:41:32 +00:00
|
|
|
from openlp.core.state import State
|
2018-04-10 19:26:56 +00:00
|
|
|
from openlp.core.common.i18n import translate
|
2024-04-17 15:14:58 +00:00
|
|
|
from openlp.core.common.registry import Registry
|
2018-08-25 14:08:19 +00:00
|
|
|
from openlp.core.lib import build_icon
|
2023-05-19 13:55:38 +00:00
|
|
|
from openlp.core.db.manager import DBManager
|
2018-10-02 04:39:42 +00:00
|
|
|
from openlp.core.lib.plugin import Plugin, StringContent
|
|
|
|
from openlp.core.ui.icons import UiIcons
|
2010-09-10 19:21:14 +00:00
|
|
|
from openlp.plugins.custom.lib.db import CustomSlide, init_schema
|
2019-12-16 03:37:54 +00:00
|
|
|
from openlp.plugins.custom.lib.mediaitem import CustomMediaItem
|
2018-10-26 18:26:12 +00:00
|
|
|
from openlp.plugins.custom.lib.customtab import CustomTab
|
2010-09-10 19:21:14 +00:00
|
|
|
|
2018-10-02 04:39:42 +00:00
|
|
|
|
2010-09-10 19:21:14 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2013-01-10 20:50:01 +00:00
|
|
|
|
2010-09-10 19:21:14 +00:00
|
|
|
class CustomPlugin(Plugin):
|
|
|
|
"""
|
2013-12-24 07:02:47 +00:00
|
|
|
This plugin enables the user to create, edit and display custom slide shows. Custom shows are divided into slides.
|
2010-09-10 19:21:14 +00:00
|
|
|
Each show is able to have it's own theme.
|
2013-12-24 07:02:47 +00:00
|
|
|
Custom shows are designed to replace the use of songs where the songs plugin has become restrictive.
|
|
|
|
Examples could be Welcome slides, Bible Reading information, Orders of service.
|
2010-09-10 19:21:14 +00:00
|
|
|
"""
|
2013-08-31 18:17:38 +00:00
|
|
|
log.info('Custom Plugin loaded')
|
2010-09-10 19:21:14 +00:00
|
|
|
|
2013-01-23 21:05:25 +00:00
|
|
|
def __init__(self):
|
2020-01-18 21:00:13 +00:00
|
|
|
super(CustomPlugin, self).__init__('custom', CustomMediaItem, CustomTab)
|
2010-09-10 19:21:14 +00:00
|
|
|
self.weight = -5
|
2023-05-19 13:55:38 +00:00
|
|
|
self.db_manager = DBManager('custom', init_schema)
|
2023-04-18 05:04:38 +00:00
|
|
|
self.icon_path = UiIcons().custom
|
2024-04-17 15:14:58 +00:00
|
|
|
Registry().register('custom_manager', self.db_manager)
|
2013-03-19 19:43:22 +00:00
|
|
|
self.icon = build_icon(self.icon_path)
|
2018-10-26 18:30:59 +00:00
|
|
|
State().add_service(self.name, self.weight, is_plugin=True)
|
2018-10-20 14:41:32 +00:00
|
|
|
State().update_pre_conditions(self.name, self.check_pre_conditions())
|
2010-09-10 19:21:14 +00:00
|
|
|
|
2016-01-04 00:18:01 +00:00
|
|
|
@staticmethod
|
|
|
|
def about():
|
2020-03-24 05:48:57 +00:00
|
|
|
about_text = translate('CustomPlugin', '<strong>Custom Slide Plugin</strong><br />The custom slide plugin '
|
2013-12-24 07:02:47 +00:00
|
|
|
'provides the ability to set up custom text slides that can be displayed on the screen '
|
|
|
|
'the same way songs are. This plugin provides greater freedom over the songs plugin.')
|
2010-09-10 19:21:14 +00:00
|
|
|
return about_text
|
|
|
|
|
2020-10-19 07:18:26 +00:00
|
|
|
def check_pre_conditions(self):
|
|
|
|
"""
|
|
|
|
Check the plugin can run.
|
|
|
|
"""
|
|
|
|
return self.db_manager.session is not None
|
|
|
|
|
2013-02-19 21:23:56 +00:00
|
|
|
def uses_theme(self, theme):
|
2010-09-10 19:21:14 +00:00
|
|
|
"""
|
|
|
|
Called to find out if the custom plugin is currently using a theme.
|
|
|
|
|
2015-10-16 16:43:48 +00:00
|
|
|
Returns count of the times the theme is used.
|
2016-01-08 13:47:52 +00:00
|
|
|
:param theme: Theme to be queried
|
2010-09-10 19:21:14 +00:00
|
|
|
"""
|
2015-10-16 16:43:48 +00:00
|
|
|
return len(self.db_manager.get_all_objects(CustomSlide, CustomSlide.theme_name == theme))
|
2010-09-10 19:21:14 +00:00
|
|
|
|
2013-12-24 07:02:47 +00:00
|
|
|
def rename_theme(self, old_theme, new_theme):
|
2010-09-10 19:21:14 +00:00
|
|
|
"""
|
2014-03-17 19:05:55 +00:00
|
|
|
Renames a theme the custom plugin is using making the plugin use the new name.
|
2010-09-10 19:21:14 +00:00
|
|
|
|
2014-03-17 19:05:55 +00:00
|
|
|
:param old_theme: The name of the theme the plugin should stop using.
|
|
|
|
:param new_theme: The new name the plugin should now use.
|
2010-09-10 19:21:14 +00:00
|
|
|
"""
|
2013-12-24 07:02:47 +00:00
|
|
|
customs_using_theme = self.db_manager.get_all_objects(CustomSlide, CustomSlide.theme_name == old_theme)
|
2013-02-19 21:23:56 +00:00
|
|
|
for custom in customs_using_theme:
|
2013-12-24 07:02:47 +00:00
|
|
|
custom.theme_name = new_theme
|
|
|
|
self.db_manager.save_object(custom)
|
2010-09-16 21:10:36 +00:00
|
|
|
|
2013-02-19 21:23:56 +00:00
|
|
|
def set_plugin_text_strings(self):
|
2010-09-10 19:21:14 +00:00
|
|
|
"""
|
|
|
|
Called to define all translatable texts of the plugin
|
|
|
|
"""
|
2014-04-12 20:19:22 +00:00
|
|
|
# Name PluginList
|
2013-03-19 19:43:22 +00:00
|
|
|
self.text_strings[StringContent.Name] = {
|
2013-08-31 18:17:38 +00:00
|
|
|
'singular': translate('CustomPlugin', 'Custom Slide', 'name singular'),
|
|
|
|
'plural': translate('CustomPlugin', 'Custom Slides', 'name plural')
|
2010-09-10 19:21:14 +00:00
|
|
|
}
|
2014-04-12 20:19:22 +00:00
|
|
|
# Name for MediaDockManager, SettingsManager
|
2013-03-19 19:43:22 +00:00
|
|
|
self.text_strings[StringContent.VisibleName] = {
|
2013-08-31 18:17:38 +00:00
|
|
|
'title': translate('CustomPlugin', 'Custom Slides', 'container title')
|
2010-09-15 17:55:27 +00:00
|
|
|
}
|
2010-09-10 19:21:14 +00:00
|
|
|
# Middle Header Bar
|
2011-02-14 17:25:51 +00:00
|
|
|
tooltips = {
|
2013-08-31 18:17:38 +00:00
|
|
|
'load': translate('CustomPlugin', 'Load a new custom slide.'),
|
|
|
|
'import': translate('CustomPlugin', 'Import a custom slide.'),
|
|
|
|
'new': translate('CustomPlugin', 'Add a new custom slide.'),
|
|
|
|
'edit': translate('CustomPlugin', 'Edit the selected custom slide.'),
|
|
|
|
'delete': translate('CustomPlugin', 'Delete the selected custom slide.'),
|
|
|
|
'preview': translate('CustomPlugin', 'Preview the selected custom slide.'),
|
|
|
|
'live': translate('CustomPlugin', 'Send the selected custom slide live.'),
|
|
|
|
'service': translate('CustomPlugin', 'Add the selected custom slide to the service.')
|
2010-09-10 19:21:14 +00:00
|
|
|
}
|
2013-03-19 19:43:22 +00:00
|
|
|
self.set_plugin_ui_text_strings(tooltips)
|
2010-10-27 15:30:30 +00:00
|
|
|
|
|
|
|
def finalise(self):
|
|
|
|
"""
|
|
|
|
Time to tidy up on exit
|
|
|
|
"""
|
2013-08-31 18:17:38 +00:00
|
|
|
log.info('Custom Finalising')
|
2020-01-01 02:53:08 +00:00
|
|
|
# call custom manager to delete pco slides
|
|
|
|
pco_slides = self.db_manager.get_all_objects(CustomSlide, CustomSlide.credits == 'pco')
|
|
|
|
for slide in pco_slides:
|
|
|
|
self.db_manager.delete_object(CustomSlide, slide.id)
|
2013-12-24 07:02:47 +00:00
|
|
|
self.db_manager.finalise()
|
2010-12-31 02:17:41 +00:00
|
|
|
Plugin.finalise(self)
|