[kupfer: 27/38] rhythmbox: Adapt "Play" action to multiple dispatch



commit 78777ad2d68f13e301a2c1d1a0220f93626b2a50
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Sat Jan 16 01:53:09 2010 +0100

    rhythmbox: Adapt "Play" action to multiple dispatch
    
    Adapt the PlayTracks action to multiple selection ("comma trick") to
    play all songs in order (play the first, enqueue the rest).
    
    The amazing thing is that now that it is possible, using the play
    action on all my 3000 songs in the library does work, only takes 3
    seconds and adds all songs to the play queue.

 kupfer/plugin/rhythmbox.py |   36 +++++++++++++++++++++++++++---------
 1 files changed, 27 insertions(+), 9 deletions(-)
---
diff --git a/kupfer/plugin/rhythmbox.py b/kupfer/plugin/rhythmbox.py
index 6d961ba..61e7503 100644
--- a/kupfer/plugin/rhythmbox.py
+++ b/kupfer/plugin/rhythmbox.py
@@ -114,16 +114,34 @@ class PlayTracks (Action):
 	rank_adjust = 5
 	def __init__(self):
 		Action.__init__(self, _("Play"))
+
 	def activate(self, leaf):
-		if isinstance(leaf, SongLeaf):
-			play_song(leaf.object)
-		if isinstance(leaf, TrackCollection):
-			songs = list(leaf.object)
-			if not songs:
-				return
-			# play first, enqueue others
-			play_song(songs[0])
-			enqueue_songs(songs[1:], clear_queue=True)
+		self.activate_multiple((leaf, ))
+
+	def activate_multiple(self, objects):
+		# for multiple dispatch, play the first and enqueue the rest
+		to_enqueue = []
+		objects = iter(objects)
+		# take only the first object in the first loop
+		# notice the break
+		for leaf in objects:
+			if isinstance(leaf, SongLeaf):
+				play_song(leaf.object)
+			if isinstance(leaf, TrackCollection):
+				songs = list(leaf.object)
+				if not songs:
+					continue
+				play_song(songs[0])
+				to_enqueue.extend(songs[1:])
+			break
+		for leaf in objects:
+			if isinstance(leaf, SongLeaf):
+				to_enqueue.append(leaf.object)
+			if isinstance(leaf, TrackCollection):
+				songs = list(leaf.object)
+				to_enqueue.extend(songs)
+		if to_enqueue:
+			enqueue_songs(to_enqueue, clear_queue=True)
 
 	def get_description(self):
 		return _("Play tracks in Rhythmbox")



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]