openlp/openlp/plugins/custom/customplugin.py

133 lines
6.2 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 #
# --------------------------------------------------------------------------- #
2013-12-24 08:56:50 +00:00
# Copyright (c) 2008-2014 Raoul Snyman #
# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
2012-11-11 21:16:14 +00:00
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
2012-10-21 13:16:22 +00:00
# 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 #
###############################################################################
"""
The :mod:`~openlp.plugins.custom.customplugin` module contains the Plugin class
for the Custom Slides plugin.
"""
import logging
from openlp.core.lib import Plugin, StringContent, build_icon, translate
from openlp.core.lib.db import Manager
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',
'custom/last search type': CustomSearch.Titles,
'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)
2013-08-31 18:17:38 +00:00
self.icon_path = ':/plugins/plugin_custom.png'
2013-03-19 19:43:22 +00:00
self.icon = build_icon(self.icon_path)
def about(self):
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.
Returns True if the theme is being used, otherwise returns False.
"""
2013-12-24 07:02:47 +00:00
if self.db_manager.get_all_objects(CustomSlide, CustomSlide.theme_name == theme):
return True
return False
2013-12-24 07:02:47 +00:00
def rename_theme(self, old_theme, new_theme):
"""
Renames a theme the custom plugin is using making the plugin use the
new name.
``oldTheme``
The name of the theme the plugin should stop using.
``newTheme``
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
"""
2010-09-15 17:55:27 +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-15 17:55:27 +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)