Move the qml/* files to the src folder. Now it is the main version
[mussorgsky] / src / albumItem.py
diff --git a/src/albumItem.py b/src/albumItem.py
new file mode 100644 (file)
index 0000000..0cf25c8
--- /dev/null
@@ -0,0 +1,75 @@
+# -*- coding: utf-8 -*-
+import os
+import sys
+import time
+from PySide import QtCore
+from PySide import QtGui
+from PySide import QtDeclarative
+
+from albumArt import AlbumArt
+
+class AlbumItem (QtCore.QObject):
+
+    def __init__ (self, title, artist):
+        QtCore.QObject.__init__(self)
+        self._title = title
+        self._artist = artist
+        self.aa = AlbumArt (self._title, self._artist)
+        self.require_download = False
+        if os.path.exists (self.aa.get_media_art_path ()):
+            self._album_art = self.aa.get_media_art_path ()
+        elif os.path.exists (self.aa.get_generated ()):
+            self._album_art = self.aa.get_generated ()
+            self.require_download = True
+        else:
+            self.require_download = True
+            self._album_art = "images/blank_record.png"
+
+    def _title (self):
+        return self._title
+
+    def _artist (self):
+        return self._artist
+
+    def _albumArt (self):
+        return self._album_art
+
+    def _setAlbumArt (self, path):
+        print "Setting the new album art to", path
+        self.require_download = False
+        self._album_art = path
+        self.album_art_changed.emit ()
+
+    def resetAlbumArt (self):
+        print "Reset album art!"
+        #self._album_art = None
+        counter = 0
+        while counter < 3:
+            if os.path.exists (self.aa.get_generated ()):
+                break
+            time.sleep (1)
+            counter += 1
+
+        if os.path.exists (self.aa.get_generated ()):
+            print "Using the generated"
+            self._album_art = self.aa.get_generated ()
+            self.require_download = True
+        else:
+            print "Setting to none (", self.aa.get_generated (), " doesn't exist)"
+            self.require_download = True
+            self._album_art = "images/blank_record.png"
+        self.album_art_changed.emit ()
+
+    def get_aa (self):
+        return self.aa
+
+    prop_changed = QtCore.Signal ()
+    album_art_changed = QtCore.Signal ()
+
+    title = QtCore.Property (unicode, _title, notify=prop_changed)
+    artist = QtCore.Property (unicode, _artist, notify=prop_changed)
+    album_art = QtCore.Property (unicode,
+                                 _albumArt,
+                                 _setAlbumArt,
+                                 notify=album_art_changed)
+