[gnome-music/freeze-break: 85/107] view: Add header bar on Playlists view



commit c1b2cae9d540f1bde34ef717cb1e0384d5e91266
Author: Arnel A. Borja <arnelborja src gnome org>
Date:   Sun Sep 8 14:49:04 2013 +0800

    view: Add header bar on Playlists view

 gnomemusic/view.py |   29 ++++++++++++++++++++++++++---
 1 files changed, 26 insertions(+), 3 deletions(-)
---
diff --git a/gnomemusic/view.py b/gnomemusic/view.py
index 6242041..295ff22 100644
--- a/gnomemusic/view.py
+++ b/gnomemusic/view.py
@@ -41,7 +41,7 @@ from gi.repository import GdkPixbuf
 from gi.repository import Tracker
 from gi.repository import Gio
 
-from gettext import gettext as _
+from gettext import gettext as _, ngettext
 from gnomemusic.grilo import grilo
 import gnomemusic.widgets as Widgets
 from gnomemusic.playlists import Playlists
@@ -627,9 +627,18 @@ class Playlist(ViewContainer):
             GObject.TYPE_BOOLEAN
         )
 
+        builder = Gtk.Builder()
+        builder.add_from_resource('/org/gnome/Music/PlaylistControls.ui')
         self.playlists_sidebar = Gd.MainView(
             shadow_type=Gtk.ShadowType.NONE
         )
+        self.headerbar = builder.get_object('grid')
+        self.name_label = builder.get_object('playlist_name')
+        self.songs_count_label = builder.get_object('songs_count')
+        self.menubutton = builder.get_object('playlist_menubutton')
+        self._grid.insert_row(0)
+        self._grid.attach(self.headerbar, 0, 0, 1, 1)
+
         self.playlists_sidebar.set_model(self.playlists_model)
         self.playlists_sidebar.set_view_type(Gd.MainViewType.LIST)
         self.playlists_sidebar.set_hexpand(False)
@@ -638,9 +647,9 @@ class Playlist(ViewContainer):
             Gtk.SelectionMode.SINGLE)
         self.playlists_sidebar.connect('item-activated', self._on_playlist_activated)
         self._grid.insert_column(0)
-        self._grid.attach(self.playlists_sidebar, 0, 0, 1, 1)
+        self._grid.attach(self.playlists_sidebar, 0, 0, 1, 2)
         self._grid.attach(Gtk.Separator(orientation=Gtk.Orientation.VERTICAL),
-                          1, 0, 1, 1)
+                          0, 0, 1, 2)
         self._add_sidebar_renderers()
         if (Gtk.Settings.get_default().get_property(
                 'gtk_application_prefer_dark_theme')):
@@ -653,6 +662,8 @@ class Playlist(ViewContainer):
         self.monitors = []
         self.iter_to_clean = None
         self.iter_to_clean_model = None
+        self.songs_count = 0
+        self._update_songs_count()
         self.player = player
         self.player.connect('playlist-item-changed', self.update_model)
         self.show_all()
@@ -793,6 +804,7 @@ class Playlist(ViewContainer):
         _iter = self.playlists_model.get_iter(path)
         playlist = self.playlists_model.get_value(_iter, 2)
         self.current_playlist = playlist
+        self.name_label.set_text(playlist)
 
         # if the active queue has been set by this playlist,
         # use it as model, otherwise build the liststore
@@ -803,6 +815,8 @@ class Playlist(ViewContainer):
             self.update_model(self.player, cached_playlist,
                               currentTrack)
             self.view.set_model(self._model)
+            self.songs_count = cached_playlist.iter_n_children(None)
+            self._update_songs_count()
         else:
             self._model = Gtk.ListStore(
                 GObject.TYPE_STRING,
@@ -819,6 +833,8 @@ class Playlist(ViewContainer):
             )
             self.view.set_model(self._model)
             playlists.parse_playlist(playlist, self._add_song)
+            self.songs_count = 0
+            self._update_songs_count()
 
     def _add_song(self, item):
         if not item:
@@ -839,6 +855,13 @@ class Playlist(ViewContainer):
                                                  None))
         self.monitors[(self._offset - 1)].connect('changed',
                                                   self._on_item_changed, _iter)
+        self.songs_count += 1
+        self._update_songs_count()
+
+    def _update_songs_count(self):
+        self.songs_count_label.set_text(
+            ngettext(_("%d Song"), _("%d Songs"), self.songs_count)
+            % self.songs_count)
 
     def populate(self):
         for item in self.playlists_list:


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