[gnome-music/wip/jfelder/mpris-cleanup: 6/12] mpris: Handle signals emissions internally
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/mpris-cleanup: 6/12] mpris: Handle signals emissions internally
- Date: Fri, 7 Jun 2019 14:00:57 +0000 (UTC)
commit 09997d451c984e20af6064f4bf604851db7ef8e4
Author: Jean Felder <jfelder src gnome org>
Date: Tue Oct 16 22:20:10 2018 +0200
mpris: Handle signals emissions internally
gnomemusic/mpris.py | 50 ++++++++++++++++++++++++++++++--------------------
1 file changed, 30 insertions(+), 20 deletions(-)
---
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index b9f6915b..26b61e67 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -54,6 +54,7 @@ class DBusInterface:
method_outargs = {}
method_inargs = {}
+ signals = {}
for interface in Gio.DBusNodeInfo.new_for_xml(self.__doc__).interfaces:
for method in interface.methods:
@@ -62,12 +63,18 @@ class DBusInterface:
method_inargs[method.name] = tuple(
arg.signature for arg in method.in_args)
+ for signal in interface.signals:
+ args = {arg.name: arg.signature for arg in signal.args}
+ signals[signal.name] = {
+ 'interface': interface.name, 'args': args}
+
self._con.register_object(
object_path=self._path, interface_info=interface,
method_call_closure=self.on_method_call)
self._method_inargs = method_inargs
self._method_outargs = method_outargs
+ self._signals = signals
def on_method_call(
self, connection, sender, object_path, interface_name, method_name,
@@ -105,6 +112,17 @@ class DBusInterface:
else:
invocation.return_value(None)
+ def _dbus_emit_signal(self, signal_name, values):
+ signal = self._signals[signal_name]
+ parameters = []
+ for arg_name, arg_signature in signal['args'].items():
+ value = values[arg_name]
+ parameters.append(GLib.Variant(arg_signature, value))
+
+ variant = GLib.Variant.new_tuple(*parameters)
+ self._con.emit_signal(
+ None, self._path, signal['interface'], signal_name, variant)
+
class MPRIS(DBusInterface):
"""
@@ -567,10 +585,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(
- None, '/org/mpris/MediaPlayer2',
- MPRIS.MEDIA_PLAYER2_PLAYLISTS_IFACE, 'PlaylistChanged',
- GLib.Variant.new_tuple(GLib.Variant('(oss)', mpris_playlist)))
+ self._dbus_emit_signal('PlaylistChanged', {'Playlist': mpris_playlist})
@log
def _on_grilo_ready(self, grilo):
@@ -641,10 +656,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(
- None, '/org/mpris/MediaPlayer2',
- MPRIS.MEDIA_PLAYER2_PLAYER_IFACE, 'Seeked', variant)
+ self._dbus_emit_signal("Seeked", {"Position": position_msecond})
def _get_tracks_metadata(self, track_paths):
metadata = []
@@ -667,11 +679,10 @@ class MPRIS(DBusInterface):
self.player.play(song_offset=song_offset)
def _track_list_replaced(self, tracks, current_song):
- self._con.emit_signal(
- None, '/org/mpris/MediaPlayer2',
- MPRIS.MEDIA_PLAYER2_TRACKLIST_IFACE, 'TrackListReplaced',
- GLib.Variant.new_tuple(
- GLib.Variant('ao', tracks), GLib.Variant('o', current_song)))
+ parameters = {
+ "Tracks": self._path_list,
+ "CurrentTrack": self._get_song_dbus_path()}
+ self._dbus_emit_signal("TrackListReplaced", parameters)
def _activate_playlist(self, playlist_path):
playlist_id = self._get_playlist_from_dbus_path(playlist_path).get_id()
@@ -788,13 +799,12 @@ 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)))
+ parameters = {
+ 'interface_name': interface_name,
+ 'changed_properties': changed_properties,
+ 'invalidated_properties': invalidated_properties
+ }
+ self._dbus_emit_signal('PropertiesChanged', parameters)
def _introspect(self):
return self.__doc__
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]