diff --git a/openlp/core/ui/wizard.py b/openlp/core/ui/wizard.py index 305e85f24..5369c9799 100644 --- a/openlp/core/ui/wizard.py +++ b/openlp/core/ui/wizard.py @@ -46,6 +46,7 @@ class WizardStrings(object): # the writers translating their own product name. CCLI = u'CCLI/SongSelect' CSV = u'CSV' + DB = u'DreamBeam' EW = u'EasyWorship' ES = u'EasySlides' FP = u'Foilpresenter' diff --git a/openlp/plugins/songs/forms/songimportform.py b/openlp/plugins/songs/forms/songimportform.py index 9498d1c79..4a44c30ef 100644 --- a/openlp/plugins/songs/forms/songimportform.py +++ b/openlp/plugins/songs/forms/songimportform.py @@ -129,6 +129,12 @@ class SongImportForm(OpenLPWizard): QtCore.QObject.connect(self.ccliRemoveButton, QtCore.SIGNAL(u'clicked()'), self.onCCLIRemoveButtonClicked) + QtCore.QObject.connect(self.dreamBeamAddButton, + QtCore.SIGNAL(u'clicked()'), + self.onDreamBeamAddButtonClicked) + QtCore.QObject.connect(self.dreamBeamRemoveButton, + QtCore.SIGNAL(u'clicked()'), + self.onDreamBeamRemoveButtonClicked) QtCore.QObject.connect(self.songsOfFellowshipAddButton, QtCore.SIGNAL(u'clicked()'), self.onSongsOfFellowshipAddButtonClicked) @@ -201,6 +207,8 @@ class SongImportForm(OpenLPWizard): self.addFileSelectItem(u'generic', None, True) # CCLI File import self.addFileSelectItem(u'ccli') + # DreamBeam + self.addFileSelectItem(u'dreamBeam') # EasySlides self.addFileSelectItem(u'easySlides', single_select=True) # EasyWorship @@ -247,6 +255,8 @@ class SongImportForm(OpenLPWizard): translate('SongsPlugin.ImportWizardForm', 'Generic Document/Presentation')) self.formatComboBox.setItemText(SongFormat.CCLI, WizardStrings.CCLI) + self.formatComboBox.setItemText( + SongFormat.DreamBeam, WizardStrings.DB) self.formatComboBox.setItemText( SongFormat.EasySlides, WizardStrings.ES) self.formatComboBox.setItemText( @@ -291,6 +301,10 @@ class SongImportForm(OpenLPWizard): translate('SongsPlugin.ImportWizardForm', 'Add Files...')) self.ccliRemoveButton.setText( translate('SongsPlugin.ImportWizardForm', 'Remove File(s)')) + self.dreamBeamAddButton.setText( + translate('SongsPlugin.ImportWizardForm', 'Add Files...')) + self.dreamBeamRemoveButton.setText( + translate('SongsPlugin.ImportWizardForm', 'Remove File(s)')) self.songsOfFellowshipAddButton.setText( translate('SongsPlugin.ImportWizardForm', 'Add Files...')) self.songsOfFellowshipRemoveButton.setText( @@ -397,6 +411,12 @@ class SongImportForm(OpenLPWizard): WizardStrings.YouSpecifyFile % WizardStrings.CCLI) self.ccliAddButton.setFocus() return False + elif source_format == SongFormat.DreamBeam: + if self.dreamBeamFileListWidget.count() == 0: + critical_error_message_box(UiStrings().NFSp, + WizardStrings.YouSpecifyFile % WizardStrings.DB) + self.dreamBeamAddButton.setFocus() + return False elif source_format == SongFormat.SongsOfFellowship: if self.songsOfFellowshipFileListWidget.count() == 0: critical_error_message_box(UiStrings().NFSp, @@ -433,7 +453,7 @@ class SongImportForm(OpenLPWizard): if self.songShowPlusFileListWidget.count() == 0: critical_error_message_box(UiStrings().NFSp, WizardStrings.YouSpecifyFile % WizardStrings.SSP) - self.wordsOfWorshipAddButton.setFocus() + self.songShowPlusAddButton.setFocus() return False elif source_format == SongFormat.FoilPresenter: if self.foilPresenterFileListWidget.count() == 0: @@ -564,6 +584,22 @@ class SongImportForm(OpenLPWizard): """ self.removeSelectedItems(self.ccliFileListWidget) + def onDreamBeamAddButtonClicked(self): + """ + Get DreamBeam song database files + """ + self.getFiles(WizardStrings.OpenTypeFile % WizardStrings.DB, + self.dreamBeamFileListWidget, u'%s (*.xml)' + % translate('SongsPlugin.ImportWizardForm', + 'DreamBeam Song Files') + ) + + def onDreamBeamRemoveButtonClicked(self): + """ + Remove selected DreamBeam files from the import list + """ + self.removeSelectedItems(self.dreamBeamFileListWidget) + def onSongsOfFellowshipAddButtonClicked(self): """ Get Songs of Fellowship song database files @@ -680,6 +716,7 @@ class SongImportForm(OpenLPWizard): self.openSongFileListWidget.clear() self.wordsOfWorshipFileListWidget.clear() self.ccliFileListWidget.clear() + self.dreamBeamFileListWidget.clear() self.songsOfFellowshipFileListWidget.clear() self.genericFileListWidget.clear() self.easySlidesFilenameEdit.setText(u'') @@ -741,6 +778,12 @@ class SongImportForm(OpenLPWizard): importer = self.plugin.importSongs(SongFormat.CCLI, filenames=self.getListOfFiles(self.ccliFileListWidget) ) + elif source_format == SongFormat.DreamBeam: + # Import DreamBeam songs + importer = self.plugin.importSongs(SongFormat.DreamBeam, + filenames=self.getListOfFiles( + self.dreamBeamFileListWidget) + ) elif source_format == SongFormat.SongsOfFellowship: # Import a Songs of Fellowship RTF file importer = self.plugin.importSongs(SongFormat.SongsOfFellowship, diff --git a/openlp/plugins/songs/lib/dreambeamimport.py b/openlp/plugins/songs/lib/dreambeamimport.py new file mode 100644 index 000000000..b251a8ce8 --- /dev/null +++ b/openlp/plugins/songs/lib/dreambeamimport.py @@ -0,0 +1,157 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2012 Raoul Snyman # +# Portions copyright (c) 2008-2012 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Michael Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, # +# Armin Köhler, Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias # +# Põldaru, Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Frode Woldsund # +# --------------------------------------------------------------------------- # +# 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:`dreambeamimport` module provides the functionality for importing +DreamBeam songs into the OpenLP database. +""" +import os +import sys +import logging + +from lxml import etree, objectify + +from openlp.core.lib import translate +from openlp.plugins.songs.lib.songimport import SongImport +from openlp.plugins.songs.lib.ui import SongStrings + +log = logging.getLogger(__name__) + +class DreamBeamImport(SongImport): + """ + The :class:`DreamBeamImport` class provides the ability to import song files from + DreamBeam. + + An example of DreamBeam xml mark-up:: + + + + false + 0.80 + Amazing Grace + John Newton + + + + F + G + false + false + + Amazing Grace, how sweet the sound, + That saved a wretch like me. + I once was lost but now am found, + Was blind, but now, I see. + T’was Grace that taught my heart to fear. + And Grace, my fears relieved. + How precious did that Grace appear… + the hour I first believed. + + + + + + false + + + Valid extensions for a DreamBeam song file are: + + * \*.xml + """ + + def doImport(self): + """ + Receive a single file or a list of files to import. + """ + if isinstance(self.importSource, list): + self.importWizard.progressBar.setMaximum(len(self.importSource)) + for file in self.importSource: + if self.stopImportFlag: + return + self.setDefaults() + parser = etree.XMLParser(remove_blank_text=True) + try: + parsed_file = etree.parse(open(file, u'r'), parser) + except etree.XMLSyntaxError: + log.exception(u'XML syntax error in file %s' % file) + self.logError(file, SongStrings.XMLSyntaxError) + continue + xml = unicode(etree.tostring(parsed_file)) + song_xml = objectify.fromstring(xml) + if song_xml.tag != u'DreamSong': + self.logError(file, unicode( + translate('SongsPlugin.DreamBeamImport', + ('Invalid DreamBeam song file. Missing ' + 'DreamSong tag.')))) + continue + if hasattr(song_xml, u'Version'): + self.version = float(song_xml.Version.text) + else: + self.version = 0 + # Version numbers found in DreamBeam Source /FileTypes/Song.cs + if self.version >= 0.5: + if hasattr(song_xml, u'Title'): + self.title = unicode(song_xml.Title.text) + if hasattr(song_xml, u'Author'): + author_copyright = song_xml.Author.text + if hasattr(song_xml, u'SongLyrics'): + for lyrics_item in song_xml.SongLyrics.iterchildren(): + verse_type = lyrics_item.get(u'Type') + verse_number = lyrics_item.get(u'Number') + verse_text = unicode(lyrics_item.text) + self.addVerse(verse_text, + (u'%s%s' % (verse_type[:1], verse_number))) + if hasattr(song_xml, u'Collection'): + self.songBookName = unicode(song_xml.Collection.text) + if hasattr(song_xml, u'Number'): + self.songNumber = unicode(song_xml.Number.text) + if hasattr(song_xml, u'Sequence'): + for LyricsSequenceItem in ( + song_xml.Sequence.iterchildren()): + self.verseOrderList.append( + "%s%s" % (LyricsSequenceItem.get(u'Type')[:1], + LyricsSequenceItem.get(u'Number'))) + if hasattr(song_xml, u'Notes'): + self.comments = unicode(song_xml.Notes.text) + else: + if hasattr(song_xml.Text0, u'Text'): + self.title = unicode(song_xml.Text0.Text.text) + if hasattr(song_xml.Text1, u'Text'): + self.lyrics = unicode(song_xml.Text1.Text.text) + for verse in self.lyrics.split(u'\n\n\n'): + self.addVerse(verse) + if hasattr(song_xml.Text2, u'Text'): + author_copyright = song_xml.Text2.Text.text + if author_copyright: + author_copyright = unicode(author_copyright) + if author_copyright.find( + unicode(SongStrings.CopyrightSymbol)) >= 0: + self.addCopyright(author_copyright) + else: + self.parseAuthor(author_copyright) + if not self.finish(): + self.logError(file) diff --git a/openlp/plugins/songs/lib/importer.py b/openlp/plugins/songs/lib/importer.py index b66bfd618..28a57339e 100644 --- a/openlp/plugins/songs/lib/importer.py +++ b/openlp/plugins/songs/lib/importer.py @@ -35,6 +35,7 @@ from olpimport import OpenLPSongImport from openlyricsimport import OpenLyricsImport from wowimport import WowImport from cclifileimport import CCLIFileImport +from dreambeamimport import DreamBeamImport from ewimport import EasyWorshipSongImport from songbeamerimport import SongBeamerImport from songshowplusimport import SongShowPlusImport @@ -73,15 +74,16 @@ class SongFormat(object): OpenLP1 = 2 Generic = 3 CCLI = 4 - EasySlides = 5 - EasyWorship = 6 - FoilPresenter = 7 - OpenSong = 8 - SongBeamer = 9 - SongShowPlus = 10 - SongsOfFellowship = 11 - WordsOfWorship = 12 - #CSV = 13 + DreamBeam = 5 + EasySlides = 6 + EasyWorship = 7 + FoilPresenter = 8 + OpenSong = 9 + SongBeamer = 10 + SongShowPlus = 11 + SongsOfFellowship = 12 + WordsOfWorship = 13 + #CSV = 14 @staticmethod def get_class(format): @@ -107,6 +109,8 @@ class SongFormat(object): return OooImport elif format == SongFormat.CCLI: return CCLIFileImport + elif format == SongFormat.DreamBeam: + return DreamBeamImport elif format == SongFormat.EasySlides: return EasySlidesImport elif format == SongFormat.EasyWorship: @@ -130,6 +134,7 @@ class SongFormat(object): SongFormat.OpenLP1, SongFormat.Generic, SongFormat.CCLI, + SongFormat.DreamBeam, SongFormat.EasySlides, SongFormat.EasyWorship, SongFormat.FoilPresenter, diff --git a/openlp/plugins/songs/lib/songshowplusimport.py b/openlp/plugins/songs/lib/songshowplusimport.py index aba2f6d05..8d2af5514 100644 --- a/openlp/plugins/songs/lib/songshowplusimport.py +++ b/openlp/plugins/songs/lib/songshowplusimport.py @@ -25,8 +25,8 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### """ -The :mod:`wowimport` module provides the functionality for importing Words of -Worship songs into the OpenLP database. +The :mod:`songshowplusimport` module provides the functionality for importing +SongShow Plus songs into the OpenLP database. """ import os import logging