--- /dev/null
+# -*- coding: utf-8 -*-
+import os
+import sys
+from PySide import QtCore
+from PySide import QtGui
+from PySide import QtDeclarative
+
+
+class AlbumItem (QtCore.QObject):
+
+ def __init__ (self, title, artist, album_art):
+ QtCore.QObject.__init__(self)
+ self._title = title
+ self._artist = artist
+ self._album_art = album_art
+
+ def _title (self):
+ return self._title
+
+ def _artist (self):
+ return self._artist
+
+ def _album_art (self):
+ return self._album_art
+
+ @QtCore.Signal
+ def changed (self): pass
+
+ title = QtCore.Property (unicode, _title, notify=changed)
+ artist = QtCore.Property (unicode, _artist, notify=changed)
+ album_art = QtCore.Property (unicode, _album_art, notify=changed)
+
--- /dev/null
+# -*- coding: utf-8 -*-
+import os
+import sys
+from PySide import QtCore
+from PySide import QtGui
+from PySide import QtDeclarative
+
+from albumItem import AlbumItem
+
+class AlbumModel (QtCore.QAbstractListModel):
+ COLUMNS = ('album', )
+
+ def __init__ (self, data):
+ QtCore.QAbstractListModel.__init__ (self)
+ self._albums = data
+ self.setRoleNames (dict(enumerate(AlbumModel.COLUMNS)))
+
+ def rowCount (self, parent=QtCore.QModelIndex()):
+ return len (self._albums)
+
+ def data (self, index, role):
+ if index.isValid () and role == AlbumModel.COLUMNS.index ('album'):
+ return self._albums[index.row ()]
+ return None
--- /dev/null
+# -*- coding: utf-8 -*-
+import os
+import sys
+from PySide import QtCore
+from PySide import QtGui
+from PySide import QtDeclarative
+
+
+class Controller (QtCore.QObject):
+
+ @QtCore.Slot (QtCore.QObject)
+ def albumSelected (self, wrapper):
+ print "Called controller, but nothing to do here yet"
+
--- /dev/null
+import os
+
+from tracker_backend_gi import TrackerBackendGI
+
+from albumItem import AlbumItem
+from album_art_spec import getCoverArtThumbFileName
+
+
+class MussorgskyLogic:
+
+ def __init__ (self):
+ self.tracker = TrackerBackendGI ()
+
+
+ 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))
+ return results
+
+
+# To test everything is fine here
+if __name__ == "__main__":
+ l = MussorgskyLogic ()
+ l.get_all_albums ()
+
+
--- /dev/null
+import gi
+from gi.repository import Tracker
+
+# (album name, artist1|artist2|... , number of artists)
+ALBUM_ARTISTS_COUNTER = """
+SELECT nie:title (?album) nmm:artistName (?artist) COUNT (?artist)
+WHERE
+ {
+ ?album a nmm:MusicAlbum ;
+ nmm:albumArtist ?artist .
+ }
+GROUP BY ?album
+"""
+
+class TrackerBackendGI:
+
+ def __init__ (self):
+ self.conn = Tracker.SparqlConnection.get (None)
+
+ def get_all_albums (self):
+ """
+ Generator returning (album_title, album_artist)
+ If the album has more than one artist, "Various artists"
+ """
+ cursor = self.conn.query (ALBUM_ARTISTS_COUNTER, None)
+ while cursor.next (None):
+ album_title = cursor.get_string (0)[0]
+ if cursor.get_integer(2) > 1:
+ album_artist = "Various artists"
+ else:
+ album_artist = cursor.get_string (1)[0]
+
+ yield (album_title, album_artist)
+
+
+
+if __name__ == "__main__":
+
+ tracker = TrackerBackendGI()
+ tracker.get_all_albums ()