mirror of
https://github.com/fergalmoran/picard.git
synced 2026-04-16 09:25:14 +00:00
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:
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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'])
|
||||
|
||||
Reference in New Issue
Block a user