[gnome-music/wip/jfelder/mpris-cleanup: 33/38] mpris: Make player attribute internal



commit f398eeba2f52580b3620ee8967efd05a7d17a43d
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 d55bfec4..d0ee14e2 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -277,14 +277,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.player_toolbar = app.get_active_window()._player_toolbar
         self.player_toolbar.connect(
             'thumbnail-updated', self._on_thumbnail_updated)
@@ -309,7 +311,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:
@@ -319,9 +321,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'
@@ -329,13 +331,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
@@ -383,12 +385,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(
@@ -400,7 +402,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)
@@ -479,10 +481,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)
 
@@ -493,12 +495,12 @@ class MPRIS(DBusInterface):
             properties['Metadata'] = GLib.Variant(
                 'a{sv}', self._get_metadata())
 
-            has_next = self.player.props.has_next
+            has_next = self._player.props.has_next
             if self._previous_can_go_next != has_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 self._previous_can_go_previous != has_previous:
                 properties['CanGoPrevious'] = GLib.Variant('b', has_previous)
                 self._previous_can_go_previous = has_previous
@@ -511,7 +513,7 @@ class MPRIS(DBusInterface):
             self._properties_changed(
                 MPRIS.MEDIA_PLAYER2_PLAYER_IFACE, properties, [])
             self._metadata_timeout = None
-            current_song = self.player.props.current_song
+            current_song = self._player.props.current_song
             self._current_thumbnail = current_song.get_thumbnail()
 
         self._update_songs_list()
@@ -528,7 +530,7 @@ class MPRIS(DBusInterface):
 
     @log
     def _on_thumbnail_updated(self, player, data=None):
-        new_thumbnail = self.player.props.current_song.get_thumbnail()
+        new_thumbnail = self._player.props.current_song.get_thumbnail()
         if (not self._metadata_timeout
                 and new_thumbnail != self._current_thumbnail):
             self._properties_changed(
@@ -556,7 +558,7 @@ class MPRIS(DBusInterface):
     def _on_repeat_mode_changed(self, player, param):
         self._update_songs_list()
         properties = {}
-        is_shuffled = self.player.props.repeat_mode == RepeatMode.SHUFFLE
+        is_shuffled = self._player.props.repeat_mode == RepeatMode.SHUFFLE
         properties['Shuffle'] = GLib.Variant('b', is_shuffled)
 
         loop_status = self._get_loop_status()
@@ -576,7 +578,7 @@ class MPRIS(DBusInterface):
     def _on_player_playlist_changed(self, klass):
         self._update_songs_list()
 
-        if (self.player.get_playlist_type() == PlayerPlaylist.Type.PLAYLIST
+        if (self._player.get_playlist_type() == PlayerPlaylist.Type.PLAYLIST
                 or self._player_previous_type == PlayerPlaylist.Type.PLAYLIST):
             variant = GLib.Variant('(b(oss))', self._get_active_playlist())
             self._properties_changed(
@@ -616,26 +618,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.
@@ -645,14 +647,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.
@@ -664,7 +666,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
@@ -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]