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



commit f7cd591da7910f3932546c678c690017f7020920
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 +++++++++++++++++++++++----------------
 3 files changed, 123 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 6c7b67f3..0c80a383 100644
--- a/gnomemusic/views/playlistsview.py
+++ b/gnomemusic/views/playlistsview.py
@@ -30,6 +30,7 @@ from gnomemusic import log
 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")
@@ -39,7 +40,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 __repr__(self):
         return '<PlaylistsView>'
@@ -58,27 +60,30 @@ 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)
 
     @log
-    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
@@ -87,40 +92,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_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()
     @log
-    def _on_playlist_activated(self, sidebar, row, untouched=False):
+    def _on_user_playlist_activated(self, sidebar, row):
         """Update view with content from selected playlist"""
-        if untouched is False:
-            self._untouched_list = False
-
+        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):
@@ -128,13 +137,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
@@ -142,10 +156,10 @@ 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)
     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


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