curds: Send the "new-playlist" notification after playlists are alloc-ed
Rather than doing this as part of the playlist constructor. This ensures that the UI is notified AFTER the playlist has been appended to the PlaylistManager to prevent race conditions. Additionally, I send the sorted index of the playlist and an indicator if this is the first playlist added as part of the notification to help make the UI's job easier. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
791e126ace
commit
ad9828c494
|
@ -32,8 +32,13 @@ class PlaylistManagerBase(list):
|
|||
if plist.name == name: return plist
|
||||
if allocate == True and self.alloc != None:
|
||||
plist = self.alloc(name)
|
||||
self.append(plist)
|
||||
self.sort()
|
||||
index = len(self)
|
||||
for i, p in enumerate(self):
|
||||
if plist < p:
|
||||
index = i
|
||||
break
|
||||
self.insert(index, plist)
|
||||
notify.notify("new-playlist", plist, index, len(self) == 1)
|
||||
return plist
|
||||
return None
|
||||
|
||||
|
|
|
@ -12,8 +12,6 @@ class Playlist():
|
|||
self.loop = False
|
||||
self.random = False
|
||||
|
||||
notify.notify("new-playlist", self)
|
||||
|
||||
def __getitem__(self, i):
|
||||
return self.list[i]
|
||||
|
||||
|
|
|
@ -25,14 +25,18 @@ class TestPlaylistManager(unittest.TestCase):
|
|||
except:
|
||||
self.playman = manager.PlaylistManager()
|
||||
self.cb_plist = None
|
||||
self.cb_index = None
|
||||
self.cb_first = None
|
||||
|
||||
def tearDown(self):
|
||||
notify.cancel("new-track", self.playman.lookup("Collection").add)
|
||||
notify.cancel("new-playlist", self.on_new_playlist)
|
||||
library.stop()
|
||||
|
||||
def on_new_playlist(self, plist):
|
||||
def on_new_playlist(self, plist, index, first):
|
||||
self.cb_plist = plist
|
||||
self.cb_index = index
|
||||
self.cb_first = first
|
||||
|
||||
def test_manager_init(self):
|
||||
self.assertIsInstance(self.playman, manager.PlaylistManager)
|
||||
|
@ -75,6 +79,9 @@ class TestPlaylistManager(unittest.TestCase):
|
|||
def test_manager_library(self):
|
||||
plist = self.playman.lookup("Library").lookup(test_library + "/", allocate=True)
|
||||
self.assertEqual(self.cb_plist, plist)
|
||||
self.assertEqual(self.cb_index, 0)
|
||||
self.assertTrue(self.cb_first)
|
||||
|
||||
self.assertEqual(str(self.playman.lookup("Library")), "<big>Library</big>")
|
||||
self.assertEqual(self.playman.lookup("Library").name, "Library")
|
||||
self.assertEqual(self.playman.lookup("Library").icon, "folder-music")
|
||||
|
@ -88,6 +95,9 @@ class TestPlaylistManager(unittest.TestCase):
|
|||
self.assertIsNone(self.playman.lookup("Library").lookup(test_album))
|
||||
alist = self.playman.lookup("Library").lookup(test_album, allocate=True)
|
||||
self.assertEqual(self.cb_plist, alist)
|
||||
self.assertEqual(self.cb_index, 0)
|
||||
self.assertFalse(self.cb_first)
|
||||
|
||||
self.assertIsInstance(alist, library.LibraryPlaylist)
|
||||
self.assertNotEqual(id(plist), id(alist))
|
||||
self.assertIn(alist, self.playman.lookup("Library"))
|
||||
|
|
|
@ -106,7 +106,7 @@ class ManagerModel(GObject.GObject, Gtk.TreeModel):
|
|||
if iter:
|
||||
self.row_changed(self.get_path(iter), iter)
|
||||
|
||||
def on_new_playlist(self, plist):
|
||||
def on_new_playlist(self, plist, index, first):
|
||||
iter = self.playlist_iter(plist)
|
||||
if iter != None:
|
||||
self.row_inserted(self.get_path(iter), iter)
|
||||
|
|
Loading…
Reference in New Issue