2010-09-10 19:21:14 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-01-01 16:33:41 +00:00
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
2010-09-10 19:21:14 +00:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# 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 #
|
2012-06-22 14:14:53 +00:00
|
|
|
# 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, #
|
2012-12-01 07:57:54 +00:00
|
|
|
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
|
2010-09-10 19:21:14 +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; 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
|
2010-09-10 19:21:14 +00:00
|
|
|
|
2013-02-04 21:22:12 +00:00
|
|
|
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
|
2011-03-31 08:43:19 +00:00
|
|
|
from openlp.core.utils.actions import ActionList
|
2013-01-10 19:33:48 +00:00
|
|
|
from openlp.plugins.bibles.lib import BibleManager, BiblesTab, BibleMediaItem, LayoutStyle, DisplayStyle, \
|
|
|
|
LanguageSelection
|
|
|
|
from openlp.plugins.bibles.lib.mediaitem import BibleSearch
|
2011-04-26 18:18:13 +00:00
|
|
|
from openlp.plugins.bibles.forms import BibleUpgradeForm
|
2010-09-10 19:21:14 +00:00
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2013-01-11 20:44:30 +00:00
|
|
|
|
2013-01-10 20:41:16 +00:00
|
|
|
__default_settings__ = {
|
2013-01-10 20:09:27 +00:00
|
|
|
u'bibles/db type': u'sqlite',
|
2013-01-10 23:07:48 +00:00
|
|
|
u'bibles/last search type': BibleSearch.Reference,
|
2013-01-10 20:09:27 +00:00
|
|
|
u'bibles/verse layout style': LayoutStyle.VersePerSlide,
|
2013-01-10 23:07:48 +00:00
|
|
|
u'bibles/book name language': LanguageSelection.Bible,
|
2013-01-10 20:09:27 +00:00
|
|
|
u'bibles/display brackets': DisplayStyle.NoBrackets,
|
2013-01-10 23:07:48 +00:00
|
|
|
u'bibles/display new chapter': False,
|
2013-01-10 20:09:27 +00:00
|
|
|
u'bibles/second bibles': True,
|
2013-01-11 20:44:30 +00:00
|
|
|
u'bibles/advanced bible': u'',
|
|
|
|
u'bibles/quick bible': u'',
|
2013-01-10 23:07:48 +00:00
|
|
|
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'',
|
2013-01-17 22:14:06 +00:00
|
|
|
u'bibles/end separator': u'',
|
2013-01-18 20:35:30 +00:00
|
|
|
u'bibles/last directory import': u''
|
2013-01-10 20:09:27 +00:00
|
|
|
}
|
2013-01-10 19:33:48 +00:00
|
|
|
|
2010-09-10 19:21:14 +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)
|
2010-09-10 19:21:14 +00:00
|
|
|
self.weight = -9
|
2012-04-22 19:37:11 +00:00
|
|
|
self.iconPath = u':/plugins/plugin_bibles.png'
|
|
|
|
self.icon = build_icon(self.iconPath)
|
2010-09-10 19:21:14 +00:00
|
|
|
self.manager = None
|
|
|
|
|
|
|
|
def initialise(self):
|
|
|
|
log.info(u'bibles Initialising')
|
|
|
|
if self.manager is None:
|
|
|
|
self.manager = BibleManager(self)
|
|
|
|
Plugin.initialise(self)
|
|
|
|
self.importBibleItem.setVisible(True)
|
2011-04-09 16:11:02 +00:00
|
|
|
action_list = ActionList.get_instance()
|
2012-05-17 18:57:01 +00:00
|
|
|
action_list.add_action(self.importBibleItem, UiStrings().Import)
|
2011-03-30 18:27:33 +00:00
|
|
|
# Do not add the action to the list yet.
|
2012-05-17 18:57:01 +00:00
|
|
|
#action_list.add_action(self.exportBibleItem, UiStrings().Export)
|
2011-03-15 20:53:36 +00:00
|
|
|
# Set to invisible until we can export bibles
|
|
|
|
self.exportBibleItem.setVisible(False)
|
2012-06-16 15:51:04 +00:00
|
|
|
self.toolsUpgradeItem.setVisible(bool(self.manager.old_bible_databases))
|
2010-09-10 19:21:14 +00:00
|
|
|
|
|
|
|
def finalise(self):
|
2010-11-03 17:19:44 +00:00
|
|
|
"""
|
|
|
|
Tidy up on exit
|
|
|
|
"""
|
2010-09-10 19:21:14 +00:00
|
|
|
log.info(u'Plugin Finalise')
|
2010-11-03 17:19:44 +00:00
|
|
|
self.manager.finalise()
|
2010-09-10 19:21:14 +00:00
|
|
|
Plugin.finalise(self)
|
2011-04-09 16:11:02 +00:00
|
|
|
action_list = ActionList.get_instance()
|
2012-05-17 18:57:01 +00:00
|
|
|
action_list.remove_action(self.importBibleItem, UiStrings().Import)
|
2010-09-10 19:21:14 +00:00
|
|
|
self.importBibleItem.setVisible(False)
|
2011-04-15 21:43:59 +00:00
|
|
|
#action_list.remove_action(self.exportBibleItem, UiStrings().Export)
|
2010-09-10 19:21:14 +00:00
|
|
|
self.exportBibleItem.setVisible(False)
|
|
|
|
|
2013-02-03 14:40:48 +00:00
|
|
|
def app_startup(self):
|
2011-05-25 14:18:03 +00:00
|
|
|
"""
|
2012-04-21 22:29:08 +00:00
|
|
|
Perform tasks on application startup
|
2011-05-25 14:18:03 +00:00
|
|
|
"""
|
2013-02-03 14:40:48 +00:00
|
|
|
Plugin.app_startup(self)
|
2012-04-29 15:31:56 +00:00
|
|
|
if self.manager.old_bible_databases:
|
2013-01-23 19:28:47 +00:00
|
|
|
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:
|
2011-05-25 14:18:03 +00:00
|
|
|
self.onToolsUpgradeItemTriggered()
|
|
|
|
|
2010-09-10 19:21:14 +00:00
|
|
|
def addImportMenuItem(self, import_menu):
|
2012-02-27 23:44:35 +00:00
|
|
|
self.importBibleItem = create_action(import_menu, u'importBibleItem',
|
|
|
|
text=translate('BiblesPlugin', '&Bible'), visible=False,
|
|
|
|
triggers=self.onBibleImportClick)
|
2010-09-10 19:21:14 +00:00
|
|
|
import_menu.addAction(self.importBibleItem)
|
|
|
|
|
|
|
|
def addExportMenuItem(self, export_menu):
|
2012-02-27 23:44:35 +00:00
|
|
|
self.exportBibleItem = create_action(export_menu, u'exportBibleItem',
|
|
|
|
text=translate('BiblesPlugin', '&Bible'),
|
|
|
|
visible=False)
|
2011-03-30 18:27:33 +00:00
|
|
|
export_menu.addAction(self.exportBibleItem)
|
2010-09-10 19:21:14 +00:00
|
|
|
|
2011-04-19 20:25:27 +00:00
|
|
|
def addToolsMenuItem(self, tools_menu):
|
|
|
|
"""
|
2011-04-26 18:18:13 +00:00
|
|
|
Give the bible plugin the opportunity to add items to the
|
2011-04-19 20:25:27 +00:00
|
|
|
**Tools** menu.
|
|
|
|
|
|
|
|
``tools_menu``
|
|
|
|
The actual **Tools** menu item, so that your actions can
|
|
|
|
use it as their parent.
|
|
|
|
"""
|
2011-05-25 19:13:37 +00:00
|
|
|
log.debug(u'add tools menu')
|
2012-02-28 09:24:42 +00:00
|
|
|
self.toolsUpgradeItem = 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.'),
|
2012-02-28 09:24:42 +00:00
|
|
|
visible=False, triggers=self.onToolsUpgradeItemTriggered)
|
2011-04-26 18:18:13 +00:00
|
|
|
tools_menu.addAction(self.toolsUpgradeItem)
|
2011-04-19 20:25:27 +00:00
|
|
|
|
2011-04-26 18:18:13 +00:00
|
|
|
def onToolsUpgradeItemTriggered(self):
|
2011-04-19 20:25:27 +00:00
|
|
|
"""
|
2011-04-26 18:18:13 +00:00
|
|
|
Upgrade older bible databases.
|
2011-04-19 20:25:27 +00:00
|
|
|
"""
|
2011-04-26 18:18:13 +00:00
|
|
|
if not hasattr(self, u'upgrade_wizard'):
|
2013-01-23 19:28:47 +00:00
|
|
|
self.upgrade_wizard = BibleUpgradeForm(self.main_window, self.manager, self)
|
2011-04-26 18:18:13 +00:00
|
|
|
# If the import was not cancelled then reload.
|
|
|
|
if self.upgrade_wizard.exec_():
|
|
|
|
self.mediaItem.reloadBibles()
|
2011-04-19 20:25:27 +00:00
|
|
|
|
2010-09-10 19:21:14 +00:00
|
|
|
def onBibleImportClick(self):
|
|
|
|
if self.mediaItem:
|
|
|
|
self.mediaItem.onImportClick()
|
|
|
|
|
|
|
|
def about(self):
|
|
|
|
about_text = translate('BiblesPlugin', '<strong>Bible Plugin</strong>'
|
2011-05-24 17:32:36 +00:00
|
|
|
'<br />The Bible plugin provides the ability to display Bible '
|
2010-09-10 19:21:14 +00:00
|
|
|
'verses from different sources during the service.')
|
|
|
|
return about_text
|
|
|
|
|
2013-02-19 21:23:56 +00:00
|
|
|
def uses_theme(self, theme):
|
2010-09-10 19:21:14 +00:00
|
|
|
"""
|
|
|
|
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``.
|
2010-09-10 19:21:14 +00:00
|
|
|
"""
|
2012-04-22 19:37:11 +00:00
|
|
|
return unicode(self.settingsTab.bible_theme) == theme
|
2010-09-10 19:21:14 +00:00
|
|
|
|
2013-02-19 21:23:56 +00:00
|
|
|
def rename_theme(self, oldTheme, newTheme):
|
2010-09-10 19:21:14 +00:00
|
|
|
"""
|
|
|
|
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.
|
|
|
|
"""
|
2012-04-21 22:29:08 +00:00
|
|
|
self.settingsTab.bible_theme = newTheme
|
|
|
|
self.settingsTab.save()
|
2010-09-10 19:21:14 +00:00
|
|
|
|
2013-02-19 21:23:56 +00:00
|
|
|
def set_plugin_text_strings(self):
|
2010-09-10 19:21:14 +00:00
|
|
|
"""
|
|
|
|
Called to define all translatable texts of the plugin
|
|
|
|
"""
|
2010-09-15 17:55:27 +00:00
|
|
|
## Name PluginList ##
|
2010-10-05 16:09:48 +00:00
|
|
|
self.textStrings[StringContent.Name] = {
|
2010-12-31 02:17:41 +00:00
|
|
|
u'singular': translate('BiblesPlugin', 'Bible', 'name singular'),
|
|
|
|
u'plural': translate('BiblesPlugin', 'Bibles', 'name plural')
|
2010-09-10 19:21:14 +00:00
|
|
|
}
|
2010-09-15 17:55:27 +00:00
|
|
|
## Name for MediaDockManager, SettingsManager ##
|
2010-10-05 16:09:48 +00:00
|
|
|
self.textStrings[StringContent.VisibleName] = {
|
2010-12-31 02:17:41 +00:00
|
|
|
u'title': translate('BiblesPlugin', 'Bibles', 'container title')
|
2010-09-15 17:55:27 +00:00
|
|
|
}
|
2010-09-10 19:21:14 +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.')
|
2010-09-10 19:21:14 +00:00
|
|
|
}
|
2011-04-19 20:25:27 +00:00
|
|
|
self.setPluginUiTextStrings(tooltips)
|