curds: Pass track index to the add-track notification
This eases up some of the work on the UI side, since we don't need to spend time trying to figure out where the track is in the playlist. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
332cd89fee
commit
35e5cd1095
|
@ -38,7 +38,7 @@ class Playlist():
|
|||
def add(self, track):
|
||||
if track is not None and track not in self:
|
||||
self.list.append(track)
|
||||
notify.Notify.notify("add-track", self, track)
|
||||
notify.Notify.notify("add-track", self, track, self.list.index(track))
|
||||
|
||||
def next(self):
|
||||
max = len(self) - 1
|
||||
|
|
|
@ -10,7 +10,7 @@ class PreviousPlaylist(playlist.Playlist):
|
|||
if track is not None and track not in self:
|
||||
self.list.insert(0, track)
|
||||
self.current = 0
|
||||
notify.Notify.notify("add-track", self, track)
|
||||
notify.Notify.notify("add-track", self, track, 0)
|
||||
|
||||
def set_loop(self, loop):
|
||||
return playlist.Playlist.set_loop(self, False)
|
||||
|
|
|
@ -14,6 +14,7 @@ class TestPlaylist(unittest.TestCase):
|
|||
notify.Notify.clear()
|
||||
self.cb_plist = None
|
||||
self.cb_track = None
|
||||
self.cb_index = None
|
||||
|
||||
def test_playlist_init(self):
|
||||
plist = playlist.Playlist("Test Playlist")
|
||||
|
@ -74,9 +75,10 @@ class TestPlaylist(unittest.TestCase):
|
|||
track.length = 172800
|
||||
self.assertEqual(plist.runtime(), "2 days")
|
||||
|
||||
def on_add(self, plist, track):
|
||||
def on_add(self, plist, track, index):
|
||||
self.cb_plist = plist
|
||||
self.cb_track = track
|
||||
self.cb_index = index
|
||||
|
||||
def test_playlist_notifications(self):
|
||||
path = os.path.join(test_library, "Test Artist 01", "Test Album 1")
|
||||
|
@ -88,9 +90,11 @@ class TestPlaylist(unittest.TestCase):
|
|||
plist.add(track)
|
||||
self.assertEqual(self.cb_plist, plist)
|
||||
self.assertEqual(self.cb_track, track)
|
||||
self.assertEqual(self.cb_index, 0)
|
||||
plist.add(None)
|
||||
self.assertEqual(self.cb_plist, plist)
|
||||
self.assertEqual(self.cb_track, track)
|
||||
self.assertEqual(self.cb_index, 0)
|
||||
|
||||
def test_playlist_next(self):
|
||||
path = os.path.join(test_library, "Test Artist 01", "Test Album 1")
|
||||
|
|
|
@ -12,14 +12,16 @@ class TestPreviousPlaylist(unittest.TestCase):
|
|||
def setUp(self):
|
||||
self.cb_plist = None
|
||||
self.cb_track = None
|
||||
self.cb_index = 0
|
||||
|
||||
def tearDown(self):
|
||||
notify.Notify.notifications.clear()
|
||||
|
||||
def on_add_track(self, plist, track):
|
||||
def on_add_track(self, plist, track, index):
|
||||
if isinstance(plist, previous.PreviousPlaylist):
|
||||
self.cb_plist = plist
|
||||
self.cb_track = track
|
||||
self.cb_index = index
|
||||
|
||||
def test_previous_playlist(self):
|
||||
plist = previous.PreviousPlaylist()
|
||||
|
@ -48,12 +50,14 @@ class TestPreviousPlaylist(unittest.TestCase):
|
|||
plist.add(track1)
|
||||
self.assertEqual(self.cb_plist, plist)
|
||||
self.assertEqual(self.cb_track, track1)
|
||||
self.assertEqual(self.cb_index, 0)
|
||||
self.assertEqual(plist.current, 0)
|
||||
self.assertEqual(plist.next(), None)
|
||||
|
||||
plist.add(track2)
|
||||
self.assertEqual(self.cb_plist, plist)
|
||||
self.assertEqual(self.cb_track, track2)
|
||||
self.assertEqual(self.cb_index, 0)
|
||||
self.assertEqual(plist.current, 0)
|
||||
|
||||
self.assertEqual(len(plist), 2)
|
||||
|
|
|
@ -100,7 +100,7 @@ class ManagerModel(GObject.GObject, Gtk.TreeModel):
|
|||
return plist
|
||||
return None
|
||||
|
||||
def on_add_track(self, plist, track):
|
||||
def on_add_track(self, plist, track, index):
|
||||
iter = self.find_playlist(plist)
|
||||
if iter:
|
||||
self.row_changed(self.get_path(iter), iter)
|
||||
|
|
|
@ -58,11 +58,10 @@ class PlaylistModel(GObject.GObject, Gtk.TreeModel):
|
|||
return (False, None)
|
||||
return (True, iter)
|
||||
|
||||
def on_add_track(self, plist, track):
|
||||
def on_add_track(self, plist, track, index):
|
||||
if plist == self.playlist:
|
||||
path = Gtk.TreePath.new_from_indices([0])
|
||||
iter = self.get_iter(path)
|
||||
self.row_inserted(path, iter)
|
||||
path = Gtk.TreePath.new_from_indices([ index ])
|
||||
self.row_inserted(path, self.get_iter(path))
|
||||
|
||||
def on_random_toggled(self, *args):
|
||||
active = RandomButton.get_active()
|
||||
|
|
Loading…
Reference in New Issue