[gnome-music: 1/3] monitor files being deleted.



commit 733d4af377d8c5a4ce7799933643f46acc89b466
Author: Sai <suman sai14 gmail com>
Date:   Mon Sep 2 10:52:39 2013 +0530

    monitor files being deleted.

 gnomemusic/view.py    |   12 ++++++++++++
 gnomemusic/widgets.py |   28 ++++++++++++++++++++++------
 2 files changed, 34 insertions(+), 6 deletions(-)
---
diff --git a/gnomemusic/view.py b/gnomemusic/view.py
index 0bb24ba..4f5b186 100644
--- a/gnomemusic/view.py
+++ b/gnomemusic/view.py
@@ -39,6 +39,7 @@ from gi.repository import Pango
 from gi.repository import GLib
 from gi.repository import GdkPixbuf
 from gi.repository import Tracker
+from gi.repository import Gio
 from gettext import gettext as _
 from gnomemusic.grilo import grilo
 import gnomemusic.widgets as Widgets
@@ -316,6 +317,7 @@ class Songs(ViewContainer):
         ViewContainer.__init__(self, _("Songs"), header_bar, selection_toolbar)
         self.countQuery = Query.SONGS_COUNT
         self._items = {}
+        self.monitors = []
         self.isStarred = None
         self.iter_to_clean = None
         self.view.set_view_type(Gd.MainViewType.LIST)
@@ -354,12 +356,22 @@ class Songs(ViewContainer):
         _iter = self._model.append()
         item.set_title(albumArtCache.get_media_title(item))
         self.player.discover_item(item, self._on_discovered, _iter)
+        g_file = Gio.file_new_for_uri(item.get_url())
+        self.monitors.append(g_file.monitor_file(Gio.FileMonitorFlags.NONE,
+                                                 None))
+        self.monitors[(self._offset - 1)].connect('changed',
+                                                  self._on_item_changed, _iter)
         self._model.set(_iter,
                         [2, 3, 5, 8, 9, 10],
                         [albumArtCache.get_media_title(item),
                          item.get_string(Grl.METADATA_KEY_ARTIST),
                          item, self.nowPlayingIconName, False, False])
 
+    def _on_item_changed(self, monitor, file1, file2, event, _iter):
+        if self._model.iter_is_valid(_iter):
+            if event == Gio.FileMonitorEvent.DELETED:
+                self._model.set(_iter, [8, 10], [self.errorIconName, True])
+
     def _add_list_renderers(self):
         list_widget = self.view.get_generic_view()
         cols = list_widget.get_columns()
diff --git a/gnomemusic/widgets.py b/gnomemusic/widgets.py
index 30ac914..d8ab888 100644
--- a/gnomemusic/widgets.py
+++ b/gnomemusic/widgets.py
@@ -32,7 +32,7 @@
 
 
 from gi.repository import Gtk, Gd, GLib, GObject, Pango
-from gi.repository import GdkPixbuf
+from gi.repository import GdkPixbuf, Gio
 from gi.repository import Grl
 from gi.repository import Tracker
 from gettext import gettext as _
@@ -123,7 +123,7 @@ class AlbumWidget(Gtk.EventBox):
         self.view.set_view_type(Gd.MainViewType.LIST)
         self.album = None
         self.view.connect('item-activated', self._on_item_activated)
-
+        self.monitors = []
         view_box = self.ui.get_object('view')
         self.ui.get_object('scrolledWindow').set_placement(Gtk.CornerType.
                                                            TOP_LEFT)
@@ -281,8 +281,12 @@ class AlbumWidget(Gtk.EventBox):
             self.tracks.append(track)
             self.duration = self.duration + track.get_duration()
             _iter = self.model.append()
-            escapedTitle = AlbumArtCache.get_media_title(track, True)
             self.player.discover_item(track, self._on_discovered, _iter)
+            g_file = Gio.file_new_for_uri(track.get_url())
+            self.monitors.append(g_file.monitor_file(Gio.FileMonitorFlags.NONE,
+                                                     None))
+            self.monitors[-1].connect('changed', self._on_item_changed, _iter)
+            escapedTitle = AlbumArtCache.get_media_title(track, True)
             self.model.set(_iter,
                            [0, 1, 2, 3, 4, 5, 7, 9],
                            [escapedTitle,
@@ -293,6 +297,11 @@ class AlbumWidget(Gtk.EventBox):
             self.ui.get_object('running_length_label_info').set_text(
                 '%d min' % (int(self.duration / 60) + 1))
 
+    def _on_item_changed(self, monitor, file1, file2, event_type, _iter):
+        if self.model.iter_is_valid(_iter):
+            if event_type == Gio.FileMonitorEvent.DELETED:
+                self.model.set(_iter, [7, 9], [ERROR_ICON_NAME, True])
+
     def _on_look_up(self, pixbuf, path, data=None):
         _iter = self.iterToClean
         if pixbuf:
@@ -495,7 +504,7 @@ class ArtistAlbumWidget(Gtk.HBox):
         self.artist = album.get_string(Grl.METADATA_KEY_ARTIST)
         self.model = model
         self.songs = []
-
+        self.monitors = []
         self.ui = Gtk.Builder()
         self.ui.add_from_resource('/org/gnome/Music/ArtistAlbumWidget.ui')
 
@@ -550,8 +559,11 @@ class ArtistAlbumWidget(Gtk.HBox):
                 song_widget._iter = itr
                 song_widget.model = self.model
                 song_widget.title = ui.get_object('title')
-
                 self.player.discover_item(track, self._on_discovered, song_widget)
+                g_file = Gio.file_new_for_uri(track.get_url())
+                self.monitors.append(g_file.monitor_file(Gio.FileMonitorFlags.NONE,
+                                                         None))
+                self.monitors[-1].connect('changed', self._on_item_changed, itr)
                 self.model.set(itr,
                                [0, 1, 2, 3, 4, 5],
                                [title, '', '', False,
@@ -565,9 +577,13 @@ class ArtistAlbumWidget(Gtk.HBox):
                 song_widget.can_be_played = True
                 song_widget.connect('button-release-event',
                                     self.track_selected)
-
             self.ui.get_object('grid1').show_all()
 
+    def _on_item_changed(self, monitor, file1, file2, event_type, _iter):
+        if self.model.iter_is_valid(_iter):
+            if event_type == Gio.FileMonitorEvent.DELETED:
+                self.model.set(_iter, [3, 4], [True, ERROR_ICON_NAME])
+
     def _update_album_art(self):
         ALBUM_ART_CACHE.lookup(self.album, 128, 128, self._get_album_cover)
 


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