openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #03020
[Merge] lp:~meths/openlp/trivialfixes into lp:openlp
Jon Tibble has proposed merging lp:~meths/openlp/trivialfixes into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
Fix OpenLP v2 song importer for correct return and progress bar stuff.
Seems to be an issue with the cancel button that seems generic rather than just this importer so proposing merge.
--
https://code.launchpad.net/~meths/openlp/trivialfixes/+merge/33931
Your team OpenLP Core is requested to review the proposed merge of lp:~meths/openlp/trivialfixes into lp:openlp.
=== modified file 'openlp/plugins/songs/forms/songimportform.py'
--- openlp/plugins/songs/forms/songimportform.py 2010-08-24 19:08:57 +0000
+++ openlp/plugins/songs/forms/songimportform.py 2010-08-27 17:05:58 +0000
@@ -302,8 +302,8 @@
Stop the import on pressing the cancel button.
"""
log.debug('Cancel button pressed!')
- if self.currentId() == 3:
- Receiver.send_message(u'song_stop_import')
+ if self.currentId() == 2:
+ Receiver.send_message(u'songs_stop_import')
def onCurrentIdChanged(self, id):
if id == 2:
=== modified file 'openlp/plugins/songs/lib/olpimport.py'
--- openlp/plugins/songs/lib/olpimport.py 2010-08-23 19:29:39 +0000
+++ openlp/plugins/songs/lib/olpimport.py 2010-08-27 17:05:58 +0000
@@ -75,18 +75,17 @@
The :class:`OpenLPSongImport` class provides OpenLP with the ability to
import song databases from other installations of OpenLP.
"""
- def __init__(self, master_manager, **kwargs):
+ def __init__(self, manager, **kwargs):
"""
Initialise the import.
- ``master_manager``
+ ``manager``
The song manager for the running OpenLP installation.
``source_db``
The database providing the data to import.
"""
- SongImport.__init__(self, master_manager)
- self.master_manager = master_manager
+ SongImport.__init__(self, manager)
self.import_source = u'sqlite:///%s' % kwargs[u'filename']
log.debug(self.import_source)
self.source_session = None
@@ -145,7 +144,12 @@
mapper(OldTopic, source_topics_table)
source_songs = self.source_session.query(OldSong).all()
+ song_total = len(source_songs)
+ self.import_wizard.importProgressBar.setMaximum(song_total)
+ song_count = 1
for song in source_songs:
+ self.import_wizard.incrementProgressBar(
+ u'Importing song %s of %s' % (song_count, song_total))
new_song = Song()
new_song.title = song.title
if has_media_files:
@@ -167,7 +171,7 @@
new_song.ccli_number = song.ccli_number
if song.authors:
for author in song.authors:
- existing_author = self.master_manager.get_object_filtered(
+ existing_author = self.manager.get_object_filtered(
Author, Author.display_name == author.display_name)
if existing_author:
new_song.authors.append(existing_author)
@@ -177,7 +181,7 @@
last_name=author.last_name,
display_name=author.display_name))
else:
- au = self.master_manager.get_object_filtered(Author,
+ au = self.manager.get_object_filtered(Author,
Author.display_name == u'Author Unknown')
if au:
new_song.authors.append(au)
@@ -185,7 +189,7 @@
new_song.authors.append(Author.populate(
display_name=u'Author Unknown'))
if song.book:
- existing_song_book = self.master_manager.get_object_filtered(
+ existing_song_book = self.manager.get_object_filtered(
Book, Book.name == song.book.name)
if existing_song_book:
new_song.book = existing_song_book
@@ -194,7 +198,7 @@
publisher=song.book.publisher)
if song.topics:
for topic in song.topics:
- existing_topic = self.master_manager.get_object_filtered(
+ existing_topic = self.manager.get_object_filtered(
Topic, Topic.name == topic.name)
if existing_topic:
new_song.topics.append(existing_topic)
@@ -204,12 +208,16 @@
# if song.media_files:
# for media_file in song.media_files:
# existing_media_file = \
-# self.master_manager.get_object_filtered(MediaFile,
+# self.manager.get_object_filtered(MediaFile,
# MediaFile.file_name == media_file.file_name)
# if existing_media_file:
# new_song.media_files.append(existing_media_file)
# else:
# new_song.media_files.append(MediaFile.populate(
# file_name=media_file.file_name))
- self.master_manager.save_object(new_song)
+ self.manager.save_object(new_song)
+ song_count += 1
+ if self.stop_import_flag:
+ return False
engine.dispose()
+ return True
=== modified file 'openlp/plugins/songs/lib/songimport.py'
--- openlp/plugins/songs/lib/songimport.py 2010-08-22 19:50:30 +0000
+++ openlp/plugins/songs/lib/songimport.py 2010-08-27 17:05:58 +0000
@@ -24,14 +24,18 @@
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
+import logging
import re
+from PyQt4 import QtCore
-from openlp.core.lib import translate
+from openlp.core.lib import Receiver, translate
from openlp.plugins.songs.lib import VerseType
from openlp.plugins.songs.lib.db import Song, Author, Topic, Book
from openlp.plugins.songs.lib.xml import SongXMLBuilder
-class SongImport(object):
+log = logging.getLogger(__name__)
+
+class SongImport(QtCore.QObject):
"""
Helper class for import a song from a third party source into OpenLP
@@ -39,7 +43,6 @@
whether the authors etc already exist and add them or refer to them
as necessary
"""
-
def __init__(self, manager):
"""
Initialise and create defaults for properties
@@ -48,6 +51,7 @@
database access is performed
"""
self.manager = manager
+ self.stop_import_flag = False
self.title = u''
self.song_number = u''
self.alternate_title = u''
@@ -67,6 +71,15 @@
'SongsPlugin.SongImport', 'copyright'))
self.copyright_symbol = unicode(translate(
'SongsPlugin.SongImport', '\xa9'))
+ QtCore.QObject.connect(Receiver.get_receiver(),
+ QtCore.SIGNAL(u'songs_stop_import'), self.stop_import)
+
+ def stop_import(self):
+ """
+ Sets the flag for importers to stop their import
+ """
+ log.debug(u'Stopping songs import')
+ self.stop_import_flag = True
def register(self, import_wizard):
self.import_wizard = import_wizard
Follow ups