Commit 88ae0c93 authored by Jean Felder's avatar Jean Felder Committed by Marinus Schraal

coremodel: Remove coresong parameter from set_playlist_model

Fix the play_plause method (the song is not restarted anymore).
parent 4250dc0f
......@@ -151,7 +151,7 @@ class CoreModel(GObject.GObject):
return albums_model_sort
def set_playlist_model(self, playlist_type, coresong, model):
def set_playlist_model(self, playlist_type, model):
def _on_items_changed(model, position, removed, added):
if removed > 0:
......@@ -195,10 +195,6 @@ class CoreModel(GObject.GObject):
"state", model_song, "state",
GObject.BindingFlags.SYNC_CREATE)
song_id = coresong.props.media.get_id()
if song.props.media.get_id() == song_id:
song.props.state = SongWidget.State.PLAYING
self.emit("playlist-loaded")
elif playlist_type == PlayerPlaylist.Type.ARTIST:
self._playlist_model.remove_all()
......@@ -222,10 +218,6 @@ class CoreModel(GObject.GObject):
"state", model_song, "state",
GObject.BindingFlags.SYNC_CREATE)
song_id = coresong.props.media.get_id()
if song.props.media.get_id() == song_id:
song.props.state = SongWidget.State.PLAYING
self.emit("playlist-loaded")
elif playlist_type == PlayerPlaylist.Type.SONGS:
if self._song_signal_id:
......@@ -239,8 +231,6 @@ class CoreModel(GObject.GObject):
if song.props.state == SongWidget.State.PLAYING:
song.props.state = SongWidget.State.PLAYED
if song is coresong:
song.props.state = SongWidget.State.PLAYING
self._song_signal_id = self._songliststore.props.model.connect(
"items-changed", _on_items_changed)
......@@ -256,9 +246,6 @@ class CoreModel(GObject.GObject):
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_flatten.connect(
"items-changed", _on_items_changed)
......@@ -276,9 +263,6 @@ class CoreModel(GObject.GObject):
self._playlist_model.append(song)
if model_song is coresong:
song.props.state = SongWidget.State.PLAYING
song.bind_property(
"state", model_song, "state",
GObject.BindingFlags.SYNC_CREATE)
......
......@@ -24,7 +24,7 @@
from enum import IntEnum
from itertools import chain
from random import randint
from random import randint, randrange
import logging
import time
......@@ -272,6 +272,31 @@ class PlayerPlaylist(GObject.GObject):
return None
def set_song(self, song):
"""Sets current song.
If no song is provided, a song is automatically selected.
:param CoreSong song: song to set
:returns: The selected song
:rtype: CoreSong
"""
if song is None:
if self.props.repeat_mode == RepeatMode.SHUFFLE:
position = randrange(0, self._model.get_n_items())
else:
position = 0
song = self._model.get_item(position)
song.props.state = SongWidget.State.PLAYING
return song
for coresong in self._model:
if coresong == song:
coresong.props.state = SongWidget.State.PLAYING
return song
return None
@log
def _on_repeat_mode_changed(self, klass, param):
......@@ -499,12 +524,10 @@ class Player(GObject.GObject):
:param bool song_changed: indicate if a new song must be loaded
"""
if self.props.current_song is None:
return
if coresong is None:
coresong = self._playlist.props.current_song
coresong = self._playlist.set_song(coresong)
self._load(coresong)
if coresong is not None:
self._load(coresong)
self._gst_player.props.state = Playback.PLAYING
......
......@@ -22,14 +22,12 @@
# code, but you are not obligated to do so. If you do not wish to do so,
# delete this exception statement from your version.
from random import randrange
from gettext import gettext as _
from gi.repository import Gdk, GObject, Gio, Gtk
from gnomemusic import log
from gnomemusic.player import PlayerPlaylist, RepeatMode
from gnomemusic.player import PlayerPlaylist
from gnomemusic.views.baseview import BaseView
from gnomemusic.widgets.notificationspopup import PlaylistNotification
from gnomemusic.widgets.playlistcontextmenu import PlaylistContextMenu
......@@ -226,20 +224,13 @@ class PlaylistsView(BaseView):
return song_widget
def _song_activated(self, widget=None, event=None):
# FIXME: Selection should be automatic in the player
coresong = None
if widget is not None:
coresong = widget.props.coresong
else:
position = 0
if self.player.props.repeat_mode == RepeatMode.SHUFFLE:
position = randrange(
0, self._current_playlist.props.model.get_n_items())
coresong = self._current_playlist.props.model.get_item(position)
self._coremodel.set_playlist_model(
PlayerPlaylist.Type.PLAYLIST, coresong,
self._current_playlist.props.model)
self.player.play()
PlayerPlaylist.Type.PLAYLIST, self._current_playlist.props.model)
self.player.play(coresong)
return True
......
......@@ -160,9 +160,8 @@ class SearchView(BaseView):
# self.emit('song-activated', widget)
self._coremodel.set_playlist_model(
PlayerPlaylist.Type.SEARCH_RESULT, widget.props.coresong,
self._model)
self.player.play()
PlayerPlaylist.Type.SEARCH_RESULT, self._model)
self.player.play(widget.props.coresong)
# FIXME: Need to ignore the event from the checkbox.
# if self.props.selection_mode:
......
......@@ -209,8 +209,9 @@ class SongsView(BaseView):
itr = self._view.props.model.get_iter(path)
coresong = self._view.props.model[itr][5]
self._window._app._coremodel.set_playlist_model(
PlayerPlaylist.Type.SONGS, coresong, self._view.props.model)
self.player.play()
PlayerPlaylist.Type.SONGS, self._view.props.model)
self.player.play(coresong)
@log
def _on_view_clicked(self, gesture, n_press, x, y):
......
......@@ -168,8 +168,7 @@ class AlbumWidget(Gtk.EventBox):
signal_id = coremodel.connect("playlist-loaded", _on_playlist_loaded)
coremodel.set_playlist_model(
PlayerPlaylist.Type.ALBUM, song_widget.props.coresong,
self._album_model)
PlayerPlaylist.Type.ALBUM, self._album_model)
return True
......
......@@ -111,9 +111,7 @@ class ArtistAlbumsWidget(Gtk.Box):
coremodel.disconnect(signal_id)
signal_id = coremodel.connect("playlist-loaded", _on_playlist_loaded)
coremodel.set_playlist_model(
PlayerPlaylist.Type.ARTIST, song_widget.props.coresong,
self._model)
coremodel.set_playlist_model(PlayerPlaylist.Type.ARTIST, self._model)
def _add_album(self, corealbum):
widget = ArtistAlbumWidget(
......
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