from tracker_backend_dbus import TrackerBackendDBus as TrackerBackend
from albumItem import AlbumItem
-from aa_spec import getCoverArtThumbFileName, getCoverArtFileName
-
+from coverModel import CoversModel
class DownloadThread (QtCore.QThread):
print "Running the thread"
MAX_OPTIONS = 4
counter = 0
- for img, thumb in self.downloader.get_alternatives (self.album.artist,
- self.album.title, MAX_OPTIONS):
+ for img in self.downloader.get_alternatives (self.album.artist,
+ self.album.title, MAX_OPTIONS):
if counter >= MAX_OPTIONS:
break
- self.model.updateData (counter, img, thumb)
+ self.model.updateData (counter, img)
counter += 1
class MussorgskyController (QtCore.QObject):
- def __init__ (self):
+ def __init__ (self, rootContext):
QtCore.QObject.__init__ (self)
self.download = None
+ self.ctx = rootContext
self.tracker = TrackerBackend ()
- @QtCore.Slot (QtCore.QObject, QtCore.QObject)
- def albumSelected (self, coversModel, album):
- """
- Starts a thread to look for possible images online.
- The thread will update the model (and the changes are visible in the UI)
- """
- print "clicked on", album.title
- self.download = DownloadThread (coversModel, album)
- self.download.start ()
-
- @QtCore.Slot (QtCore.QObject, QtCore.QObject, int)
- def coverSelected (self, coverObject, albumModel, index):
- """
- The user has clicked in one cover!
- """
- albumObject = albumModel.getAlbumInRow (index)
-
- print "Selected cover", albumObject.title
- filename = getCoverArtFileName (albumObject.title)
- thumbnail = getCoverArtThumbFileName (albumObject.title)
-
- coverObject.save (filename, thumbnail)
+# @QtCore.Slot (QtCore.QObject, QtCore.QObject, int)
+# def coverSelected (self, coverObject, albumModel, index):
+# """
+# The user has clicked in one cover!
+# """
+# albumObject = albumModel.getAlbumInRow (index)
+#
+# print "Selected cover", albumObject.title
+# filename = getCoverArtFileName (albumObject.title)
+# thumbnail = getCoverArtThumbFileName (albumObject.title)
+#
+# coverObject.save (filename, thumbnail)
+#
+# albumModel.updateThumb (index, filename)
+# #albumObject.album_art = thumbnail
+# albumObject.album_art_changed.emit ()
+
+ #@QtCore.Slot (QtCore.QObject)
+ #def resetAlternatives (self, coversModel):
+ # print "Reseting alternatives", coversModel
+ # QtGui.QPixmapCache.clear ()
+ # coversModel.resetAlternatives ()
- albumModel.updateThumb (index, filename)
- #albumObject.album_art = thumbnail
- albumObject.album_art_changed.emit ()
+ @QtCore.Slot (QtCore.QObject)
+ def download_all (self, albumModel):
+ print "well, we will do as soon as possible"
+ downloader = MussorgskyAlbumArt ()
+ for albumItem in albumModel.get_albums ():
+ if albumItem.require_download:
+ downloader.get_album_art (albumItem)
@QtCore.Slot (QtCore.QObject)
- def resetAlternatives (self, coversModel):
- print "Reseting alternatives", coversModel
- QtGui.QPixmapCache.clear ()
- coversModel.resetAlternatives ()
+ def get_options_for (self, albumItem):
+ print "Getting options for", albumItem.title
+ m = CoversModel (albumItem)
+ print m.rowCount ()
+ self.ctx.setContextProperty ("coversModel", m)
+ self.download = DownloadThread (m, albumItem)
+ self.download.start ()
+ @QtCore.Slot (QtCore.QObject, int)
+ def save_option_for (self, coversModel, index):
+ print "Saving option", index
+ coverItem = coversModel.getData (index)
+ print "Moving image:", coverItem.url, "to", coversModel.albumItem.get_aa ().get_media_art_path ()
+ os.rename (coverItem.url, coversModel.albumItem.get_aa().get_media_art_path ())
+ # Update the main model. Is this enough?
+ coversModel.albumItem.album_art = None
+ coversModel.albumItem.album_art = coversModel.albumItem.get_aa().get_media_art_path ()
+
+ @QtCore.Slot ()
+ def stop_pending_jobs (self):
+ if self.download :
+ self.download.quit ()
def get_all_albums (self):
"""
"""
results = []
for album_title, album_artist in self.tracker.get_all_albums ():
- album_art = getCoverArtThumbFileName (album_title)
- if (not os.path.exists (album_art)):
- album_art = None
-
- results.append (AlbumItem (album_title, album_artist, album_art))
+ results.append (AlbumItem (album_title, album_artist))
return results