[gnome-music/wip/mschraal/core: 32/42] albumwidget2: Fix selection mode



commit 64672d5b7f77fabb89a3a81ac2c5270d6206d8fe
Author: Marinus Schraal <mschraal gnome org>
Date:   Thu May 9 17:39:24 2019 +0200

    albumwidget2: Fix selection mode

 gnomemusic/coresong.py             |  1 +
 gnomemusic/views/albumsview.py     |  2 +-
 gnomemusic/widgets/albumwidget2.py | 51 +++++++++++++++++++++-----------------
 3 files changed, 30 insertions(+), 24 deletions(-)
---
diff --git a/gnomemusic/coresong.py b/gnomemusic/coresong.py
index 577b05e0..8e47f67d 100644
--- a/gnomemusic/coresong.py
+++ b/gnomemusic/coresong.py
@@ -16,6 +16,7 @@ class CoreSong(GObject.GObject):
     artist = GObject.Property(type=str)
     duration = GObject.Property(type=int)
     play_count = GObject.Property(type=int)
+    selected = GObject.Property(type=bool, default=False)
     title = GObject.Property(type=str)
     track_number = GObject.Property(type=int)
     url = GObject.Property(type=str)
diff --git a/gnomemusic/views/albumsview.py b/gnomemusic/views/albumsview.py
index 564d49e3..9dd30a6c 100644
--- a/gnomemusic/views/albumsview.py
+++ b/gnomemusic/views/albumsview.py
@@ -129,7 +129,7 @@ class AlbumsView(BaseView):
         # FIXME: we call into private objects with full knowledge of
         # what is there
         if self._headerbar.props.state == HeaderBar.State.CHILD:
-            callback(self._album_widget._disc_listbox.get_selected_items())
+            callback(self._album_widget.get_selected_songs())
         else:
             self.items_selected = []
             self.items_selected_callback = callback
diff --git a/gnomemusic/widgets/albumwidget2.py b/gnomemusic/widgets/albumwidget2.py
index b487aec4..c1cdeb6e 100644
--- a/gnomemusic/widgets/albumwidget2.py
+++ b/gnomemusic/widgets/albumwidget2.py
@@ -90,10 +90,8 @@ class AlbumWidget2(Gtk.EventBox):
         self._set_composer_label(album)
 
         self._album = album
-
-        self._listbox.bind_model(
-            self._parent_view._window._app._coremodel.get_album_model(album),
-            self._create_widget)
+        self._model = self._parent_view._window._app._coremodel.get_album_model(album)
+        self._listbox.bind_model(self._model, self._create_widget)
 
     @log
     def _create_widget(self, song):
@@ -103,6 +101,15 @@ class AlbumWidget2(Gtk.EventBox):
             "favorite", song_widget, "favorite",
             GObject.BindingFlags.BIDIRECTIONAL
             | GObject.BindingFlags.SYNC_CREATE)
+        song.bind_property(
+            "selected", song_widget, "selected",
+            GObject.BindingFlags.BIDIRECTIONAL
+            | GObject.BindingFlags.SYNC_CREATE)
+
+        self.bind_property(
+            "selection-mode", song_widget, "selection-mode")
+
+        song.connect("notify::selected", self._on_selection_changed)
 
         return song_widget
 
@@ -126,24 +133,14 @@ class AlbumWidget2(Gtk.EventBox):
         self._running_info_label.props.label = ngettext(
             "{} minute", "{} minutes", mins).format(mins)
 
-    # @Gtk.Template.Callback()
     @log
-    def _on_selection_changed(self, widget):
-        n_items = len(self._disc_listbox.get_selected_items())
-        self.props.selected_items_count = n_items
+    def _on_selection_changed(self, klass, value):
+        n_items = 0
+        for song in self._model:
+            if song.props.selected:
+                n_items += 1
 
-    @log
-    def _create_disc_box(self, disc_nr, disc_songs):
-        disc_box = DiscBox(self._model)
-        disc_box.set_songs(disc_songs)
-        disc_box.set_disc_number(disc_nr)
-        disc_box.props.columns = 1
-        disc_box.props.show_durations = True
-        disc_box.props.show_favorites = True
-        disc_box.props.show_song_numbers = False
-        disc_box.connect('song-activated', self._song_activated)
-
-        return disc_box
+        self.props.selected_items_count = n_items
 
     @log
     def _song_activated(self, widget, song_widget):
@@ -159,11 +156,13 @@ class AlbumWidget2(Gtk.EventBox):
 
     @log
     def select_all(self):
-        pass
+        for song in self._model:
+            song.props.selected = True
 
     @log
     def select_none(self):
-        pass
+        for song in self._model:
+            song.props.selected = False
 
     @log
     def get_selected_songs(self):
@@ -172,7 +171,13 @@ class AlbumWidget2(Gtk.EventBox):
         :returns: selected songs
         :rtype: list
         """
-        return []
+        selected_songs = []
+
+        for song in self._model:
+            if song.props.selected:
+                selected_songs.append(song._media)
+
+        return selected_songs
 
     @GObject.Property(
         type=Grl.Media, default=False, flags=GObject.ParamFlags.READABLE)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]