db: Give Playlists an "icon-name" property

This will be used by the sidebar to display playlist rows

Implements: Issue #20 (Give Playlist database items a icon-name property)
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2021-10-13 17:04:26 -04:00
parent 063b93b66f
commit 2aad28f708
18 changed files with 43 additions and 13 deletions

View File

@ -16,7 +16,7 @@ from . import sql
class Album(playlist.ParentPlaylist):
def __init__(self, row):
playlist.ParentPlaylist.__init__(self, row)
playlist.ParentPlaylist.__init__(self, row, "media-optical-cd-audio")
self._name = row["name"]
@GObject.Property

View File

@ -16,7 +16,7 @@ from . import sql
class Artist(playlist.ParentPlaylist):
def __init__(self, row):
playlist.ParentPlaylist.__init__(self, row)
playlist.ParentPlaylist.__init__(self, row, "avatar-default-symbolic")
self._name = row["name"]
@GObject.Property

View File

@ -11,7 +11,7 @@ from . import year
class Decade(playlist.ParentPlaylist):
def __init__(self, row):
playlist.ParentPlaylist.__init__(self, row)
playlist.ParentPlaylist.__init__(self, row, "x-office-calendar")
self._decade = row["decade"]
@GObject.Property

View File

@ -10,7 +10,7 @@ from . import sql
class Disc(playlist.Playlist):
def __init__(self, row):
playlist.Playlist.__init__(self, row)
playlist.Playlist.__init__(self, row, "media-optical")
self._number = row["number"]
self._subtitle = row["subtitle"]

View File

@ -22,7 +22,7 @@ from . import sql
class Genre(playlist.Playlist):
def __init__(self, row):
playlist.Playlist.__init__(self, row)
playlist.Playlist.__init__(self, row, "emblem-generic")
self._name = row["name"]
@GObject.Property

View File

@ -12,7 +12,7 @@ from . import track
class Library(playlist.Playlist):
def __init__(self, row):
playlist.Playlist.__init__(self, row)
playlist.Playlist.__init__(self, row, "folder-music")
self._path = pathlib.Path(row["path"])
self._enabled = row["enabled"]

View File

@ -5,16 +5,20 @@ from . import state
from . import table
class Playlist(GObject.GObject):
def __init__(self, row):
def __init__(self, row, icon_name):
GObject.GObject.__init__(self)
self._rowid = row[0]
self._plstate = state.Table.get(row["plstateid"])
self._icon_name = icon_name
def has_children(self): return False
@GObject.Property
def name(self): raise NotImplementedError
@GObject.Property
def icon_name(self): return self._icon_name
@GObject.Property
def plist_state(self): return self._plstate

View File

@ -13,6 +13,7 @@ class TestAlbum(unittest.TestCase):
album = artist.find_album("Test Album")
self.assertIsInstance(album, db.playlist.ParentPlaylist)
self.assertEqual(album.get_property("name"), "Test Album")
self.assertEqual(album.get_property("icon-name"), "media-optical-cd-audio")
self.assertEqual(album.get_child_table(), db.disc.Table)
def test_find_disc(self):

View File

@ -12,6 +12,7 @@ class TestArtist(unittest.TestCase):
artist = db.artist.Table.find("Test Artist", "Test Sort")
self.assertIsInstance(artist, db.playlist.ParentPlaylist)
self.assertEqual(artist.get_property("name"), "Test Artist")
self.assertEqual(artist.get_property("icon-name"), "avatar-default-symbolic")
self.assertEqual(artist.get_child_table(), db.album.Table)
def test_find_album(self):

View File

@ -15,6 +15,7 @@ class TestDecade(unittest.TestCase):
decade = db.decade.Table.insert(2020)
self.assertIsInstance(decade, db.playlist.ParentPlaylist)
self.assertEqual(decade.get_property("name"), "2020s")
self.assertEqual(decade.get_property("icon-name"), "x-office-calendar")
self.assertEqual(decade.get_child_table(), db.year.Table)
def test_decade(self):

View File

@ -15,6 +15,7 @@ class TestDisc(unittest.TestCase):
def test_init(self):
disc = self.make_disc("Test Artist", "Test Album", 1, "")
self.assertIsInstance(disc, db.playlist.Playlist)
self.assertEqual(disc.get_property("icon-name"), "media-optical")
self.assertEqual(disc._number, 1)
def test_subtitle(self):

View File

@ -14,6 +14,7 @@ class TestGenre(unittest.TestCase):
self.assertIsInstance(genre, db.playlist.Playlist)
self.assertEqual(genre._name, "Test Genre")
self.assertEqual(genre.get_property("name"), "Test Genre")
self.assertEqual(genre.get_property("icon-name"), "emblem-generic")
class TestGenreTable(unittest.TestCase):

View File

@ -14,6 +14,7 @@ class TestLibrary(unittest.TestCase):
library = db.library.Table.insert(pathlib.Path("/a/b/c"))
self.assertIsInstance(library, db.playlist.Playlist)
self.assertEqual(library.get_property("name"), "/a/b/c")
self.assertEqual(library.get_property("icon-name"), "folder-music")
def test_path(self):
library = db.library.Table.insert(pathlib.Path("/a/b/c"))

View File

@ -7,13 +7,16 @@ from . import playlist
class TestPlaylist(unittest.TestCase):
def test_init(self):
db.reset()
plist = playlist.Playlist({ 0:1, "plstateid":10 })
plist = playlist.Playlist({ 0:1, "plstateid":10 }, "missing-icon")
self.assertIsInstance(plist, GObject.GObject)
self.assertFalse(plist.has_children())
self.assertEqual(plist._rowid, 1)
self.assertEqual(plist.get_property("rowid"), 1)
self.assertEqual(plist._icon_name, "missing-icon")
self.assertEqual(plist.get_property("icon-name"), "missing-icon")
self.assertIsNone(plist._plstate)
self.assertIsNone(plist.get_property("plist_state"))
@ -23,7 +26,7 @@ class TestPlaylist(unittest.TestCase):
class TestParentPlaylist(unittest.TestCase):
def test_init(self):
parent = playlist.ParentPlaylist({ 0:1, "plstateid":10 })
parent = playlist.ParentPlaylist({ 0:1, "plstateid":10 }, "missing-icon")
self.assertIsInstance(parent, playlist.Playlist)
self.assertTrue(parent.has_children())

View File

@ -8,30 +8,35 @@ class TestCollection(unittest.TestCase):
def test_init(self):
collection = db.user.Table.find("Collection")
self.assertIsInstance(collection, db.user.UserPlaylist)
self.assertEqual(collection.icon_name, "media-playback-start")
class TestFavorites(unittest.TestCase):
def test_init(self):
favorites = db.user.Table.find("Favorites")
self.assertIsInstance(favorites, db.user.UserPlaylist)
self.assertEqual(favorites.icon_name, "emmental-favorites")
class TestNewTracks(unittest.TestCase):
def test_init(self):
new = db.user.Table.find("New Tracks")
self.assertIsInstance(new, db.user.UserPlaylist)
self.assertEqual(new.icon_name, "starred")
class TestPrevious(unittest.TestCase):
def test_init(self):
previous = db.user.Table.find("Previous")
self.assertIsInstance(previous, db.user.UserPlaylist)
self.assertEqual(previous.icon_name, "edit-undo")
class TestQueuedTracks(unittest.TestCase):
def test_init(self):
queued = db.user.Table.find("Queued Tracks")
self.assertIsInstance(queued, db.user.UserPlaylist)
self.assertEqual(queued.icon_name, "edit-redo")
class TestUserPlaylist(unittest.TestCase):
@ -40,6 +45,7 @@ class TestUserPlaylist(unittest.TestCase):
self.assertIsInstance(plist, db.playlist.Playlist)
self.assertEqual(plist._name, "Test Playlist")
self.assertEqual(plist.get_property("name"), "Test Playlist")
self.assertEqual(plist.icon_name, "audio-x-generic")
class TestUserTable(unittest.TestCase):

View File

@ -14,6 +14,7 @@ class TestYear(unittest.TestCase):
self.assertIsInstance(year, db.playlist.Playlist)
self.assertEqual(year.get_property("name"), "2021")
self.assertEqual(year.get_property("year"), 2021)
self.assertEqual(year.get_property("icon-name"), "x-office-calendar")
class TestYearTable(unittest.TestCase):

View File

@ -16,8 +16,8 @@ from . import sql
from . import track
class UserPlaylist(playlist.Playlist):
def __init__(self, row):
playlist.Playlist.__init__(self, row)
def __init__(self, row, icon_name):
playlist.Playlist.__init__(self, row, icon_name)
self._name = row["name"]
@GObject.Property
@ -44,7 +44,17 @@ class UserTable(playlist.Model):
self.find("Queued Tracks")
def do_factory(self, row):
return UserPlaylist(row)
if row["name"] == "Collection":
return UserPlaylist(row, "media-playback-start")
elif row["name"] == "Favorites":
return UserPlaylist(row, "emmental-favorites")
elif row["name"] == "New Tracks":
return UserPlaylist(row, "starred")
elif row["name"] == "Previous":
return UserPlaylist(row, "edit-undo")
elif row["name"] == "Queued Tracks":
return UserPlaylist(row, "edit-redo")
return UserPlaylist(row, "audio-x-generic")
def do_insert(self, plstate, name):
return sql.execute("INSERT INTO playlists (plstateid, name, sort) "

View File

@ -10,7 +10,7 @@ from . import sql
class Year(playlist.Playlist):
def __init__(self, row):
playlist.Playlist.__init__(self, row)
playlist.Playlist.__init__(self, row, "x-office-calendar")
self._year = row["year"]
@GObject.Property