Commit eab5009b authored by Marinus Schraal's avatar Marinus Schraal

coremodel: Flatten the song search model

The idea is to concat several search results. Every source
can provide it's own this way.
parent 2a7ce99b
......@@ -60,8 +60,9 @@ class CoreModel(GObject.GObject):
self._playlist_model = Gio.ListStore.new(CoreSong)
self._playlist_model_sort = Gfm.SortListModel.new(self._playlist_model)
self._song_search_model = Dazzle.ListModelFilter.new(self._model)
self._song_search_model.set_filter_func(lambda a: False)
self._song_search_proxy = Gio.ListStore.new(Gfm.FilterListModel)
self._song_search_flatten = Gfm.FlattenListModel.new(CoreSong)
self._song_search_flatten.set_model(self._song_search_proxy)
self._album_search_model = Dazzle.ListModelFilter.new(
self._album_model)
......@@ -247,17 +248,18 @@ class CoreModel(GObject.GObject):
self.emit("playlist-loaded")
elif playlist_type == PlayerPlaylist.Type.SEARCH_RESULT:
if self._search_signal_id:
self._song_search_model.disconnect(self._search_signal_id)
self._song_search_flatten.disconnect(
self._search_signal_id)
self._playlist_model.remove_all()
for song in self._song_search_model:
for song in self._song_search_flatten:
self._playlist_model.append(song)
if song is coresong:
song.props.state = SongWidget.State.PLAYING
self._search_signal_id = self._song_search_model.connect(
self._search_signal_id = self._song_search_flatten.connect(
"items-changed", _on_items_changed)
self.emit("playlist-loaded")
......@@ -331,7 +333,13 @@ class CoreModel(GObject.GObject):
type=Dazzle.ListModelFilter, default=None,
flags=GObject.ParamFlags.READABLE)
def songs_search(self):
return self._song_search_model
return self._song_search_flatten
@GObject.Property(
type=Gio.ListStore, default=None,
flags=GObject.ParamFlags.READABLE)
def songs_search_proxy(self):
return self._song_search_proxy
@GObject.Property(
type=Dazzle.ListModelFilter, default=None,
......
import gi
gi.require_versions({"Grl": "0.3", 'Tracker': "2.0"})
from gi.repository import Grl, GLib, GObject, Tracker
gi.require_versions({"Gfm": "0.1", "Grl": "0.3", 'Tracker': "2.0"})
from gi.repository import Gfm, Grl, GLib, GObject, Tracker
from gnomemusic.corealbum import CoreAlbum
from gnomemusic.coreartist import CoreArtist
......@@ -43,10 +43,14 @@ class GrlTrackerSource(GObject.GObject):
self._album_ids = {}
self._artists_model = self._coremodel.props.artists
self._hash = {}
self._song_search_model = self._coremodel.props.songs_search
self._song_search_proxy = self._coremodel.props.songs_search_proxy
self._album_search_model = self._coremodel.props.albums_search
self._artist_search_model = self._coremodel.props.artists_search
self._song_search_tracker = Gfm.FilterListModel.new(self._model)
self._song_search_tracker.set_filter_func(lambda a: False)
self._song_search_proxy.append(self._song_search_tracker)
self._fast_options = Grl.OperationOptions()
self._fast_options.set_resolution_flags(
Grl.ResolutionFlags.FAST_ONLY | Grl.ResolutionFlags.IDLE_RELAY)
......@@ -526,7 +530,7 @@ class GrlTrackerSource(GObject.GObject):
return
if not media:
self._song_search_model.set_filter_func(songs_filter)
self._song_search_tracker.set_filter_func(songs_filter)
return
filter_ids.append(media.get_id())
......
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