Bugfix: Duplicates were reported more than once.

This commit is contained in:
Patrick Zimmermann 2013-01-28 23:20:50 +01:00
parent d09c8f20a6
commit cdd52c363f
1 changed files with 38 additions and 19 deletions

View File

@ -164,6 +164,9 @@ class DuplicateSongRemovalForm(OpenLPWizard):
#search duplicate songs #search duplicate songs
maxSongs = self.plugin.manager.get_object_count(Song) maxSongs = self.plugin.manager.get_object_count(Song)
if maxSongs == 0 or maxSongs == 1: if maxSongs == 0 or maxSongs == 1:
self.duplicateSearchProgressBar.setMaximum(1)
self.duplicateSearchProgressBar.setValue(1)
self.notifyNoDuplicates()
return return
# with x songs we have x*(x-1)/2 comparisons # with x songs we have x*(x-1)/2 comparisons
maxProgressCount = maxSongs*(maxSongs-1)/2 maxProgressCount = maxSongs*(maxSongs-1)/2
@ -173,26 +176,36 @@ class DuplicateSongRemovalForm(OpenLPWizard):
for innerSongCounter in range(outerSongCounter+1, maxSongs): for innerSongCounter in range(outerSongCounter+1, maxSongs):
doubleFinder = DuplicateSongFinder() doubleFinder = DuplicateSongFinder()
if doubleFinder.songsProbablyEqual(songs[outerSongCounter], songs[innerSongCounter]): if doubleFinder.songsProbablyEqual(songs[outerSongCounter], songs[innerSongCounter]):
self.addDuplicatesToSongList(songs[outerSongCounter], songs[innerSongCounter]) duplicateAdded = self.addDuplicatesToSongList(songs[outerSongCounter], songs[innerSongCounter])
self.foundDuplicatesEdit.appendPlainText(songs[outerSongCounter].title + " = " + if duplicateAdded:
self.foundDuplicatesEdit.appendPlainText(songs[outerSongCounter].title + " = " +
songs[innerSongCounter].title) songs[innerSongCounter].title)
self.duplicateSearchProgressBar.setValue(self.duplicateSearchProgressBar.value()+1) self.duplicateSearchProgressBar.setValue(self.duplicateSearchProgressBar.value()+1)
self.reviewTotalCount = len(self.duplicateSongList) self.reviewTotalCount = len(self.duplicateSongList)
if self.reviewTotalCount == 0: if self.reviewTotalCount == 0:
self.button(QtGui.QWizard.FinishButton).show() self.notifyNoDuplicates()
self.button(QtGui.QWizard.FinishButton).setEnabled(True)
self.button(QtGui.QWizard.NextButton).hide()
QtGui.QMessageBox.information(self, translate(u'Wizard', u'Information'),
translate(u'Wizard', u'No duplicate songs have been found in the database.'),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
elif pageId == self.reviewPageId: elif pageId == self.reviewPageId:
self.nextReviewButtonClicked() self.nextReviewButtonClicked()
def notifyNoDuplicates(self):
"""
Notifies the user, that there were no duplicates found in the database.
"""
self.button(QtGui.QWizard.FinishButton).show()
self.button(QtGui.QWizard.FinishButton).setEnabled(True)
self.button(QtGui.QWizard.NextButton).hide()
QtGui.QMessageBox.information(self, translate(u'Wizard', u'Information'),
translate(u'Wizard', u'No duplicate songs have been found in the database.'),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
def addDuplicatesToSongList(self, searchSong, duplicateSong): def addDuplicatesToSongList(self, searchSong, duplicateSong):
""" """
Inserts a song duplicate (two simliar songs) to the duplicate song list. Inserts a song duplicate (two simliar songs) to the duplicate song list.
If one of the two songs is already part of the duplicate song list, If one of the two songs is already part of the duplicate song list,
don't add another duplicate group but add the other song to that group. don't add another duplicate group but add the other song to that group.
Retruns True if at least one of the songs was added, False if both were already
member of a group.
``searchSong`` ``searchSong``
The song we searched the duplicate for. The song we searched the duplicate for.
@ -201,21 +214,27 @@ class DuplicateSongRemovalForm(OpenLPWizard):
The duplicate song. The duplicate song.
""" """
duplicateGroupFound = False duplicateGroupFound = False
for duplicates in self.duplicateSongList: duplicateAdded = False
for duplicateGroup in self.duplicateSongList:
#skip the first song in the duplicate lists, since the first one has to be an earlier song #skip the first song in the duplicate lists, since the first one has to be an earlier song
for duplicate in duplicates[1:]: if searchSong in duplicateGroup and not duplicateSong in duplicateGroup:
if duplicate == searchSong: duplicateGroup.append(duplicateSong)
duplicates.append(duplicateSong) duplicateGroupFound = True
duplicateGroupFound = True duplicateAdded = True
break break
elif duplicate == duplicateSong: elif not searchSong in duplicateGroup and duplicateSong in duplicateGroup:
duplicates.append(searchSong) duplicateGroup.append(searchSong)
duplicateGroupFound = True duplicateGroupFound = True
break duplicateAdded = True
if duplicateGroupFound: break
elif searchSong in duplicateGroup and duplicateSong in duplicateGroup:
duplicateGroupFound = True
duplicateAdded = False
break break
if not duplicateGroupFound: if not duplicateGroupFound:
self.duplicateSongList.append([searchSong, duplicateSong]) self.duplicateSongList.append([searchSong, duplicateSong])
duplicateGroupFound = True
return duplicateAdded
def onWizardExit(self): def onWizardExit(self):
""" """