1 # -*- coding: utf-8 -*-
4 from PySide import QtCore
5 from PySide import QtGui
6 from PySide import QtDeclarative
8 from aa_search import MussorgskyAlbumArt
11 from tracker_backend_gi import TrackerBackendGI as TrackerBackend
13 from tracker_backend_dbus import TrackerBackendDBus as TrackerBackend
15 from albumItem import AlbumItem
16 from aa_spec import getCoverArtThumbFileName, getCoverArtFileName
19 class DownloadThread (QtCore.QThread):
21 def __init__ (self, model, album):
22 QtCore.QThread.__init__ (self)
23 self.downloader = MussorgskyAlbumArt ()
28 print "Running the thread"
31 for img, thumb in self.downloader.get_alternatives (self.album.artist,
32 self.album.title, MAX_OPTIONS):
33 if counter >= MAX_OPTIONS:
36 self.model.updateData (counter, img, thumb)
40 class MussorgskyController (QtCore.QObject):
43 QtCore.QObject.__init__ (self)
45 self.tracker = TrackerBackend ()
47 @QtCore.Slot (QtCore.QObject, QtCore.QObject)
48 def albumSelected (self, coversModel, album):
50 Starts a thread to look for possible images online.
51 The thread will update the model (and the changes are visible in the UI)
53 print "clicked on", album.title
54 self.download = DownloadThread (coversModel, album)
55 self.download.start ()
57 @QtCore.Slot (QtCore.QObject, QtCore.QObject, int)
58 def coverSelected (self, coverObject, albumModel, index):
60 The user has clicked in one cover!
62 albumObject = albumModel.getAlbumInRow (index)
64 print "Selected cover", albumObject.title
65 filename = getCoverArtFileName (albumObject.title)
66 thumbnail = getCoverArtThumbFileName (albumObject.title)
68 coverObject.save (filename, thumbnail)
70 albumModel.updateThumb (index, filename)
71 #albumObject.album_art = thumbnail
72 albumObject.album_art_changed.emit ()
74 @QtCore.Slot (QtCore.QObject)
75 def resetAlternatives (self, coversModel):
76 print "Reseting alternatives", coversModel
77 QtGui.QPixmapCache.clear ()
78 coversModel.resetAlternatives ()
81 def get_all_albums (self):
83 Return a list of AlbumItem objects to build the model
84 This is not called from QML, no need to make it a slot
87 for album_title, album_artist in self.tracker.get_all_albums ():
88 album_art = getCoverArtThumbFileName (album_title)
89 if (not os.path.exists (album_art)):
92 results.append (AlbumItem (album_title, album_artist, album_art))