[gnome-music/wip/jfelder/core-restore-player-validation: 4/7] songliststore: Remove unused columns and reorder them



commit 0df0fad5e46217410c5c26516ac3d20597c13af4
Author: Jean Felder <jfelder src gnome org>
Date:   Sun Jul 14 12:11:10 2019 +0200

    songliststore: Remove unused columns and reorder them
    
    The columns are now ordered the same way they are displayed.

 gnomemusic/songliststore.py             | 30 ++++++++++---------
 gnomemusic/views/baseview.py            |  2 +-
 gnomemusic/views/songsview.py           | 51 ++++++++++-----------------------
 gnomemusic/widgets/starhandlerwidget.py |  2 +-
 4 files changed, 33 insertions(+), 52 deletions(-)
---
diff --git a/gnomemusic/songliststore.py b/gnomemusic/songliststore.py
index 10b5a130..a460aeb0 100644
--- a/gnomemusic/songliststore.py
+++ b/gnomemusic/songliststore.py
@@ -1,6 +1,8 @@
-from gi.repository import Gfm, Gio, GObject, Gtk, GdkPixbuf
+from gi.repository import Gfm, Gio, GObject, Gtk
 from gi._gi import pygobject_new_full
 
+import gnomemusic.utils as utils
+
 
 class SongListStore(Gtk.ListStore):
 
@@ -12,18 +14,16 @@ class SongListStore(Gtk.ListStore):
             self._wrap_list_store_sort_func(self._songs_sort))
 
         self.set_column_types([
-            GObject.TYPE_STRING,
-            GObject.TYPE_STRING,
+            GObject.TYPE_STRING,    # play or invalid icon
+            GObject.TYPE_BOOLEAN,   # selected
             GObject.TYPE_STRING,    # title
             GObject.TYPE_STRING,    # artist
-            GdkPixbuf.Pixbuf,       # album art
-            GObject.TYPE_OBJECT,    # Grl.Media
-            GObject.TYPE_BOOLEAN,   # selected
-            GObject.TYPE_INT,
-            GObject.TYPE_STRING,    # play icon (?)
+            GObject.TYPE_STRING,    # album
+            GObject.TYPE_STRING,    # duration
             GObject.TYPE_INT,       # favorite
+            GObject.TYPE_OBJECT,    # coresong
+            GObject.TYPE_INT,       # validation
             GObject.TYPE_BOOLEAN,   # iter_to_clean
-            GObject.TYPE_INT        # validation
         ])
 
         self._model.connect("items-changed", self._on_items_changed)
@@ -62,17 +62,19 @@ class SongListStore(Gtk.ListStore):
         if added > 0:
             for i in list(range(added)):
                 coresong = model[position]
+                time = utils.seconds_to_string(coresong.props.duration)
                 self.insert_with_valuesv(
-                    position, [2, 3, 5, 9],
-                    [coresong.props.title, coresong.props.artist, coresong,
-                     int(coresong.props.favorite)])
+                    position, [2, 3, 4, 5, 6, 7],
+                    [coresong.props.title, coresong.props.artist,
+                     coresong.props.album, time,
+                     int(coresong.props.favorite), coresong])
                 coresong.connect(
                     "notify::favorite", self._on_favorite_changed)
 
     def _on_favorite_changed(self, coresong, value):
         for row in self:
-            if coresong == row[5]:
-                row[9] = coresong.props.favorite
+            if coresong == row[7]:
+                row[6] = coresong.props.favorite
                 break
 
     @GObject.Property(
diff --git a/gnomemusic/views/baseview.py b/gnomemusic/views/baseview.py
index 4827c10b..e82bf986 100644
--- a/gnomemusic/views/baseview.py
+++ b/gnomemusic/views/baseview.py
@@ -64,7 +64,7 @@ class BaseView(Gtk.Stack):
 
         self._grid.add(self._box)
 
-        self._star_handler = StarHandlerWidget(self, 9)
+        self._star_handler = StarHandlerWidget(self, 6)
         self._window = window
         self._headerbar = window._headerbar
 
diff --git a/gnomemusic/views/songsview.py b/gnomemusic/views/songsview.py
index 31a617a1..39508b1f 100644
--- a/gnomemusic/views/songsview.py
+++ b/gnomemusic/views/songsview.py
@@ -30,7 +30,6 @@ from gnomemusic import log
 from gnomemusic.grilo import grilo
 from gnomemusic.player import PlayerPlaylist
 from gnomemusic.views.baseview import BaseView
-import gnomemusic.utils as utils
 
 logger = logging.getLogger(__name__)
 
@@ -106,7 +105,7 @@ class SongsView(BaseView):
 
         selection_renderer = Gtk.CellRendererToggle()
         column_selection = Gtk.TreeViewColumn(
-            "Selected", selection_renderer, active=6)
+            "Selected", selection_renderer, active=1)
         column_selection.props.visible = False
         column_selection.props.fixed_width = 48
         self._view.append_column(column_selection)
@@ -126,45 +125,25 @@ class SongsView(BaseView):
 
         album_renderer = Gtk.CellRendererText(
             xpad=32, ellipsize=Pango.EllipsizeMode.END)
-        column_album = Gtk.TreeViewColumn()
+        column_album = Gtk.TreeViewColumn("Album", album_renderer, text=4)
         column_album.props.expand = True
-        column_album.pack_start(album_renderer, True)
-        column_album.set_cell_data_func(
-            album_renderer, self._on_list_widget_album_render, None)
         self._view.append_column(column_album)
 
         duration_renderer = Gtk.CellRendererText(xalign=1.0)
-        column_duration = Gtk.TreeViewColumn()
-        column_duration.pack_start(duration_renderer, False)
-        column_duration.set_cell_data_func(
-            duration_renderer, self._on_list_widget_duration_render, None)
+        column_duration = Gtk.TreeViewColumn(
+            "Duration", duration_renderer, text=5)
         self._view.append_column(column_duration)
 
         column_star = Gtk.TreeViewColumn()
         self._view.append_column(column_star)
         self._star_handler.add_star_renderers(column_star)
 
-    def _on_list_widget_duration_render(self, col, cell, model, itr, data):
-        item = model[itr][5]
-        if item:
-            seconds = item.props.duration
-            track_time = utils.seconds_to_string(seconds)
-            cell.props.text = '{}'.format(track_time)
-
-    def _on_list_widget_album_render(self, coll, cell, model, _iter, data):
-        if not model.iter_is_valid(_iter):
-            return
-
-        item = model[_iter][5]
-        if item:
-            cell.props.text = item.props.album
-
     def _on_list_widget_icon_render(self, col, cell, model, itr, data):
         current_song = self.player.props.current_song
         if current_song is None:
             return
 
-        if model[itr][5].props.grlid == current_song.props.grlid:
+        if model[itr][7].props.grlid == current_song.props.grlid:
             cell.props.icon_name = self._now_playing_icon_name
             cell.props.visible = True
         else:
@@ -209,7 +188,7 @@ class SongsView(BaseView):
             return
 
         itr = self._view.props.model.get_iter(path)
-        coresong = self._view.props.model[itr][5]
+        coresong = self._view.props.model[itr][7]
         self._window._app._coremodel.set_playlist_model(
             PlayerPlaylist.Type.SONGS, self._view.props.model)
 
@@ -229,8 +208,8 @@ class SongsView(BaseView):
         if self.props.selection_mode:
             path, col, cell_x, cell_y = self._view.get_path_at_pos(x, y)
             iter_ = self._view.props.model.get_iter(path)
-            self._model[iter_][6] = not self._model[iter_][6]
-            self._model[iter_][5].props.selected = self._model[iter_][6]
+            self._model[iter_][1] = not self._model[iter_][1]
+            self._model[iter_][7].props.selected = self._model[iter_][7]
 
     @log
     def _update_model(self, player):
@@ -239,20 +218,20 @@ class SongsView(BaseView):
         :param Player player: The main player object
         """
         if self._iter_to_clean:
-            self._view.props.model[self._iter_to_clean][10] = False
+            self._view.props.model[self._iter_to_clean][9] = False
 
         index = self.player.props.position
         current_coresong = self._playlist_model[index]
         for idx, liststore in enumerate(self._view.props.model):
-            if liststore[5] == current_coresong:
+            if liststore[7] == current_coresong:
                 break
 
         iter_ = self._view.props.model.get_iter_from_string(str(idx))
         path = self._view.props.model.get_path(iter_)
-        self._view.props.model[iter_][10] = True
+        self._view.props.model[iter_][9] = True
         self._view.scroll_to_cell(path, None, True, 0.5, 0.5)
 
-        if self._view.props.model[iter_][8] != self._error_icon_name:
+        if self._view.props.model[iter_][0] != self._error_icon_name:
             self._iter_to_clean = iter_.copy()
 
         return False
@@ -263,7 +242,7 @@ class SongsView(BaseView):
             return
 
         iter_ = self.model.get_iter_from_string(str(index))
-        self.model[iter_][11] = status
+        self.model[iter_][8] = status
 
     @log
     def _populate(self, data=None):
@@ -274,8 +253,8 @@ class SongsView(BaseView):
         with self._model.freeze_notify():
             itr = self._model.iter_children(None)
             while itr is not None:
-                self._model[itr][5].props.selected = value
-                self._model[itr][6] = value
+                self._model[itr][7].props.selected = value
+                self._model[itr][1] = value
 
                 itr = self._model.iter_next(itr)
 
diff --git a/gnomemusic/widgets/starhandlerwidget.py b/gnomemusic/widgets/starhandlerwidget.py
index 134171ad..5e88571c 100644
--- a/gnomemusic/widgets/starhandlerwidget.py
+++ b/gnomemusic/widgets/starhandlerwidget.py
@@ -150,7 +150,7 @@ class StarHandlerWidget(object):
 
         new_value = not model[_iter][self._star_index]
         model[_iter][self._star_index] = new_value
-        coresong = model[_iter][5]
+        coresong = model[_iter][7]
         # FIXME: Playlists pass a Grl.Media. Not supported at the
         # moment. Port to core first.
         if coresong.__gtype__.name != Grl.Media.new().__gtype__.name:


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