openlp/openlp/plugins/bibles/bibleplugin.py

216 lines
9.4 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-01-10 20:09:27 +00:00
u'bibles/db type': u'sqlite',
u'bibles/last search type': BibleSearch.Reference,
2013-01-10 20:09:27 +00:00
u'bibles/verse layout style': LayoutStyle.VersePerSlide,
u'bibles/book name language': LanguageSelection.Bible,
2013-01-10 20:09:27 +00:00
u'bibles/display brackets': DisplayStyle.NoBrackets,
u'bibles/display new chapter': False,
2013-01-10 20:09:27 +00:00
u'bibles/second bibles': True,
u'bibles/advanced bible': u'',
u'bibles/quick bible': u'',
u'bibles/proxy name': u'',
u'bibles/proxy address': u'',
u'bibles/proxy username': u'',
u'bibles/proxy password': u'',
u'bibles/bible theme': u'',
u'bibles/verse separator': u'',
u'bibles/range separator': u'',
u'bibles/list separator': u'',
u'bibles/end separator': u'',
2013-01-18 20:35:30 +00:00
u'bibles/last directory import': u''
2013-03-19 19:43:22 +00:00
}
class BiblePlugin(Plugin):
log.info(u'Bible Plugin loaded')
2013-01-23 21:05:25 +00:00
def __init__(self):
Plugin.__init__(self, u'bibles', __default_settings__, BibleMediaItem, BiblesTab)
self.weight = -9
2013-03-19 19:43:22 +00:00
self.icon_path = u':/plugins/plugin_bibles.png'
self.icon = build_icon(self.icon_path)
self.manager = None
def initialise(self):
log.info(u'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
"""
log.info(u'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):
self.import_bible_item = create_action(import_menu, u'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):
self.export_bible_item = create_action(export_menu, u'exportBibleItem',
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):
"""
Give the bible plugin the opportunity to add items to the
**Tools** menu.
``tools_menu``
The actual **Tools** menu item, so that your actions can
use it as their parent.
"""
log.debug(u'add tools menu')
2013-03-19 19:43:22 +00:00
self.tools_upgrade_item = create_action(tools_menu, u'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.
"""
if not hasattr(self, u'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:
self.media_item.onImportClick()
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):
"""
Called to find out if the bible plugin is currently using a theme.
2012-04-16 07:02:24 +00:00
Returns ``True`` if the theme is being used, otherwise returns
``False``.
"""
2013-03-19 19:43:22 +00:00
return unicode(self.settings_tab.bible_theme) == theme
2013-02-19 21:23:56 +00:00
def rename_theme(self, oldTheme, newTheme):
"""
Rename the theme the bible plugin is using making the plugin use the
new name.
``oldTheme``
The name of the theme the plugin should stop using. Unused for
this particular plugin.
``newTheme``
The new name the plugin should now use.
"""
2013-03-19 19:43:22 +00:00
self.settings_tab.bible_theme = newTheme
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] = {
u'singular': translate('BiblesPlugin', 'Bible', 'name singular'),
u'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] = {
u'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 = {
2011-02-14 19:08:18 +00:00
u'load': u'',
2011-05-06 05:17:13 +00:00
u'import': translate('BiblesPlugin', 'Import a Bible.'),
u'new': translate('BiblesPlugin', 'Add a new Bible.'),
u'edit': translate('BiblesPlugin', 'Edit the selected Bible.'),
u'delete': translate('BiblesPlugin', 'Delete the selected Bible.'),
u'preview': translate('BiblesPlugin',
'Preview the selected Bible.'),
u'live': translate('BiblesPlugin', 'Send the selected Bible live.'),
2013-01-01 16:33:41 +00:00
u'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)