openlp/openlp/plugins/bibles/bibleplugin.py

212 lines
9.3 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2013-01-01 16:33:41 +00:00
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2012-12-29 20:56:56 +00:00
# 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, #
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 #
###############################################################################
import logging
2013-01-18 23:31:02 +00:00
from PyQt4 import QtGui
from openlp.core.lib import Plugin, StringContent, build_icon, translate
2013-02-05 08:05:28 +00:00
from openlp.core.lib.ui import UiStrings, create_action
from openlp.core.utils.actions import ActionList
from openlp.plugins.bibles.lib import BibleManager, BiblesTab, BibleMediaItem, LayoutStyle, DisplayStyle, \
LanguageSelection
from openlp.plugins.bibles.lib.mediaitem import BibleSearch
from openlp.plugins.bibles.forms import BibleUpgradeForm
log = logging.getLogger(__name__)
2013-01-10 20:41:16 +00:00
__default_settings__ = {
2013-08-31 18:17:38 +00:00
'bibles/db type': 'sqlite',
'bibles/last search type': BibleSearch.Reference,
'bibles/verse layout style': LayoutStyle.VersePerSlide,
'bibles/book name language': LanguageSelection.Bible,
'bibles/display brackets': DisplayStyle.NoBrackets,
2013-08-31 19:59:13 +00:00
'bibles/is verse number visible': True,
2013-08-31 18:17:38 +00:00
'bibles/display new chapter': False,
'bibles/second bibles': True,
'bibles/advanced bible': '',
'bibles/quick bible': '',
'bibles/proxy name': '',
'bibles/proxy address': '',
'bibles/proxy username': '',
'bibles/proxy password': '',
'bibles/bible theme': '',
'bibles/verse separator': '',
'bibles/range separator': '',
'bibles/list separator': '',
'bibles/end separator': '',
'bibles/last directory import': ''
2013-03-19 19:43:22 +00:00
}
class BiblePlugin(Plugin):
2013-08-31 18:17:38 +00:00
log.info('Bible Plugin loaded')
2013-01-23 21:05:25 +00:00
def __init__(self):
2013-08-31 18:17:38 +00:00
super(BiblePlugin, self).__init__('bibles', __default_settings__, BibleMediaItem, BiblesTab)
self.weight = -9
2013-08-31 18:17:38 +00:00
self.icon_path = ':/plugins/plugin_bibles.png'
2013-03-19 19:43:22 +00:00
self.icon = build_icon(self.icon_path)
self.manager = None
def initialise(self):
2013-08-31 18:17:38 +00:00
log.info('bibles Initialising')
if self.manager is None:
self.manager = BibleManager(self)
Plugin.initialise(self)
2013-03-19 19:43:22 +00:00
self.import_bible_item.setVisible(True)
2011-04-09 16:11:02 +00:00
action_list = ActionList.get_instance()
2013-03-19 19:43:22 +00:00
action_list.add_action(self.import_bible_item, UiStrings().Import)
2011-03-30 18:27:33 +00:00
# Do not add the action to the list yet.
2013-03-19 19:43:22 +00:00
#action_list.add_action(self.export_bible_item, UiStrings().Export)
2011-03-15 20:53:36 +00:00
# Set to invisible until we can export bibles
2013-03-19 19:43:22 +00:00
self.export_bible_item.setVisible(False)
self.tools_upgrade_item.setVisible(bool(self.manager.old_bible_databases))
def finalise(self):
2010-11-03 17:19:44 +00:00
"""
Tidy up on exit
"""
2013-08-31 18:17:38 +00:00
log.info('Plugin Finalise')
2010-11-03 17:19:44 +00:00
self.manager.finalise()
Plugin.finalise(self)
2011-04-09 16:11:02 +00:00
action_list = ActionList.get_instance()
2013-03-19 19:43:22 +00:00
action_list.remove_action(self.import_bible_item, UiStrings().Import)
self.import_bible_item.setVisible(False)
#action_list.remove_action(self.export_bible_item, UiStrings().Export)
self.export_bible_item.setVisible(False)
def app_startup(self):
"""
Perform tasks on application startup
"""
Plugin.app_startup(self)
if self.manager.old_bible_databases:
if QtGui.QMessageBox.information(self.main_window,
2013-01-01 16:33:41 +00:00
translate('OpenLP', 'Information'),
translate('OpenLP', 'Bible format has changed.\nYou have to upgrade your existing Bibles.\n'
'Should OpenLP upgrade now?'),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)) == \
QtGui.QMessageBox.Yes:
2013-03-19 19:43:22 +00:00
self.on_tools_upgrade_Item_triggered()
2013-03-19 19:43:22 +00:00
def add_import_menu_item(self, import_menu):
2013-08-31 18:17:38 +00:00
self.import_bible_item = create_action(import_menu, 'importBibleItem',
text=translate('BiblesPlugin', '&Bible'), visible=False,
2013-03-19 19:43:22 +00:00
triggers=self.on_bible_import_click)
import_menu.addAction(self.import_bible_item)
2013-03-19 19:43:22 +00:00
def add_export_menu_Item(self, export_menu):
2013-08-31 18:17:38 +00:00
self.export_bible_item = create_action(export_menu, 'exportBibleItem',
2013-04-18 17:45:14 +00:00
text=translate('BiblesPlugin', '&Bible'), visible=False)
2013-03-19 19:43:22 +00:00
export_menu.addAction(self.export_bible_item)
2013-03-19 19:43:22 +00:00
def add_tools_menu_item(self, tools_menu):
"""
2013-04-18 17:45:14 +00:00
Give the bible plugin the opportunity to add items to the **Tools** menu.
``tools_menu``
2013-04-18 17:45:14 +00:00
The actual **Tools** menu item, so that your actions can use it as their parent.
"""
2013-08-31 18:17:38 +00:00
log.debug('add tools menu')
self.tools_upgrade_item = create_action(tools_menu, 'toolsUpgradeItem',
text=translate('BiblesPlugin', '&Upgrade older Bibles'),
2013-01-01 16:33:41 +00:00
statustip=translate('BiblesPlugin', 'Upgrade the Bible databases to the latest format.'),
2013-03-19 19:43:22 +00:00
visible=False, triggers=self.on_tools_upgrade_Item_triggered)
tools_menu.addAction(self.tools_upgrade_item)
2013-03-19 19:43:22 +00:00
def on_tools_upgrade_Item_triggered(self):
"""
Upgrade older bible databases.
"""
2013-08-31 18:17:38 +00:00
if not hasattr(self, 'upgrade_wizard'):
self.upgrade_wizard = BibleUpgradeForm(self.main_window, self.manager, self)
# If the import was not cancelled then reload.
if self.upgrade_wizard.exec_():
2013-03-19 19:43:22 +00:00
self.media_item.reloadBibles()
2013-03-19 19:43:22 +00:00
def on_bible_import_click(self):
if self.media_item:
2013-03-19 20:05:13 +00:00
self.media_item.on_import_click()
def about(self):
about_text = translate('BiblesPlugin', '<strong>Bible Plugin</strong>'
'<br />The Bible plugin provides the ability to display Bible '
'verses from different sources during the service.')
return about_text
2013-02-19 21:23:56 +00:00
def uses_theme(self, theme):
"""
2013-04-18 17:45:14 +00:00
Called to find out if the bible plugin is currently using a theme. Returns ``True`` if the theme is being used,
otherwise returns ``False``.
"""
2013-08-31 18:17:38 +00:00
return str(self.settings_tab.bible_theme) == theme
2013-04-18 17:45:14 +00:00
def rename_theme(self, old_theme, new_theme):
"""
Rename the theme the bible plugin is using making the plugin use the
new name.
2013-04-18 17:45:14 +00:00
``old_theme``
The name of the theme the plugin should stop using. Unused for this particular plugin.
2013-04-18 17:45:14 +00:00
``new_theme``
The new name the plugin should now use.
"""
2013-04-18 17:45:14 +00:00
self.settings_tab.bible_theme = new_theme
2013-03-19 19:43:22 +00:00
self.settings_tab.save()
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('BiblesPlugin', 'Bible', 'name singular'),
'plural': translate('BiblesPlugin', 'Bibles', '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('BiblesPlugin', 'Bibles', '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': '',
'import': translate('BiblesPlugin', 'Import a Bible.'),
'new': translate('BiblesPlugin', 'Add a new Bible.'),
'edit': translate('BiblesPlugin', 'Edit the selected Bible.'),
'delete': translate('BiblesPlugin', 'Delete the selected Bible.'),
'preview': translate('BiblesPlugin',
2011-05-06 05:17:13 +00:00
'Preview the selected Bible.'),
2013-08-31 18:17:38 +00:00
'live': translate('BiblesPlugin', 'Send the selected Bible live.'),
'service': translate('BiblesPlugin', 'Add the selected Bible to the service.')
}
2013-03-19 19:43:22 +00:00
self.set_plugin_ui_text_strings(tooltips)