SOF fixes+delete all selected songs

This commit is contained in:
Jonathan Corwin 2010-04-03 00:24:51 +01:00
parent ca4e85b496
commit dad04bfd90
4 changed files with 64 additions and 29 deletions

View File

@ -271,12 +271,21 @@ class SongMediaItem(MediaManagerItem):
self.edit_song_form.exec_() self.edit_song_form.exec_()
def onDeleteClick(self): def onDeleteClick(self):
item = self.ListView.currentItem() items = self.ListView.selectedIndexes()
if item: if items:
if len(items) > 1:
ans = QtGui.QMessageBox.question(None,
self.trUtf8('Delete Confirmation'),
self.trUtf8('Delete %d songs?' % len(items)),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok|
QtGui.QMessageBox.Cancel),
QtGui.QMessageBox.Ok)
if ans == QtGui.QMessageBox.Cancel:
return
for item in items[:]:
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
self.parent.songmanager.delete_song(item_id) self.parent.songmanager.delete_song(item_id)
row = self.ListView.row(item) self.ListView.takeItem(item.row())
self.ListView.takeItem(row)
def generateSlideData(self, service_item): def generateSlideData(self, service_item):
raw_footer = [] raw_footer = []

View File

@ -1,4 +1,4 @@
# -*- coding: utf-8 -*- property# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 # vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
############################################################################### ###############################################################################
@ -32,7 +32,7 @@
import re import re
import os import os
import time import time
from PyQt4 import QtCore from PyQt4 import QtCore, QtGui
from songimport import SongImport from songimport import SongImport
if os.name == u'nt': if os.name == u'nt':
@ -44,7 +44,6 @@ if os.name == u'nt':
PAGE_BOTH = 6 PAGE_BOTH = 6
else: else:
import uno import uno
from com.sun.star.beans import PropertyValue
from com.sun.star.awt.FontWeight import BOLD from com.sun.star.awt.FontWeight import BOLD
from com.sun.star.awt.FontSlant import ITALIC from com.sun.star.awt.FontSlant import ITALIC
from com.sun.star.style.BreakType import PAGE_BEFORE, PAGE_AFTER, PAGE_BOTH from com.sun.star.style.BreakType import PAGE_BEFORE, PAGE_AFTER, PAGE_BOTH
@ -274,6 +273,7 @@ class SofImport(object):
number to work out which songbook we're in number to work out which songbook we're in
""" """
self.song.set_song_number(song_no) self.song.set_song_number(song_no)
self.song.set_alternate_title(song_no + u'.')
if int(song_no) <= 640: if int(song_no) <= 640:
self.song.set_song_book(u'Songs of Fellowship 1', self.song.set_song_book(u'Songs of Fellowship 1',
u'Kingsway Publications') u'Kingsway Publications')
@ -314,6 +314,8 @@ class SofImport(object):
if author2.find(u' ') == -1 and i < len(authors) - 1: if author2.find(u' ') == -1 and i < len(authors) - 1:
author2 = author2 + u' ' \ author2 = author2 + u' ' \
+ authors[i + 1].strip().split(u' ')[-1] + authors[i + 1].strip().split(u' ')[-1]
if author2.endswith(u'.'):
author2 = author2[:-1]
self.song.add_author(author2) self.song.add_author(author2)
def add_verse_line(self, text): def add_verse_line(self, text):
@ -338,7 +340,14 @@ class SofImport(object):
if self.currentverse.strip() == u'': if self.currentverse.strip() == u'':
return return
if self.is_chorus: if self.is_chorus:
if not self.song.contains_verse('C'):
versetag = 'C' versetag = 'C'
elif not self.song.contains_verse('B'):
versetag = 'B'
elif not self.song.contains_verse('E'):
versetag = 'E'
else:
versetag = 'O'
splitat = None splitat = None
else: else:
versetag = 'V' versetag = 'V'

View File

@ -46,6 +46,7 @@ class SongImport(object):
self.manager = song_manager self.manager = song_manager
self.title = u'' self.title = u''
self.song_number = u'' self.song_number = u''
self.alternate_title = u''
self.copyright = u'' self.copyright = u''
self.comment = u'' self.comment = u''
self.theme_name = u'' self.theme_name = u''
@ -73,7 +74,7 @@ class SongImport(object):
def get_song_number(self): def get_song_number(self):
""" """
Return the song number (also known as alternate title) Return the song number
""" """
return self.song_number return self.song_number
@ -83,9 +84,15 @@ class SongImport(object):
""" """
self.title = title self.title = title
def set_alternate_title(self, title):
"""
Set the alternate title
"""
self.alternate_title = title
def set_song_number(self, song_number): def set_song_number(self, song_number):
""" """
Set the song number/alternate title Set the song number
""" """
self.song_number = song_number self.song_number = song_number
@ -113,8 +120,8 @@ class SongImport(object):
def add_verse(self, verse, versetag): def add_verse(self, verse, versetag):
""" """
Add a verse. This is the whole verse, lines split by \n Add a verse. This is the whole verse, lines split by \n
Verse tag can be V1/C1/B1 etc, or 'V' and 'C' (will count the verses/ Verse tag can be V1/C/B etc, or 'V' (will count the verses/
choruses itself) or None, where it will assume verse itself) or None, where it will assume verse
It will also attempt to detect duplicates. In this case it will just It will also attempt to detect duplicates. In this case it will just
add to the verse order add to the verse order
""" """
@ -122,16 +129,13 @@ class SongImport(object):
if oldverse.strip() == verse.strip(): if oldverse.strip() == verse.strip():
self.verse_order_list.append(oldversetag) self.verse_order_list.append(oldversetag)
return return
if versetag == u'C':
self.choruscount += 1
versetag += unicode(self.choruscount)
if versetag == u'V' or not versetag: if versetag == u'V' or not versetag:
self.versecount += 1 self.versecount += 1
versetag = u'V' + unicode(self.versecount) versetag = u'V' + unicode(self.versecount)
self.verses.append([versetag, verse]) self.verses.append([versetag, verse.rstrip()])
self.verse_order_list.append(versetag) self.verse_order_list.append(versetag)
if self.choruscount > 0 and not versetag.startswith(u'C'): if versetag.startswith(u'V') and self.contains_verse(u'C'):
self.verse_order_list.append(u'C1') self.verse_order_list.append(u'C')
def repeat_verse(self): def repeat_verse(self):
""" """
@ -139,6 +143,9 @@ class SongImport(object):
""" """
self.verse_order_list.append(self.verse_order_list[-1]) self.verse_order_list.append(self.verse_order_list[-1])
def contains_verse(self, versetag):
return versetag in self.verse_order_list
def check_complete(self): def check_complete(self):
""" """
Check the mandatory fields are entered (i.e. title and a verse) Check the mandatory fields are entered (i.e. title and a verse)
@ -173,7 +180,8 @@ class SongImport(object):
""" """
song = Song() song = Song()
song.title = self.title song.title = self.title
song.search_title = self.remove_punctuation(self.title) song.search_title = self.remove_punctuation(self.title) \
+ '@' + self.alternate_title
song.song_number = self.song_number song.song_number = self.song_number
song.search_lyrics = u'' song.search_lyrics = u''
sxml = SongXMLBuilder() sxml = SongXMLBuilder()
@ -235,6 +243,7 @@ class SongImport(object):
print u'========================================' \ print u'========================================' \
+ u'========================================' + u'========================================'
print u'TITLE: ' + self.title print u'TITLE: ' + self.title
print u'ALT TITLE: ' + self.alternate_title
for (versetag, versetext) in self.verses: for (versetag, versetext) in self.verses:
print u'VERSE ' + versetag + u': ' + versetext print u'VERSE ' + versetag + u': ' + versetext
print u'ORDER: ' + u' '.join(self.verse_order_list) print u'ORDER: ' + u' '.join(self.verse_order_list)

View File

@ -187,8 +187,16 @@ class SongsPlugin(Plugin):
filename = QtGui.QFileDialog.getOpenFileName( filename = QtGui.QFileDialog.getOpenFileName(
None, self.trUtf8('Open Songs of Fellowship file'), None, self.trUtf8('Open Songs of Fellowship file'),
u'', u'Songs of Fellowship file (*.rtf *.RTF)') u'', u'Songs of Fellowship file (*.rtf *.RTF)')
try:
sofimport = SofImport(self.songmanager) sofimport = SofImport(self.songmanager)
sofimport.import_sof(unicode(filename)) sofimport.import_sof(unicode(filename))
except:
log.exception('Could not import SoF file')
QtGui.QMessageBox.critical(None,
self.ImportSongMenu.trUtf8('Import Error'),
self.ImportSongMenu.trUtf8('Error importing Songs of Fellowship file'),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok),
QtGui.QMessageBox.Ok)
def onExportOpenlp1ItemClicked(self): def onExportOpenlp1ItemClicked(self):
self.openlp_export_form.show() self.openlp_export_form.show()