From 3ceb0267e986059c5a27a2445c2301d88a6aebec Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Sat, 3 Apr 2010 20:17:37 +0100 Subject: [PATCH] cleanups+multi-song delete --- openlp/plugins/songs/lib/manager.py | 4 ++++ openlp/plugins/songs/lib/mediaitem.py | 24 +++++++++++++----------- openlp/plugins/songs/lib/sofimport.py | 18 ++++++------------ openlp/plugins/songs/lib/songimport.py | 14 +++++++++----- openlp/plugins/songs/songsplugin.py | 5 ++++- 5 files changed, 36 insertions(+), 29 deletions(-) diff --git a/openlp/plugins/songs/lib/manager.py b/openlp/plugins/songs/lib/manager.py index dcb49bfcd..0dfed09b6 100644 --- a/openlp/plugins/songs/lib/manager.py +++ b/openlp/plugins/songs/lib/manager.py @@ -111,12 +111,16 @@ class SongManager(): return False def delete_song(self, songid): + print songid song = self.get_song(songid) + print song.title try: self.session.delete(song) self.session.commit() + print "ok" return True except: + print "error" self.session.rollback() log.exception(u'Could not delete song from song database') return False diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 145646a02..1ce69f407 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -273,19 +273,21 @@ class SongMediaItem(MediaManagerItem): def onDeleteClick(self): items = self.ListView.selectedIndexes() 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[:]: + if len(items) == 1: + del_message = self.trUtf8('Delete song?') + else: + del_message = self.trUtf8('Delete %d song?' % len(items)) + ans = QtGui.QMessageBox.question(None, + self.trUtf8('Delete Confirmation'), del_message, + 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] self.parent.songmanager.delete_song(item_id) - self.ListView.takeItem(item.row()) + self.onSearchTextButtonClick() def generateSlideData(self, service_item): raw_footer = [] diff --git a/openlp/plugins/songs/lib/sofimport.py b/openlp/plugins/songs/lib/sofimport.py index df0ffd5bc..6fb3cfb6e 100644 --- a/openlp/plugins/songs/lib/sofimport.py +++ b/openlp/plugins/songs/lib/sofimport.py @@ -32,7 +32,7 @@ property# -*- coding: utf-8 -*- import re import os import time -from PyQt4 import QtCore, QtGui +from PyQt4 import QtCore from songimport import SongImport if os.name == u'nt': @@ -315,8 +315,9 @@ class SofImport(object): author2 = author2 + u' ' \ + authors[i + 1].strip().split(u' ')[-1] if author2.endswith(u'.'): - author2 = author2[:-1] - self.song.add_author(author2) + author2 = author2[:-1] + if author2: + self.song.add_author(author2) def add_verse_line(self, text): """ @@ -340,17 +341,10 @@ class SofImport(object): if self.currentverse.strip() == u'': return if self.is_chorus: - if not self.song.contains_verse('C'): - versetag = 'C' - elif not self.song.contains_verse('B'): - versetag = 'B' - elif not self.song.contains_verse('E'): - versetag = 'E' - else: - versetag = 'O' + versetag = u'C' splitat = None else: - versetag = 'V' + versetag = u'V' splitat = self.verse_splits(self.song.get_song_number()) if splitat: ln = 0 diff --git a/openlp/plugins/songs/lib/songimport.py b/openlp/plugins/songs/lib/songimport.py index 15e8e00eb..6adfcad7f 100644 --- a/openlp/plugins/songs/lib/songimport.py +++ b/openlp/plugins/songs/lib/songimport.py @@ -120,22 +120,26 @@ class SongImport(object): def add_verse(self, verse, versetag): """ Add a verse. This is the whole verse, lines split by \n - Verse tag can be V1/C/B etc, or 'V' (will count the verses/ - itself) or None, where it will assume verse + Verse tag can be V1/C1/B etc, or 'V' and 'C' (will count the verses/ + choruses itself) or None, where it will assume verse It will also attempt to detect duplicates. In this case it will just add to the verse order """ for (oldversetag, oldverse) in self.verses: if oldverse.strip() == verse.strip(): self.verse_order_list.append(oldversetag) - return + return + if versetag.startswith(u'C'): + self.choruscount += 1 + if versetag == u'C': + versetag += unicode(self.choruscount) if versetag == u'V' or not versetag: self.versecount += 1 versetag = u'V' + unicode(self.versecount) self.verses.append([versetag, verse.rstrip()]) self.verse_order_list.append(versetag) - if versetag.startswith(u'V') and self.contains_verse(u'C'): - self.verse_order_list.append(u'C') + if versetag.startswith(u'V') and self.contains_verse(u'C1'): + self.verse_order_list.append(u'C1') def repeat_verse(self): """ diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index 3e245690a..d7c0aa7ca 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -194,7 +194,10 @@ class SongsPlugin(Plugin): 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'), + self.ImportSongMenu.trUtf8('Error importing Songs of ' + + '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'), QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok), QtGui.QMessageBox.Ok)