[gnome-music/gbsneto/untangle-player-window-mpris: 9/9] window: Move Player to Application



commit 9f01b0f638771a44f8a3d931802524a8ec86d011
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Apr 10 12:32:46 2019 -0300

    window: Move Player to Application
    
    Architecturally-wise, the music player object is not
    tied to the active window in any form. So holding it
    in Window is an anti-pattern - Window is not the right
    place for Player to be.
    
    Move Player to Application, and make it a property so
    that it can be accessed as application.props.player.
    It is a readable property, since there is no reason
    to change it.

 gnomemusic/application.py | 14 +++++++++++++-
 gnomemusic/mpris.py       |  2 +-
 gnomemusic/window.py      |  4 ++--
 3 files changed, 16 insertions(+), 4 deletions(-)
---
diff --git a/gnomemusic/application.py b/gnomemusic/application.py
index 9a496093..8e543042 100644
--- a/gnomemusic/application.py
+++ b/gnomemusic/application.py
@@ -33,10 +33,11 @@
 from gettext import gettext as _
 import logging
 
-from gi.repository import Gtk, Gio, GLib, Gdk
+from gi.repository import Gtk, Gio, GLib, Gdk, GObject
 
 from gnomemusic import log
 from gnomemusic.mpris import MediaPlayer2Service
+from gnomemusic.player import Player
 from gnomemusic.widgets.aboutdialog import AboutDialog
 from gnomemusic.window import Window
 
@@ -59,6 +60,7 @@ class Application(Gtk.Application):
         self._init_style()
         self._window = None
         self._application_id = application_id
+        self._player = Player(self)
 
     def _init_style(self):
         css_provider = Gtk.CssProvider()
@@ -68,6 +70,16 @@ class Application(Gtk.Application):
         style_context.add_provider_for_screen(
             screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
 
+    @GObject.Property(
+        type=Player, default=None, flags=GObject.ParamFlags.READABLE)
+    def player(self):
+        """Get application-wide music player.
+
+        :returns: the player
+        :rtype: Player
+        """
+        return self._player
+
     @log
     def _build_app_menu(self):
         action_entries = [
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index 6639c080..a00b6f60 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -219,7 +219,7 @@ class MediaPlayer2Service(Server):
         super().__init__(self.con, '/org/mpris/MediaPlayer2')
 
         self.app = app
-        self.player = app.get_active_window()._player
+        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)
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index 462e5c2f..02f13cb3 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -35,7 +35,7 @@ from gettext import gettext as _
 from gnomemusic import log
 from gnomemusic.grilo import grilo
 from gnomemusic.mediakeys import MediaKeys
-from gnomemusic.player import Player, RepeatMode
+from gnomemusic.player import RepeatMode
 from gnomemusic.playlists import Playlists
 from gnomemusic.query import Query
 from gnomemusic.search import Search
@@ -87,7 +87,7 @@ class Window(Gtk.ApplicationWindow):
         self.prev_view = None
         self.curr_view = None
 
-        self._player = Player(app)
+        self._player = app.props.player
 
         self.notifications_popup = NotificationsPopup()
         self._setup_view()


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