[gnome-music/wip/jfelder/albumsview-selection-mode-launch: 2/2] artistsview: Correctly select the first artist on launch
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/albumsview-selection-mode-launch: 2/2] artistsview: Correctly select the first artist on launch
- Date: Tue, 24 Mar 2020 19:07:57 +0000 (UTC)
commit 66458b41b1718919cd0fc7fea885776ac1bd8e8c
Author: Jean Felder <jfelder src gnome org>
Date: Tue Mar 24 16:32:11 2020 +0100
artistsview: Correctly select the first artist on launch
On some setups (mostly flatpak), the first artist from the
ArtistsView's sidebar may not be selected on launch.
Indeed, it relies on listening to the artists-loaded signal from the
CoreModel to select the first artist once the artists model is
loaded. However, this signal may already have been emitted when the
ArtistView is built. In that case, the first artist will never be
selected.
Fix the issue by changing artists-loaded signal to a property. This
allows to check if the artist model is already loaded:
- if the artists are available, the first first artist can be selected
- if the artists are not available, listen to artists_available change
to select the first artist when the artists are available
gnomemusic/coremodel.py | 2 +-
gnomemusic/grilowrappers/grltrackerwrapper.py | 2 +-
gnomemusic/views/artistsview.py | 18 +++++++++++++-----
3 files changed, 15 insertions(+), 7 deletions(-)
---
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index ef3b19ce..897fe2e8 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -65,7 +65,6 @@ class CoreModel(GObject.GObject):
"""
__gsignals__ = {
- "artists-loaded": (GObject.SignalFlags.RUN_FIRST, None, ()),
"playlist-loaded": (GObject.SignalFlags.RUN_FIRST, None, (int,)),
"smart-playlist-change": (GObject.SignalFlags.RUN_FIRST, None, ())
}
@@ -73,6 +72,7 @@ class CoreModel(GObject.GObject):
active_playlist = GObject.Property(type=Playlist, default=None)
grilo = GObject.Property(type=CoreGrilo, default=None)
songs_available = GObject.Property(type=bool, default=False)
+ artists_available = GObject.Property(type=bool, default=False)
def __init__(self, application):
"""Initiate the CoreModel object
diff --git a/gnomemusic/grilowrappers/grltrackerwrapper.py b/gnomemusic/grilowrappers/grltrackerwrapper.py
index 22e7796f..b4c163e3 100644
--- a/gnomemusic/grilowrappers/grltrackerwrapper.py
+++ b/gnomemusic/grilowrappers/grltrackerwrapper.py
@@ -499,7 +499,7 @@ class GrlTrackerWrapper(GObject.GObject):
if not media:
self._artists_model.splice(
self._artists_model.get_n_items(), 0, artists_added)
- self._coremodel.emit("artists-loaded")
+ self._coremodel.props.artists_available = True
self._window.notifications_popup.pop_loading()
return
diff --git a/gnomemusic/views/artistsview.py b/gnomemusic/views/artistsview.py
index a5454ae5..7a25b107 100644
--- a/gnomemusic/views/artistsview.py
+++ b/gnomemusic/views/artistsview.py
@@ -53,6 +53,7 @@ class ArtistsView(BaseView):
self._artists = {}
self._selected_artist = None
+ self._loaded_artists = []
self._window = application.props.window
self._coremodel = application.props.coremodel
@@ -61,8 +62,13 @@ class ArtistsView(BaseView):
self._model.connect_after(
"items-changed", self._on_model_items_changed)
self._sidebar.bind_model(self._model, self._create_widget)
- self._loaded_id = self._coremodel.connect(
- "artists-loaded", self._on_artists_loaded)
+
+ if self._coremodel.props.artists_available is False:
+ self._loaded_id = self._coremodel.connect(
+ "notify::artists-available", self._on_artists_available)
+ else:
+ self._loaded_id = 0
+ self._on_artists_available()
sidebar_container.props.width_request = 220
sidebar_container.get_style_context().add_class('sidebar')
@@ -74,7 +80,6 @@ class ArtistsView(BaseView):
self._ctrl.props.button = Gdk.BUTTON_PRIMARY
self._ctrl.connect("released", self._on_sidebar_clicked)
- self._loaded_artists = []
self._loading_id = 0
self.show_all()
@@ -112,8 +117,11 @@ class ArtistsView(BaseView):
removed_frame = self._view.get_child_by_name(removed_artist)
self._view.remove(removed_frame)
- def _on_artists_loaded(self, klass):
- self._coremodel.disconnect(self._loaded_id)
+ def _on_artists_available(self, klass=None, value=None):
+ if self._loaded_id > 0:
+ self._coremodel.disconnect(self._loaded_id)
+ self._loaded_id = 0
+
first_row = self._sidebar.get_row_at_index(0)
if first_row is None:
return
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]