diff --git a/gnomemusic/widgets/albumwidget.py b/gnomemusic/widgets/albumwidget.py index fe9f5aedc4895f75386dd3135fca5142e0c52639..e0b324fdfec91342577f397ffce984a6ab28313a 100644 --- a/gnomemusic/widgets/albumwidget.py +++ b/gnomemusic/widgets/albumwidget.py @@ -53,6 +53,21 @@ class AlbumWidget(Gtk.EventBox): """ super().__init__() + self._model = Gtk.ListStore( + GObject.TYPE_STRING, # title + GObject.TYPE_STRING, + GObject.TYPE_STRING, + GObject.TYPE_STRING, + GdkPixbuf.Pixbuf, # icon + GObject.TYPE_OBJECT, # song object + GObject.TYPE_BOOLEAN, # item selected + GObject.TYPE_STRING, + GObject.TYPE_BOOLEAN, + GObject.TYPE_INT, # icon shown + GObject.TYPE_BOOLEAN, + GObject.TYPE_INT + ) + self._songs = [] self._player = player @@ -62,7 +77,6 @@ class AlbumWidget(Gtk.EventBox): self._builder = Gtk.Builder() self._builder.add_from_resource('/org/gnome/Music/AlbumWidget.ui') - self._create_model() self._album = None self._header_bar = None self._selection_mode_allowed = True @@ -100,24 +114,6 @@ class AlbumWidget(Gtk.EventBox): """Selection mode toggled.""" self._header_bar._select_button.clicked() - @log - def _create_model(self): - """Create the ListStore model for this widget.""" - self._model = Gtk.ListStore( - GObject.TYPE_STRING, # title - GObject.TYPE_STRING, - GObject.TYPE_STRING, - GObject.TYPE_STRING, - GdkPixbuf.Pixbuf, # icon - GObject.TYPE_OBJECT, # song object - GObject.TYPE_BOOLEAN, # item selected - GObject.TYPE_STRING, - GObject.TYPE_BOOLEAN, - GObject.TYPE_INT, # icon shown - GObject.TYPE_BOOLEAN, - GObject.TYPE_INT - ) - @log def update(self, artist, album, item, header_bar, selection_toolbar): """Update the album widget. @@ -130,7 +126,7 @@ class AlbumWidget(Gtk.EventBox): """ # reset view self._songs = [] - self._create_model() + self._model.clear() for widget in self._disc_listbox.get_children(): self._disc_listbox.remove(widget) @@ -247,6 +243,12 @@ class AlbumWidget(Gtk.EventBox): self._player.set_playing(True) return True + @log + def _set_duration_label(self): + duration = self._duration // 60 + 1 + self._builder.get_object('running_length_label_info').set_text( + _("%d min") % duration) + @log def add_item(self, source, prefs, song, remaining, data=None): """Add a song to the item to album list. @@ -277,9 +279,13 @@ class AlbumWidget(Gtk.EventBox): disc.show_disc_label(False) if remaining == 0: - self._builder.get_object('running_length_label_info').set_text( - _("%d min") % (int(self._duration / 60) + 1)) - + if self._player.running_playlist('Album', self._album): + current_path = self._player.currentTrack.get_path() + current_track = self._player.playlist.get_iter(current_path) + self._update_model( + self._player, self._player.playlist, current_track) + else: + self._set_duration_label() self.show_all() @log @@ -298,16 +304,15 @@ class AlbumWidget(Gtk.EventBox): self._duration = 0 song_passed = False - _iter = playlist.get_iter_first() + _iter = self._model.get_iter_first() while _iter: - song = playlist[_iter][player.Field.SONG] + song = self._model[_iter][5] song_widget = song.song_widget self._duration += song.get_duration() escaped_title = GLib.markup_escape_text( utils.get_media_title(song)) - - if (song == current_song): + if song.get_id() == current_song.get_id(): song_widget.now_playing_sign.show() song_widget.title.set_markup("{}".format(escaped_title)) song_passed = True @@ -320,10 +325,9 @@ class AlbumWidget(Gtk.EventBox): song_widget.title.set_markup( "{}".format(escaped_title)) - _iter = playlist.iter_next(_iter) + _iter = self._model.iter_next(_iter) - self._builder.get_object('running_length_label_info').set_text( - _("%d min") % (int(self._duration / 60) + 1)) + self._set_duration_label() return True