openlp/openlp/plugins/custom/customplugin.py

132 lines
6.1 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2013-01-05 22:17:30 +00:00
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2017-12-29 09:15:48 +00:00
# Copyright (c) 2008-2018 OpenLP Developers #
# --------------------------------------------------------------------------- #
# 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 #
###############################################################################
"""
The :mod:`~openlp.plugins.custom.customplugin` module contains the Plugin class
for the Custom Slides plugin.
"""
import logging
2016-08-10 20:52:27 +00:00
from openlp.core.api.http import register_endpoint
2018-04-10 19:26:56 +00:00
from openlp.core.common.i18n import translate
from openlp.core.ui.icons import UiIcons
2017-10-07 07:05:07 +00:00
from openlp.core.lib import Plugin, StringContent, build_icon
from openlp.core.lib.db import Manager
2016-08-10 20:52:27 +00:00
from openlp.plugins.custom.endpoint import api_custom_endpoint, custom_endpoint
from openlp.plugins.custom.lib import CustomMediaItem, CustomTab
from openlp.plugins.custom.lib.db import CustomSlide, init_schema
from openlp.plugins.custom.lib.mediaitem import CustomSearch
log = logging.getLogger(__name__)
2013-01-10 20:41:16 +00:00
__default_settings__ = {
2013-12-24 07:02:47 +00:00
'custom/db type': 'sqlite',
2015-02-11 20:56:13 +00:00
'custom/db username': '',
'custom/db password': '',
'custom/db hostname': '',
'custom/db database': '',
'custom/last used search type': CustomSearch.Titles,
2013-12-24 07:02:47 +00:00
'custom/display footer': True,
'custom/add custom from service': True
2013-03-17 09:21:18 +00:00
}
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):
2013-08-31 18:17:38 +00:00
super(CustomPlugin, self).__init__('custom', __default_settings__, CustomMediaItem, CustomTab)
self.weight = -5
2013-12-24 07:02:47 +00:00
self.db_manager = Manager('custom', init_schema)
2018-04-07 16:57:44 +00:00
self.icon_path = UiIcons().clone
2013-03-19 19:43:22 +00:00
self.icon = build_icon(self.icon_path)
2016-08-10 20:52:27 +00:00
register_endpoint(custom_endpoint)
register_endpoint(api_custom_endpoint)
2016-01-04 00:18:01 +00:00
@staticmethod
def about():
2013-01-05 22:17:30 +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.')
return about_text
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')
2013-12-24 07:02:47 +00:00
self.db_manager.finalise()
Plugin.finalise(self)