Replace Metadata.get_single_front_image() with ImageList.get_front_image()

- it makes much more sense, Metadata.images is an ImageList
- minimal changes required
- add tests for it
This commit is contained in:
Laurent Monin
2019-03-21 14:22:07 +01:00
parent d60afe35d7
commit eb73ea6bc4
4 changed files with 14 additions and 11 deletions

View File

@@ -444,7 +444,7 @@ class File(QtCore.QObject, Item):
counters = defaultdict(lambda: 0)
images = []
if config.setting["caa_save_single_front_image"]:
images = metadata.get_single_front_image()
images = [metadata.images.get_front_image()]
if not images:
images = metadata.images
for image in images:

View File

@@ -103,19 +103,11 @@ class Metadata(MutableMapping):
return ()
images = [img for img in self.images if img.can_be_saved_to_tags]
if config.setting["embed_only_one_front_image"]:
front_image = self.get_single_front_image(images)
front_image = self.images.get_front_image()
if front_image:
return front_image
return [front_image]
return images
def get_single_front_image(self, images=None):
if not images:
images = self.images
for img in images:
if img.is_front_image():
return [img]
return []
def remove_image(self, index):
self.images.pop(index)

View File

@@ -34,6 +34,12 @@ class ImageList(list):
except TypeError:
return result
def get_front_image(self):
for img in self:
if img.is_front_image():
return img
return None
class ImageListState:
def __init__(self):

View File

@@ -264,3 +264,8 @@ class ImageListTest(PicardTestCase):
self.assertTrue(list1 == list2)
self.assertFalse(list1 == list3)
def test_get_front_image(self):
self.imagelist.append(self.images['a'])
self.imagelist.append(self.images['b'])
self.assertEqual(self.imagelist.get_front_image(), self.images['b'])