Fix ProPresenter import

Fixes: https://launchpad.net/bugs/1358418
This commit is contained in:
Samuel Mehrbrodt 2014-08-18 20:45:15 +02:00
parent 04bafa62fa
commit 63f08f0c4a
4 changed files with 21 additions and 3 deletions

View File

@ -292,7 +292,7 @@ class SongFormat(object):
'class': ProPresenterImport,
'name': 'ProPresenter',
'prefix': 'proPresenter',
'filter': '%s (*.pro4)' % translate('SongsPlugin.ImportWizardForm', 'ProPresenter Song Files')
'filter': '%s (*.pro4)' % translate('SongsPlugin.ImportWizardForm', 'ProPresenter 4 Song Files')
},
SongBeamer: {
'class': SongBeamerImport,

View File

@ -27,5 +27,5 @@
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
"""
The :mod:`~openlp.plugins.songs.lib.import` module contains importers for the Songs plugin.
The :mod:`~openlp.plugins.songs.lib.importers` module contains importers for the Songs plugin.
"""

View File

@ -33,17 +33,20 @@ ProPresenter song files into the current installation database.
import os
import base64
import logging
from lxml import objectify
from openlp.core.ui.wizard import WizardStrings
from openlp.plugins.songs.lib import strip_rtf
from .songimport import SongImport
log = logging.getLogger(__name__)
class ProPresenterImport(SongImport):
"""
The :class:`ProPresenterImport` class provides OpenLP with the
ability to import ProPresenter song files.
ability to import ProPresenter 4 song files.
"""
def do_import(self):
self.import_wizard.progress_bar.setMaximum(len(self.import_source))
@ -67,9 +70,15 @@ class ProPresenterImport(SongImport):
count = 0
for slide in root.slides.RVDisplaySlide:
count += 1
if not hasattr(slide.displayElements, 'RVTextElement'):
log.debug('No text found, may be an image slide')
continue
RTFData = slide.displayElements.RVTextElement.get('RTFData')
rtf = base64.standard_b64decode(RTFData)
words, encoding = strip_rtf(rtf.decode())
self.add_verse(words, "v%d" % count)
# Some songs don't have a title - use the first line as title
if not self.title:
self.title = self.guess_title()
if not self.finish():
self.log_error(self.import_source)

View File

@ -316,6 +316,15 @@ class SongImport(QtCore.QObject):
self.verse_order_list_generated.append(self.verse_order_list_generated[-1])
self.verse_order_list_generated_useful = True
def guess_title(self):
"""
Guess the title from the first verse (to be used when the song has no title information)
:return: The guessed title
"""
if not self.verses:
return ''
return self.verses[0][1].split('\n')[0].strip()
def check_complete(self):
"""
Check the mandatory fields are entered (i.e. title and a verse)