openlp/openlp/plugins/custom/customplugin.py

133 lines
6.1 KiB
Python
Raw Normal View History

# -*- 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/>. #
##########################################################################
"""
The :mod:`~openlp.plugins.custom.customplugin` module contains the Plugin class
for the Custom Slides plugin.
"""
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
from openlp.core.common.registry import Registry
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
from openlp.plugins.custom.lib.db import CustomSlide, init_schema
from openlp.plugins.custom.lib.mediaitem import CustomMediaItem
from openlp.plugins.custom.lib.customtab import CustomTab
2018-10-02 04:39:42 +00:00
log = logging.getLogger(__name__)
2013-01-10 20:50:01 +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.
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.
"""
2013-08-31 18:17:38 +00:00
log.info('Custom Plugin loaded')
2013-01-23 21:05:25 +00:00
def __init__(self):
super(CustomPlugin, self).__init__('custom', CustomMediaItem, CustomTab)
self.weight = -5
2023-05-19 13:55:38 +00:00
self.db_manager = DBManager('custom', init_schema)
self.icon_path = UiIcons().custom
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())
2016-01-04 00:18:01 +00:00
@staticmethod
def about():
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.')
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):
"""
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.
:param theme: Theme to be queried
"""
2015-10-16 16:43:48 +00:00
return len(self.db_manager.get_all_objects(CustomSlide, CustomSlide.theme_name == theme))
2013-12-24 07:02:47 +00:00
def rename_theme(self, old_theme, new_theme):
"""
2014-03-17 19:05:55 +00:00
Renames a theme the custom plugin is using making the plugin use the new name.
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.
"""
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)
2013-02-19 21:23:56 +00:00
def set_plugin_text_strings(self):
"""
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')
}
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
}
# 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.')
}
2013-03-19 19:43:22 +00:00
self.set_plugin_ui_text_strings(tooltips)
def finalise(self):
"""
Time to tidy up on exit
"""
2013-08-31 18:17:38 +00:00
log.info('Custom Finalising')
# 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()
Plugin.finalise(self)