[gnome-music/wip/jfelder/smartplaylists-ui-v2: 23/25] playlistsview: Revamp smart playlists ui



commit 68691b3a31b9e169e64713b8f5639709cc406969
Author: Jean Felder <jfelder src gnome org>
Date:   Fri Jan 17 12:33:15 2020 +0100

    playlistsview: Revamp smart playlists ui
    
    Closes: #49

 data/ui/PlaylistTile.ui           | 24 +++++++++---
 data/ui/PlaylistsView.ui          | 59 ++++++++++++++++++++++++++--
 gnomemusic/views/playlistsview.py | 82 +++++++++++++++++++++++----------------
 po/POTFILES.in                    |  1 +
 4 files changed, 124 insertions(+), 42 deletions(-)
---
diff --git a/data/ui/PlaylistTile.ui b/data/ui/PlaylistTile.ui
index dceea3c9..14b5b0f8 100644
--- a/data/ui/PlaylistTile.ui
+++ b/data/ui/PlaylistTile.ui
@@ -3,13 +3,27 @@
   <template class="PlaylistTile" parent="GtkListBoxRow">
     <property name="visible">True</property>
     <child>
-      <object class="GtkLabel" id="_label">
-        <property name="can_focus">False</property>
-        <property name="ellipsize">end</property>
-        <property name="halign">start</property>
-        <property name="hexpand">False</property>
+      <object class="GtkBox">
         <property name="margin">16</property>
         <property name="visible">True</property>
+        <child>
+          <object class="GtkImage" id="icon">
+            <property name="can_focus">False</property>
+            <property name="icon-name">view-list-bullet-symbolic</property>
+            <property name="icon-size">1</property>
+            <property name="visible">True</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel" id="_label">
+            <property name="can_focus">False</property>
+            <property name="ellipsize">end</property>
+            <property name="halign">start</property>
+            <property name="hexpand">False</property>
+            <property name="margin-left">8</property>
+            <property name="visible">True</property>
+          </object>
+        </child>
       </object>
     </child>
   </template>
diff --git a/data/ui/PlaylistsView.ui b/data/ui/PlaylistsView.ui
index f1714731..58294101 100644
--- a/data/ui/PlaylistsView.ui
+++ b/data/ui/PlaylistsView.ui
@@ -14,10 +14,63 @@
               <class name="sidebar"/>
             </style>
             <child>
-              <object class="GtkListBox" id="_sidebar">
-                <property name="selection-mode">single</property>
+              <object class="GtkBox">
+                <property name="orientation">vertical</property>
                 <property name="visible">True</property>
-                <signal name="row-activated" handler="_on_playlist_activated" swapped="no"/>
+                <child>
+                  <object class="GtkListBox" id="_smart_sidebar">
+                    <property name="margin-top">2</property>
+                    <property name="margin-bottom">2</property>
+                    <property name="visible">True</property>
+                    <property name="selection-mode">single</property>
+                    <signal name="row-activated" handler="_on_smart_playlist_activated" swapped="no"/>
+                    <child>
+                      <object class="GtkListBoxRow">
+                        <property name="visible">True</property>
+                        <child>
+                          <object class="GtkBox">
+                            <property name="margin">16</property>
+                            <property name="visible">True</property>
+                            <child>
+                              <object class="GtkImage" id="icon">
+                                <property name="can_focus">False</property>
+                                <property name="icon-name">folder-music-symbolic</property>
+                                <property name="icon-size">1</property>
+                                <property name="visible">True</property>
+                              </object>
+                            </child>
+                            <child>
+                              <object class="GtkLabel">
+                                <property name="can_focus">False</property>
+                                <property name="ellipsize">end</property>
+                                <property name="halign">start</property>
+                                <property name="hexpand">False</property>
+                                <property name="margin-left">8</property>
+                                <property name="visible">True</property>
+                                <property name="label" translatable="yes">Smart Playlists</property>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkSeparator">
+                    <property name="orientation">horizontal</property>
+                    <property name="visible">True</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkListBox" id="_user_sidebar">
+                    <property name="margin-top">2</property>
+                    <property name="margin-bottom">2</property>
+                    <property name="selection-mode">single</property>
+                    <property name="visible">True</property>
+                    <signal name="row-activated" handler="_on_user_playlist_activated" swapped="no"/>
+                  </object>
+                </child>
               </object>
             </child>
           </object>
diff --git a/gnomemusic/views/playlistsview.py b/gnomemusic/views/playlistsview.py
index 25a63a20..6a375b44 100644
--- a/gnomemusic/views/playlistsview.py
+++ b/gnomemusic/views/playlistsview.py
@@ -29,6 +29,7 @@ from gi.repository import GObject, Gtk
 from gnomemusic.grilowrappers.grltrackerplaylists import Playlist
 from gnomemusic.widgets.playlistswidget import PlaylistsWidget
 from gnomemusic.widgets.playlisttile import PlaylistTile
+from gnomemusic.widgets.smartplaylistswidget import SmartPlaylistsWidget
 
 
 @Gtk.Template(resource_path="/org/gnome/Music/ui/PlaylistsView.ui")
@@ -38,7 +39,8 @@ class PlaylistsView(Gtk.Stack):
     __gtype_name__ = "PlaylistsView"
 
     _main_container = Gtk.Template.Child()
-    _sidebar = Gtk.Template.Child()
+    _smart_sidebar = Gtk.Template.Child()
+    _user_sidebar = Gtk.Template.Child()
 
     def __init__(self, application, player):
         """Initialize
@@ -53,26 +55,29 @@ class PlaylistsView(Gtk.Stack):
         self.title = _("Playlists")
 
         self._coremodel = application.props.coremodel
-        self._model = self._coremodel.props.playlists_sort
+        self._users_playlists_model = self._coremodel.props.user_playlists_sort
         self._window = application.props.window
         self._player = player
 
-        # This indicates if the current list has been empty and has
-        # had no user interaction since.
-        self._untouched_list = True
+        self._user_playlist_view = PlaylistsWidget(application, self)
+        self._main_container.add(self._user_playlist_view)
 
-        self._playlist_widget = PlaylistsWidget(application, self)
-        self._main_container.add(self._playlist_widget)
+        self._smart_playlist_view = SmartPlaylistsWidget(
+            self._coremodel, player)
+        self._main_container.add(self._smart_playlist_view)
 
-        self._sidebar.bind_model(self._model, self._add_playlist_to_sidebar)
+        self._user_sidebar.bind_model(
+            self._users_playlists_model, self._add_user_playlist_to_sidebar)
 
         self._coremodel.connect(
             "notify::active-playlist", self._on_active_playlist_changed)
 
-        self._model.connect("items-changed", self._on_playlists_model_changed)
-        self._on_playlists_model_changed(self._model, 0, 0, 0)
+        self._users_playlists_model.connect(
+            "items-changed", self._on_user_playlists_model_changed)
+        self._on_user_playlists_model_changed(
+            self._users_playlists_model, 0, 0, 0)
 
-    def _add_playlist_to_sidebar(self, playlist):
+    def _add_user_playlist_to_sidebar(self, playlist):
         """Add a playlist to sidebar
 
         :param GrlMedia playlist: playlist to add
@@ -81,40 +86,44 @@ class PlaylistsView(Gtk.Stack):
         row = PlaylistTile(playlist)
         return row
 
-    def _on_playlists_model_changed(self, model, position, removed, added):
+    def _on_user_playlists_model_changed(
+            self, model, position, removed, added):
         if model.get_n_items() == 0:
-            self._untouched_list = True
-            return
-        elif self._untouched_list is True:
-            first_row = self._sidebar.get_row_at_index(0)
-            self._sidebar.select_row(first_row)
-            self._on_playlist_activated(self._sidebar, first_row, True)
+            smart_row = self._smart_sidebar.get_row_at_index(0)
+            self._smart_sidebar.select_row(smart_row)
+            self._on_smart_playlist_activated(self._smart_sidebar, smart_row)
             return
 
         if removed == 0:
             return
 
-        row_next = (self._sidebar.get_row_at_index(position)
-                    or self._sidebar.get_row_at_index(position - 1))
+        row_next = (self._user_sidebar.get_row_at_index(position)
+                    or self._user_sidebar.get_row_at_index(position - 1))
         if row_next:
-            self._sidebar.select_row(row_next)
-            self._on_playlist_activated(self._sidebar, row_next, True)
+            self._user_sidebar.select_row(row_next)
+            self._on_user_playlist_activated(self._user_sidebar, row_next)
 
     @GObject.Property(
         type=Playlist, default=None, flags=GObject.ParamFlags.READABLE)
     def current_playlist(self):
-        selection = self._sidebar.get_selected_row()
+        selection = self._user_sidebar.get_selected_row()
         if selection is None:
             return None
 
         return selection.props.playlist
 
     @Gtk.Template.Callback()
-    def _on_playlist_activated(self, sidebar, row, untouched=False):
-        """Update view with content from selected playlist"""
-        if untouched is False:
-            self._untouched_list = False
+    def _on_smart_playlist_activated(self, sidebar, row):
+        self._user_sidebar.unselect_all()
+        self._user_playlist_view.props.visible = False
+        self._smart_playlist_view.props.visible = True
 
+    @Gtk.Template.Callback()
+    def _on_user_playlist_activated(self, sidebar, row):
+        """Update view with content from selected playlist"""
+        self._smart_sidebar.unselect_all()
+        self._smart_playlist_view.props.visible = False
+        self._user_playlist_view.props.visible = True
         self.notify("current-playlist")
 
     def _on_active_playlist_changed(self, klass, val):
@@ -122,13 +131,18 @@ class PlaylistsView(Gtk.Stack):
            has changed it.
         """
         playlist = self._coremodel.props.active_playlist
-        selection = self._sidebar.get_selected_row()
-        if (playlist is None
-                or playlist == selection.props.playlist):
+        if playlist is None:
+            return
+
+        if playlist.props.is_smart:
+            smart_row = self._smart_sidebar.get_row_at_index(0)
+            self._smart_sidebar.select_row(smart_row)
+            self._on_smart_playlist_activated(self._smart_sidebar, smart_row)
+            self._smart_playlist_view.select(playlist)
             return
 
         playlist_row = None
-        for row in self._sidebar:
+        for row in self._user_sidebar:
             if row.props.playlist == playlist:
                 playlist_row = row
                 break
@@ -136,11 +150,11 @@ class PlaylistsView(Gtk.Stack):
         if not playlist_row:
             return
 
-        self._sidebar.select_row(playlist_row)
-        self._on_playlist_activated(self._sidebar, playlist_row)
+        self._user_sidebar.select_row(playlist_row)
+        self._on_user_playlist_activated(self._user_sidebar, playlist_row)
 
     @GObject.Property(
         type=bool, default=False, flags=GObject.ParamFlags.READABLE)
     def rename_active(self):
         """Indicate if renaming dialog is active"""
-        return self._playlist_widget.props.rename_active
+        return self._user_playlist_view.props.rename_active
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 04006ddc..1cae7428 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -12,6 +12,7 @@ data/ui/PlayerToolbar.ui
 data/ui/PlaylistContextMenu.ui
 data/ui/PlaylistControls.ui
 data/ui/PlaylistDialog.ui
+data/ui/PlaylistsView.ui
 data/ui/SearchHeaderBar.ui
 data/ui/SearchView.ui
 data/ui/SelectionBarMenuButton.ui


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