Show a message asking the user if they want to remove a file that doesn't exist

bzr-revno: 2629
Fixes: https://launchpad.net/bugs/1559336
This commit is contained in:
raoul@snyman.info 2016-04-29 22:19:27 +01:00 committed by Tim Bentley
commit 654241246d
2 changed files with 33 additions and 1 deletions

View File

@ -1054,8 +1054,23 @@ class EditSongForm(QtWidgets.QDialog, Ui_EditSongDialog, RegistryProperties):
filename = item.data(QtCore.Qt.UserRole)
if not filename.startswith(save_path):
old_file, filename = filename, os.path.join(save_path, os.path.split(filename)[1])
shutil.copyfile(old_file, filename)
try:
shutil.copyfile(old_file, filename)
except FileNotFoundError:
# show a dialog
button = QtWidgets.QMessageBox.critical(
self,
translate('SongsPlugin.EditSongForm', 'File not found'),
translate('SongsPlugin.EditSongForm', 'Unable to find the following file:\n' +
'%s\nDo you want to remove the entry from the song?') % old_file,
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
QtWidgets.QMessageBox.Yes
)
if button == QtWidgets.QMessageBox.Yes:
# If they want the file removed, skip the rest and move onto the next file
continue
files.append(filename)
# Add the file to the media_file table
media_file = MediaFile()
media_file.file_name = filename
media_file.type = 'audio'

View File

@ -78,6 +78,23 @@ class TestFirstTimeForm(TestCase, TestMixin):
if os.path.isfile(self.tempfile):
os.remove(self.tempfile)
@patch('openlp.core.ui.firsttimewizard.is_macosx')
def constructor_macosx_test(self, mocked_is_macosx):
"""
Test that the form is resized correctly on OS X
"""
# GIVEN: The platform is OS X
mocked_is_macosx.return_value = True
# WHEN: The wizard is created
frw = FirstTimeForm(None)
# THEN: The form should have been resized
size = frw.size()
self.assertEqual(634, size.width())
self.assertEqual(386, size.height())
def initialise_test(self):
"""
Test if we can intialise the FirstTimeForm