The coverItem saves and removes its files
authorIvan Frade <ivan.frade@gmail.com>
Tue, 5 Jul 2011 07:16:33 +0000 (10:16 +0300)
committerIvan Frade <ivan.frade@gmail.com>
Tue, 5 Jul 2011 07:16:33 +0000 (10:16 +0300)
src/qml/coverItem.py

index 5f429a4..5033364 100644 (file)
@@ -8,10 +8,11 @@ from PySide import QtDeclarative
 
 class CoverItem (QtCore.QObject):
 
-    def __init__ (self, initial_image):
+    def __init__ (self, image, initialImage=False, deleteAction=False):
         QtCore.QObject.__init__(self)
-        self._initial_image = initial_image
-        self._url = initial_image
+        self.initialImage = initialImage
+        self.deleteAction = deleteAction
+        self._url = image
         
     def _url (self):
         return self._url
@@ -20,23 +21,26 @@ class CoverItem (QtCore.QObject):
         self._url = url
         self.url_changed.emit ()
 
+    def save (self, destination):
+        if self.initialImage:
+            print " -> No changes"
+            return
 
-#    def reset (self):
-#        cached_image = self._url
-#        if cached_image and os.path.exists (cached_image):
-#            os.remove (cached_image)
-#            
-#        if cached_thumb and os.path.exists (cached_thumb):
-#            os.remove (cached_thumb)
-#
-#        self.url = self._initial_image
-#        self.url_changed.emit ()
+        if self.deleteAction:
+            print " -> Remove the album art"
+            if os.path.exists (destination):
+                os.remove (destination)
+            return
 
-    def save (self, cover, thumbnail):
-        assert not self.url == self._initial_image
-        os.rename (self.url, cover)
+        print " -> Saving:", self.url, "to", destination
+        os.rename (self.url, destination)
 
 
-    url_changed = QtCore.Signal ()
+    def remove (self):
+        print "Removing", self.url
+        if os.path.exists (self.url):
+            os.remove (self.url)
+
 
+    url_changed = QtCore.Signal ()
     url = QtCore.Property (unicode, _url, _setUrl, notify=url_changed)