← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~raoul-snyman/openlp/bug-851706 into lp:openlp

 

Raoul Snyman has proposed merging lp:~raoul-snyman/openlp/bug-851706 into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)
Related bugs:
  Bug #851706 in OpenLP: "Song import progress bar (triggered by FTW) does not change on a song-by-song basis"
  https://bugs.launchpad.net/openlp/+bug/851706

For more details, see:
https://code.launchpad.net/~raoul-snyman/openlp/bug-851706/+merge/129496

Fixed bug #851706: The song import dialog now shows individual songs being imported. Also tried to make the progress page of the FTW work better, pity it is only slightly...
-- 
https://code.launchpad.net/~raoul-snyman/openlp/bug-851706/+merge/129496
Your team OpenLP Core is requested to review the proposed merge of lp:~raoul-snyman/openlp/bug-851706 into lp:openlp.
=== modified file 'openlp/core/ui/firsttimeform.py'
--- openlp/core/ui/firsttimeform.py	2012-06-26 16:14:42 +0000
+++ openlp/core/ui/firsttimeform.py	2012-10-12 19:00:27 +0000
@@ -177,8 +177,10 @@
             return FirstTimePage.Progress
         elif self.currentId() == FirstTimePage.Themes:
             Receiver.send_message(u'cursor_busy')
+            Receiver.send_message(u'openlp_process_events')
             while not self.themeScreenshotThread.isFinished():
                 time.sleep(0.1)
+                Receiver.send_message(u'openlp_process_events')
             # Build the screenshot icons, as this can not be done in the thread.
             self._buildThemeScreenshots()
             Receiver.send_message(u'cursor_normal')
@@ -188,10 +190,11 @@
 
     def onCurrentIdChanged(self, pageId):
         """
-        Detects Page changes and updates as approprate.
+        Detects Page changes and updates as appropriate.
         """
         # Keep track of the page we are at.  Triggering "Cancel" causes pageId
         # to be a -1.
+        Receiver.send_message(u'openlp_process_events')
         if pageId != -1:
             self.lastId = pageId
         if pageId == FirstTimePage.Plugins:
@@ -227,6 +230,10 @@
                 self.cancelButton.setVisible(False)
         elif pageId == FirstTimePage.Progress:
             Receiver.send_message(u'cursor_busy')
+            self.update()
+            Receiver.send_message(u'openlp_process_events')
+            time.sleep(0.5)
+            Receiver.send_message(u'openlp_process_events')
             self._preWizard()
             Receiver.send_message(u'openlp_process_events')
             self._performWizard()
@@ -342,8 +349,10 @@
         self.max_progress = 0
         self.finishButton.setVisible(False)
         Receiver.send_message(u'openlp_process_events')
+        time.sleep(0.1)
         # Loop through the songs list and increase for each selected item
         for i in xrange(self.songsListWidget.count()):
+            Receiver.send_message(u'openlp_process_events')
             item = self.songsListWidget.item(i)
             if item.checkState() == QtCore.Qt.Checked:
                 filename = item.data(QtCore.Qt.UserRole).toString()
@@ -352,6 +361,7 @@
         # Loop through the Bibles list and increase for each selected item
         iterator = QtGui.QTreeWidgetItemIterator(self.biblesTreeWidget)
         while iterator.value():
+            Receiver.send_message(u'openlp_process_events')
             item = iterator.value()
             if item.parent() and item.checkState(0) == QtCore.Qt.Checked:
                 filename = item.data(0, QtCore.Qt.UserRole).toString()
@@ -360,6 +370,7 @@
             iterator += 1
         # Loop through the themes list and increase for each selected item
         for i in xrange(self.themesListWidget.count()):
+            Receiver.send_message(u'openlp_process_events')
             item = self.themesListWidget.item(i)
             if item.checkState() == QtCore.Qt.Checked:
                 filename = item.data(QtCore.Qt.UserRole).toString()
@@ -381,6 +392,7 @@
             self.progressPage.setTitle(translate('OpenLP.FirstTimeWizard',
                 'Setting Up'))
             self.progressPage.setSubTitle(u'Setup complete.')
+        Receiver.send_message(u'openlp_process_events')
 
     def _postWizard(self):
         """

=== modified file 'openlp/plugins/songs/lib/olpimport.py'
--- openlp/plugins/songs/lib/olpimport.py	2012-06-22 14:14:53 +0000
+++ openlp/plugins/songs/lib/olpimport.py	2012-10-12 19:00:27 +0000
@@ -63,10 +63,14 @@
         SongImport.__init__(self, manager, **kwargs)
         self.sourceSession = None
 
-    def doImport(self):
+    def doImport(self, progressDialog=None):
         """
         Run the import for an OpenLP version 2 song database.
+
+        ``progressDialog``
+            The QProgressDialog used when importing songs from the FRW.
         """
+
         class OldAuthor(BaseModel):
             """
             Author model
@@ -101,13 +105,14 @@
             """
             pass
 
-
+        # Check the file type
         if not self.importSource.endswith(u'.sqlite'):
             self.logError(self.importSource,
                 translate('SongsPlugin.OpenLPSongImport',
                 'Not a valid OpenLP 2.0 song database.'))
             return
         self.importSource = u'sqlite:///%s' % self.importSource
+        # Load the db file
         engine = create_engine(self.importSource)
         source_meta = MetaData()
         source_meta.reflect(engine)
@@ -224,7 +229,11 @@
                                 file_name=media_file.file_name))
             clean_song(self.manager, new_song)
             self.manager.save_object(new_song)
-            if self.importWizard:
+            if progressDialog:
+                progressDialog.setValue(progressDialog.value() + 1)
+                progressDialog.setLabelText(
+                    WizardStrings.ImportingType % new_song.title)
+            else:
                 self.importWizard.incrementProgressBar(
                     WizardStrings.ImportingType % new_song.title)
             if self.stopImportFlag:

=== modified file 'openlp/plugins/songs/songsplugin.py'
--- openlp/plugins/songs/songsplugin.py	2012-08-04 14:43:44 +0000
+++ openlp/plugins/songs/songsplugin.py	2012-10-12 19:00:27 +0000
@@ -29,6 +29,7 @@
 import logging
 import os
 from tempfile import gettempdir
+import sqlite3
 
 from PyQt4 import QtCore, QtGui
 
@@ -82,7 +83,7 @@
             unicode(UiStrings().Tools))
         QtCore.QObject.connect(Receiver.get_receiver(),
             QtCore.SIGNAL(u'servicemanager_new_service'),
-        self.clearTemporarySongs)
+            self.clearTemporarySongs)
 
 
     def addImportMenuItem(self, import_menu):
@@ -235,31 +236,37 @@
         If the first time wizard has run, this function is run to import all the
         new songs into the database.
         """
+        Receiver.send_message(u'openlp_process_events')
         self.onToolsReindexItemTriggered()
+        Receiver.send_message(u'openlp_process_events')
         db_dir = unicode(os.path.join(
             unicode(gettempdir(), get_filesystem_encoding()), u'openlp'))
         if not os.path.exists(db_dir):
             return
         song_dbs = []
+        song_count = 0
         for sfile in os.listdir(db_dir):
             if sfile.startswith(u'songs_') and sfile.endswith(u'.sqlite'):
+                Receiver.send_message(u'openlp_process_events')
                 song_dbs.append(os.path.join(db_dir, sfile))
+                song_count += self._countSongs(os.path.join(db_dir, sfile))
         if not song_dbs:
             return
+        Receiver.send_message(u'openlp_process_events')
         progress = QtGui.QProgressDialog(self.formParent)
         progress.setWindowModality(QtCore.Qt.WindowModal)
         progress.setWindowTitle(translate('OpenLP.Ui', 'Importing Songs'))
         progress.setLabelText(translate('OpenLP.Ui', 'Starting import...'))
         progress.setCancelButton(None)
-        progress.setRange(0, len(song_dbs))
+        progress.setRange(0, song_count)
         progress.setMinimumDuration(0)
         progress.forceShow()
-        for idx, db in enumerate(song_dbs):
-            progress.setValue(idx)
+        Receiver.send_message(u'openlp_process_events')
+        for db in song_dbs:
+            importer = OpenLPSongImport(self.manager, filename=db)
+            importer.doImport(progress)
             Receiver.send_message(u'openlp_process_events')
-            importer = OpenLPSongImport(self.manager, filename=db)
-            importer.doImport()
-        progress.setValue(len(song_dbs))
+        progress.setValue(song_count)
         self.mediaItem.onSearchTextButtonClicked()
 
     def finalise(self):
@@ -287,3 +294,15 @@
         songs = self.manager.get_all_objects(Song, Song.temporary == True)
         for song in songs:
             self.manager.delete_object(Song, song.id)
+
+    def _countSongs(self, db_file):
+        connection = sqlite3.connect(db_file)
+        cursor = connection.cursor()
+        cursor.execute(u'SELECT COUNT(id) AS song_count FROM songs')
+        song_count = cursor.fetchone()[0]
+        connection.close()
+        try:
+            song_count = int(song_count)
+        except (TypeError, ValueError):
+            song_count = 0
+        return song_count


Follow ups