[gnome-music/wip/jfelder/playback-status-v4: 4/12] coremodel: Add an active_media property to create a player playlist
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/playback-status-v4: 4/12] coremodel: Add an active_media property to create a player playlist
- Date: Mon, 1 Jun 2020 00:28:37 +0000 (UTC)
commit 1ab67efa8922e0adcfcd498f1befb5fc4c82f73f
Author: Jean Felder <jfelder src gnome org>
Date: Sat Jan 11 23:09:26 2020 +0100
coremodel: Add an active_media property to create a player playlist
Only some widgets and the MPRIS objet can set the playlist player by
calling the set_player_model() function from the CoreModel. Once the
player playlist is loaded, the appropriate is loaded and the player
starts playing.
Each type of player playlist can be set by only one widget. However, a
playlist type can also set by the MPRIS object. When PlaylistsWidget
or MPRIS set a new player playlist, the active_playlist property is
used to inform the other object of the change.
This commit generalizes this approach by introducing a new
active_media property. A set_player_model call is replaced by setting
the active_media. Based on the type of media, _set_player_model() is
called with the correct parameters.
The next commit will remove the active_playlist property which is
redundant with the active_media property.
gnomemusic/coremodel.py | 32 +++++++++++++++++++++++++++++++-
gnomemusic/mpris.py | 3 +--
gnomemusic/views/searchview.py | 3 +--
gnomemusic/views/songsview.py | 5 ++---
gnomemusic/widgets/albumwidget.py | 3 +--
gnomemusic/widgets/artistalbumswidget.py | 2 +-
gnomemusic/widgets/playlistswidget.py | 3 +--
7 files changed, 38 insertions(+), 13 deletions(-)
---
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index f3d46b16..a1694317 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -29,6 +29,8 @@ gi.require_version("Gfm", "0.1")
from gi.repository import GObject, Gio, Gfm, Gtk
from gnomemusic.coreartist import CoreArtist
+from gnomemusic.corealbum import CoreAlbum
+from gnomemusic.coregrilo import CoreGrilo
from gnomemusic.coresong import CoreSong
from gnomemusic.grilowrappers.grltrackerplaylists import Playlist
from gnomemusic.player import PlayerPlaylist
@@ -104,6 +106,7 @@ class CoreModel(GObject.GObject):
self._playlist_model_sort = Gfm.SortListModel.new(self._playlist_model)
self._playlist_model_recent = Gfm.SliceListModel.new(
self._playlist_model_sort, 0, self._recent_size)
+ self._active_media = None
self._songs_search_proxy = Gio.ListStore.new(Gfm.FilterListModel)
self._songs_search_flatten = Gfm.FlattenListModel.new(CoreSong)
@@ -138,6 +141,8 @@ class CoreModel(GObject.GObject):
self._user_playlists_model_sort.set_sort_func(
utils.wrap_list_store_sort_func(self._playlists_sort))
+ self._search = application.props.search
+
self._songs_model.connect(
"items-changed", self._on_songs_items_changed)
@@ -181,7 +186,7 @@ class CoreModel(GObject.GObject):
playlist_a.props.creation_date)
return math.copysign(1, date_diff)
- def set_player_model(self, playlist_type, model):
+ def _set_player_model(self, playlist_type, model):
"""Set the model for PlayerPlaylist to use
This fills playlist model based on the playlist type and model
@@ -296,6 +301,31 @@ class CoreModel(GObject.GObject):
self.emit("playlist-loaded", playlist_type)
+ @GObject.Property(default=None)
+ def active_media(self):
+ return self._active_media
+
+ @active_media.setter
+ def active_media(self, value):
+ self._active_media = value
+ if isinstance(value, CoreAlbum):
+ playlist_type = PlayerPlaylist.Type.ALBUM
+ model = value.props.model
+ elif isinstance(value, CoreArtist):
+ playlist_type = PlayerPlaylist.Type.ARTIST
+ model = value.props.model
+ elif isinstance(value, Playlist):
+ playlist_type = PlayerPlaylist.Type.PLAYLIST
+ model = value.props.model
+ elif self._search.props.search_mode_active:
+ playlist_type = PlayerPlaylist.Type.SEARCH_RESULT
+ model = self._song_search_flatten
+ else:
+ playlist_type = PlayerPlaylist.Type.SONGS
+ model = self._songs_model
+
+ self._set_player_model(playlist_type, model)
+
@GObject.Property(
type=Gio.ListStore, default=None, flags=GObject.ParamFlags.READABLE)
def songs(self):
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index d27c226d..a7c26328 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -751,8 +751,7 @@ class MPRIS(DBusInterface):
loaded_id = self._coremodel.connect(
"playlist-loaded", _on_playlist_loaded)
self._coremodel.props.active_playlist = playlist
- self._coremodel.set_player_model(
- PlayerPlaylist.Type.PLAYLIST, playlist.props.model)
+ self._coremodel.props.active_media = playlist
def _activate_playlist(self, playlist_path):
"""Starts playing the given playlist (MPRIS Method).
diff --git a/gnomemusic/views/searchview.py b/gnomemusic/views/searchview.py
index 1b727e09..4e4e39ce 100644
--- a/gnomemusic/views/searchview.py
+++ b/gnomemusic/views/searchview.py
@@ -249,8 +249,7 @@ class SearchView(Gtk.Stack):
and not self.props.selection_mode):
# self.emit('song-activated', widget)
- self._coremodel.set_player_model(
- PlayerPlaylist.Type.SEARCH_RESULT, self._model)
+ self._coremodel.props.active_media = widget.props.coresong
self._player.play(widget.props.coresong)
# FIXME: Need to ignore the event from the checkbox.
diff --git a/gnomemusic/views/songsview.py b/gnomemusic/views/songsview.py
index 267e39cb..0c5e7b8c 100644
--- a/gnomemusic/views/songsview.py
+++ b/gnomemusic/views/songsview.py
@@ -149,10 +149,9 @@ class SongsView(Gtk.ScrolledWindow):
if self.props.selection_mode:
return
- itr = self._model.get_iter(path)
+ itr = self._songs_view.props.model.get_iter(path)
coresong = self._model[itr][7]
- self._coremodel.set_player_model(
- PlayerPlaylist.Type.SONGS, self._model)
+ self._coremodel.props.active_media = coresong
self._player.play(coresong)
diff --git a/gnomemusic/widgets/albumwidget.py b/gnomemusic/widgets/albumwidget.py
index 635b19cd..8c616a26 100644
--- a/gnomemusic/widgets/albumwidget.py
+++ b/gnomemusic/widgets/albumwidget.py
@@ -167,8 +167,7 @@ class AlbumWidget(Gtk.EventBox):
signal_id = self._coremodel.connect(
"playlist-loaded", _on_playlist_loaded)
- self._coremodel.set_player_model(
- PlayerPlaylist.Type.ALBUM, self._album_model)
+ self._coremodel.props.active_media = self._corealbum
return True
diff --git a/gnomemusic/widgets/artistalbumswidget.py b/gnomemusic/widgets/artistalbumswidget.py
index be262e2b..45330411 100644
--- a/gnomemusic/widgets/artistalbumswidget.py
+++ b/gnomemusic/widgets/artistalbumswidget.py
@@ -74,7 +74,7 @@ class ArtistAlbumsWidget(Gtk.ListBox):
coremodel.disconnect(signal_id)
signal_id = coremodel.connect("playlist-loaded", _on_playlist_loaded)
- coremodel.set_player_model(PlayerPlaylist.Type.ARTIST, self._model)
+ coremodel.props.active_media = self._artist
def _add_album(self, corealbum):
row = Gtk.ListBoxRow()
diff --git a/gnomemusic/widgets/playlistswidget.py b/gnomemusic/widgets/playlistswidget.py
index 084b42e7..8028cb6c 100644
--- a/gnomemusic/widgets/playlistswidget.py
+++ b/gnomemusic/widgets/playlistswidget.py
@@ -119,8 +119,7 @@ class PlaylistsWidget(Gtk.Box):
signal_id = self._coremodel.connect(
"playlist-loaded", _on_playlist_loaded)
self._coremodel.props.active_playlist = current_playlist
- self._coremodel.set_player_model(
- PlayerPlaylist.Type.PLAYLIST, current_playlist.props.model)
+ self._coremodel.props.active_media = current_playlist
def _on_song_widget_moved(self, target, source_position):
target_position = target.get_parent().get_index()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]