Skip to content

Commit

Permalink
If restore_play_state is active (#828)
Browse files Browse the repository at this point in the history
* If restore_play_state is active
* won't start with an empty queue
* won't select the last played song in a playlist with more than 500 tracks
  • Loading branch information
luzip665 committed Oct 10, 2022
1 parent 52c671c commit a089e63
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion xl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ def __init(self):
)

if self.gui:
self.gui.get_playlist_container().show_current_track()
GLib.idle_add(self.gui.get_playlist_container().show_current_track)

# pylint: enable-msg=W0201

Expand Down
5 changes: 3 additions & 2 deletions xlgui/playlist_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,9 @@ def show_current_track(self):
continue

self.set_current_page(n)
page.view.scroll_to_cell(page.playlist.current_position)
page.view.set_cursor(page.playlist.current_position)
if page.playlist.current_position > -1:
page.view.scroll_to_cell(page.playlist.current_position)
page.view.set_cursor(page.playlist.current_position)
return True

def on_page_added(self, notebook, child, page_number):
Expand Down
13 changes: 12 additions & 1 deletion xlgui/widgets/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -1177,12 +1177,23 @@ def _refresh_columns(self):

def _setup_models(self):
self.model = PlaylistModel(self.playlist, [], self.player, self)
self.model.connect('row-inserted', self.on_row_inserted)
self.__setup_model_hook = self.model.connect(
'data-loading', self._on_after_model_loading
)

self.modelfilter = self.model.filter_new()
self.modelfilter.set_visible_func(self._modelfilter_visible_func)
self.set_model(self.modelfilter)

def _on_after_model_loading(self, ar1, now_loading):
"""
This is necessary to ensure that row-insert is connected after the initial loading
due to threaded PlaylistModel::_load_data_thread and playlists greater than 500 tracks
"""
if not now_loading:
self.model.connect('row-inserted', self.on_row_inserted)
self.model.disconnect(self.__setup_model_hook)

def _modelfilter_visible_func(self, model, iter, data):
if self._filter_matcher is not None:
track = model.get_value(iter, 0)
Expand Down

0 comments on commit a089e63

Please sign in to comment.