db: Give Playlists a passthrough for PlaylistState properties
This lets us handle changes easier, since we'll catch them as they happen. This lets us emit the "refreshed" signal when sorting changes, for example. Implements: Issue #32 (Passthrough PlaylistState properties) Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
edb6857292
commit
14724aa81e
|
@ -74,6 +74,32 @@ class Playlist(GObject.GObject):
|
|||
@GObject.Property
|
||||
def plist_state(self): return self._plstate
|
||||
|
||||
@GObject.Property
|
||||
def current(self): return self._plstate.get_property("current")
|
||||
|
||||
@current.setter
|
||||
def current(self, newval): self._plstate.set_property("current", newval)
|
||||
|
||||
@GObject.Property(type=bool,default=False)
|
||||
def loop(self): return self._plstate.get_property("loop")
|
||||
|
||||
@loop.setter
|
||||
def loop(self, newval): self._plstate.set_property("loop", newval)
|
||||
|
||||
@GObject.Property(type=bool,default=False)
|
||||
def random(self): return self._plstate.get_property("random")
|
||||
|
||||
@random.setter
|
||||
def random(self, newval): self._plstate.set_property("random", newval)
|
||||
|
||||
@GObject.Property(type=GObject.TYPE_PYOBJECT)
|
||||
def sort(self): return self._plstate.get_property("sort")
|
||||
|
||||
@sort.setter
|
||||
def sort(self, newval):
|
||||
self._plstate.set_property("sort", newval)
|
||||
self.refresh()
|
||||
|
||||
@GObject.Property
|
||||
def rowid(self): return self._rowid
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@ class TestRow:
|
|||
return 10
|
||||
|
||||
class TestPlaylist(unittest.TestCase):
|
||||
def on_refresh(self, plist): self.refreshed = True
|
||||
|
||||
def test_init(self):
|
||||
db.reset()
|
||||
plist = playlist.Playlist(TestRow(), "missing-icon")
|
||||
|
@ -35,6 +37,36 @@ class TestPlaylist(unittest.TestCase):
|
|||
with self.assertRaises(NotImplementedError):
|
||||
plist.delete()
|
||||
|
||||
def test_passthrough_current(self):
|
||||
plist = db.user.Table.find("Test Playlist")
|
||||
self.assertEqual(plist.get_property("current"), -1)
|
||||
plist.set_property("current", 5)
|
||||
self.assertEqual(plist.get_property("current"), 5)
|
||||
self.assertEqual(plist.plist_state.get_property("current"), 5)
|
||||
|
||||
def test_passthrough_loop(self):
|
||||
plist = db.user.Table.find("Test Playlist")
|
||||
self.assertFalse(plist.get_property("loop"))
|
||||
plist.set_property("loop", True)
|
||||
self.assertTrue(plist.get_property("loop"))
|
||||
self.assertTrue(plist.plist_state.get_property("loop"))
|
||||
|
||||
def test_passthrough_random(self):
|
||||
plist = db.user.Table.find("Test Playlist")
|
||||
self.assertFalse(plist.get_property("random"))
|
||||
plist.set_property("random", True)
|
||||
self.assertTrue(plist.get_property("random"))
|
||||
self.assertTrue(plist.plist_state.get_property("random"))
|
||||
|
||||
def test_passthrough_sort(self):
|
||||
plist = db.user.Table.find("Test Playlist")
|
||||
plist.connect("refreshed", self.on_refresh)
|
||||
self.assertEqual(plist.get_property("sort"), plist.plist_state.sort)
|
||||
plist.set_property("sort", [ "rowid ASC" ])
|
||||
self.assertEqual(plist.get_property("sort"), [ "rowid ASC" ])
|
||||
self.assertEqual(plist.plist_state.get_property("sort"), [ "rowid ASC" ])
|
||||
self.assertTrue(self.refreshed)
|
||||
|
||||
|
||||
class TestMappedPlaylist(unittest.TestCase):
|
||||
def test_init(self):
|
||||
|
|
Loading…
Reference in New Issue