[gnome-music/wip/jfelder/new-album-design-v3: 6/10] corealbum: Add a release-info property
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/new-album-design-v3: 6/10] corealbum: Add a release-info property
- Date: Fri, 30 Jul 2021 15:49:25 +0000 (UTC)
commit 0c46b72db8c771189901f9f718ae231cde6bd230
Author: Jean Felder <jfelder src gnome org>
Date: Sat Nov 21 00:22:57 2020 +0100
corealbum: Add a release-info property
This contains the publication year and the duration of an album. It
will be used in the following to port AlbumWidget and
ArtistAlbumWidget to the new design.
gnomemusic/corealbum.py | 27 +++++++++++++++++++++++++++
po/POTFILES.in | 1 +
2 files changed, 28 insertions(+)
---
diff --git a/gnomemusic/corealbum.py b/gnomemusic/corealbum.py
index 9ce98772a..a104b740e 100644
--- a/gnomemusic/corealbum.py
+++ b/gnomemusic/corealbum.py
@@ -22,6 +22,11 @@
# 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 __future__ import annotations
+
+from gettext import ngettext
+from typing import Optional
+
import gi
gi.require_versions({"Gfm": "0.1", "Grl": "0.3"})
from gi.repository import Gfm, Gio, Grl, GObject
@@ -54,9 +59,12 @@ class CoreAlbum(GObject.GObject):
self._application = application
self._coregrilo = application.props.coregrilo
self._model = None
+ self._release_info = ""
self._selected = False
self._thumbnail = None
+ self.connect("notify::year", self._on_release_info_changed)
+
self.update(media)
def update(self, media):
@@ -114,6 +122,7 @@ class CoreAlbum(GObject.GObject):
duration += coredisc.props.duration
self.props.duration = duration
+ self._on_release_info_changed(self, None)
@GObject.Property(type=bool, default=False)
def selected(self):
@@ -153,3 +162,21 @@ class CoreAlbum(GObject.GObject):
:param string value: uri or "generic"
"""
self._thumbnail = value
+
+ def _on_release_info_changed(
+ self, klass: CoreAlbum,
+ value: Optional[GObject.ParamSpecString]) -> None:
+ mins = (self.props.duration // 60) + 1
+ year = self.props.year
+ self._release_info = ngettext(
+ "{}, {} minute", "{}, {} minutes", mins).format(year, mins)
+ self.notify("release-info")
+
+ @GObject.Property(type=str, default="", flags=GObject.ParamFlags.READABLE)
+ def release_info(self) -> str:
+ """Get release info (year and duration) as string
+
+ :return: The release info
+ :rtype: str
+ """
+ return self._release_info
diff --git a/po/POTFILES.in b/po/POTFILES.in
index c88c5b2cc..50b80c21a 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -21,6 +21,7 @@ data/ui/SelectionBarMenuButton.ui
data/ui/SelectionToolbar.ui
gnomemusic/__init__.py
gnomemusic/application.py
+gnomemusic/corealbum.py
gnomemusic/grilowrappers/grltrackerplaylists.py
gnomemusic/gstplayer.py
gnomemusic/inhibitsuspend.py
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]