[gnome-music] grilo: rework add and remove clauses for content rescan



commit 99595c62b56c136be7faf219b3735084d6e38411
Author: Vadim Rutkovsky <vrutkovs redhat com>
Date:   Fri Apr 4 17:41:37 2014 +0200

    grilo: rework add and remove clauses for content rescan

 gnomemusic/grilo.py |   29 ++++++++++++++++++-----------
 1 files changed, 18 insertions(+), 11 deletions(-)
---
diff --git a/gnomemusic/grilo.py b/gnomemusic/grilo.py
index 641ede8..409d8ff 100644
--- a/gnomemusic/grilo.py
+++ b/gnomemusic/grilo.py
@@ -83,21 +83,28 @@ class Grilo(GObject.GObject):
     @log
     def _on_content_changed(self, mediaSource, changedMedias, changeType, locationUnknown):
         try:
-            if changeType == Grl.SourceChangeType.ADDED or changeType == Grl.SourceChangeType.REMOVED:
-                for media in changedMedias:
-                    media_id = media.get_id()
+            for media in changedMedias:
+                media_id = media.get_id()
+                if changeType == Grl.SourceChangeType.ADDED:
+                    # Check that this media is an audio file
                     query = "select DISTINCT rdf:type nie:mimeType(?urn) as mime-type" +\
                             " { ?urn rdf:type nie:InformationElement . FILTER (tracker:id(?urn) = %s) }" % 
media_id
                     mimeType = grilo.tracker.query_sync(query, [Grl.METADATA_KEY_MIME], 
grilo.options)[0].get_mime()
                     if mimeType.startswith("audio"):
-                        self.changed_media_ids.append(media.get_id())
-                if len(self.changed_media_ids) >= self.CHANGED_MEDIA_MAX_ITEMS:
-                    self.emit_change_signal()
-                elif self.changed_media_ids != []:
-                    if self.pending_event_id > 0:
-                        GLib.Source.remove(self.pending_event_id)
-                        self.pending_event_id = 0
-                    self.pending_event_id = GLib.timeout_add(self.CHANGED_MEDIA_SIGNAL_TIMEOUT, 
self.emit_change_signal)
+                        self.changed_media_ids.append(media_id)
+                if changeType == Grl.SourceChangeType.REMOVED:
+                    # There is no way to check that removed item is a media
+                    # so always do the refresh
+                    # todo: remove one single url
+                    self.changed_media_ids.append(media.get_id())
+
+            if len(self.changed_media_ids) >= self.CHANGED_MEDIA_MAX_ITEMS:
+                self.emit_change_signal()
+            elif self.changed_media_ids != []:
+                if self.pending_event_id > 0:
+                    GLib.Source.remove(self.pending_event_id)
+                    self.pending_event_id = 0
+                self.pending_event_id = GLib.timeout_add(self.CHANGED_MEDIA_SIGNAL_TIMEOUT, 
self.emit_change_signal)
         except Exception as e:
             logger.warn("Exception in _on_content_changed: %s" % e)
 


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