[gnome-music/wip/jfelder/mpris-cleanup: 10/17] mpris: Move dbus connection logic to DBusInterface



commit c0bea5cffd8574cdaa1f1dc530fccd51fd38c3aa
Author: Jean Felder <jfelder src gnome org>
Date:   Tue Oct 16 23:23:50 2018 +0200

    mpris: Move dbus connection logic to DBusInterface

 gnomemusic/mpris.py | 41 +++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 20 deletions(-)
---
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index 1d730982..2e310eee 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -46,7 +46,12 @@ def camelcase_to_snake_case(name):
 
 class DBusInterface:
 
-    def __init__(self, con, path):
+    def __init__(self, name, path):
+        self._con = Gio.bus_get_sync(Gio.BusType.SESSION, None)
+        Gio.bus_own_name_on_connection(
+            self._con, name, Gio.BusNameOwnerFlags.NONE, None, None)
+        self._path = path
+
         method_outargs = {}
         method_inargs = {}
         for interface in Gio.DBusNodeInfo.new_for_xml(self.__doc__).interfaces:
@@ -57,8 +62,8 @@ class DBusInterface:
                 method_inargs[method.name] = tuple(
                     arg.signature for arg in method.in_args)
 
-            con.register_object(
-                object_path=path, interface_info=interface,
+            self._con.register_object(
+                object_path=self._path, interface_info=interface,
                 method_call_closure=self.on_method_call)
 
         self._method_inargs = method_inargs
@@ -250,13 +255,9 @@ class MPRIS(DBusInterface):
         return "<MPRIS>"
 
     def __init__(self, app):
-        self.con = Gio.bus_get_sync(Gio.BusType.SESSION, None)
-        Gio.bus_own_name_on_connection(self.con,
-                                       'org.mpris.MediaPlayer2.GnomeMusic',
-                                       Gio.BusNameOwnerFlags.NONE,
-                                       None,
-                                       None)
-        super().__init__(self.con, '/org/mpris/MediaPlayer2')
+        name = 'org.mpris.MediaPlayer2.GnomeMusic'
+        path = '/org/mpris/MediaPlayer2'
+        super().__init__(name, path)
 
         self.app = app
         self.player = app.props.player
@@ -403,7 +404,7 @@ class MPRIS(DBusInterface):
                 or previous_path_list[0] != self._path_list[0]
                 or previous_path_list[-1] != self._path_list[-1]):
             current_song_path = self._get_song_dbus_path()
-            self.TrackListReplaced(self._path_list, current_song_path)
+            self._track_list_replaced(self._path_list, current_song_path)
 
     @log
     def _get_playlist_dbus_path(self, playlist):
@@ -574,7 +575,7 @@ class MPRIS(DBusInterface):
     def _on_playlist_renamed(self, playlists, renamed_playlist):
         mpris_playlist = self._get_mpris_playlist_from_playlist(
             renamed_playlist)
-        self.con.emit_signal(
+        self._con.emit_signal(
             None, '/org/mpris/MediaPlayer2',
             MPRIS.MEDIA_PLAYER2_PLAYLISTS_IFACE, 'PlaylistChanged',
             GLib.Variant.new_tuple(GLib.Variant('(oss)', mpris_playlist)))
@@ -649,7 +650,7 @@ class MPRIS(DBusInterface):
         :param int position_msecond: new position in microseconds.
         """
         variant = GLib.Variant.new_tuple(GLib.Variant('x', position_msecond))
-        self.con.emit_signal(
+        self._con.emit_signal(
             None, '/org/mpris/MediaPlayer2',
             MPRIS.MEDIA_PLAYER2_PLAYER_IFACE, 'Seeked', variant)
 
@@ -796,13 +797,13 @@ class MPRIS(DBusInterface):
 
     def _properties_changed(self, interface_name, changed_properties,
                             invalidated_properties):
-        self.con.emit_signal(None,
-                             '/org/mpris/MediaPlayer2',
-                             'org.freedesktop.DBus.Properties',
-                             'PropertiesChanged',
-                             GLib.Variant.new_tuple(GLib.Variant('s', interface_name),
-                                                    GLib.Variant('a{sv}', changed_properties),
-                                                    GLib.Variant('as', invalidated_properties)))
+        self._con.emit_signal(
+            None, '/org/mpris/MediaPlayer2', 'org.freedesktop.DBus.Properties',
+            'PropertiesChanged',
+            GLib.Variant.new_tuple(
+                GLib.Variant('s', interface_name),
+                GLib.Variant('a{sv}', changed_properties),
+                GLib.Variant('as', invalidated_properties)))
 
     def _introspect(self):
         return self.__doc__


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