This commit is contained in:
Tim Bentley 2011-12-14 19:07:56 +00:00
commit fa1a721c26
26 changed files with 231 additions and 106 deletions

View File

@ -80,6 +80,9 @@ def get_text_file_string(text_file):
content_string = None content_string = None
try: try:
file_handle = open(text_file, u'r') file_handle = open(text_file, u'r')
if not file_handle.read(3) == '\xEF\xBB\xBF':
# no BOM was found
file_handle.seek(0)
content = file_handle.read() content = file_handle.read()
content_string = content.decode(u'utf-8') content_string = content.decode(u'utf-8')
except (IOError, UnicodeError): except (IOError, UnicodeError):

View File

@ -358,10 +358,17 @@ class Manager(object):
def delete_all_objects(self, object_class, filter_clause=None): def delete_all_objects(self, object_class, filter_clause=None):
""" """
Delete all object records Delete all object records.
This method should only be used for simple tables and not ones with
relationships. The relationships are not deleted from the database and
this will lead to database corruptions.
``object_class`` ``object_class``
The type of object to delete The type of object to delete
``filter_clause``
The filter governing selection of objects to return. Defaults to
None.
""" """
try: try:
query = self.session.query(object_class) query = self.session.query(object_class)

View File

@ -115,8 +115,12 @@ class EventReceiver(QtCore.QObject):
``slidecontroller_live_stop_loop`` ``slidecontroller_live_stop_loop``
Stop the loop on the main display. Stop the loop on the main display.
**Servicemanager related signals** **Servicemanager related signals**
``servicemanager_new_service``
A new service is being loaded or created.
``servicemanager_previous_item`` ``servicemanager_previous_item``
Display the previous item in the service. Display the previous item in the service.

View File

@ -149,11 +149,17 @@ class FormattingTags(object):
tags = [] tags = []
for tag in FormattingTags.html_expands: for tag in FormattingTags.html_expands:
if not tag[u'protected'] and not tag.get(u'temporary'): if not tag[u'protected'] and not tag.get(u'temporary'):
tags.append(tag) # Using dict ensures that copy is made and encoding of values
# Remove key 'temporary' from tags. It is not needed to be saved. # a little later does not affect tags in the original list
for tag in tags: tags.append(dict(tag))
if u'temporary' in tag: tag = tags[-1]
del tag[u'temporary'] # Remove key 'temporary' from tags.
# It is not needed to be saved.
if u'temporary' in tag:
del tag[u'temporary']
for element in tag:
if isinstance(tag[element], unicode):
tag[element] = tag[element].encode('utf8')
# Formatting Tags were also known as display tags. # Formatting Tags were also known as display tags.
QtCore.QSettings().setValue(u'displayTags/html_tags', QtCore.QSettings().setValue(u'displayTags/html_tags',
QtCore.QVariant(cPickle.dumps(tags) if tags else u'')) QtCore.QVariant(cPickle.dumps(tags) if tags else u''))
@ -171,9 +177,13 @@ class FormattingTags(object):
user_expands = QtCore.QSettings().value(u'displayTags/html_tags', user_expands = QtCore.QSettings().value(u'displayTags/html_tags',
QtCore.QVariant(u'')).toString() QtCore.QVariant(u'')).toString()
# cPickle only accepts str not unicode strings # cPickle only accepts str not unicode strings
user_expands_string = str(unicode(user_expands).encode(u'utf8')) user_expands_string = str(user_expands)
if user_expands_string: if user_expands_string:
user_tags = cPickle.loads(user_expands_string) user_tags = cPickle.loads(user_expands_string)
for tag in user_tags:
for element in tag:
if isinstance(tag[element], str):
tag[element] = tag[element].decode('utf8')
# If we have some user ones added them as well # If we have some user ones added them as well
FormattingTags.add_html_tags(user_tags) FormattingTags.add_html_tags(user_tags)

View File

@ -119,6 +119,7 @@ class ServiceItem(object):
self.image_border = u'#000000' self.image_border = u'#000000'
self.background_audio = [] self.background_audio = []
self.theme_overwritten = False self.theme_overwritten = False
self.temporary_edit = False
self._new_item() self._new_item()
def _new_item(self): def _new_item(self):
@ -365,6 +366,7 @@ class ServiceItem(object):
""" """
self._uuid = other._uuid self._uuid = other._uuid
self.notes = other.notes self.notes = other.notes
self.temporary_edit = other.temporary_edit
# Copy theme over if present. # Copy theme over if present.
if other.theme is not None: if other.theme is not None:
self.theme = other.theme self.theme = other.theme

View File

@ -125,3 +125,9 @@ class SettingsTab(QtGui.QWidget):
""" """
pass pass
def tabVisible(self):
"""
Tab has just been made visible to the user
"""
pass

View File

@ -45,7 +45,7 @@ log = logging.getLogger(__name__)
class Display(QtGui.QGraphicsView): class Display(QtGui.QGraphicsView):
""" """
This is a general display screen class. Here the general display settings This is a general display screen class. Here the general display settings
will done. It will be used as specialized classes by Main Display and will done. It will be used as specialized classes by Main Display and
Preview display. Preview display.
""" """
@ -66,7 +66,7 @@ class Display(QtGui.QGraphicsView):
""" """
Set up and build the screen base Set up and build the screen base
""" """
log.debug(u'Start Display base setup (live = %s)' % self.isLive) log.debug(u'Start Display base setup (live = %s)' % self.isLive)
self.setGeometry(self.screen[u'size']) self.setGeometry(self.screen[u'size'])
log.debug(u'Setup webView') log.debug(u'Setup webView')
self.webView = QtWebKit.QWebView(self) self.webView = QtWebKit.QWebView(self)

View File

@ -37,7 +37,7 @@ log = logging.getLogger(__name__)
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.core.lib import OpenLPToolbar, ServiceItem, Receiver, build_icon, \ from openlp.core.lib import OpenLPToolbar, ServiceItem, Receiver, build_icon, \
ItemCapabilities, SettingsManager, translate ItemCapabilities, SettingsManager, translate, str_to_bool
from openlp.core.lib.theme import ThemeLevel from openlp.core.lib.theme import ThemeLevel
from openlp.core.lib.ui import UiStrings, critical_error_message_box, \ from openlp.core.lib.ui import UiStrings, critical_error_message_box, \
context_menu_action, context_menu_separator, find_and_set_in_combo_box context_menu_action, context_menu_separator, find_and_set_in_combo_box
@ -465,6 +465,7 @@ class ServiceManager(QtGui.QWidget):
self.setModified(False) self.setModified(False)
QtCore.QSettings(). \ QtCore.QSettings(). \
setValue(u'servicemanager/last file',QtCore.QVariant(u'')) setValue(u'servicemanager/last file',QtCore.QVariant(u''))
Receiver.send_message(u'servicemanager_new_service')
def saveFile(self): def saveFile(self):
""" """
@ -663,13 +664,14 @@ class ServiceManager(QtGui.QWidget):
serviceItem.renderer = self.mainwindow.renderer serviceItem.renderer = self.mainwindow.renderer
serviceItem.set_from_service(item, self.servicePath) serviceItem.set_from_service(item, self.servicePath)
self.validateItem(serviceItem) self.validateItem(serviceItem)
self.loadItem_uuid = 0 self.load_item_uuid = 0
if serviceItem.is_capable(ItemCapabilities.OnLoadUpdate): if serviceItem.is_capable(ItemCapabilities.OnLoadUpdate):
Receiver.send_message(u'%s_service_load' % Receiver.send_message(u'%s_service_load' %
serviceItem.name.lower(), serviceItem) serviceItem.name.lower(), serviceItem)
# if the item has been processed # if the item has been processed
if serviceItem._uuid == self.loadItem_uuid: if serviceItem._uuid == self.load_item_uuid:
serviceItem.edit_id = int(self.loadItem_editId) serviceItem.edit_id = int(self.load_item_edit_id)
serviceItem.temporary_edit = self.load_item_temporary
self.addServiceItem(serviceItem, repaint=False) self.addServiceItem(serviceItem, repaint=False)
delete_file(p_file) delete_file(p_file)
self.setFileName(fileName) self.setFileName(fileName)
@ -999,6 +1001,17 @@ class ServiceManager(QtGui.QWidget):
painter.drawImage(0, 0, overlay) painter.drawImage(0, 0, overlay)
painter.end() painter.end()
treewidgetitem.setIcon(0, build_icon(icon)) treewidgetitem.setIcon(0, build_icon(icon))
elif serviceitem.temporary_edit:
icon = QtGui.QImage(serviceitem.icon)
icon = icon.scaled(80, 80, QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation)
overlay = QtGui.QImage(':/general/general_export.png')
overlay = overlay.scaled(40, 40, QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation)
painter = QtGui.QPainter(icon)
painter.drawImage(40, 0, overlay)
painter.end()
treewidgetitem.setIcon(0, build_icon(icon))
else: else:
treewidgetitem.setIcon(0, serviceitem.iconic_representation) treewidgetitem.setIcon(0, serviceitem.iconic_representation)
else: else:
@ -1006,6 +1019,11 @@ class ServiceManager(QtGui.QWidget):
build_icon(u':/general/general_delete.png')) build_icon(u':/general/general_delete.png'))
treewidgetitem.setText(0, serviceitem.get_display_title()) treewidgetitem.setText(0, serviceitem.get_display_title())
tips = [] tips = []
if serviceitem.temporary_edit:
tips.append(u'<strong>%s:</strong> <em>%s</em>' %
(unicode(translate('OpenLP.ServiceManager', 'Edit')),
(unicode(translate('OpenLP.ServiceManager',
'Service copy only')))))
if serviceitem.theme and serviceitem.theme != -1: if serviceitem.theme and serviceitem.theme != -1:
tips.append(u'<strong>%s:</strong> <em>%s</em>' % tips.append(u'<strong>%s:</strong> <em>%s</em>' %
(unicode(translate('OpenLP.ServiceManager', 'Slide theme')), (unicode(translate('OpenLP.ServiceManager', 'Slide theme')),
@ -1127,8 +1145,9 @@ class ServiceManager(QtGui.QWidget):
Triggered from plugins to update service items. Triggered from plugins to update service items.
Save the values as they will be used as part of the service load Save the values as they will be used as part of the service load
""" """
editId, self.loadItem_uuid = message.split(u':') edit_id, self.load_item_uuid, temporary = message.split(u':')
self.loadItem_editId = int(editId) self.load_item_edit_id = int(edit_id)
self.load_item_temporary = str_to_bool(temporary)
def replaceServiceItem(self, newItem): def replaceServiceItem(self, newItem):
""" """

View File

@ -55,7 +55,7 @@ class Ui_SettingsDialog(object):
QtCore.QMetaObject.connectSlotsByName(settingsDialog) QtCore.QMetaObject.connectSlotsByName(settingsDialog)
QtCore.QObject.connect(self.settingListWidget, QtCore.QObject.connect(self.settingListWidget,
QtCore.SIGNAL(u'currentRowChanged(int)'), QtCore.SIGNAL(u'currentRowChanged(int)'),
self.stackedLayout.setCurrentIndex) self.tabChanged)
def retranslateUi(self, settingsDialog): def retranslateUi(self, settingsDialog):
settingsDialog.setWindowTitle(translate('OpenLP.SettingsForm', settingsDialog.setWindowTitle(translate('OpenLP.SettingsForm',

View File

@ -116,3 +116,10 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog):
for plugin in self.plugins: for plugin in self.plugins:
if plugin.settings_tab: if plugin.settings_tab:
plugin.settings_tab.postSetUp() plugin.settings_tab.postSetUp()
def tabChanged(self, tabIndex):
"""
A different settings tab is selected
"""
self.stackedLayout.setCurrentIndex(tabIndex)
self.stackedLayout.currentWidget().tabVisible()

View File

@ -526,13 +526,11 @@ class ThemeManager(QtGui.QWidget):
zip = zipfile.ZipFile(filename) zip = zipfile.ZipFile(filename)
themename = None themename = None
for file in zip.namelist(): for file in zip.namelist():
# Handle UTF-8 files
ucsfile = file_is_unicode(file) ucsfile = file_is_unicode(file)
if not ucsfile: if not ucsfile:
critical_error_message_box( # Handle native Unicode files from Windows
message=translate('OpenLP.ThemeManager', ucsfile = file
'File is not a valid theme.\n'
'The content encoding is not UTF-8.'))
continue
osfile = unicode(QtCore.QDir.toNativeSeparators(ucsfile)) osfile = unicode(QtCore.QDir.toNativeSeparators(ucsfile))
theme_dir = None theme_dir = None
if osfile.endswith(os.path.sep): if osfile.endswith(os.path.sep):
@ -620,7 +618,7 @@ class ThemeManager(QtGui.QWidget):
""" """
name = theme.theme_name name = theme.theme_name
theme_pretty_xml = theme.extract_formatted_xml() theme_pretty_xml = theme.extract_formatted_xml()
log.debug(u'saveTheme %s %s', name, theme_pretty_xml) log.debug(u'saveTheme %s %s', name, theme_pretty_xml.decode(u'utf-8'))
theme_dir = os.path.join(self.path, name) theme_dir = os.path.join(self.path, name)
check_directory_exists(theme_dir) check_directory_exists(theme_dir)
theme_file = os.path.join(theme_dir, name + u'.xml') theme_file = os.path.join(theme_dir, name + u'.xml')

View File

@ -28,17 +28,7 @@
The :mod:`cvsbible` modules provides a facility to import bibles from a set of The :mod:`cvsbible` modules provides a facility to import bibles from a set of
CSV files. CSV files.
The module expects two mandatory files containing the books and the verses and The module expects two mandatory files containing the books and the verses.
will accept an optional third file containing the testaments.
The format of the testament file is:
<testament_id>,<testament_name>
For example:
1,Old Testament
2,New Testament
The format of the books file is: The format of the books file is:
@ -110,6 +100,9 @@ class CSVBible(BibleDB):
try: try:
details = get_file_encoding(self.booksfile) details = get_file_encoding(self.booksfile)
books_file = open(self.booksfile, 'r') books_file = open(self.booksfile, 'r')
if not books_file.read(3) == '\xEF\xBB\xBF':
# no BOM was found
books_file.seek(0)
books_reader = csv.reader(books_file, delimiter=',', quotechar='"') books_reader = csv.reader(books_file, delimiter=',', quotechar='"')
for line in books_reader: for line in books_reader:
if self.stop_import_flag: if self.stop_import_flag:
@ -144,6 +137,9 @@ class CSVBible(BibleDB):
book_ptr = None book_ptr = None
details = get_file_encoding(self.versesfile) details = get_file_encoding(self.versesfile)
verse_file = open(self.versesfile, 'rb') verse_file = open(self.versesfile, 'rb')
if not verse_file.read(3) == '\xEF\xBB\xBF':
# no BOM was found
verse_file.seek(0)
verse_reader = csv.reader(verse_file, delimiter=',', quotechar='"') verse_reader = csv.reader(verse_file, delimiter=',', quotechar='"')
for line in verse_reader: for line in verse_reader:
if self.stop_import_flag: if self.stop_import_flag:

View File

@ -78,8 +78,7 @@ class OSISBible(BibleDB):
fbibles = open(filepath, u'r') fbibles = open(filepath, u'r')
for line in fbibles: for line in fbibles:
book = line.split(u',') book = line.split(u',')
self.books[book[0]] = (book[1].lstrip().rstrip(), self.books[book[0]] = (book[1].strip(), book[2].strip())
book[2].lstrip().rstrip())
except IOError: except IOError:
log.exception(u'OSIS bible import failed') log.exception(u'OSIS bible import failed')
finally: finally:

View File

@ -184,7 +184,15 @@ class ImpressController(PresentationController):
if not desktop: if not desktop:
return return
docs = desktop.getComponents() docs = desktop.getComponents()
cnt = 0
if docs.hasElements(): if docs.hasElements():
list = docs.createEnumeration()
while list.hasMoreElements():
doc = list.nextElement()
if doc.getImplementationName() != \
u'com.sun.star.comp.framework.BackingComp':
cnt = cnt + 1
if cnt > 0:
log.debug(u'OpenOffice not terminated as docs are still open') log.debug(u'OpenOffice not terminated as docs are still open')
else: else:
try: try:

View File

@ -378,7 +378,7 @@ class PresentationController(object):
self.name = name self.name = name
self.document_class = document_class self.document_class = document_class
self.settings_section = self.plugin.settingsSection self.settings_section = self.plugin.settingsSection
self.available = self.check_available() self.available = None
self.temp_folder = os.path.join( self.temp_folder = os.path.join(
AppLocation.get_section_data_path(self.settings_section), name) AppLocation.get_section_data_path(self.settings_section), name)
self.thumbnail_folder = os.path.join( self.thumbnail_folder = os.path.join(
@ -392,14 +392,19 @@ class PresentationController(object):
""" """
Return whether the controller is currently enabled Return whether the controller is currently enabled
""" """
if self.available: if QtCore.QSettings().value(
return QtCore.QSettings().value( self.settings_section + u'/' + self.name,
self.settings_section + u'/' + self.name, QtCore.QVariant(QtCore.Qt.Checked)).toInt()[0] == \
QtCore.QVariant(QtCore.Qt.Checked)).toInt()[0] == \ QtCore.Qt.Checked:
QtCore.Qt.Checked return self.is_available()
else: else:
return False return False
def is_available(self):
if self.available is None:
self.available = self.check_available()
return self.available
def check_available(self): def check_available(self):
""" """
Presentation app is able to run on this machine Presentation app is able to run on this machine

View File

@ -55,7 +55,6 @@ class PresentationTab(SettingsTab):
for key in self.controllers: for key in self.controllers:
controller = self.controllers[key] controller = self.controllers[key]
checkbox = QtGui.QCheckBox(self.ControllersGroupBox) checkbox = QtGui.QCheckBox(self.ControllersGroupBox)
checkbox.setEnabled(controller.available)
checkbox.setObjectName(controller.name + u'CheckBox') checkbox.setObjectName(controller.name + u'CheckBox')
self.PresenterCheckboxes[controller.name] = checkbox self.PresenterCheckboxes[controller.name] = checkbox
self.ControllersLayout.addWidget(checkbox) self.ControllersLayout.addWidget(checkbox)
@ -81,17 +80,20 @@ class PresentationTab(SettingsTab):
for key in self.controllers: for key in self.controllers:
controller = self.controllers[key] controller = self.controllers[key]
checkbox = self.PresenterCheckboxes[controller.name] checkbox = self.PresenterCheckboxes[controller.name]
if controller.available: self.setControllerText(checkbox, controller)
checkbox.setText(controller.name)
else:
checkbox.setText(
unicode(translate('PresentationPlugin.PresentationTab',
'%s (unavailable)')) % controller.name)
self.AdvancedGroupBox.setTitle(UiStrings().Advanced) self.AdvancedGroupBox.setTitle(UiStrings().Advanced)
self.OverrideAppCheckBox.setText( self.OverrideAppCheckBox.setText(
translate('PresentationPlugin.PresentationTab', translate('PresentationPlugin.PresentationTab',
'Allow presentation application to be overriden')) 'Allow presentation application to be overriden'))
def setControllerText(self, checkbox, controller):
if checkbox.isEnabled():
checkbox.setText(controller.name)
else:
checkbox.setText(
unicode(translate('PresentationPlugin.PresentationTab',
'%s (unavailable)')) % controller.name)
def load(self): def load(self):
""" """
Load the settings. Load the settings.
@ -113,7 +115,7 @@ class PresentationTab(SettingsTab):
changed = False changed = False
for key in self.controllers: for key in self.controllers:
controller = self.controllers[key] controller = self.controllers[key]
if controller.available: if controller.is_available():
checkbox = self.PresenterCheckboxes[controller.name] checkbox = self.PresenterCheckboxes[controller.name]
setting_key = self.settingsSection + u'/' + controller.name setting_key = self.settingsSection + u'/' + controller.name
if QtCore.QSettings().value(setting_key) != \ if QtCore.QSettings().value(setting_key) != \
@ -133,3 +135,13 @@ class PresentationTab(SettingsTab):
changed = True changed = True
if changed: if changed:
Receiver.send_message(u'mediaitem_presentation_rebuild') Receiver.send_message(u'mediaitem_presentation_rebuild')
def tabVisible(self):
"""
Tab has just been made visible to the user
"""
for key in self.controllers:
controller = self.controllers[key]
checkbox = self.PresenterCheckboxes[controller.name]
checkbox.setEnabled(controller.is_available())
self.setControllerText(checkbox, controller)

View File

@ -252,6 +252,9 @@ class SongExportForm(OpenLPWizard):
songs = self.plugin.manager.get_all_objects(Song) songs = self.plugin.manager.get_all_objects(Song)
songs.sort(cmp=locale.strcoll, key=lambda song: song.title.lower()) songs.sort(cmp=locale.strcoll, key=lambda song: song.title.lower())
for song in songs: for song in songs:
# No need to export temporary songs.
if song.temporary:
continue
authors = u', '.join([author.display_name authors = u', '.join([author.display_name
for author in song.authors]) for author in song.authors])
title = u'%s (%s)' % (unicode(song.title), authors) title = u'%s (%s)' % (unicode(song.title), authors)

View File

@ -191,32 +191,32 @@ class SongImportForm(OpenLPWizard):
QtGui.QSizePolicy.Expanding) QtGui.QSizePolicy.Expanding)
self.formatStack = QtGui.QStackedLayout() self.formatStack = QtGui.QStackedLayout()
self.formatStack.setObjectName(u'FormatStack') self.formatStack.setObjectName(u'FormatStack')
# OpenLyrics
self.addFileSelectItem(u'openLyrics', u'OpenLyrics', True)
# OpenLP 2.0 # OpenLP 2.0
self.addFileSelectItem(u'openLP2', single_select=True) self.addFileSelectItem(u'openLP2', single_select=True)
# openlp.org 1.x # openlp.org 1.x
self.addFileSelectItem(u'openLP1', None, True, True) self.addFileSelectItem(u'openLP1', None, True, True)
# OpenLyrics
self.addFileSelectItem(u'openLyrics', u'OpenLyrics', True)
# Open Song
self.addFileSelectItem(u'openSong', u'OpenSong')
# Words of Worship
self.addFileSelectItem(u'wordsOfWorship')
# CCLI File import
self.addFileSelectItem(u'ccli')
# Songs of Fellowship
self.addFileSelectItem(u'songsOfFellowship', None, True)
# Generic Document/Presentation import # Generic Document/Presentation import
self.addFileSelectItem(u'generic', None, True) self.addFileSelectItem(u'generic', None, True)
# EasySlides # CCLI File import
self.addFileSelectItem(u'ccli')
# EasiSlides
self.addFileSelectItem(u'easiSlides', single_select=True) self.addFileSelectItem(u'easiSlides', single_select=True)
# EasyWorship # EasyWorship
self.addFileSelectItem(u'ew', single_select=True) self.addFileSelectItem(u'ew', single_select=True)
# Words of Worship # Foilpresenter
self.addFileSelectItem(u'foilPresenter')
# Open Song
self.addFileSelectItem(u'openSong', u'OpenSong')
# SongBeamer
self.addFileSelectItem(u'songBeamer') self.addFileSelectItem(u'songBeamer')
# Song Show Plus # Song Show Plus
self.addFileSelectItem(u'songShowPlus') self.addFileSelectItem(u'songShowPlus')
# Foilpresenter # Songs of Fellowship
self.addFileSelectItem(u'foilPresenter') self.addFileSelectItem(u'songsOfFellowship', None, True)
# Words of Worship
self.addFileSelectItem(u'wordsOfWorship')
# Commented out for future use. # Commented out for future use.
# self.addFileSelectItem(u'csv', u'CSV', single_select=True) # self.addFileSelectItem(u'csv', u'CSV', single_select=True)
self.sourceLayout.addLayout(self.formatStack) self.sourceLayout.addLayout(self.formatStack)
@ -238,30 +238,30 @@ class SongImportForm(OpenLPWizard):
self.sourcePage.setTitle(WizardStrings.ImportSelect) self.sourcePage.setTitle(WizardStrings.ImportSelect)
self.sourcePage.setSubTitle(WizardStrings.ImportSelectLong) self.sourcePage.setSubTitle(WizardStrings.ImportSelectLong)
self.formatLabel.setText(WizardStrings.FormatLabel) self.formatLabel.setText(WizardStrings.FormatLabel)
self.formatComboBox.setItemText(SongFormat.OpenLP2, UiStrings().OLPV2)
self.formatComboBox.setItemText(SongFormat.OpenLP1, UiStrings().OLPV1)
self.formatComboBox.setItemText(SongFormat.OpenLyrics, self.formatComboBox.setItemText(SongFormat.OpenLyrics,
translate('SongsPlugin.ImportWizardForm', translate('SongsPlugin.ImportWizardForm',
'OpenLyrics or OpenLP 2.0 Exported Song')) 'OpenLyrics or OpenLP 2.0 Exported Song'))
self.formatComboBox.setItemText(SongFormat.OpenSong, WizardStrings.OS) self.formatComboBox.setItemText(SongFormat.OpenLP2, UiStrings().OLPV2)
self.formatComboBox.setItemText( self.formatComboBox.setItemText(SongFormat.OpenLP1, UiStrings().OLPV1)
SongFormat.WordsOfWorship, WizardStrings.WoW)
self.formatComboBox.setItemText(SongFormat.CCLI, WizardStrings.CCLI)
self.formatComboBox.setItemText(
SongFormat.SongsOfFellowship, WizardStrings.SoF)
self.formatComboBox.setItemText(SongFormat.Generic, self.formatComboBox.setItemText(SongFormat.Generic,
translate('SongsPlugin.ImportWizardForm', translate('SongsPlugin.ImportWizardForm',
'Generic Document/Presentation')) 'Generic Document/Presentation'))
self.formatComboBox.setItemText(SongFormat.CCLI, WizardStrings.CCLI)
self.formatComboBox.setItemText( self.formatComboBox.setItemText(
SongFormat.EasiSlides, WizardStrings.ES) SongFormat.EasiSlides, WizardStrings.ES)
self.formatComboBox.setItemText( self.formatComboBox.setItemText(
SongFormat.EasyWorship, WizardStrings.EW) SongFormat.EasyWorship, WizardStrings.EW)
self.formatComboBox.setItemText(
SongFormat.FoilPresenter, WizardStrings.FP)
self.formatComboBox.setItemText(SongFormat.OpenSong, WizardStrings.OS)
self.formatComboBox.setItemText( self.formatComboBox.setItemText(
SongFormat.SongBeamer, WizardStrings.SB) SongFormat.SongBeamer, WizardStrings.SB)
self.formatComboBox.setItemText( self.formatComboBox.setItemText(
SongFormat.SongShowPlus, WizardStrings.SSP) SongFormat.SongShowPlus, WizardStrings.SSP)
self.formatComboBox.setItemText( self.formatComboBox.setItemText(
SongFormat.FoilPresenter, WizardStrings.FP) SongFormat.SongsOfFellowship, WizardStrings.SoF)
self.formatComboBox.setItemText(
SongFormat.WordsOfWorship, WizardStrings.WoW)
# self.formatComboBox.setItemText(SongFormat.CSV, WizardStrings.CSV) # self.formatComboBox.setItemText(SongFormat.CSV, WizardStrings.CSV)
self.openLP2FilenameLabel.setText( self.openLP2FilenameLabel.setText(
translate('SongsPlugin.ImportWizardForm', 'Filename:')) translate('SongsPlugin.ImportWizardForm', 'Filename:'))
@ -359,6 +359,8 @@ class SongImportForm(OpenLPWizard):
return True return True
elif self.currentPage() == self.sourcePage: elif self.currentPage() == self.sourcePage:
source_format = self.formatComboBox.currentIndex() source_format = self.formatComboBox.currentIndex()
QtCore.QSettings().setValue(u'songs/last import type',
source_format)
if source_format == SongFormat.OpenLP2: if source_format == SongFormat.OpenLP2:
if self.openLP2FilenameEdit.text().isEmpty(): if self.openLP2FilenameEdit.text().isEmpty():
critical_error_message_box(UiStrings().NFSs, critical_error_message_box(UiStrings().NFSs,
@ -657,7 +659,12 @@ class SongImportForm(OpenLPWizard):
self.restart() self.restart()
self.finishButton.setVisible(False) self.finishButton.setVisible(False)
self.cancelButton.setVisible(True) self.cancelButton.setVisible(True)
self.formatComboBox.setCurrentIndex(0) last_import_type = QtCore.QSettings().value(
u'songs/last import type').toInt()[0]
if last_import_type < 0 or \
last_import_type >= self.formatComboBox.count():
last_import_type = 0
self.formatComboBox.setCurrentIndex(last_import_type)
self.openLP2FilenameEdit.setText(u'') self.openLP2FilenameEdit.setText(u'')
self.openLP1FilenameEdit.setText(u'') self.openLP1FilenameEdit.setText(u'')
self.openLyricsFileListWidget.clear() self.openLyricsFileListWidget.clear()

View File

@ -75,6 +75,9 @@ class CCLIFileImport(SongImport):
details = chardet.detect(detect_content) details = chardet.detect(detect_content)
detect_file.close() detect_file.close()
infile = codecs.open(filename, u'r', details['encoding']) infile = codecs.open(filename, u'r', details['encoding'])
if not infile.read(3) == '\xEF\xBB\xBF':
# not UTF or no BOM was found
infile.seek(0)
lines = infile.readlines() lines = infile.readlines()
infile.close() infile.close()
ext = os.path.splitext(filename)[1] ext = os.path.splitext(filename)[1]

View File

@ -199,7 +199,8 @@ def init_schema(url):
Column(u'search_lyrics', types.UnicodeText, nullable=False), Column(u'search_lyrics', types.UnicodeText, nullable=False),
Column(u'create_date', types.DateTime(), default=func.now()), Column(u'create_date', types.DateTime(), default=func.now()),
Column(u'last_modified', types.DateTime(), default=func.now(), Column(u'last_modified', types.DateTime(), default=func.now(),
onupdate=func.now()) onupdate=func.now()),
Column(u'temporary', types.Boolean(), default=False)
) )
# Definition of the "topics" table # Definition of the "topics" table

View File

@ -68,19 +68,19 @@ class SongFormat(object):
""" """
_format_availability = {} _format_availability = {}
Unknown = -1 Unknown = -1
OpenLP2 = 0 OpenLyrics = 0
OpenLP1 = 1 OpenLP2 = 1
OpenLyrics = 2 OpenLP1 = 2
OpenSong = 3 Generic = 3
WordsOfWorship = 4 CCLI = 4
CCLI = 5 EasiSlides = 5
SongsOfFellowship = 6 EasyWorship = 6
Generic = 7 FoilPresenter = 7
EasiSlides = 8 OpenSong = 8
EasyWorship = 9 SongBeamer = 9
SongBeamer = 10 SongShowPlus = 10
SongShowPlus = 11 SongsOfFellowship = 11
FoilPresenter = 12 WordsOfWorship = 12
#CSV = 13 #CSV = 13
@staticmethod @staticmethod
@ -125,19 +125,19 @@ class SongFormat(object):
Return a list of the supported song formats. Return a list of the supported song formats.
""" """
return [ return [
SongFormat.OpenLyrics,
SongFormat.OpenLP2, SongFormat.OpenLP2,
SongFormat.OpenLP1, SongFormat.OpenLP1,
SongFormat.OpenLyrics,
SongFormat.OpenSong,
SongFormat.WordsOfWorship,
SongFormat.CCLI,
SongFormat.SongsOfFellowship,
SongFormat.Generic, SongFormat.Generic,
SongFormat.CCLI,
SongFormat.EasiSlides, SongFormat.EasiSlides,
SongFormat.EasyWorship, SongFormat.EasyWorship,
SongFormat.FoilPresenter,
SongFormat.OpenSong,
SongFormat.SongBeamer, SongFormat.SongBeamer,
SongFormat.SongShowPlus, SongFormat.SongShowPlus,
SongFormat.FoilPresenter SongFormat.SongsOfFellowship,
SongFormat.WordsOfWorship
] ]
@staticmethod @staticmethod

View File

@ -270,6 +270,9 @@ class SongMediaItem(MediaManagerItem):
searchresults.sort( searchresults.sort(
cmp=locale.strcoll, key=lambda song: song.title.lower()) cmp=locale.strcoll, key=lambda song: song.title.lower())
for song in searchresults: for song in searchresults:
# Do not display temporary songs
if song.temporary:
continue
author_list = [author.display_name for author in song.authors] author_list = [author.display_name for author in song.authors]
song_title = unicode(song.title) song_title = unicode(song.title)
song_detail = u'%s (%s)' % (song_title, u', '.join(author_list)) song_detail = u'%s (%s)' % (song_title, u', '.join(author_list))
@ -286,6 +289,9 @@ class SongMediaItem(MediaManagerItem):
self.listView.clear() self.listView.clear()
for author in searchresults: for author in searchresults:
for song in author.songs: for song in author.songs:
# Do not display temporary songs
if song.temporary:
continue
song_detail = u'%s (%s)' % (author.display_name, song.title) song_detail = u'%s (%s)' % (author.display_name, song.title)
song_name = QtGui.QListWidgetItem(song_detail) song_name = QtGui.QListWidgetItem(song_detail)
song_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(song.id)) song_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(song.id))
@ -534,6 +540,7 @@ class SongMediaItem(MediaManagerItem):
Song.search_title.asc()) Song.search_title.asc())
editId = 0 editId = 0
add_song = True add_song = True
temporary = False
if search_results: if search_results:
for song in search_results: for song in search_results:
author_list = item.data_string[u'authors'] author_list = item.data_string[u'authors']
@ -559,13 +566,18 @@ class SongMediaItem(MediaManagerItem):
self._updateBackgroundAudio(song, item) self._updateBackgroundAudio(song, item)
editId = song.id editId = song.id
self.onSearchTextButtonClick() self.onSearchTextButtonClick()
else: elif add_song and not self.addSongFromService:
# Make sure we temporary import formatting tags. # Make sure we temporary import formatting tags.
self.openLyrics.xml_to_song(item.xml_version, True) song = self.openLyrics.xml_to_song(item.xml_version, True)
# If there's any backing tracks, copy them over.
if len(item.background_audio) > 0:
self._updateBackgroundAudio(song, item)
editId = song.id
temporary = True
# Update service with correct song id. # Update service with correct song id.
if editId: if editId:
Receiver.send_message(u'service_item_update', Receiver.send_message(u'service_item_update',
u'%s:%s' % (editId, item._uuid)) u'%s:%s:%s' % (editId, item._uuid, temporary))
def search(self, string): def search(self, string):
""" """

View File

@ -345,7 +345,8 @@ class SofImport(OooImport):
u'I\'M', u'I\'LL', u'SAVIOUR', u'O', u'YOU\'RE', u'HE', u'HIS', u'I\'M', u'I\'LL', u'SAVIOUR', u'O', u'YOU\'RE', u'HE', u'HIS',
u'HIM', u'ZION', u'EMMANUEL', u'MAJESTY', u'JESUS\'', u'JIREH', u'HIM', u'ZION', u'EMMANUEL', u'MAJESTY', u'JESUS\'', u'JIREH',
u'JUDAH', u'LION', u'LORD\'S', u'ABRAHAM', u'GOD\'S', u'JUDAH', u'LION', u'LORD\'S', u'ABRAHAM', u'GOD\'S',
u'FATHER\'S', u'ELIJAH'): u'FATHER\'S', u'ELIJAH' u'MARTHA', u'CHRISTMAS', u'ALPHA',
u'OMEGA'):
textarr[i] = textarr[i].capitalize() textarr[i] = textarr[i].capitalize()
else: else:
textarr[i] = textarr[i].lower() textarr[i] = textarr[i].lower()

View File

@ -33,7 +33,9 @@ from sqlalchemy import Column, Table, types
from sqlalchemy.sql.expression import func from sqlalchemy.sql.expression import func
from migrate.changeset.constraint import ForeignKeyConstraint from migrate.changeset.constraint import ForeignKeyConstraint
__version__ = 2 from openlp.plugins.songs.lib.db import Song
__version__ = 3
def upgrade_setup(metadata): def upgrade_setup(metadata):
""" """
@ -86,3 +88,12 @@ def upgrade_2(session, metadata, tables):
Column(u'last_modified', types.DateTime(), default=func.now())\ Column(u'last_modified', types.DateTime(), default=func.now())\
.create(table=tables[u'songs']) .create(table=tables[u'songs'])
def upgrade_3(session, metadata, tables):
"""
Version 3 upgrade.
This upgrade adds a temporary song flag to the songs table
"""
Column(u'temporary', types.Boolean(), default=False)\
.create(table=tables[u'songs'])

View File

@ -346,7 +346,7 @@ class OpenLyrics(object):
lines_element.set(u'break', u'optional') lines_element.set(u'break', u'optional')
return self._extract_xml(song_xml) return self._extract_xml(song_xml)
def xml_to_song(self, xml, parse_and_not_save=False): def xml_to_song(self, xml, parse_and_temporary_save=False):
""" """
Create and save a song from OpenLyrics format xml to the database. Since Create and save a song from OpenLyrics format xml to the database. Since
we also export XML from external sources (e. g. OpenLyrics import), we we also export XML from external sources (e. g. OpenLyrics import), we
@ -355,9 +355,9 @@ class OpenLyrics(object):
``xml`` ``xml``
The XML to parse (unicode). The XML to parse (unicode).
``parse_and_not_save`` ``parse_and_temporary_save``
Switch to skip processing the whole song and to prevent storing the Switch to skip processing the whole song and storing the songs in
songs to the database. Defaults to ``False``. the database with a temporary flag. Defaults to ``False``.
""" """
# No xml get out of here. # No xml get out of here.
if not xml: if not xml:
@ -371,14 +371,13 @@ class OpenLyrics(object):
return None return None
# Formatting tags are new in OpenLyrics 0.8 # Formatting tags are new in OpenLyrics 0.8
if float(song_xml.get(u'version')) > 0.7: if float(song_xml.get(u'version')) > 0.7:
self._process_formatting_tags(song_xml, parse_and_not_save) self._process_formatting_tags(song_xml, parse_and_temporary_save)
if parse_and_not_save:
return
song = Song() song = Song()
# Values will be set when cleaning the song. # Values will be set when cleaning the song.
song.search_lyrics = u'' song.search_lyrics = u''
song.verse_order = u'' song.verse_order = u''
song.search_title = u'' song.search_title = u''
song.temporary = parse_and_temporary_save
self._process_copyright(properties, song) self._process_copyright(properties, song)
self._process_cclinumber(properties, song) self._process_cclinumber(properties, song)
self._process_titles(properties, song) self._process_titles(properties, song)

View File

@ -78,6 +78,10 @@ class SongsPlugin(Plugin):
action_list.add_action(self.songExportItem, unicode(UiStrings().Export)) action_list.add_action(self.songExportItem, unicode(UiStrings().Export))
action_list.add_action(self.toolsReindexItem, action_list.add_action(self.toolsReindexItem,
unicode(UiStrings().Tools)) unicode(UiStrings().Tools))
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'servicemanager_new_service'),
self.clearTemporarySongs)
def addImportMenuItem(self, import_menu): def addImportMenuItem(self, import_menu):
""" """
@ -265,6 +269,8 @@ class SongsPlugin(Plugin):
Time to tidy up on exit Time to tidy up on exit
""" """
log.info(u'Songs Finalising') log.info(u'Songs Finalising')
self.clearTemporarySongs()
# Clean up files and connections
self.manager.finalise() self.manager.finalise()
self.songImportItem.setVisible(False) self.songImportItem.setVisible(False)
self.songExportItem.setVisible(False) self.songExportItem.setVisible(False)
@ -277,3 +283,9 @@ class SongsPlugin(Plugin):
action_list.remove_action(self.toolsReindexItem, action_list.remove_action(self.toolsReindexItem,
unicode(UiStrings().Tools)) unicode(UiStrings().Tools))
Plugin.finalise(self) Plugin.finalise(self)
def clearTemporarySongs(self):
# Remove temporary songs
songs = self.manager.get_all_objects(Song, Song.temporary == True)
for song in songs:
self.manager.delete_object(Song, song.id)