[gnome-music/wip/jfelder/simplify-player-model: 2/5] player: Refactor currentTrackUri attribute
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/simplify-player-model: 2/5] player: Refactor currentTrackUri attribute
- Date: Sun, 4 Mar 2018 23:19:15 +0000 (UTC)
commit 031c577e0525da57ee0934848c2c11663f527474
Author: Jean Felder <jfelder src gnome org>
Date: Sat Mar 3 18:22:12 2018 +0100
player: Refactor currentTrackUri attribute
Rename currentTrackUri to _current_track_uri.
Add a getter to _current_track_uri attribute.
Directly set _current_track_uri from load method.
gnomemusic/player.py | 30 ++++++++++++------------------
gnomemusic/views/playlistview.py | 2 +-
gnomemusic/views/songsview.py | 2 +-
3 files changed, 14 insertions(+), 20 deletions(-)
---
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index 7d8be7b..a797c9a 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -109,7 +109,7 @@ class Player(GObject.GObject):
self.playlistId = None
self.playlistField = None
self.currentTrack = None
- self.currentTrackUri = None
+ self._current_track_uri = None
self._missingPluginMessages = []
Gst.init(None)
@@ -143,6 +143,11 @@ class Player(GObject.GObject):
self._lastfm = LastFmScrobbler()
+ @GObject.Property
+ @log
+ def current_track_uri(self):
+ return self._current_track_uri
+
@log
def _on_replaygain_setting_changed(self, settings, value):
self.replaygain = settings.get_value('replaygain') is not None
@@ -357,8 +362,6 @@ class Player(GObject.GObject):
currentTrack = self.playlist.get_path(self.playlist.get_iter_first())
if currentTrack:
self.currentTrack = Gtk.TreeRowReference.new(self.playlist, currentTrack)
- self.currentTrackUri = self.playlist.get_value(
- self.playlist.get_iter(self.currentTrack.get_path()), 5).get_url()
else:
self.currentTrack = None
self.load(self.get_current_media())
@@ -374,9 +377,6 @@ class Player(GObject.GObject):
@log
def _on_glib_idle(self):
self.currentTrack = self.nextTrack
- if self.currentTrack and self.currentTrack.valid():
- self.currentTrackUri = self.playlist.get_value(
- self.playlist.get_iter(self.currentTrack.get_path()), 5).get_url()
self.play()
@log
@@ -593,8 +593,12 @@ class Player(GObject.GObject):
if self.currentTrack and self.currentTrack.valid():
currentTrack = self.playlist.get_iter(self.currentTrack.get_path())
+ uri = self.playlist[currentTrack][self.playlistField].get_url()
+ self._current_track_uri = uri
self.emit('playlist-item-changed', self.playlist, currentTrack)
self.emit('current-changed')
+ else:
+ self._current_track_uri = None
self._validate_next_track()
@@ -687,11 +691,7 @@ class Player(GObject.GObject):
self.stop()
self.currentTrack = self.nextTrack
-
- if self.currentTrack and self.currentTrack.valid():
- self.currentTrackUri = self.playlist.get_value(
- self.playlist.get_iter(self.currentTrack.get_path()), 5).get_url()
- self.play()
+ self.play()
@log
def play_previous(self):
@@ -710,10 +710,7 @@ class Player(GObject.GObject):
self.stop()
self.currentTrack = self._get_previous_track()
- if self.currentTrack and self.currentTrack.valid():
- self.currentTrackUri = self.playlist.get_value(
- self.playlist.get_iter(self.currentTrack.get_path()), 5).get_url()
- self.play()
+ self.play()
@log
def play_pause(self):
@@ -738,9 +735,6 @@ class Player(GObject.GObject):
self.playlistType = type
self.playlistId = id
self.currentTrack = Gtk.TreeRowReference.new(model, model.get_path(iter))
- if self.currentTrack and self.currentTrack.valid():
- self.currentTrackUri = self.playlist.get_value(
- self.playlist.get_iter(self.currentTrack.get_path()), 5).get_url()
self.playlistField = field
self.discovery_status_field = discovery_status_field
diff --git a/gnomemusic/views/playlistview.py b/gnomemusic/views/playlistview.py
index 33c78c6..acc1e37 100644
--- a/gnomemusic/views/playlistview.py
+++ b/gnomemusic/views/playlistview.py
@@ -252,7 +252,7 @@ class PlaylistView(BaseView):
if model[_iter][11] == DiscoveryStatus.FAILED:
cell.set_property('icon-name', self._error_icon_name)
cell.set_visible(True)
- elif model[_iter][5].get_url() == self.player.currentTrackUri:
+ elif model[_iter][5].get_url() == self.player.current_track_uri:
cell.set_property('icon-name', self._now_playing_icon_name)
cell.set_visible(True)
else:
diff --git a/gnomemusic/views/songsview.py b/gnomemusic/views/songsview.py
index c373dd0..dfcd71a 100644
--- a/gnomemusic/views/songsview.py
+++ b/gnomemusic/views/songsview.py
@@ -219,7 +219,7 @@ class SongsView(BaseView):
cell.set_property('text', utils.get_album_title(item))
def _on_list_widget_icon_render(self, col, cell, model, itr, data):
- track_uri = self.player.currentTrackUri
+ track_uri = self.player.current_track_uri
if not track_uri:
cell.set_visible(False)
return
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]