[gnome-music/freeze-break: 96/107] view: Connect to Playlists signals



commit efbfbd1110c270be360ff0b0e56a98019c260c59
Author: Arnel A. Borja <arnelborja src gnome org>
Date:   Sun Sep 8 21:39:57 2013 +0800

    view: Connect to Playlists signals

 gnomemusic/view.py |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)
---
diff --git a/gnomemusic/view.py b/gnomemusic/view.py
index fda6da9..eedb09b 100644
--- a/gnomemusic/view.py
+++ b/gnomemusic/view.py
@@ -671,10 +671,13 @@ class Playlist(ViewContainer):
         self.monitors = []
         self.iter_to_clean = None
         self.iter_to_clean_model = None
+        self.current_playlist = None
         self.songs_count = 0
         self._update_songs_count()
         self.player = player
         self.player.connect('playlist-item-changed', self.update_model)
+        playlists.connect('playlist-created', self._on_playlist_created)
+        playlists.connect('song-added-to-playlist', self._on_song_added_to_playlist)
         self.show_all()
 
     def _add_list_renderers(self):
@@ -846,6 +849,9 @@ class Playlist(ViewContainer):
             self._update_songs_count()
 
     def _add_item(self, source, param, item):
+        self._add_item_to_model(item, self._model)
+
+    def _add_item_to_model(self, item, model):
         if not item:
             return
         self._offset += 1
@@ -853,7 +859,7 @@ class Playlist(ViewContainer):
         artist = item.get_string(Grl.METADATA_KEY_ARTIST)\
             or item.get_author()\
             or _("Unknown Artist")
-        _iter = self._model.insert_with_valuesv(
+        _iter = model.insert_with_valuesv(
             -1,
             [2, 3, 5, 8, 9, 10],
             [albumArtCache.get_media_title(item),
@@ -895,6 +901,17 @@ class Playlist(ViewContainer):
         playlists.delete_playlist(playlist)
         self.playlists_model.remove(_iter)
 
+    def _on_playlist_created(self, playlists, name):
+        self._add_playlist_item(name)
+
+    def _on_song_added_to_playlist(self, playlists, name, item):
+        if name == self.current_playlist:
+            self._add_item_to_model(item, self._model)
+
+        cached_playlist = self.player.running_playlist('Playlist', name)
+        if cached_playlist and cached_playlist != self._model:
+            self._add_item_to_model(item, cached_playlist)
+
     def populate(self):
         for item in self.playlists_list:
             self._add_playlist_item(item)


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