openlp/openlp/plugins/songs/songsplugin.py

192 lines
8.4 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2009-12-31 12:52:01 +00:00
# Copyright (c) 2008-2010 Raoul Snyman #
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
2010-03-21 23:58:01 +00:00
# Gorven, Scott Guerrieri, Christian Richter, Maikel Stuivenberg, Martin #
# Thompson, Jon Tibble, Carsten Tinggaard #
# --------------------------------------------------------------------------- #
# 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
from PyQt4 import QtCore, QtGui
2010-06-08 15:38:09 +00:00
from openlp.core.lib import Plugin, build_icon, PluginStatus, Receiver, \
translate
2010-04-02 14:10:10 +00:00
from openlp.plugins.songs.lib import SongManager, SongMediaItem, SongsTab, \
2010-04-12 07:22:56 +00:00
SofImport, OooImport
2010-02-27 15:31:23 +00:00
log = logging.getLogger(__name__)
class SongsPlugin(Plugin):
"""
This is the number 1 plugin, if importance were placed on any
plugins. This plugin enables the user to create, edit and display
songs. Songs are divided into verses, and the verse order can be
specified. Authors, topics and song books can be assigned to songs
as well.
"""
log.info(u'Song Plugin loaded')
def __init__(self, plugin_helpers):
"""
Create and set up the Songs plugin.
"""
2010-02-06 10:33:33 +00:00
Plugin.__init__(self, u'Songs', u'1.9.1', plugin_helpers)
self.weight = -10
2010-05-17 20:48:16 +00:00
self.manager = SongManager()
self.icon = build_icon(u':/media/media_song.png')
2010-02-06 10:33:33 +00:00
self.status = PluginStatus.Active
2009-10-17 05:47:17 +00:00
def get_settings_tab(self):
2009-10-30 17:44:16 +00:00
return SongsTab(self.name)
2009-10-17 05:47:17 +00:00
2009-10-08 17:28:59 +00:00
def initialise(self):
log.info(u'Songs Initialising')
2009-10-08 19:35:24 +00:00
#if self.songmanager is None:
2010-04-27 16:27:57 +00:00
# self.songmanager = SongManager()
2009-10-08 17:28:59 +00:00
Plugin.initialise(self)
2009-10-30 20:34:11 +00:00
self.insert_toolbox_item()
2010-04-02 12:23:40 +00:00
#self.ImportSongMenu.menuAction().setVisible(True)
#self.ExportSongMenu.menuAction().setVisible(True)
self.media_item.displayResultsSong(self.manager.get_songs())
2009-10-08 17:28:59 +00:00
def finalise(self):
log.info(u'Plugin Finalise')
Plugin.finalise(self)
self.remove_toolbox_item()
2010-04-02 12:23:40 +00:00
#self.ImportSongMenu.menuAction().setVisible(False)
#self.ExportSongMenu.menuAction().setVisible(False)
2009-10-08 17:28:59 +00:00
def get_media_manager_item(self):
"""
Create the MediaManagerItem object, which is displaed in the
Media Manager.
"""
2009-10-30 17:44:16 +00:00
return SongMediaItem(self, self.icon, self.name)
def add_import_menu_item(self, import_menu):
"""
Give the Songs plugin the opportunity to add items to the
**Import** menu.
``import_menu``
The actual **Import** menu item, so that your actions can
use it as their parent.
"""
2010-05-17 20:48:16 +00:00
# Main song import menu item - will eventually be the only one
2010-04-02 12:23:40 +00:00
self.SongImportItem = QtGui.QAction(import_menu)
self.SongImportItem.setObjectName(u'SongImportItem')
self.SongImportItem.setText(import_menu.trUtf8('&Song'))
self.SongImportItem.setToolTip(
import_menu.trUtf8('Import songs using the import wizard.'))
import_menu.addAction(self.SongImportItem)
2010-05-17 20:48:16 +00:00
# Songs of Fellowship import menu item - will be removed and the
# functionality will be contained within the import wizard
2010-04-02 14:10:10 +00:00
self.ImportSofItem = QtGui.QAction(import_menu)
self.ImportSofItem.setObjectName(u'ImportSofItem')
self.ImportSofItem.setText(
2010-05-17 20:48:16 +00:00
import_menu.trUtf8('Songs of Fellowship (temp menu item)'))
2010-04-02 14:10:10 +00:00
self.ImportSofItem.setToolTip(
import_menu.trUtf8('Import songs from the VOLS1_2.RTF, sof3words' \
+ '.rtf and sof4words.rtf supplied with the music books'))
self.ImportSofItem.setStatusTip(
import_menu.trUtf8('Import songs from the VOLS1_2.RTF, sof3words' \
+ '.rtf and sof4words.rtf supplied with the music books'))
2010-05-17 20:48:16 +00:00
import_menu.addAction(self.ImportSofItem)
# OpenOffice.org import menu item - will be removed and the
# functionality will be contained within the import wizard
self.ImportOooItem = QtGui.QAction(import_menu)
self.ImportOooItem.setObjectName(u'ImportOooItem')
2010-04-12 07:22:56 +00:00
self.ImportOooItem.setText(
2010-05-18 21:32:58 +00:00
import_menu.trUtf8('Generic Document/Presentation Import '
'(temp menu item)'))
2010-04-12 07:22:56 +00:00
self.ImportOooItem.setToolTip(
2010-05-18 21:32:58 +00:00
import_menu.trUtf8('Import songs from '
'Word/Writer/Powerpoint/Impress'))
2010-04-12 07:22:56 +00:00
self.ImportOooItem.setStatusTip(
2010-05-18 21:32:58 +00:00
import_menu.trUtf8('Import songs from '
'Word/Writer/Powerpoint/Impress'))
2010-05-17 20:48:16 +00:00
import_menu.addAction(self.ImportOooItem)
# Signals and slots
2010-04-02 12:23:40 +00:00
QtCore.QObject.connect(self.SongImportItem,
QtCore.SIGNAL(u'triggered()'), self.onSongImportItemClicked)
2010-04-02 14:10:10 +00:00
QtCore.QObject.connect(self.ImportSofItem,
QtCore.SIGNAL(u'triggered()'), self.onImportSofItemClick)
2010-04-12 07:22:56 +00:00
QtCore.QObject.connect(self.ImportOooItem,
QtCore.SIGNAL(u'triggered()'), self.onImportOooItemClick)
2010-04-02 12:23:40 +00:00
def add_export_menu_item(self, export_menu):
"""
Give the Songs plugin the opportunity to add items to the
**Export** menu.
``export_menu``
The actual **Export** menu item, so that your actions can
use it as their parent.
"""
2010-05-17 20:48:16 +00:00
# No menu items for now.
pass
2010-04-02 12:23:40 +00:00
def onSongImportItemClicked(self):
if self.media_item:
self.media_item.onImportClick()
2010-04-02 14:10:10 +00:00
def onImportSofItemClick(self):
2010-04-12 07:22:56 +00:00
filenames = QtGui.QFileDialog.getOpenFileNames(
None, translate(u'SongsPlugin.Songsplugin',
u'Open Songs of Fellowship file'),
2010-04-02 14:10:10 +00:00
u'', u'Songs of Fellowship file (*.rtf *.RTF)')
2010-04-02 23:24:51 +00:00
try:
2010-04-12 07:22:56 +00:00
for filename in filenames:
2010-05-18 21:32:58 +00:00
sofimport = SofImport(self.manager)
2010-04-12 07:22:56 +00:00
sofimport.import_sof(unicode(filename))
2010-04-02 23:24:51 +00:00
except:
log.exception('Could not import SoF file')
QtGui.QMessageBox.critical(None,
self.ImportSongMenu.trUtf8('Import Error'),
2010-04-03 19:17:37 +00:00
self.ImportSongMenu.trUtf8('Error importing Songs of '
2010-05-18 21:32:58 +00:00
'Fellowship file.\nOpenOffice.org must be installed'
' and you must be using an unedited copy of the RTF'
' included with the Songs of Fellowship Music Editions'),
2010-04-02 23:24:51 +00:00
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok),
QtGui.QMessageBox.Ok)
2010-04-16 07:31:01 +00:00
Receiver.send_message(u'songs_load_list')
2010-04-02 14:10:10 +00:00
2010-04-12 07:22:56 +00:00
def onImportOooItemClick(self):
filenames = QtGui.QFileDialog.getOpenFileNames(
None, translate(u'SongsPlugin.Songsplugin',
u'Open documents or presentations'),
2010-04-12 07:22:56 +00:00
u'', u'All Files(*.*)')
2010-05-18 21:32:58 +00:00
oooimport = OooImport(self.manager)
2010-04-12 07:22:56 +00:00
oooimport.import_docs(filenames)
2010-04-16 07:31:01 +00:00
Receiver.send_message(u'songs_load_list')
2009-10-01 16:56:42 +00:00
def about(self):
about_text = translate(u'SongsPlugin.Songsplugin',
u'<strong>Song Plugin</strong><br />'
u'This plugin allows songs to be managed and displayed.')
2010-02-06 10:33:33 +00:00
return about_text
def can_delete_theme(self, theme):
2010-04-02 12:23:40 +00:00
if len(self.manager.get_songs_for_theme(theme)) == 0:
return True
return False
2010-05-17 20:48:16 +00:00