[gnome-music/freeze-break: 70/107] view: Load songs of playlist when selected



commit 9d369d174ba31dc435d0d3b38bf98944b648ad29
Author: Arnel A. Borja <arnelborja src gnome org>
Date:   Thu Sep 5 00:26:13 2013 +0800

    view: Load songs of playlist when selected

 gnomemusic/view.py |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/gnomemusic/view.py b/gnomemusic/view.py
index 0fc9546..05a6fe9 100644
--- a/gnomemusic/view.py
+++ b/gnomemusic/view.py
@@ -629,6 +629,7 @@ class Playlist(ViewContainer):
         self.playlists_sidebar.get_style_context().add_class('artist-panel')
         self.playlists_sidebar.get_generic_view().get_selection().set_mode(
             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(Gtk.Separator(orientation=Gtk.Orientation.VERTICAL),
@@ -642,6 +643,7 @@ class Playlist(ViewContainer):
             self.playlists_sidebar.get_generic_view().get_style_context().\
                 add_class("artist-panel-white")
 
+        self.player = player
         self.show_all()
 
     def _add_list_renderers(self):
@@ -753,6 +755,42 @@ class Playlist(ViewContainer):
         self._playlist_list[item] = {"iter": _iter, "albums": []}
         self.playlists_model.set(_iter, [2], [item])
 
+    def _on_playlist_activated(self, widget, item_id, path):
+        self._model = Gtk.ListStore(
+            GObject.TYPE_STRING,
+            GObject.TYPE_STRING,
+            GObject.TYPE_STRING,
+            GObject.TYPE_STRING,
+            GdkPixbuf.Pixbuf,
+            GObject.TYPE_OBJECT,
+            GObject.TYPE_BOOLEAN,
+            GObject.TYPE_INT,
+            GObject.TYPE_STRING,
+            GObject.TYPE_BOOLEAN,
+            GObject.TYPE_BOOLEAN
+        )
+        self.view.set_model(self._model)
+        _iter = self.playlists_model.get_iter(path)
+        playlist = self.playlists_model.get_value(_iter, 2)
+        playlists.parse_playlist(self.playlists_model.get_value(_iter, 2), self._add_song)
+        self.current_playlist = playlist
+        playlists.parse_playlist(playlist, self._add_song)
+
+    def _add_song(self, item):
+        if not item:
+            return
+        self._offset += 1
+        item.set_title(albumArtCache.get_media_title(item))
+        artist = item.get_string(Grl.METADATA_KEY_ARTIST)\
+            or item.get_author()\
+            or _("Unknown Artist")
+        _iter = self._model.insert_with_valuesv(
+            -1,
+            [2, 3, 5, 8, 9, 10],
+            [albumArtCache.get_media_title(item),
+             artist, item, self.nowPlayingIconName, False, False])
+        self.player.discover_item(item, self._on_discovered, _iter)
+
     def populate(self):
         for item in self.playlists_list:
             self._add_item(item)


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