[gnome-music/wip/jfelder/mpris-cleanup: 2/17] mpris: Rename MediaPlayer2Service class to MPRIS



commit 1683b2b88ede305937dcb1581342674696eb9f26
Author: Jean Felder <jfelder src gnome org>
Date:   Tue Oct 23 15:32:33 2018 +0200

    mpris: Rename MediaPlayer2Service class to MPRIS
    
    MediaPlayer2Service name is too long and it's not really accurate.

 gnomemusic/application.py |  4 ++--
 gnomemusic/mpris.py       | 39 +++++++++++++++++++--------------------
 2 files changed, 21 insertions(+), 22 deletions(-)
---
diff --git a/gnomemusic/application.py b/gnomemusic/application.py
index 3cb88ed1..6f505399 100644
--- a/gnomemusic/application.py
+++ b/gnomemusic/application.py
@@ -37,7 +37,7 @@ from gi.repository import Gtk, Gio, GLib, Gdk, GObject
 
 from gnomemusic import log
 from gnomemusic.inhibitsuspend import InhibitSuspend
-from gnomemusic.mpris import MediaPlayer2Service
+from gnomemusic.mpris import MPRIS
 from gnomemusic.pauseonsuspend import PauseOnSuspend
 from gnomemusic.player import Player
 from gnomemusic.widgets.aboutdialog import AboutDialog
@@ -137,7 +137,7 @@ class Application(Gtk.Application):
             self._window.set_default_icon_name(self.props.application_id)
             if self.props.application_id == 'org.gnome.MusicDevel':
                 self._window.get_style_context().add_class('devel')
-            MediaPlayer2Service(self)
+            MPRIS(self)
 
         # gtk_window_present does not work on Wayland.
         # Use gtk_present_with_time as a workaround instead.
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index 19b92aec..06818319 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -94,7 +94,7 @@ class DBusInterface:
             invocation.return_value(None)
 
 
-class MediaPlayer2Service(DBusInterface):
+class MPRIS(DBusInterface):
     '''
     <!DOCTYPE node PUBLIC '-//freedesktop//DTD D-BUS Object Introspection 1.0//EN'
     'http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd'>
@@ -234,7 +234,7 @@ class MediaPlayer2Service(DBusInterface):
     MEDIA_PLAYER2_PLAYLISTS_IFACE = 'org.mpris.MediaPlayer2.Playlists'
 
     def __repr__(self):
-        return '<MediaPlayer2Service>'
+        return "<MPRIS>"
 
     def __init__(self, app):
         self.con = Gio.bus_get_sync(Gio.BusType.SESSION, None)
@@ -492,7 +492,7 @@ class MediaPlayer2Service(DBusInterface):
             self._previous_can_play = True
 
         self.PropertiesChanged(
-            MediaPlayer2Service.MEDIA_PLAYER2_PLAYER_IFACE, properties, [])
+            MPRIS.MEDIA_PLAYER2_PLAYER_IFACE, properties, [])
 
     @log
     def _on_player_state_changed(self, klass, args):
@@ -501,7 +501,7 @@ class MediaPlayer2Service(DBusInterface):
             return
 
         self._previous_playback_status = playback_status
-        self.PropertiesChanged(MediaPlayer2Service.MEDIA_PLAYER2_PLAYER_IFACE,
+        self.PropertiesChanged(MPRIS.MEDIA_PLAYER2_PLAYER_IFACE,
                                {
                                    'PlaybackStatus': GLib.Variant('s', playback_status),
                                },
@@ -526,7 +526,7 @@ class MediaPlayer2Service(DBusInterface):
         if not properties:
             return
         self.PropertiesChanged(
-            MediaPlayer2Service.MEDIA_PLAYER2_PLAYER_IFACE, properties, [])
+            MPRIS.MEDIA_PLAYER2_PLAYER_IFACE, properties, [])
 
     @log
     def _on_seek_finished(self, player):
@@ -545,14 +545,14 @@ class MediaPlayer2Service(DBusInterface):
         properties = {
             "ActivePlaylist": GLib.Variant("(b(oss))", mpris_playlist)}
         self.PropertiesChanged(
-            MediaPlayer2Service.MEDIA_PLAYER2_PLAYLISTS_IFACE, properties, [])
+            MPRIS.MEDIA_PLAYER2_PLAYLISTS_IFACE, properties, [])
 
     @log
     def _reload_playlists(self):
         def query_playlists_callback(playlists):
             self._stored_playlists = playlists
             self.PropertiesChanged(
-                MediaPlayer2Service.MEDIA_PLAYER2_PLAYLISTS_IFACE,
+                MPRIS.MEDIA_PLAYER2_PLAYLISTS_IFACE,
                 {'PlaylistCount': GLib.Variant('u', len(playlists)), }, [])
 
         self._query_playlists(query_playlists_callback)
@@ -567,8 +567,7 @@ class MediaPlayer2Service(DBusInterface):
             renamed_playlist)
         self.con.emit_signal(
             None, '/org/mpris/MediaPlayer2',
-            MediaPlayer2Service.MEDIA_PLAYER2_PLAYLISTS_IFACE,
-            'PlaylistChanged',
+            MPRIS.MEDIA_PLAYER2_PLAYLISTS_IFACE, 'PlaylistChanged',
             GLib.Variant.new_tuple(GLib.Variant('(oss)', mpris_playlist)))
 
     @log
@@ -641,7 +640,7 @@ class MediaPlayer2Service(DBusInterface):
         variant = GLib.Variant.new_tuple(GLib.Variant('x', position_msecond))
         self.con.emit_signal(
             None, '/org/mpris/MediaPlayer2',
-            MediaPlayer2Service.MEDIA_PLAYER2_PLAYER_IFACE, 'Seeked', variant)
+            MPRIS.MEDIA_PLAYER2_PLAYER_IFACE, 'Seeked', variant)
 
     def GetTracksMetadata(self, track_paths):
         metadata = []
@@ -666,7 +665,7 @@ class MediaPlayer2Service(DBusInterface):
     def TrackListReplaced(self, tracks, current_song):
         self.con.emit_signal(None,
                              '/org/mpris/MediaPlayer2',
-                             MediaPlayer2Service.MEDIA_PLAYER2_TRACKLIST_IFACE,
+                             MPRIS.MEDIA_PLAYER2_TRACKLIST_IFACE,
                              'TrackListReplaced',
                              GLib.Variant.new_tuple(GLib.Variant('ao', tracks),
                                                     GLib.Variant('o', current_song)))
@@ -674,7 +673,7 @@ class MediaPlayer2Service(DBusInterface):
     def TrackAdded(self, metadata, after_track):
         self.con.emit_signal(None,
                              '/org/mpris/MediaPlayer2',
-                             MediaPlayer2Service.MEDIA_PLAYER2_TRACKLIST_IFACE,
+                             MPRIS.MEDIA_PLAYER2_TRACKLIST_IFACE,
                              'TrackAdded',
                              GLib.Variant.new_tuple(GLib.Variant('a{sv}', metadata),
                                                     GLib.Variant('o', after_track)))
@@ -682,13 +681,13 @@ class MediaPlayer2Service(DBusInterface):
     def TrackRemoved(self, path):
         self.con.emit_signal(
             None, '/org/mpris/MediaPlayer2',
-            MediaPlayer2Service.MEDIA_PLAYER2_TRACKLIST_IFACE, 'TrackRemoved',
+            MPRIS.MEDIA_PLAYER2_TRACKLIST_IFACE, 'TrackRemoved',
             GLib.Variant.new_tuple(GLib.Variant('o', path)))
 
     def TrackMetadataChanged(self, path, metadata):
         self.con.emit_signal(
             None, '/org/mpris/MediaPlayer2',
-            MediaPlayer2Service.MEDIA_PLAYER2_TRACKLIST_IFACE,
+            MPRIS.MEDIA_PLAYER2_TRACKLIST_IFACE,
             'TrackMetadataChanged',
             GLib.Variant.new_tuple(
                 GLib.Variant('o', path), GLib.Variant('a{sv}', metadata)))
@@ -725,7 +724,7 @@ class MediaPlayer2Service(DBusInterface):
         return self.GetAll(interface_name)[property_name]
 
     def GetAll(self, interface_name):
-        if interface_name == MediaPlayer2Service.MEDIA_PLAYER2_IFACE:
+        if interface_name == MPRIS.MEDIA_PLAYER2_IFACE:
             application_id = self.app.props.application_id
             return {
                 'CanQuit': GLib.Variant('b', True),
@@ -745,7 +744,7 @@ class MediaPlayer2Service(DBusInterface):
                     'audio/mpeg'
                 ]),
             }
-        elif interface_name == MediaPlayer2Service.MEDIA_PLAYER2_PLAYER_IFACE:
+        elif interface_name == MPRIS.MEDIA_PLAYER2_PLAYER_IFACE:
             position_msecond = int(self.player.get_position() * 1e6)
             return {
                 'PlaybackStatus': GLib.Variant('s', self._get_playback_status()),
@@ -763,12 +762,12 @@ class MediaPlayer2Service(DBusInterface):
                 'CanSeek': GLib.Variant('b', True),
                 'CanControl': GLib.Variant('b', True),
             }
-        elif interface_name == MediaPlayer2Service.MEDIA_PLAYER2_TRACKLIST_IFACE:
+        elif interface_name == MPRIS.MEDIA_PLAYER2_TRACKLIST_IFACE:
             return {
                 'Tracks': GLib.Variant('ao', self._path_list),
                 'CanEditTracks': GLib.Variant('b', False)
             }
-        elif interface_name == MediaPlayer2Service.MEDIA_PLAYER2_PLAYLISTS_IFACE:
+        elif interface_name == MPRIS.MEDIA_PLAYER2_PLAYLISTS_IFACE:
             playlist_count = len(self._stored_playlists)
             return {
                 'PlaylistCount': GLib.Variant('u', playlist_count),
@@ -784,10 +783,10 @@ class MediaPlayer2Service(DBusInterface):
                 "MPRIS does not implement {} interface".format(interface_name))
 
     def Set(self, interface_name, property_name, new_value):
-        if interface_name == MediaPlayer2Service.MEDIA_PLAYER2_IFACE:
+        if interface_name == MPRIS.MEDIA_PLAYER2_IFACE:
             if property_name == 'Fullscreen':
                 pass
-        elif interface_name == MediaPlayer2Service.MEDIA_PLAYER2_PLAYER_IFACE:
+        elif interface_name == MPRIS.MEDIA_PLAYER2_PLAYER_IFACE:
             if property_name in ['Rate', 'Volume']:
                 pass
             elif property_name == 'LoopStatus':


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