From 3a9820528ad0b1b26d67261a893b382485579b50 Mon Sep 17 00:00:00 2001 From: Patrick Zimmermann Date: Wed, 9 Jan 2013 00:17:00 +0100 Subject: [PATCH] Added detection logic to wizard. --- .../songs/forms/duplicatesongremovalform.py | 19 +++++++++++- openlp/plugins/songs/songsplugin.py | 29 +++++++++---------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/openlp/plugins/songs/forms/duplicatesongremovalform.py b/openlp/plugins/songs/forms/duplicatesongremovalform.py index 33cd64b4a..3e58a1757 100644 --- a/openlp/plugins/songs/forms/duplicatesongremovalform.py +++ b/openlp/plugins/songs/forms/duplicatesongremovalform.py @@ -38,7 +38,9 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import Receiver, Settings, SettingsManager, translate from openlp.core.lib.ui import UiStrings, critical_error_message_box from openlp.core.ui.wizard import OpenLPWizard, WizardStrings +from openlp.plugins.songs.lib.db import Song from openlp.plugins.songs.lib.importer import SongFormat, SongFormatSelect +from openlp.plugins.songs.lib.duplicatesongfinder import DuplicateSongFinder log = logging.getLogger(__name__) @@ -88,6 +90,7 @@ class DuplicateSongRemovalForm(OpenLPWizard): self.verticalLayout.setObjectName('verticalLayout') self.duplicateSearchProgressBar = QtGui.QProgressBar(self.searchingPage) self.duplicateSearchProgressBar.setObjectName(u'duplicateSearchProgressBar') + self.duplicateSearchProgressBar.setFormat(WizardStrings.PercentSymbolFormat) self.verticalLayout.addWidget(self.duplicateSearchProgressBar) self.foundDuplicatesEdit = QtGui.QPlainTextEdit(self.searchingPage) self.foundDuplicatesEdit.setUndoRedoEnabled(False) @@ -115,7 +118,20 @@ class DuplicateSongRemovalForm(OpenLPWizard): """ Called when changing to a page other than the progress page. """ - pass + if self.page(pageId) == self.searchingPage: + maxSongs = self.plugin.manager.get_object_count(Song) + if maxSongs == 0 or maxSongs == 1: + return + # with x songs we have x*(x-1)/2 comparisons + maxProgressCount = maxSongs*(maxSongs-1)/2 + self.duplicateSearchProgressBar.setMaximum(maxProgressCount) + songs = self.plugin.manager.get_all_objects(Song) + for outerSongCounter in range(maxSongs-1): + for innerSongCounter in range(outerSongCounter+1, maxSongs): + doubleFinder = DuplicateSongFinder() + if doubleFinder.songsProbablyEqual(songs[outerSongCounter], songs[innerSongCounter]): + self.foundDuplicatesEdit.appendPlainText(songs[outerSongCounter].title + " = " + songs[innerSongCounter].title) + self.duplicateSearchProgressBar.setValue(self.duplicateSearchProgressBar.value()+1) def onAddButtonClicked(self): pass @@ -128,6 +144,7 @@ class DuplicateSongRemovalForm(OpenLPWizard): Set default form values for the song import wizard. """ self.restart() + self.duplicateSearchProgressBar.setValue(0) self.foundDuplicatesEdit.clear() def performWizard(self): diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index b19eee5e7..b006eb19a 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -45,7 +45,6 @@ from openlp.plugins.songs.lib import clean_song, upgrade, SongMediaItem, \ from openlp.plugins.songs.lib.db import init_schema, Song from openlp.plugins.songs.lib.importer import SongFormat from openlp.plugins.songs.lib.olpimport import OpenLPSongImport -from openlp.plugins.songs.lib.duplicatesongfinder import DuplicateSongFinder from openlp.plugins.songs.forms.duplicatesongremovalform import \ DuplicateSongRemovalForm @@ -172,20 +171,20 @@ class SongsPlugin(Plugin): """ Search for duplicates in the song database. """ - maxSongs = self.manager.get_object_count(Song) - if maxSongs == 0: - return - QtGui.QMessageBox.information(self.formParent, - "Find duplicates called", "Called...") - songs = self.manager.get_all_objects(Song) - for outerSongCounter in range(maxSongs-1): - for innerSongCounter in range(outerSongCounter+1, maxSongs): - doubleFinder = DuplicateSongFinder() - if doubleFinder.songsProbablyEqual(songs[outerSongCounter], - songs[innerSongCounter]): - QtGui.QMessageBox.information(self.formParent, - "Double found", str(innerSongCounter) + " " + - str(outerSongCounter)) + #maxSongs = self.manager.get_object_count(Song) + #if maxSongs == 0: + # return + #QtGui.QMessageBox.information(self.formParent, + # "Find duplicates called", "Called...") + #songs = self.manager.get_all_objects(Song) + #for outerSongCounter in range(maxSongs-1): + # for innerSongCounter in range(outerSongCounter+1, maxSongs): + # doubleFinder = DuplicateSongFinder() + # if doubleFinder.songsProbablyEqual(songs[outerSongCounter], + # songs[innerSongCounter]): + # QtGui.QMessageBox.information(self.formParent, + # "Double found", str(innerSongCounter) + " " + + # str(outerSongCounter)) if not hasattr(self, u'duplicate_removal_wizard'): self.duplicate_removal_wizard = \ DuplicateSongRemovalForm(self.formParent, self)