db: Create a MappedPlaylist type
For genre and most user playlists that rely on an extra map table to figure out which tracks they have. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
72f654508c
commit
0688088318
|
@ -20,9 +20,9 @@ from . import playlist
|
|||
from . import track
|
||||
from . import sql
|
||||
|
||||
class Genre(playlist.Playlist):
|
||||
class Genre(playlist.MappedPlaylist):
|
||||
def __init__(self, row):
|
||||
playlist.Playlist.__init__(self, row, "emblem-generic")
|
||||
playlist.MappedPlaylist.__init__(self, row, "emblem-generic", "genre_map")
|
||||
self._name = row["name"]
|
||||
|
||||
def delete(self): Table.delete(self)
|
||||
|
|
|
@ -32,6 +32,15 @@ class Playlist(GObject.GObject):
|
|||
def rowkey(self): return self._rowkey
|
||||
|
||||
|
||||
class MappedPlaylist(Playlist):
|
||||
def __init__(self, row, icon_name, map_table):
|
||||
Playlist.__init__(self, row, icon_name)
|
||||
self._map_table = map_table
|
||||
|
||||
@GObject.Property
|
||||
def map_table(self): return self._map_table
|
||||
|
||||
|
||||
class ParentPlaylist(Playlist):
|
||||
def has_children(self): return True
|
||||
def get_child_table(self): raise NotImplementedError
|
||||
|
|
|
@ -11,10 +11,11 @@ class TestGenre(unittest.TestCase):
|
|||
|
||||
def test_init(self):
|
||||
genre = db.genre.Table.find("Test Genre")
|
||||
self.assertIsInstance(genre, db.playlist.Playlist)
|
||||
self.assertIsInstance(genre, db.playlist.MappedPlaylist)
|
||||
self.assertEqual(genre._name, "Test Genre")
|
||||
self.assertEqual(genre.get_property("name"), "Test Genre")
|
||||
self.assertEqual(genre.get_property("icon-name"), "emblem-generic")
|
||||
self.assertEqual(genre.get_property("map-table"), "genre_map")
|
||||
|
||||
def test_delete(self):
|
||||
genre = db.genre.Table.find("Test Genre")
|
||||
|
|
|
@ -36,6 +36,15 @@ class TestPlaylist(unittest.TestCase):
|
|||
plist.delete()
|
||||
|
||||
|
||||
class TestMappedPlaylist(unittest.TestCase):
|
||||
def test_init(self):
|
||||
mapped = playlist.MappedPlaylist(TestRow(), "missing-icon", "test_map")
|
||||
|
||||
self.assertIsInstance(mapped, playlist.Playlist)
|
||||
self.assertEqual(mapped._map_table, "test_map")
|
||||
self.assertEqual(mapped.get_property("map-table"), "test_map")
|
||||
|
||||
|
||||
class TestParentPlaylist(unittest.TestCase):
|
||||
def test_init(self):
|
||||
parent = playlist.ParentPlaylist(TestRow(), "missing-icon")
|
||||
|
|
|
@ -7,7 +7,9 @@ from gi.repository import GObject
|
|||
class TestCollection(unittest.TestCase):
|
||||
def test_init(self):
|
||||
collection = db.user.Table.find("Collection")
|
||||
self.assertIsInstance(collection, db.user.UserPlaylist)
|
||||
self.assertIsInstance(collection, db.playlist.Playlist)
|
||||
self.assertIsInstance(collection, db.user.Collection)
|
||||
self.assertEqual(collection.name, "Collection")
|
||||
self.assertEqual(collection.icon_name, "media-playback-start")
|
||||
self.assertTrue(collection.plist_state.loop)
|
||||
|
||||
|
@ -15,24 +17,33 @@ class TestCollection(unittest.TestCase):
|
|||
class TestFavorites(unittest.TestCase):
|
||||
def test_init(self):
|
||||
favorites = db.user.Table.find("Favorites")
|
||||
self.assertIsInstance(favorites, db.playlist.MappedPlaylist)
|
||||
self.assertIsInstance(favorites, db.user.UserPlaylist)
|
||||
self.assertEqual(favorites.name, "Favorites")
|
||||
self.assertEqual(favorites.icon_name, "emmental-favorites")
|
||||
self.assertEqual(favorites.map_table, "playlist_map")
|
||||
self.assertFalse(favorites.plist_state.loop)
|
||||
|
||||
|
||||
class TestNewTracks(unittest.TestCase):
|
||||
def test_init(self):
|
||||
new = db.user.Table.find("New Tracks")
|
||||
self.assertIsInstance(new, db.playlist.MappedPlaylist)
|
||||
self.assertIsInstance(new, db.user.UserPlaylist)
|
||||
self.assertEqual(new.name, "New Tracks")
|
||||
self.assertEqual(new.icon_name, "starred")
|
||||
self.assertEqual(new.map_table, "temp_playlist_map")
|
||||
self.assertFalse(new.plist_state.loop)
|
||||
|
||||
|
||||
class TestPrevious(unittest.TestCase):
|
||||
def test_init(self):
|
||||
previous = db.user.Table.find("Previous")
|
||||
self.assertIsInstance(previous, db.playlist.MappedPlaylist)
|
||||
self.assertIsInstance(previous, db.user.UserPlaylist)
|
||||
self.assertEqual(previous.name, "Previous")
|
||||
self.assertEqual(previous.icon_name, "edit-undo")
|
||||
self.assertEqual(previous.map_table, "temp_playlist_map")
|
||||
self.assertEqual(previous.plist_state.sort, [ "temp_playlist_map.rowid DESC" ])
|
||||
self.assertFalse(previous.plist_state.loop)
|
||||
|
||||
|
@ -40,8 +51,11 @@ class TestPrevious(unittest.TestCase):
|
|||
class TestQueuedTracks(unittest.TestCase):
|
||||
def test_init(self):
|
||||
queued = db.user.Table.find("Queued Tracks")
|
||||
self.assertIsInstance(queued, db.playlist.MappedPlaylist)
|
||||
self.assertIsInstance(queued, db.user.UserPlaylist)
|
||||
self.assertEqual(queued.name, "Queued Tracks")
|
||||
self.assertEqual(queued.icon_name, "edit-redo")
|
||||
self.assertEqual(queued.map_table, "playlist_map")
|
||||
self.assertEqual(queued.plist_state.sort, [ "playlist_map.rowid ASC" ])
|
||||
self.assertFalse(queued.plist_state.loop)
|
||||
|
||||
|
@ -49,10 +63,11 @@ class TestQueuedTracks(unittest.TestCase):
|
|||
class TestUserPlaylist(unittest.TestCase):
|
||||
def test_init(self):
|
||||
plist = db.user.Table.find("Test Playlist")
|
||||
self.assertIsInstance(plist, db.playlist.Playlist)
|
||||
self.assertEqual(plist._name, "Test Playlist")
|
||||
self.assertEqual(plist.get_property("name"), "Test Playlist")
|
||||
self.assertIsInstance(plist, db.playlist.MappedPlaylist)
|
||||
self.assertIsInstance(plist, db.user.UserPlaylist)
|
||||
self.assertEqual(plist.name, "Test Playlist")
|
||||
self.assertEqual(plist.icon_name, "audio-x-generic")
|
||||
self.assertEqual(plist.map_table, "playlist_map")
|
||||
self.assertFalse(plist.plist_state.loop)
|
||||
|
||||
def test_delete(self):
|
||||
|
|
28
db/user.py
28
db/user.py
|
@ -16,9 +16,19 @@ from . import sql
|
|||
from . import state
|
||||
from . import track
|
||||
|
||||
class UserPlaylist(playlist.Playlist):
|
||||
def __init__(self, row, icon_name):
|
||||
playlist.Playlist.__init__(self, row, icon_name)
|
||||
|
||||
class Collection(playlist.Playlist):
|
||||
def __init__(self, row):
|
||||
playlist.Playlist.__init__(self, row, "media-playback-start")
|
||||
self._name = row["name"]
|
||||
|
||||
@GObject.Property
|
||||
def name(self): return self._name
|
||||
|
||||
|
||||
class UserPlaylist(playlist.MappedPlaylist):
|
||||
def __init__(self, row, icon_name, map_table):
|
||||
playlist.MappedPlaylist.__init__(self, row, icon_name, map_table)
|
||||
self._name = row["name"]
|
||||
|
||||
def delete(self): Table.delete(self)
|
||||
|
@ -48,16 +58,16 @@ class UserTable(playlist.Model):
|
|||
|
||||
def do_factory(self, row):
|
||||
if row["name"] == "Collection":
|
||||
return UserPlaylist(row, "media-playback-start")
|
||||
return Collection(row)
|
||||
elif row["name"] == "Favorites":
|
||||
return UserPlaylist(row, "emmental-favorites")
|
||||
return UserPlaylist(row, "emmental-favorites", "playlist_map")
|
||||
elif row["name"] == "New Tracks":
|
||||
return UserPlaylist(row, "starred")
|
||||
return UserPlaylist(row, "starred", "temp_playlist_map")
|
||||
elif row["name"] == "Previous":
|
||||
return UserPlaylist(row, "edit-undo")
|
||||
return UserPlaylist(row, "edit-undo", "temp_playlist_map")
|
||||
elif row["name"] == "Queued Tracks":
|
||||
return UserPlaylist(row, "edit-redo")
|
||||
return UserPlaylist(row, "audio-x-generic")
|
||||
return UserPlaylist(row, "edit-redo", "playlist_map")
|
||||
return UserPlaylist(row, "audio-x-generic", "playlist_map")
|
||||
|
||||
def do_insert(self, plstate, name):
|
||||
return sql.execute("INSERT INTO playlists (plstateid, name, sort) "
|
||||
|
|
Loading…
Reference in New Issue