A couple of bugfixes.

This commit is contained in:
Raoul Snyman 2010-09-07 00:02:48 +02:00
parent 63139e8c3b
commit f30aecfd46
3 changed files with 37 additions and 26 deletions

View File

@ -31,7 +31,6 @@ from PyQt4 import QtCore, QtGui
from songimportwizard import Ui_SongImportWizard from songimportwizard import Ui_SongImportWizard
from openlp.core.lib import Receiver, SettingsManager, translate from openlp.core.lib import Receiver, SettingsManager, translate
#from openlp.core.utils import AppLocation
from openlp.plugins.songs.lib.importer import SongFormat from openlp.plugins.songs.lib.importer import SongFormat
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -136,7 +135,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_SongImportWizard):
self.openLP2BrowseButton.setFocus() self.openLP2BrowseButton.setFocus()
return False return False
elif source_format == SongFormat.OpenLP1: elif source_format == SongFormat.OpenLP1:
if self.openSongFilenameEdit.text().isEmpty(): if self.openLP1FilenameEdit.text().isEmpty():
QtGui.QMessageBox.critical(self, QtGui.QMessageBox.critical(self,
translate('SongsPlugin.ImportWizardForm', translate('SongsPlugin.ImportWizardForm',
'No openlp.org 1.x Song Database Selected'), 'No openlp.org 1.x Song Database Selected'),
@ -292,7 +291,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_SongImportWizard):
def onCCLIRemoveButtonClicked(self): def onCCLIRemoveButtonClicked(self):
self.removeSelectedItems(self.ccliFileListWidget) self.removeSelectedItems(self.ccliFileListWidget)
def onSongsOfFellowshipAddButtonClicked(self): def onSongsOfFellowshipAddButtonClicked(self):
self.getFiles( self.getFiles(
translate('SongsPlugin.ImportWizardForm', translate('SongsPlugin.ImportWizardForm',
@ -374,11 +373,11 @@ class ImportWizardForm(QtGui.QWizard, Ui_SongImportWizard):
importer = self.plugin.importSongs(SongFormat.OpenLP2, importer = self.plugin.importSongs(SongFormat.OpenLP2,
filename=unicode(self.openLP2FilenameEdit.text()) filename=unicode(self.openLP2FilenameEdit.text())
) )
#elif source_format == SongFormat.OpenLP1: elif source_format == SongFormat.OpenLP1:
# # Import an openlp.org database # Import an openlp.org database
# importer = self.plugin.importSongs(SongFormat.OpenLP1, importer = self.plugin.importSongs(SongFormat.OpenLP1,
# filename=unicode(self.field(u'openlp1_filename').toString()) filename=unicode(self.openLP1FilenameEdit.text())
# ) )
elif source_format == SongFormat.OpenLyrics: elif source_format == SongFormat.OpenLyrics:
# Import OpenLyrics songs # Import OpenLyrics songs
importer = self.plugin.importSongs(SongFormat.OpenLyrics, importer = self.plugin.importSongs(SongFormat.OpenLyrics,

View File

@ -26,6 +26,7 @@
from opensongimport import OpenSongImport from opensongimport import OpenSongImport
from olpimport import OpenLPSongImport from olpimport import OpenLPSongImport
from olp1import import OpenLP1SongImport
try: try:
from sofimport import SofImport from sofimport import SofImport
from oooimport import OooImport from oooimport import OooImport
@ -61,6 +62,8 @@ class SongFormat(object):
""" """
if format == SongFormat.OpenLP2: if format == SongFormat.OpenLP2:
return OpenLPSongImport return OpenLPSongImport
if format == SongFormat.OpenLP1:
return OpenLP1SongImport
elif format == SongFormat.OpenSong: elif format == SongFormat.OpenSong:
return OpenSongImport return OpenSongImport
elif format == SongFormat.SongsOfFellowship: elif format == SongFormat.SongsOfFellowship:
@ -70,7 +73,7 @@ class SongFormat(object):
elif format == SongFormat.Generic: elif format == SongFormat.Generic:
return OooImport return OooImport
elif format == SongFormat.CCLI: elif format == SongFormat.CCLI:
return CCLIFileImport return CCLIFileImport
# else: # else:
return None return None

View File

@ -30,8 +30,7 @@ openlp.org 1.x song databases into the current installation database.
import logging import logging
import sqlite import sqlite
#from openlp.core.lib.db import BaseModel from openlp.core.lib import translate
from openlp.plugins.songs.lib.db import Author, Book, Song, Topic #, MediaFile
from songimport import SongImport from songimport import SongImport
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -66,6 +65,12 @@ class OpenLP1SongImport(SongImport):
count = int(cursor.fetchone()[0]) count = int(cursor.fetchone()[0])
success = True success = True
self.import_wizard.importProgressBar.setMaximum(count) self.import_wizard.importProgressBar.setMaximum(count)
# "cache" our list of authors
cursor.execute(u'SELECT authorid, authorname FROM authors')
authors = cursor.fetchall()
# "cache" our list of tracks
cursor.execute(u'SELECT trackid, fulltrackname FROM tracks')
tracks = cursor.fetchall()
# Import the songs # Import the songs
cursor.execute(u'SELECT songid, songtitle, lyrics || \'\' AS lyrics, ' cursor.execute(u'SELECT songid, songtitle, lyrics || \'\' AS lyrics, '
u'copyrightinfo FROM songs') u'copyrightinfo FROM songs')
@ -77,39 +82,43 @@ class OpenLP1SongImport(SongImport):
break break
song_id = song[0] song_id = song[0]
title = unicode(song[1], u'cp1252') title = unicode(song[1], u'cp1252')
lyrics = unicode(song[2], u'cp1252') lyrics = unicode(song[2], u'cp1252').replace(u'\r', u'')
copyright = unicode(song[3], u'cp1252') copyright = unicode(song[3], u'cp1252')
self.import_wizard.incrementProgressBar( self.import_wizard.incrementProgressBar(
unicode(translate('SongsPlugin.ImportWizardForm', unicode(translate('SongsPlugin.ImportWizardForm',
'Importing %s...')) % title) 'Importing "%s"...')) % title)
self.title = title self.title = title
self.process_song_text(lyrics) self.process_song_text(lyrics)
self.add_copyright(copyright) self.add_copyright(copyright)
cursor.execute(u'SELECT displayname FROM authors a ' cursor.execute(u'SELECT authorid FROM songauthors '
u'JOIN songauthors sa ON a.authorid = sa.authorid ' u'WHERE songid = %s' % song_id)
u'WHERE sa.songid = %s' % song_id) author_ids = cursor.fetchall()
authors = cursor.fetchall() for author_id in author_ids:
for author in authors:
if self.stop_import_flag: if self.stop_import_flag:
success = False success = False
break break
self.parse_author(unicode(author[0], u'cp1252')) for author in authors:
if author[0] == author_id[0]:
self.parse_author(unicode(author[1], u'cp1252'))
break
if self.stop_import_flag: if self.stop_import_flag:
success = False success = False
break break
cursor.execute(u'SELECT name FROM sqlite_master ' cursor.execute(u'SELECT name FROM sqlite_master '
u'WHERE type = \'table\' NAME name = \'tracks\'') u'WHERE type = \'table\' AND name = \'tracks\'')
table_list = cursor.fetchall() table_list = cursor.fetchall()
if len(table_list) > 0: if len(table_list) > 0:
cursor.execute(u'SELECT fulltrackname FROM tracks t ' cursor.execute(u'SELECT trackid FROM songtracks '
u'JOIN songtracks st ON t.trackid = st.trackid ' u'WHERE songid = %s ORDER BY listindex' % song_id)
u'WHERE st.songid = %s ORDER BY st.listindex' % song_id) track_ids = cursor.fetchall()
tracks = cursor.fetchall() for track_id in track_ids:
for track in tracks:
if self.stop_import_flag: if self.stop_import_flag:
success = False success = False
break break
self.add_media_file(unicode(track[0], u'cp1252')) for track in tracks:
if track[0] == track_id[0]:
self.add_media_file(unicode(track[1], u'cp1252'))
break
if self.stop_import_flag: if self.stop_import_flag:
success = False success = False
break break