Implement getting of LoopStatus

This commit is contained in:
Stein Magnus Jodal 2011-06-05 02:21:36 +02:00
parent f3cfa22c75
commit 7f20cf4e83
2 changed files with 31 additions and 2 deletions

View File

@ -114,8 +114,8 @@ class MprisObject(dbus.service.Object):
def _get_player_iface_properties(self):
return {
'PlaybackStatus': (self.get_PlaybackStatus, None),
# TODO Get/set loop status
'LoopStatus': ('None', None),
# TODO Set loop status
'LoopStatus': (self.get_LoopStatus, None),
'Rate': (1.0, None),
# TODO Get/set backend.playback.random
'Shuffle': (False, None),
@ -240,6 +240,17 @@ class MprisObject(dbus.service.Object):
elif state == PlaybackController.STOPPED:
return 'Stopped'
def get_LoopStatus(self):
single = self.backend.playback.single.get()
repeat = self.backend.playback.repeat.get()
if not repeat:
return 'None'
else:
if single:
return 'Track'
else:
return 'Playlist'
@dbus.service.method(dbus_interface=PLAYER_IFACE)
def Next(self):
logger.debug(u'%s.Next called', PLAYER_IFACE)

View File

@ -30,6 +30,24 @@ class PlayerInterfaceTest(unittest.TestCase):
result = self.mpris_object.Get(mpris.PLAYER_IFACE, 'PlaybackStatus')
self.assertEqual('Stopped', result)
def test_loop_status_is_none_when_not_looping(self):
self.backend.playback.repeat.get.return_value = False
self.backend.playback.single.get.return_value = False
result = self.mpris_object.Get(mpris.PLAYER_IFACE, 'LoopStatus')
self.assertEqual('None', result)
def test_loop_status_is_track_when_looping_a_single_track(self):
self.backend.playback.repeat.get.return_value = True
self.backend.playback.single.get.return_value = True
result = self.mpris_object.Get(mpris.PLAYER_IFACE, 'LoopStatus')
self.assertEqual('Track', result)
def test_loop_status_is_playlist_when_looping_the_current_playlist(self):
self.backend.playback.repeat.get.return_value = True
self.backend.playback.single.get.return_value = False
result = self.mpris_object.Get(mpris.PLAYER_IFACE, 'LoopStatus')
self.assertEqual('Playlist', result)
def test_next_should_call_next_on_backend(self):
self.mpris_object.Next()
self.assert_(self.backend.playback.next.called)