counter += 1
+class MassiveDownloadsThread (QtCore.QThread):
+
+ def __init__ (self, albumModel):
+ QtCore.QThread.__init__ (self)
+ self.downloader = MussorgskyAlbumArt ()
+ self.albumModel = albumModel
+
+ def run (self):
+ print "Download one cover per-album in a thread"
+ import time
+ time.sleep (4)
+ for albumItem in self.albumModel.get_albums ():
+ if albumItem.require_download:
+ self.downloader.get_album_art (albumItem)
+
+
class MussorgskyController (QtCore.QObject):
def __init__ (self, rootContext):
self.download = None
self.ctx = rootContext
self.tracker = TrackerBackend ()
+ self.__is_downloading = False
-# @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 ()
+ def _is_downloading (self):
+ return self.__is_downloading
+
+ def _set_is_downloading (self, value):
+ if (value != self.__is_downloading):
+ self.__is_downloading = value
+ self.is_downloading_changed.emit ()
+
+ is_downloading_changed = QtCore.Signal ()
+ is_downloading = QtCore.Property (bool, _is_downloading, notify=is_downloading_changed)
@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)
+ self._set_is_downloading (True)
+ self.download_all_thread = MassiveDownloadsThread (albumModel)
+ self.download_all_thread.finished.connect (self.download_all_finished)
+ self.download_all_thread.start ()
+ print "now we are downloading..."
+
+ @QtCore.Slot ()
+ def download_all_finished (self):
+ self._set_is_downloading (False)
+
@QtCore.Slot (QtCore.QObject)
def get_options_for (self, albumItem):
for album_title, album_artist in self.tracker.get_all_albums ():
results.append (AlbumItem (album_title, album_artist))
return results
+