Commit 7774bcf3 authored by Jean Felder's avatar Jean Felder Committed by Jean Felder

widgets: Use utils functions

Create a new utils function get_media_year to get the creation year of
a media.
parent dd603b20
......@@ -87,6 +87,21 @@ def get_media_title(item):
or _("Untitled"))
def get_media_year(item):
"""Returns the year when the media was created.
:param item: A Grilo Media object
:return: The creation year or None if not defined
:rtype: string
"""
date = item.get_creation_date()
if not date:
return None
return str(date.get_year())
def seconds_to_string(duration):
"""Convert a time in seconds to a mm:ss string
......
......@@ -106,15 +106,12 @@ class AlbumsView(BaseView):
child.check.set_active(not child.check.get_active())
return
title = utils.get_media_title(item)
artist = utils.get_artist_name(item)
self._album_widget.update(
artist, title, item, self._header_bar, self._selection_toolbar)
item, self._header_bar, self._selection_toolbar)
self._header_bar.set_state(ToolbarState.CHILD_VIEW)
self._header_bar.header_bar.set_title(title)
self._header_bar.header_bar.set_subtitle(artist)
self._header_bar.header_bar.set_title(utils.get_album_title(item))
self._header_bar.header_bar.set_subtitle(utils.get_artist_name(item))
self.set_visible_child(self._album_widget)
@log
......
......@@ -118,7 +118,7 @@ class SearchView(BaseView):
item = self.model[_iter][5]
self._album_widget.update(
artist, title, item, self._header_bar, self._selection_toolbar)
item, self._header_bar, self._selection_toolbar)
self._header_bar.set_state(ToolbarState.SEARCH_VIEW)
self._header_bar.header_bar.set_title(title)
......
......@@ -120,11 +120,9 @@ class AlbumWidget(Gtk.EventBox):
)
@log
def update(self, artist, album, item, header_bar, selection_toolbar):
def update(self, item, header_bar, selection_toolbar):
"""Update the album widget.
:param str artist: The artist name
:param str album: The album name
:param item: The grilo media item
:param header_bar: The header bar object
:param selection_toolbar: The selection toolbar object
......@@ -137,7 +135,6 @@ class AlbumWidget(Gtk.EventBox):
self.selection_toolbar = selection_toolbar
self._header_bar = header_bar
self._album = album
self._duration = 0
art = ArtImage(Art.Size.LARGE, item)
art.image = self._builder.get_object('cover')
......@@ -148,17 +145,15 @@ class AlbumWidget(Gtk.EventBox):
header_bar._cancel_button.connect(
'clicked', self._on_header_cancel_button_clicked)
# FIXME: use utils
escaped_artist = GLib.markup_escape_text(artist)
escaped_album = GLib.markup_escape_text(album)
self._builder.get_object('artist_label').set_markup(escaped_artist)
self._builder.get_object('title_label').set_markup(escaped_album)
self._album = utils.get_album_title(item)
self._builder.get_object('artist_label').set_text(
utils.get_artist_name(item))
self._builder.get_object('title_label').set_text(self._album)
if (item.get_creation_date()):
self._builder.get_object('released_label_info').set_text(
str(item.get_creation_date().get_year()))
else:
self._builder.get_object('released_label_info').set_text('----')
year = utils.get_media_year(item)
if not year:
year = '----'
self._builder.get_object('released_label_info').set_text(year)
self._set_composer_label(item)
......
......@@ -78,9 +78,8 @@ class ArtistAlbumWidget(Gtk.Box):
self._selection_mode_allowed)
ui.get_object('title').set_label(self._album_title)
creation_date = self._media.get_creation_date()
if creation_date:
year = creation_date.get_year()
year = utils.get_media_year(self._media)
if year:
ui.get_object('year').set_markup(
'<span color=\'grey\'>{}</span>'.format(year))
......
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