[gnome-music/wip/jfelder/expose-grilo-application-wide: 6/6] application: Expose grilo as an application property
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/expose-grilo-application-wide: 6/6] application: Expose grilo as an application property
- Date: Tue, 7 May 2019 15:42:06 +0000 (UTC)
commit 442a0acbc528f0dc1a274657a74e4e0e09b192bc
Author: Jean Felder <jfelder src gnome org>
Date: Fri May 3 17:30:21 2019 +0200
application: Expose grilo as an application property
Do not instanciate Grilo object in its own file. Grilo should be
initialized as soon as possible because Window and Views need to know
at startup if the tracker plugin is available. So, moving it to
Application makes sense.
Move Grilo 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/albumartcache.py | 21 +++++++++++---------
gnomemusic/application.py | 12 +++++++++++
gnomemusic/grilo.py | 3 ---
gnomemusic/mpris.py | 6 +++---
gnomemusic/player.py | 7 ++++---
gnomemusic/playlists.py | 16 +++++++++------
gnomemusic/views/albumsview.py | 13 ++++++------
gnomemusic/views/artistsview.py | 11 +++++------
gnomemusic/views/baseview.py | 8 ++++----
gnomemusic/views/playlistview.py | 5 ++---
gnomemusic/views/searchview.py | 25 +++++++++++------------
gnomemusic/views/songsview.py | 9 ++++-----
gnomemusic/widgets/albumcover.py | 4 +++-
gnomemusic/widgets/albumwidget.py | 7 ++++---
gnomemusic/widgets/artistalbumswidget.py | 6 ++++--
gnomemusic/widgets/artistalbumwidget.py | 7 ++++---
gnomemusic/widgets/coverstack.py | 29 ++++++++++++++++++++++++++-
gnomemusic/widgets/playertoolbar.py | 4 +++-
gnomemusic/widgets/playlistdialog.py | 6 +++---
gnomemusic/widgets/searchbar.py | 34 ++++++++++++++++++++------------
gnomemusic/window.py | 20 +++++++++----------
21 files changed, 154 insertions(+), 99 deletions(-)
---
diff --git a/gnomemusic/albumartcache.py b/gnomemusic/albumartcache.py
index c9585d8f..ad1a2b41 100644
--- a/gnomemusic/albumartcache.py
+++ b/gnomemusic/albumartcache.py
@@ -35,7 +35,6 @@ from gi.repository import (Gdk, GdkPixbuf, Gio, GLib, GObject, Gtk, MediaArt,
Gst, GstTag, GstPbutils)
from gnomemusic import log
-from gnomemusic.grilo import grilo
import gnomemusic.utils as utils
@@ -179,9 +178,10 @@ class Art(GObject.GObject):
return '<Art>'
@log
- def __init__(self, size, media, scale=1):
+ def __init__(self, grilo, size, media, scale=1):
super().__init__()
+ self._grilo = grilo
self._size = size
self._media = media
self._media_url = self._media.get_url()
@@ -232,7 +232,7 @@ class Art(GObject.GObject):
@log
def _embedded_art_unavailable(self, klass):
- remote_art = RemoteArt()
+ remote_art = RemoteArt(self._grilo)
remote_art.connect('retrieved', self._remote_art_retrieved)
remote_art.connect('unavailable', self._remote_art_unavailable)
remote_art.connect('no-remote-sources', self._remote_art_no_sources)
@@ -550,9 +550,11 @@ class RemoteArt(GObject.GObject):
return '<RemoteArt>'
@log
- def __init__(self):
+ def __init__(self, grilo):
super().__init__()
+ self._grilo = grilo
+
self._artist = None
self._album = None
@@ -566,18 +568,19 @@ class RemoteArt(GObject.GObject):
self._artist = utils.get_artist_name(media)
self._media = media
- if not grilo.props.cover_sources:
+ if not self._grilo.props.cover_sources:
self.emit('no-remote-sources')
- grilo.connect(
+ self._grilo.connect(
'notify::cover-sources', self._on_grilo_cover_sources_changed)
else:
# FIXME: It seems this Grilo query does not always return,
# especially on queries with little info.
- grilo.get_album_art_for_item(media, self._remote_album_art)
+ self._grilo.get_album_art_for_item(media, self._remote_album_art)
def _on_grilo_cover_sources_changed(self, klass, data):
- if grilo.props.cover_sources:
- grilo.get_album_art_for_item(self._media, self._remote_album_art)
+ if self._grilo.props.cover_sources:
+ self._grilo.get_album_art_for_item(
+ self._media, self._remote_album_art)
@log
def _delete_callback(self, src, result, data):
diff --git a/gnomemusic/application.py b/gnomemusic/application.py
index 5521960f..4bd03ac5 100644
--- a/gnomemusic/application.py
+++ b/gnomemusic/application.py
@@ -36,6 +36,7 @@ import logging
from gi.repository import Gtk, Gio, GLib, Gdk, GObject
from gnomemusic import log
+from gnomemusic.grilo import Grilo
from gnomemusic.inhibitsuspend import InhibitSuspend
from gnomemusic.mpris import MediaPlayer2Service
from gnomemusic.pauseonsuspend import PauseOnSuspend
@@ -63,6 +64,7 @@ class Application(Gtk.Application):
self._init_style()
self._window = None
+ self._grilo = Grilo()
self._settings = Gio.Settings.new('org.gnome.Music')
self._playlists = Playlists(self)
self._player = Player(self)
@@ -78,6 +80,16 @@ class Application(Gtk.Application):
style_context.add_provider_for_screen(
screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
+ @GObject.Property(
+ type=Grilo, default=None, flags=GObject.ParamFlags.READABLE)
+ def grilo(self):
+ """Get application-wide grilo.
+
+ :returns: the grilo instance
+ :rtype: Grilo
+ """
+ return self._grilo
+
@GObject.Property(
type=Player, default=None, flags=GObject.ParamFlags.READABLE)
def player(self):
diff --git a/gnomemusic/grilo.py b/gnomemusic/grilo.py
index e7e0a838..8ecf1717 100644
--- a/gnomemusic/grilo.py
+++ b/gnomemusic/grilo.py
@@ -521,6 +521,3 @@ class Grilo(GObject.GObject):
self.tracker_sparql.query_async(
Query.all_songs_count(), None, songs_query_cb, None)
-
-
-grilo = Grilo()
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index 93457770..b277268a 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -25,7 +25,6 @@
from gnomemusic.gstplayer import Playback
from gnomemusic.player import PlayerPlaylist, RepeatMode
-from gnomemusic.grilo import grilo
from gnomemusic.utils import View
import gnomemusic.utils as utils
@@ -233,7 +232,8 @@ class MediaPlayer2Service(Server):
playlists = app.props.playlists
playlists.connect('playlist-created', self._on_playlists_count_changed)
playlists.connect('playlist-deleted', self._on_playlists_count_changed)
- grilo.connect('ready', self._on_grilo_ready)
+ self._grilo = app.props.grilo
+ self._grilo.connect('ready', self._on_grilo_ready)
self.playlists = []
self._player_previous_type = None
self._path_list = []
@@ -416,7 +416,7 @@ class MediaPlayer2Service(Server):
else:
callback(playlists)
- grilo.populate_playlists(0, populate_callback)
+ self._grilo.populate_playlists(0, populate_callback)
@log
def _get_active_playlist(self):
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index 94634a35..a2922ab8 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -38,7 +38,6 @@ from gi.repository import GObject, Grl, GstPbutils
from gnomemusic import log
from gnomemusic.gstplayer import GstPlayer, Playback
-from gnomemusic.grilo import grilo
from gnomemusic.scrobbler import LastFmScrobbler
@@ -560,6 +559,8 @@ class Player(GObject.GObject):
"""
super().__init__()
+ self._grilo = application.props.grilo
+
self._playlist = PlayerPlaylist()
self._playlist.connect('song-validated', self._on_song_validated)
@@ -799,8 +800,8 @@ class Player(GObject.GObject):
# playlists here but removing it may introduce
# a bug. So, we keep it for the time being.
self._playlists.update_all_static_playlists()
- grilo.bump_play_count(current_song)
- grilo.set_last_played(current_song)
+ self._grilo.bump_play_count(current_song)
+ self._grilo.set_last_played(current_song)
@log
def _on_repeat_setting_changed(self, settings, value):
diff --git a/gnomemusic/playlists.py b/gnomemusic/playlists.py
index 553d731b..20576ec7 100644
--- a/gnomemusic/playlists.py
+++ b/gnomemusic/playlists.py
@@ -29,7 +29,6 @@
import gi
gi.require_version('Grl', '0.3')
from gi.repository import Grl, GLib, GObject
-from gnomemusic.grilo import grilo
from gnomemusic.query import Query
from gettext import gettext as _
import inspect
@@ -135,12 +134,17 @@ class Playlists(GObject.GObject):
return '<Playlists>'
@log
- def __init__(self):
+ def __init__(self, application):
+ """Initialize the playlists
+
+ :param Application application: Application object
+ """
super().__init__()
self._static_playlists = StaticPlaylists()
- grilo.connect('ready', self._on_grilo_ready)
+ self._grilo = application.props.grilo
+ self._grilo.connect('ready', self._on_grilo_ready)
@log
def _on_grilo_ready(self, data=None):
@@ -175,7 +179,7 @@ class Playlists(GObject.GObject):
# Search for the playlist ID
cursor.next_async(None, playlist_id_fetched_cb, playlist)
- self._tracker = grilo.tracker_sparql
+ self._tracker = self._grilo.tracker_sparql
# Start fetching all the static playlists
for playlist in self._static_playlists.get_all():
self._tracker.query_async(
@@ -319,7 +323,7 @@ class Playlists(GObject.GObject):
return
playlist_id = cursor.get_integer(0)
- grilo.get_playlist_with_id(playlist_id, get_callback)
+ self._grilo.get_playlist_with_id(playlist_id, get_callback)
def query_callback(conn, res, data):
try:
@@ -383,7 +387,7 @@ class Playlists(GObject.GObject):
if not cursor or not cursor.next():
return
entry_id = cursor.get_integer(0)
- grilo.get_playlist_song_with_id(
+ self._grilo.get_playlist_song_with_id(
playlist_id, entry_id, get_callback)
def update_callback(conn, res, data):
diff --git a/gnomemusic/views/albumsview.py b/gnomemusic/views/albumsview.py
index fdee5c68..6278ebbe 100644
--- a/gnomemusic/views/albumsview.py
+++ b/gnomemusic/views/albumsview.py
@@ -26,7 +26,6 @@ from gettext import gettext as _
from gi.repository import GObject, Gtk
from gnomemusic import log
-from gnomemusic.grilo import grilo
from gnomemusic.views.baseview import BaseView
from gnomemusic.widgets.headerbar import HeaderBar
from gnomemusic.widgets.albumcover import AlbumCover
@@ -46,7 +45,7 @@ class AlbumsView(BaseView):
super().__init__('albums', _("Albums"), window)
self.player = player
- self._album_widget = AlbumWidget(player, self)
+ self._album_widget = AlbumWidget(player, self._grilo, self)
self.add(self._album_widget)
self.albums_selected = []
self.all_items = []
@@ -61,14 +60,14 @@ class AlbumsView(BaseView):
if (self._init and not self.props.selection_mode):
self._offset = 0
self._populate()
- grilo.changes_pending['Albums'] = False
+ self._grilo.changes_pending['Albums'] = False
@log
def _on_selection_mode_changed(self, widget, data=None):
super()._on_selection_mode_changed(widget, data)
if (not self.props.selection_mode
- and grilo.changes_pending['Albums']):
+ and self._grilo.changes_pending['Albums']):
self._on_changes_pending()
@log
@@ -121,7 +120,7 @@ class AlbumsView(BaseView):
@log
def _populate(self, data=None):
self._window.notifications_popup.push_loading()
- grilo.populate_albums(self._offset, self._add_item)
+ self._grilo.populate_albums(self._offset, self._add_item)
self._init = True
@log
@@ -153,7 +152,7 @@ class AlbumsView(BaseView):
self._init = False
def _create_album_item(self, item):
- child = AlbumCover(item)
+ child = AlbumCover(self._grilo, item)
child.connect('notify::selected', self._on_selection_changed)
@@ -176,7 +175,7 @@ class AlbumsView(BaseView):
@log
def _get_selected_album_songs(self):
- grilo.populate_album_songs(
+ self._grilo.populate_album_songs(
self.albums_selected[self.albums_index],
self._add_selected_item)
self.albums_index += 1
diff --git a/gnomemusic/views/artistsview.py b/gnomemusic/views/artistsview.py
index 1eb93a01..b118b60b 100644
--- a/gnomemusic/views/artistsview.py
+++ b/gnomemusic/views/artistsview.py
@@ -27,7 +27,6 @@ from gettext import gettext as _
from gi.repository import Gdk, Gtk
from gnomemusic import log
-from gnomemusic.grilo import grilo
from gnomemusic.player import PlayerPlaylist
from gnomemusic.views.baseview import BaseView
from gnomemusic.widgets.artistalbumswidget import ArtistAlbumsWidget
@@ -97,7 +96,7 @@ class ArtistsView(BaseView):
self._artists.clear()
self._offset = 0
self._populate()
- grilo.changes_pending['Artists'] = False
+ self._grilo.changes_pending['Artists'] = False
@log
def _on_artist_activated(self, sidebar, row, data=None):
@@ -170,7 +169,7 @@ class ArtistsView(BaseView):
def _populate(self, data=None):
"""Populates the view"""
self._window.notifications_popup.push_loading()
- grilo.populate_artists(self._offset, self._add_item)
+ self._grilo.populate_artists(self._offset, self._add_item)
self._init = True
@log
@@ -201,7 +200,7 @@ class ArtistsView(BaseView):
self._sidebar.props.selection_mode = Gtk.SelectionMode.SINGLE
if (not self.props.selection_mode
- and grilo.changes_pending['Artists']):
+ and self._grilo.changes_pending['Artists']):
self._on_changes_pending()
@log
@@ -246,9 +245,9 @@ class ArtistsView(BaseView):
if remaining == 0:
self._album_index += 1
if self._album_index < len(albums):
- grilo.populate_album_songs(
+ self._grilo.populate_album_songs(
albums[self._album_index], add_songs)
else:
callback(selected_songs)
- grilo.populate_album_songs(albums[self._album_index], add_songs)
+ self._grilo.populate_album_songs(albums[self._album_index], add_songs)
diff --git a/gnomemusic/views/baseview.py b/gnomemusic/views/baseview.py
index be11d1bd..64f5df46 100644
--- a/gnomemusic/views/baseview.py
+++ b/gnomemusic/views/baseview.py
@@ -25,7 +25,6 @@
from gi.repository import GdkPixbuf, GObject, Gtk
from gnomemusic import log
-from gnomemusic.grilo import grilo
from gnomemusic.widgets.starhandlerwidget import StarHandlerWidget
@@ -80,6 +79,7 @@ class BaseView(Gtk.Stack):
self._star_handler = StarHandlerWidget(self, 9)
self._window = window
+ self._grilo = window._grilo
self._headerbar = window._headerbar
self.name = name
@@ -90,15 +90,15 @@ class BaseView(Gtk.Stack):
self._view.hide()
self._init = False
- grilo.connect('ready', self._on_grilo_ready)
+ self._grilo.connect('ready', self._on_grilo_ready)
self.connect('notify::selection-mode', self._on_selection_mode_changed)
- grilo.connect('changes-pending', self._on_changes_pending)
+ self._grilo.connect('changes-pending', self._on_changes_pending)
self.bind_property(
'selection-mode', self._window, 'selection-mode',
GObject.BindingFlags.BIDIRECTIONAL)
- if (grilo.tracker is not None
+ if (self._grilo.tracker is not None
and not self._init):
self._on_grilo_ready()
diff --git a/gnomemusic/views/playlistview.py b/gnomemusic/views/playlistview.py
index 16fab384..b9b295f3 100644
--- a/gnomemusic/views/playlistview.py
+++ b/gnomemusic/views/playlistview.py
@@ -27,7 +27,6 @@ from gettext import gettext as _
from gi.repository import Gdk, Gio, GLib, GObject, Gtk, Pango
from gnomemusic import log
-from gnomemusic.grilo import grilo
from gnomemusic.player import ValidationStatus, PlayerPlaylist
from gnomemusic.playlists import StaticPlaylists
from gnomemusic.views.baseview import BaseView
@@ -545,7 +544,7 @@ class PlaylistView(BaseView):
self._iter_to_clean_model = None
self._update_songs_count(0)
self._pl_ctrls.props.display_songs_count = False
- grilo.populate_playlist_songs(playlist, self._add_song)
+ self._grilo.populate_playlist_songs(playlist, self._add_song)
if self._current_playlist_is_protected():
self._playlist_delete_action.set_enabled(False)
@@ -783,7 +782,7 @@ class PlaylistView(BaseView):
Do not reload playlists already displayed.
"""
self._window.notifications_popup.push_loading()
- grilo.populate_playlists(
+ self._grilo.populate_playlists(
self._offset, self._add_playlist_item, -1, data)
self._init = True
diff --git a/gnomemusic/views/searchview.py b/gnomemusic/views/searchview.py
index 15cdb960..96b32607 100644
--- a/gnomemusic/views/searchview.py
+++ b/gnomemusic/views/searchview.py
@@ -28,7 +28,6 @@ gi.require_version('Gd', '1.0')
from gi.repository import Gd, Gdk, GdkPixbuf, GObject, Grl, Gtk, Pango
from gnomemusic.albumartcache import Art
-from gnomemusic.grilo import grilo
from gnomemusic import log
from gnomemusic.player import ValidationStatus, PlayerPlaylist
from gnomemusic.query import Query
@@ -62,7 +61,7 @@ class SearchView(BaseView):
self._albums_selected = []
self._albums = {}
self._albums_index = 0
- self._album_widget = AlbumWidget(player, self)
+ self._album_widget = AlbumWidget(player, self._grilo, self)
self.add(self._album_widget)
self._artists_albums_selected = []
@@ -244,8 +243,8 @@ class SearchView(BaseView):
@log
def _add_search_item(self, source, param, item, remaining=0, data=None):
if not item:
- if (grilo._search_callback_counter == 0
- and grilo.search_source):
+ if (self._grilo._search_callback_counter == 0
+ and self._grilo.search_source):
self.props.search_state = Search.State.NO_RESULT
return
@@ -351,7 +350,7 @@ class SearchView(BaseView):
# FIXME: Figure out why iter can be None here, seems illogical.
if _iter is not None:
scale = self._view.get_scale_factor()
- art = Art(Art.Size.SMALL, item, scale)
+ art = Art(self._grilo, Art.Size.SMALL, item, scale)
self.model[_iter][13] = art.surface
art.connect(
'finished', self._retrieval_finished, self.model, _iter)
@@ -478,7 +477,7 @@ class SearchView(BaseView):
@log
def _get_selected_albums_songs(self):
- grilo.populate_album_songs(
+ self._grilo.populate_album_songs(
self._albums_selected[self._albums_index],
self._add_selected_albums_songs)
self._albums_index += 1
@@ -514,7 +513,7 @@ class SearchView(BaseView):
@log
def _get_selected_artists_albums_songs(self):
- grilo.populate_album_songs(
+ self._grilo.populate_album_songs(
self._artists_albums_selected[self._artists_albums_index],
self._add_selected_artists_albums_songs)
self._artists_albums_index += 1
@@ -620,14 +619,14 @@ class SearchView(BaseView):
self.model.get_path(songs_iter))
# Use queries for Tracker
- if (not grilo.search_source
- or grilo.search_source.get_id() == 'grl-tracker-source'):
+ if (not self._grilo.search_source
+ or self._grilo.search_source.get_id() == 'grl-tracker-source'):
for category in ('album', 'artist', 'song'):
query = query_matcher[category][fields_filter](search_term)
self._window.notifications_popup.push_loading()
- grilo.populate_custom_query(
+ self._grilo.populate_custom_query(
query, self._add_item, -1, [self.model, category])
- if (not grilo.search_source
- or grilo.search_source.get_id() != 'grl-tracker-source'):
+ if (not self._grilo.search_source
+ or self._grilo.search_source.get_id() != 'grl-tracker-source'):
# nope, can't do - reverting to Search
- grilo.search(search_term, self._add_search_item, self.model)
+ self._grilo.search(search_term, self._add_search_item, self.model)
diff --git a/gnomemusic/views/songsview.py b/gnomemusic/views/songsview.py
index 90029a0f..9c12c23b 100644
--- a/gnomemusic/views/songsview.py
+++ b/gnomemusic/views/songsview.py
@@ -27,7 +27,6 @@ from gettext import gettext as _
from gi.repository import Gdk, Gtk, Pango
from gnomemusic import log
-from gnomemusic.grilo import grilo
from gnomemusic.player import ValidationStatus, PlayerPlaylist
from gnomemusic.views.baseview import BaseView
import gnomemusic.utils as utils
@@ -174,7 +173,7 @@ class SongsView(BaseView):
self.model.clear()
self._offset = 0
self._populate()
- grilo.changes_pending['Songs'] = False
+ self._grilo.changes_pending['Songs'] = False
@log
def _on_selection_mode_changed(self, widget, data=None):
@@ -184,7 +183,7 @@ class SongsView(BaseView):
cols[1].props.visible = self.props.selection_mode
if (not self.props.selection_mode
- and grilo.changes_pending['Songs']):
+ and self._grilo.changes_pending['Songs']):
self._on_changes_pending()
@log
@@ -279,9 +278,9 @@ class SongsView(BaseView):
def _populate(self, data=None):
"""Populates the view"""
self._init = True
- if grilo.tracker:
+ if self._grilo.tracker:
self._window.notifications_popup.push_loading()
- grilo.populate_songs(self._offset, self._add_item)
+ self._grilo.populate_songs(self._offset, self._add_item)
@log
def get_selected_songs(self, callback=None):
diff --git a/gnomemusic/widgets/albumcover.py b/gnomemusic/widgets/albumcover.py
index f76ecb65..252c6996 100644
--- a/gnomemusic/widgets/albumcover.py
+++ b/gnomemusic/widgets/albumcover.py
@@ -58,9 +58,10 @@ class AlbumCover(Gtk.FlowBoxChild):
return '<AlbumCover>'
@log
- def __init__(self, media):
+ def __init__(self, grilo, media):
"""Initialize the AlbumCover
+ :param Grilo grilo: The Grilo instance
:param Grl.Media media: The media object to use
"""
super().__init__()
@@ -92,6 +93,7 @@ class AlbumCover(Gtk.FlowBoxChild):
self._events.add_events(Gdk.EventMask.TOUCH_MASK)
+ self._cover_stack.props.grilo = grilo
self._cover_stack.props.size = Art.Size.MEDIUM
self.show()
diff --git a/gnomemusic/widgets/albumwidget.py b/gnomemusic/widgets/albumwidget.py
index debb8c73..17ee40bd 100644
--- a/gnomemusic/widgets/albumwidget.py
+++ b/gnomemusic/widgets/albumwidget.py
@@ -27,7 +27,6 @@ from gi.repository import GdkPixbuf, GObject, Grl, Gtk
from gnomemusic import log
from gnomemusic.albumartcache import Art
-from gnomemusic.grilo import grilo
from gnomemusic.player import PlayerPlaylist
from gnomemusic.widgets.disclistboxwidget import DiscBox
from gnomemusic.widgets.disclistboxwidget import DiscListBox # noqa: F401
@@ -63,7 +62,7 @@ class AlbumWidget(Gtk.EventBox):
return '<AlbumWidget>'
@log
- def __init__(self, player, parent_view):
+ def __init__(self, player, grilo, parent_view):
"""Initialize the AlbumWidget.
:param player: The player object
@@ -74,8 +73,10 @@ class AlbumWidget(Gtk.EventBox):
self._album = None
self._songs = []
+ self._cover_stack.props.grilo = grilo
self._cover_stack.props.size = Art.Size.LARGE
self._parent_view = parent_view
+ self._grilo = grilo
self._player = player
self._iter_to_clean = None
@@ -148,7 +149,7 @@ class AlbumWidget(Gtk.EventBox):
self._player.connect('song-changed', self._update_model)
- grilo.populate_album_songs(album, self.add_item)
+ self._grilo.populate_album_songs(album, self.add_item)
@log
def _set_composer_label(self, album):
diff --git a/gnomemusic/widgets/artistalbumswidget.py b/gnomemusic/widgets/artistalbumswidget.py
index b9150d71..aa1d7bf0 100644
--- a/gnomemusic/widgets/artistalbumswidget.py
+++ b/gnomemusic/widgets/artistalbumswidget.py
@@ -61,6 +61,7 @@ class ArtistAlbumsWidget(Gtk.Box):
self._player = player
self._artist = artist
self._window = window
+ self._grilo = window._grilo
self._selection_mode_allowed = selection_mode_allowed
self._artist_label.props.label = self._artist
@@ -123,8 +124,9 @@ class ArtistAlbumsWidget(Gtk.Box):
@log
def _add_album(self, album):
widget = ArtistAlbumWidget(
- album, self._player, self._model, self._selection_mode_allowed,
- self._songs_grid_size_group, self._cover_size_group)
+ self._grilo, album, self._player, self._model,
+ self._selection_mode_allowed, self._songs_grid_size_group,
+ self._cover_size_group)
self.bind_property(
'selection-mode', widget, 'selection-mode',
diff --git a/gnomemusic/widgets/artistalbumwidget.py b/gnomemusic/widgets/artistalbumwidget.py
index 8d8fda88..0c6cedf7 100644
--- a/gnomemusic/widgets/artistalbumwidget.py
+++ b/gnomemusic/widgets/artistalbumwidget.py
@@ -26,7 +26,6 @@ from gi.repository import GObject, Gtk
from gnomemusic import log
from gnomemusic.albumartcache import Art
-from gnomemusic.grilo import grilo
from gnomemusic.player import PlayerPlaylist
from gnomemusic.widgets.disclistboxwidget import DiscBox
import gnomemusic.utils as utils
@@ -54,13 +53,14 @@ class ArtistAlbumWidget(Gtk.Box):
@log
def __init__(
- self, media, player, model, selection_mode_allowed,
+ self, grilo, media, player, model, selection_mode_allowed,
size_group=None, cover_size_group=None):
super().__init__(orientation=Gtk.Orientation.HORIZONTAL)
self._size_group = size_group
self._cover_size_group = cover_size_group
+ self._grilo = grilo
self._media = media
self._player = player
self._artist = utils.get_artist_name(self._media)
@@ -71,6 +71,7 @@ class ArtistAlbumWidget(Gtk.Box):
self._songs = []
+ self._cover_stack.props.grilo = grilo
self._cover_stack.props.size = Art.Size.MEDIUM
self._cover_stack.update(self._media)
@@ -94,7 +95,7 @@ class ArtistAlbumWidget(Gtk.Box):
if self._cover_size_group:
self._cover_size_group.add_widget(self._cover_stack)
- grilo.populate_album_songs(self._media, self._add_item)
+ self._grilo.populate_album_songs(self._media, self._add_item)
@log
def _create_disc_box(self, disc_nr, disc_songs):
diff --git a/gnomemusic/widgets/coverstack.py b/gnomemusic/widgets/coverstack.py
index 4a981193..d7445393 100644
--- a/gnomemusic/widgets/coverstack.py
+++ b/gnomemusic/widgets/coverstack.py
@@ -60,6 +60,8 @@ class CoverStack(Gtk.Stack):
self._size = None
self._timeout = None
+ self._grilo = None
+
self._loading_cover = Gtk.Image()
self._cover_a = Gtk.Image()
self._cover_b = Gtk.Image()
@@ -74,6 +76,30 @@ class CoverStack(Gtk.Stack):
self.show_all()
+ # FIXME: This is a workaround for not being able to pass the grilo
+ # object via init when using Gtk.Builder.
+ @GObject.Property
+ def grilo(self):
+ """The Grilo object used
+
+ :return: grilo object
+ :rtype: Grilo
+ """
+ return self._grilo
+
+ @grilo.setter
+ def grilo(self, grilo):
+ """Set the Grilo object used
+
+ :param Grilo grilo: The Grilo to use
+ """
+ if (grilo is None
+ or (self._grilo is not None
+ and self._grilo != grilo)):
+ return
+
+ self._grilo = grilo
+
@GObject.Property(type=object, flags=GObject.ParamFlags.READWRITE)
def size(self):
"""Size of the cover
@@ -113,7 +139,8 @@ class CoverStack(Gtk.Stack):
self._active_child = self.props.visible_child_name
- self._art = Art(self.props.size, media, self.props.scale_factor)
+ self._art = Art(
+ self._grilo, self.props.size, media, self.props.scale_factor)
self._handler_id = self._art.connect('finished', self._art_retrieved)
self._art.lookup()
diff --git a/gnomemusic/widgets/playertoolbar.py b/gnomemusic/widgets/playertoolbar.py
index 3c38f051..fcaacb01 100644
--- a/gnomemusic/widgets/playertoolbar.py
+++ b/gnomemusic/widgets/playertoolbar.py
@@ -66,13 +66,15 @@ class PlayerToolbar(Gtk.ActionBar):
return '<PlayerToolbar>'
@log
- def __init__(self, player, main_window):
+ def __init__(self, player, grilo, main_window):
super().__init__()
+ self._grilo = grilo
self._main_window = main_window
self._player = player
self._progress_scale.props.player = self._player
+ self._cover_stack.props.grilo = self._grilo
self._cover_stack.props.size = Art.Size.XSMALL
self._cover_stack.connect('updated', self._on_cover_stack_updated)
diff --git a/gnomemusic/widgets/playlistdialog.py b/gnomemusic/widgets/playlistdialog.py
index 5e4ab2bd..56238b90 100644
--- a/gnomemusic/widgets/playlistdialog.py
+++ b/gnomemusic/widgets/playlistdialog.py
@@ -25,7 +25,6 @@
from gi.repository import Gtk, Pango
from gnomemusic import log
-from gnomemusic.grilo import grilo
import gnomemusic.utils as utils
@@ -53,7 +52,7 @@ class PlaylistDialog(Gtk.Dialog):
return '<PlaylistDialog>'
@log
- def __init__(self, parent, playlists_todelete):
+ def __init__(self, parent, grilo, playlists_todelete):
super().__init__()
self._add_playlist_button = None
@@ -62,6 +61,7 @@ class PlaylistDialog(Gtk.Dialog):
self.props.transient_for = parent
self.set_titlebar(self._title_bar)
self._add_list_renderers()
+ self._grilo = grilo
self._populate()
self._playlists_todelete_ids = playlists_todelete.keys()
@@ -103,7 +103,7 @@ class PlaylistDialog(Gtk.Dialog):
@log
def _populate(self):
- grilo.populate_user_playlists(0, self._add_item)
+ self._grilo.populate_user_playlists(0, self._add_item)
@log
def _add_item(self, source, param, item, remaining=0, data=None):
diff --git a/gnomemusic/widgets/searchbar.py b/gnomemusic/widgets/searchbar.py
index 4d5c07a7..e29c3aef 100644
--- a/gnomemusic/widgets/searchbar.py
+++ b/gnomemusic/widgets/searchbar.py
@@ -32,7 +32,6 @@ from gi.repository import Gd, GLib, GObject, Gtk, Pango
from gi.repository.Gd import TaggedEntry # noqa: F401
from gnomemusic import log
-from gnomemusic.grilo import grilo
from gnomemusic.search import Search
@@ -110,7 +109,7 @@ class SourceManager(BaseManager):
return '<SourceManager>'
@log
- def __init__(self, id_, label, entry):
+ def __init__(self, grilo, id_, label, entry):
super().__init__(id_, label, entry)
self.values.append(['', '', self._label])
@@ -118,7 +117,8 @@ class SourceManager(BaseManager):
self.values.append(['grl-tracker-source', _("Local"), ''])
self.props.default_value = 2
- grilo.connect('new-source-added', self._add_new_source)
+ self._grilo = grilo
+ self._grilo.connect('new-source-added', self._add_new_source)
@log
def fill_in_values(self, model):
@@ -144,8 +144,8 @@ class SourceManager(BaseManager):
Adds available Grilo sources to the internal model.
"""
- for id_ in grilo.props.sources:
- self._add_new_source(None, grilo.props.sources[id_])
+ for id_ in self._grilo.props.sources:
+ self._add_new_source(None, self._grilo.props.sources[id_])
@GObject.Property
def active(self):
@@ -159,8 +159,10 @@ class SourceManager(BaseManager):
# https://gitlab.gnome.org/GNOME/gnome-music/snippets/31
super(SourceManager, self.__class__).active.fset(self, selected_id)
- src = grilo.sources[selected_id] if selected_id != 'all' else None
- grilo.search_source = src
+ src = None
+ if selected_id != 'all':
+ src = self._grilo.sources[selected_id]
+ self._grilo.search_source = src
@Gtk.Template(resource_path="/org/gnome/Music/ui/FilterView.ui")
@@ -275,16 +277,17 @@ class DropDown(Gtk.Revealer):
return '<DropDown>'
@log
- def __init__(self):
+ def __init__(self, grilo):
super().__init__()
+ self._grilo = grilo
self._source_manager = None
self.search_manager = None
@log
def initialize_filters(self, searchbar):
self._source_manager = SourceManager(
- 'source', _("Sources"), searchbar._search_entry)
+ self._grilo, 'source', _("Sources"), searchbar._search_entry)
self._source_manager.connect(
"notify::active", self._on_source_manager_value_changed)
@@ -337,13 +340,18 @@ class SearchBar(Gtk.SearchBar):
return '<SearchBar>'
@log
- def __init__(self):
- """Initialize the SearchBar"""
+ def __init__(self, grilo):
+ """Initialize the SearchBar
+
+ :param Grilo grilo: the grilo instance
+ """
super().__init__()
+ self._grilo = grilo
+
self._timeout = None
- self._dropdown = DropDown()
+ self._dropdown = DropDown(grilo)
self._dropdown.initialize_filters(self)
self.connect(
@@ -375,7 +383,7 @@ class SearchBar(Gtk.SearchBar):
self._timeout = None
search_term = self._search_entry.get_text()
- if grilo.search_source:
+ if self._grilo.search_source:
fields_filter = self._dropdown.search_manager.active
else:
fields_filter = 'search_all'
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index a3ee1299..2ca31a87 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -33,7 +33,6 @@ from gi.repository import Gtk, Gdk, Gio, GLib, GObject
from gettext import gettext as _
from gnomemusic import log
-from gnomemusic.grilo import grilo
from gnomemusic.mediakeys import MediaKeys
from gnomemusic.player import RepeatMode
from gnomemusic.playlists import StaticPlaylists
@@ -91,6 +90,9 @@ class Window(Gtk.ApplicationWindow):
self.prev_view = None
self.curr_view = None
+ self._grilo = app.props.grilo
+ self._grilo.connect('changes-pending', self._on_changes_pending)
+
self._player = app.props.player
self.notifications_popup = NotificationsPopup()
@@ -98,8 +100,6 @@ class Window(Gtk.ApplicationWindow):
MediaKeys(self._player, self)
- grilo.connect('changes-pending', self._on_changes_pending)
-
@log
def _on_changes_pending(self, data=None):
# FIXME: This is not working right.
@@ -120,7 +120,7 @@ class Window(Gtk.ApplicationWindow):
self._switch_to_empty_view()
- grilo.songs_available(songs_available_cb)
+ self._grilo.songs_available(songs_available_cb)
@log
def _setup_view(self):
@@ -128,7 +128,7 @@ class Window(Gtk.ApplicationWindow):
self._search = Search()
self._headerbar = HeaderBar()
- self._searchbar = SearchBar()
+ self._searchbar = SearchBar(self._grilo)
self._search.bind_property(
"search-mode-active", self._headerbar, "search-mode-active",
GObject.BindingFlags.BIDIRECTIONAL
@@ -140,7 +140,7 @@ class Window(Gtk.ApplicationWindow):
"state", self._searchbar, "search-state",
GObject.BindingFlags.SYNC_CREATE)
- self._player_toolbar = PlayerToolbar(self._player, self)
+ self._player_toolbar = PlayerToolbar(self._player, self._grilo, self)
selection_toolbar = SelectionToolbar()
self.views = [None] * len(View)
self._stack = Gtk.Stack(
@@ -207,7 +207,7 @@ class Window(Gtk.ApplicationWindow):
self._switch_to_empty_view()
if Query().music_folder:
- grilo.songs_available(songs_available_cb)
+ self._grilo.songs_available(songs_available_cb)
else:
self._switch_to_empty_view()
@@ -215,7 +215,7 @@ class Window(Gtk.ApplicationWindow):
def _switch_to_empty_view(self):
did_initial_state = self._settings.get_boolean('did-initial-state')
- if not grilo.props.tracker_available:
+ if not self._grilo.props.tracker_available:
self.views[View.EMPTY].props.state = EmptyView.State.NO_TRACKER
elif did_initial_state:
self.views[View.EMPTY].props.state = EmptyView.State.EMPTY
@@ -506,7 +506,7 @@ class Window(Gtk.ApplicationWindow):
return
playlist_dialog = PlaylistDialog(
- self, self.views[View.PLAYLIST].pls_todelete)
+ self, self._grilo, self.views[View.PLAYLIST].pls_todelete)
if playlist_dialog.run() == Gtk.ResponseType.ACCEPT:
self._playlists.add_to_playlist(
playlist_dialog.get_selected(), selected_songs)
@@ -525,7 +525,7 @@ class Window(Gtk.ApplicationWindow):
@log
def refresh_views_favorite(self, visible_view, media):
- grilo.toggle_favorite(media)
+ self._grilo.toggle_favorite(media)
self._playlists.update_static_playlist(StaticPlaylists.Favorites)
# FIXME: the refresh should be triggered by listening to the
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]