[gnome-music/wip/jfelder/mpris-cleanup: 21/25] mpris: Make player attribute internal



commit 871f6236146286a489aba02d06cda97791c25ed2
Author: Jean Felder <jfelder src gnome org>
Date:   Thu Mar 14 10:54:24 2019 +0100

    mpris: Make player attribute internal

 gnomemusic/mpris.py | 92 +++++++++++++++++++++++++++--------------------------
 1 file changed, 47 insertions(+), 45 deletions(-)
---
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index a01fee7c..4eec6ec9 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -279,14 +279,16 @@ class MPRIS(DBusInterface):
         super().__init__(name, path)
 
         self._app = app
-        self.player = app.props.player
-        self.player.connect(
+        self._player = app.props.player
+        self._player.connect(
             'song-changed', self._on_current_song_changed)
-        self.player.connect('notify::state', self._on_player_state_changed)
-        self.player.connect('notify::repeat-mode', self._on_repeat_mode_changed)
-        self.player.connect('seek-finished', self._on_seek_finished)
-        self.player.connect(
+        self._player.connect('notify::state', self._on_player_state_changed)
+        self._player.connect(
+            'notify::repeat-mode', self._on_repeat_mode_changed)
+        self._player.connect('seek-finished', self._on_seek_finished)
+        self._player.connect(
             'playlist-changed', self._on_player_playlist_changed)
+
         self._playlists = Playlists.get_default()
         self._playlists.connect(
             'playlist-created', self._on_playlists_count_changed)
@@ -308,7 +310,7 @@ class MPRIS(DBusInterface):
 
     @log
     def _get_playback_status(self):
-        state = self.player.props.state
+        state = self._player.props.state
         if state == Playback.STOPPED:
             return 'Stopped'
         elif state == Playback.PAUSED:
@@ -318,9 +320,9 @@ class MPRIS(DBusInterface):
 
     @log
     def _get_loop_status(self):
-        if self.player.props.repeat_mode == RepeatMode.NONE:
+        if self._player.props.repeat_mode == RepeatMode.NONE:
             return 'None'
-        elif self.player.props.repeat_mode == RepeatMode.SONG:
+        elif self._player.props.repeat_mode == RepeatMode.SONG:
             return 'Track'
         else:
             return 'Playlist'
@@ -328,13 +330,13 @@ class MPRIS(DBusInterface):
     @log
     def _get_metadata(self, media=None, index=None):
         song_dbus_path = self._get_song_dbus_path(media, index)
-        if not self.player.props.current_song:
+        if not self._player.props.current_song:
             return {
                 'mpris:trackid': GLib.Variant('o', song_dbus_path)
             }
 
         if not media:
-            media = self.player.props.current_song
+            media = self._player.props.current_song
 
         length = media.get_duration() * 1e6
         user_rating = 1.0 if media.get_favourite() else 0.0
@@ -398,12 +400,12 @@ class MPRIS(DBusInterface):
         :return: a D-Bus id to uniquely identify the song
         :rtype: str
         """
-        if not self.player.props.current_song:
+        if not self._player.props.current_song:
             return "/org/mpris/MediaPlayer2/TrackList/NoTrack"
 
         if not media:
-            media = self.player.props.current_song
-            index = self.player.props.current_song_index
+            media = self._player.props.current_song
+            index = self._player.props.current_song_index
 
         id_hex = media.get_id().encode('ascii').hex()
         path = "/org/gnome/GnomeMusic/TrackList/{}_{}".format(
@@ -415,7 +417,7 @@ class MPRIS(DBusInterface):
         previous_path_list = self._path_list
         self._path_list = []
         self._metadata_list = []
-        for index, song in self.player.get_mpris_playlist():
+        for index, song in self._player.get_mpris_playlist():
             path = self._get_song_dbus_path(song, index)
             metadata = self._get_metadata(song, index)
             self._path_list.append(path)
@@ -476,10 +478,10 @@ class MPRIS(DBusInterface):
         :returns: playlist existence and its structure
         :rtype: tuple
         """
-        if self.player.get_playlist_type() != PlayerPlaylist.Type.PLAYLIST:
+        if self._player.get_playlist_type() != PlayerPlaylist.Type.PLAYLIST:
             return (False, ("/", "", ""))
 
-        playlist = self._get_playlist_from_id(self.player.get_playlist_id())
+        playlist = self._get_playlist_from_id(self._player.get_playlist_id())
         mpris_playlist = self._get_mpris_playlist_from_playlist(playlist)
         return (True, mpris_playlist)
 
@@ -487,7 +489,7 @@ class MPRIS(DBusInterface):
     def _on_current_song_changed(self, player):
         # In repeat song mode, no metadata has changed if the
         # player was already started
-        if self.player.props.repeat_mode == RepeatMode.SONG:
+        if self._player.props.repeat_mode == RepeatMode.SONG:
             self._seeked(0)
             if self._previous_can_play is True:
                 return
@@ -497,12 +499,12 @@ class MPRIS(DBusInterface):
         properties = {}
         properties["Metadata"] = GLib.Variant("a{sv}", self._get_metadata())
 
-        has_next = self.player.props.has_next
+        has_next = self._player.props.has_next
         if has_next != self._previous_can_go_next:
             properties["CanGoNext"] = GLib.Variant("b", has_next)
             self._previous_can_go_next = has_next
 
-        has_previous = self.player.props.has_previous
+        has_previous = self._player.props.has_previous
         if has_previous != self._previous_can_go_previous:
             properties["CanGoPrevious"] = GLib.Variant("b", has_previous)
             self._previous_can_go_previous = has_previous
@@ -534,7 +536,7 @@ class MPRIS(DBusInterface):
 
         properties = {}
 
-        is_shuffled = self.player.props.repeat_mode == RepeatMode.SHUFFLE
+        is_shuffled = self._player.props.repeat_mode == RepeatMode.SHUFFLE
         if is_shuffled != self._previous_is_shuffled:
             properties["Shuffle"] = GLib.Variant("b", is_shuffled)
             self._previous_is_shuffled = is_shuffled
@@ -551,7 +553,7 @@ class MPRIS(DBusInterface):
 
     @log
     def _on_seek_finished(self, player):
-        position_second = self.player.get_position()
+        position_second = self._player.get_position()
         self._seeked(int(position_second * 1e6))
 
     @log
@@ -603,26 +605,26 @@ class MPRIS(DBusInterface):
         self._app.quit()
 
     def _next(self):
-        self.player.next()
+        self._player.next()
 
     def _previous(self):
-        self.player.previous()
+        self._player.previous()
 
     def _pause(self):
-        self.player.pause()
+        self._player.pause()
 
     def _play_pause(self):
-        self.player.play_pause()
+        self._player.play_pause()
 
     def _stop(self):
-        self.player.stop()
+        self._player.stop()
 
     def _play(self):
         """Start or resume playback.
 
         If there is no track to play, this has no effect.
         """
-        self.player.play()
+        self._player.play()
 
     def _seek(self, offset_msecond):
         """Seek forward in the current track.
@@ -632,14 +634,14 @@ class MPRIS(DBusInterface):
         acts like a call to Next.
         :param int offset_msecond: number of microseconds
         """
-        current_position_second = self.player.get_position()
+        current_position_second = self._player.get_position()
         new_position_second = current_position_second + offset_msecond / 1e6
 
-        duration_second = self.player.props.duration
+        duration_second = self._player.props.duration
         if new_position_second <= duration_second:
-            self.player.set_position(new_position_second)
+            self._player.set_position(new_position_second)
         else:
-            self.player.next()
+            self._player.next()
 
     def _set_position(self, track_id, position_msecond):
         """Set the current track position in microseconds.
@@ -651,7 +653,7 @@ class MPRIS(DBusInterface):
         current_track_id = metadata["mpris:trackid"].get_string()
         if track_id != current_track_id:
             return
-        self.player.set_position(position_msecond / 1e6)
+        self._player.set_position(position_msecond / 1e6)
 
     def _open_uri(self, uri):
         pass
@@ -681,7 +683,7 @@ class MPRIS(DBusInterface):
         current_song_index = self._path_list.index(current_song_path)
         goto_index = self._path_list.index(path)
         song_offset = goto_index - current_song_index
-        self.player.play(song_offset=song_offset)
+        self._player.play(song_offset=song_offset)
 
     def _track_list_replaced(self, tracks, current_song):
         parameters = {
@@ -742,20 +744,20 @@ class MPRIS(DBusInterface):
                 ]),
             }
         elif interface_name == MPRIS.MEDIA_PLAYER2_PLAYER_IFACE:
-            position_msecond = int(self.player.get_position() * 1e6)
+            position_msecond = int(self._player.get_position() * 1e6)
             return {
                 'PlaybackStatus': GLib.Variant('s', self._get_playback_status()),
                 'LoopStatus': GLib.Variant('s', self._get_loop_status()),
                 'Rate': GLib.Variant('d', 1.0),
-                'Shuffle': GLib.Variant('b', self.player.props.repeat_mode == RepeatMode.SHUFFLE),
+                'Shuffle': GLib.Variant('b', self._player.props.repeat_mode == RepeatMode.SHUFFLE),
                 'Metadata': GLib.Variant('a{sv}', self._get_metadata()),
                 'Position': GLib.Variant('x', position_msecond),
                 'MinimumRate': GLib.Variant('d', 1.0),
                 'MaximumRate': GLib.Variant('d', 1.0),
-                'CanGoNext': GLib.Variant('b', self.player.props.has_next),
-                'CanGoPrevious': GLib.Variant('b', self.player.props.has_previous),
-                'CanPlay': GLib.Variant('b', self.player.props.current_song is not None),
-                'CanPause': GLib.Variant('b', self.player.props.current_song is not None),
+                'CanGoNext': GLib.Variant('b', self._player.props.has_next),
+                'CanGoPrevious': GLib.Variant('b', self._player.props.has_previous),
+                'CanPlay': GLib.Variant('b', self._player.props.current_song is not None),
+                'CanPause': GLib.Variant('b', self._player.props.current_song is not None),
                 'CanSeek': GLib.Variant('b', True),
                 'CanControl': GLib.Variant('b', True),
             }
@@ -788,16 +790,16 @@ class MPRIS(DBusInterface):
                 pass
             elif property_name == 'LoopStatus':
                 if new_value == 'None':
-                    self.player.props.repeat_mode = RepeatMode.NONE
+                    self._player.props.repeat_mode = RepeatMode.NONE
                 elif new_value == 'Track':
-                    self.player.props.repeat_mode = RepeatMode.SONG
+                    self._player.props.repeat_mode = RepeatMode.SONG
                 elif new_value == 'Playlist':
-                    self.player.props.repeat_mode = RepeatMode.ALL
+                    self._player.props.repeat_mode = RepeatMode.ALL
             elif property_name == 'Shuffle':
                 if new_value:
-                    self.player.props.repeat_mode = RepeatMode.SHUFFLE
+                    self._player.props.repeat_mode = RepeatMode.SHUFFLE
                 else:
-                    self.player.props.repeat_mode = RepeatMode.NONE
+                    self._player.props.repeat_mode = RepeatMode.NONE
         else:
             logger.warning(
                 "MPRIS does not implement {} interface".format(interface_name))


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