Commit 41c60ec7 authored by Marinus Schraal's avatar Marinus Schraal

grltrackerplaylists: Bind playlist songs to main coresong

Playlist songs do not receive change notifications as they are created
as separate CoreSong's from the main song model.

To fix this, create a binding for all properties between the main
CoreSong and the Playlist equivalent.
parent 5f982488
......@@ -55,7 +55,8 @@ class GrlTrackerPlaylists(GObject.GObject):
]
def __init__(
self, source, coremodel, application, grilo, tracker_wrapper):
self, source, coremodel, application, grilo, tracker_wrapper,
songs_hash):
"""Initialize GrlTrackerPlaylists.
:param Grl.TrackerSource source: The Tracker source to wrap
......@@ -78,6 +79,7 @@ class GrlTrackerPlaylists(GObject.GObject):
self._model_filter = self._coremodel.props.playlists_filter
self._user_model_filter = self._coremodel.props.user_playlists_filter
self._pls_todelete = []
self._songs_hash = songs_hash
self._tracker = tracker_wrapper.props.tracker
self._tracker_wrapper = tracker_wrapper
self._window = application.props.window
......@@ -95,7 +97,8 @@ class GrlTrackerPlaylists(GObject.GObject):
"source": self._source,
"application": self._application,
"grilo": self._grilo,
"tracker_wrapper": self._tracker_wrapper
"tracker_wrapper": self._tracker_wrapper,
"songs_hash": self._songs_hash
}
smart_playlists = {
......@@ -149,7 +152,7 @@ class GrlTrackerPlaylists(GObject.GObject):
playlist = Playlist(
media=media, source=self._source, coremodel=self._coremodel,
application=self._application, grilo=self._grilo,
tracker_wrapper=self._tracker_wrapper)
tracker_wrapper=self._tracker_wrapper, songs_hash=self._songs_hash)
self._model.append(playlist)
callback = data
......@@ -306,7 +309,7 @@ class Playlist(GObject.GObject):
def __init__(
self, media=None, query=None, tag_text=None, source=None,
coremodel=None, application=None, grilo=None,
tracker_wrapper=None):
tracker_wrapper=None, songs_hash=None):
super().__init__()
"""Initialize a playlist
......@@ -338,6 +341,7 @@ class Playlist(GObject.GObject):
self._coreselection = application.props.coreselection
self._grilo = grilo
self._log = application.props.log
self._songs_hash = songs_hash
self._tracker = tracker_wrapper.props.tracker
self._tracker_wrapper = tracker_wrapper
self._window = application.props.window
......@@ -412,6 +416,7 @@ class Playlist(GObject.GObject):
return
coresong = CoreSong(media, self._coreselection, self._grilo)
self._bind_to_main_song(coresong)
if coresong not in self._songs_todelete:
self._model.append(coresong)
......@@ -422,6 +427,20 @@ class Playlist(GObject.GObject):
self._source.query(
query, self.METADATA_KEYS, options, _add_to_playlist_cb, None)
def _bind_to_main_song(self, coresong):
main_coresong = self._songs_hash[coresong.props.media.get_id()]
properties = [
"album", "album_disc_number", "artist", "duration", "media",
"grlid", "play_count", "state", "title", "track_number", "url",
"validation", "favorite", "selected"]
for prop in properties:
main_coresong.bind_property(
prop, coresong, prop,
GObject.BindingFlags.BIDIRECTIONAL
| GObject.BindingFlags.SYNC_CREATE)
@GObject.Property(type=str, default=None)
def title(self):
"""Playlist title
......@@ -584,6 +603,7 @@ class Playlist(GObject.GObject):
return
coresong = CoreSong(media, self._coreselection, self._grilo)
self._bind_to_main_song(coresong)
if coresong not in self._songs_todelete:
self._model.append(coresong)
......@@ -734,6 +754,7 @@ class SmartPlaylist(Playlist):
return
coresong = CoreSong(media, self._coreselection, self._grilo)
self._bind_to_main_song(coresong)
self._model.append(coresong)
options = self._fast_options.copy()
......@@ -785,6 +806,7 @@ class SmartPlaylist(Playlist):
for idx, media in enumerate(new_model_medias):
if media.get_id() not in current_models_ids:
coresong = CoreSong(media, self._coreselection, self._grilo)
self._bind_to_main_song(coresong)
self._model.append(coresong)
self.props.count += 1
......
......@@ -74,6 +74,7 @@ class GrlTrackerWrapper(GObject.GObject):
"""
super().__init__()
self._application = application
self._coremodel = coremodel
self._coreselection = application.props.coreselection
self._grilo = grilo
......@@ -90,6 +91,7 @@ class GrlTrackerWrapper(GObject.GObject):
self._artist_search_model = self._coremodel.props.artists_search
self._batch_changed_media_ids = {}
self._content_changed_timeout = None
self._tracker_playlists = None
self._tracker_wrapper = tracker_wrapper
self._window = application.props.window
......@@ -108,9 +110,6 @@ class GrlTrackerWrapper(GObject.GObject):
self._initial_albums_fill(self.props.source)
self._initial_artists_fill(self.props.source)
self._tracker_playlists = GrlTrackerPlaylists(
source, coremodel, application, grilo, tracker_wrapper)
@GObject.Property(type=Grl.Source, default=None)
def source(self):
return self._source
......@@ -383,6 +382,14 @@ class GrlTrackerWrapper(GObject.GObject):
if not media:
self._model.splice(self._model.get_n_items(), 0, songs_added)
self._window.notifications_popup.pop_loading()
# Initialize the playlists subwrapper after the initial
# songs model fill, the playlists expect a filled songs
# hashtable.
self._tracker_playlists = GrlTrackerPlaylists(
self.props.source, self._coremodel, self._application,
self._grilo, self._tracker_wrapper, self._hash)
return
song = CoreSong(media, self._coreselection, self._grilo)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment