[gnome-music/wip/mschraal/grltrackerplaylists-remove-requery: 1/4] coresong: Add last-played property
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/grltrackerplaylists-remove-requery: 1/4] coresong: Add last-played property
- Date: Wed, 1 Jun 2022 09:58:58 +0000 (UTC)
commit 05bbd46ac0be01ef32bdbf9cc8715e0e415cbefe
Author: Marinus Schraal <mschraal gnome org>
Date: Wed Jun 1 09:56:08 2022 +0200
coresong: Add last-played property
Replace the set_last_played function with a property.
gnomemusic/coresong.py | 29 +++++++++++++++++++++++++++--
gnomemusic/player.py | 4 ++--
2 files changed, 29 insertions(+), 4 deletions(-)
---
diff --git a/gnomemusic/coresong.py b/gnomemusic/coresong.py
index 585f28e8d..4df97c35d 100644
--- a/gnomemusic/coresong.py
+++ b/gnomemusic/coresong.py
@@ -117,6 +117,29 @@ class CoreSong(GObject.GObject):
self._coregrilo.writeback_tracker(
self.props.media, "favorite")
+ @GObject.Property(type=GLib.DateTime, default=None)
+ def last_played(self) -> Optional[GLib.DateTime]:
+ """Get last played time
+
+ :returns: Last played date time
+ :rtype: GLib.DateTime
+ """
+ return self.props.media.get_last_played()
+
+ @last_played.setter # type: ignore
+ def last_played(self, value: Optional[GLib.DateTime]) -> None:
+ """Set last played time
+
+ :param GLib.DateTime value: The datetime to set
+ """
+ if value is None:
+ return
+
+ self.props.media.set_last_played(value)
+
+ if self._is_tracker:
+ self._coregrilo.writeback_tracker(self.props.media, "last-played")
+
@GObject.Property(type=bool, default=False)
def selected(self) -> bool:
return self._selected
@@ -163,6 +186,7 @@ class CoreSong(GObject.GObject):
self.props.artist = utils.get_artist_name(media)
self.props.duration = media.get_duration()
self.props.favorite = media.get_favourite()
+ self.props.last_played = media.get_last_played()
self.props.play_count = media.get_play_count()
self.props.title = utils.get_media_title(media)
self.props.track_number = media.get_track_number()
@@ -176,11 +200,12 @@ class CoreSong(GObject.GObject):
self._coregrilo.writeback_tracker(
self.props.media, "play-count")
- def set_last_played(self) -> None:
+ def set_last_played(
+ self, dt: GLib.DateTime = GLib.DateTime.new_now_utc()) -> None:
if not self._is_tracker:
return
- self.props.media.set_last_played(GLib.DateTime.new_now_utc())
+ self.props.media.set_last_played(dt)
self._coregrilo.writeback_tracker(
self.props.media, "last-played")
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index c0c2fa961..e3652ccd8 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -30,7 +30,7 @@ import typing
import gi
gi.require_version('GstPbutils', '1.0')
-from gi.repository import GObject, GstPbutils, Gtk
+from gi.repository import GLib, GObject, GstPbutils, Gtk
from gnomemusic.coresong import CoreSong
from gnomemusic.gstplayer import GstPlayer, Playback
@@ -598,7 +598,7 @@ class Player(GObject.GObject):
# FIXME: Not using Playlist class anymore.
# playlists.update_all_smart_playlists()
current_song.bump_play_count()
- current_song.set_last_played()
+ current_song.props.last_played = GLib.DateTime.new_now_utc()
@GObject.Property(type=object)
def repeat_mode(self) -> RepeatMode:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]