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
10 from tracker_backend_gi import TrackerBackendGI
12 from albumItem import AlbumItem
13 from aa_spec import getCoverArtThumbFileName, getCoverArtFileName
16 class DownloadThread (QtCore.QThread):
18 def __init__ (self, model, album):
19 QtCore.QThread.__init__ (self)
20 self.downloader = MussorgskyAlbumArt ()
25 print "Running the thread"
28 for img, thumb in self.downloader.get_alternatives (self.album.artist,
29 self.album.title, MAX_OPTIONS):
30 if counter >= MAX_OPTIONS:
33 self.model.updateData (counter, img, thumb)
37 class MussorgskyController (QtCore.QObject):
40 QtCore.QObject.__init__ (self)
42 self.tracker = TrackerBackendGI ()
44 @QtCore.Slot (QtCore.QObject, QtCore.QObject)
45 def albumSelected (self, model, album):
47 Starts a thread to look for possible images online.
48 The thread will update the model (and the changes are visible in the UI)
50 print "clicked on", album.title
51 self.download = DownloadThread (model, album)
52 self.download.start ()
54 @QtCore.Slot (QtCore.QObject, QtCore.QObject)
55 def albumSelected (self, model, album):
57 Starts a thread to look for possible images online.
58 The thread will update the model (and the changes are visible in the UI)
60 print "clicked on", album.title
61 self.download = DownloadThread (model, album)
62 self.download.start ()
64 @QtCore.Slot (str, QtCore.QObject)
65 def coverSelected (self, coverObject, albumObject):
67 The user has clicked in one cover!
69 print "Selected cover"
70 filename = getCoverArtFileName (albumObject.title)
71 thumbnail = getCoverArtThumbFileName (albumObject.title)
73 os.rename (cover.url, filename)
74 os.rename (cover.thumb, thumbnail)
76 albumObject.album_art = thumbnail
77 albumObject.album_art_changed.emit ()
79 @QtCore.Slot (QtCore.QObject)
80 def resetAlternatives (self, coversModel):
81 print "Reseting alternatives", coversModel
82 QtGui.QPixmapCache.clear ()
83 coversModel.resetAlternatives ()
86 def get_all_albums (self):
88 Return a list of AlbumItem objects to build the model
89 This is not called from QML, no need to make it a slot
92 for album_title, album_artist in self.tracker.get_all_albums ():
93 album_art = getCoverArtThumbFileName (album_title)
94 if (not os.path.exists (album_art)):
97 results.append (AlbumItem (album_title, album_artist, album_art))