[gnome-music] Add initial "Artsits" view
- From: Seif Lotfy <seiflotfy src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music] Add initial "Artsits" view
- Date: Wed, 10 Apr 2013 11:13:30 +0000 (UTC)
commit 0206004575b0383b50e16f57cbefdd4bfc250a89
Author: Seif Lotfy <seif lotfy com>
Date: Wed Apr 10 13:12:58 2013 +0200
Add initial "Artsits" view
src/grilo.js | 4 +++
src/query.js | 4 ++-
src/view.js | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/widgets.js | 54 ++++++++++++++++++++++++++++++++++++++++++
4 files changed, 132 insertions(+), 1 deletions(-)
---
diff --git a/src/grilo.js b/src/grilo.js
index 4d92564..5dce815 100644
--- a/src/grilo.js
+++ b/src/grilo.js
@@ -65,6 +65,10 @@ const Grilo = new Lang.Class({
}
},
+ populateArtists: function (offset, callback) {
+ this.populateItems (Query.artist, offset, callback)
+ },
+
populateAlbums: function (offset, callback) {
this.populateItems (Query.album, offset, callback)
},
diff --git a/src/query.js b/src/query.js
index 1cae593..7bd4e17 100644
--- a/src/query.js
+++ b/src/query.js
@@ -20,7 +20,9 @@
const Tracker = imports.gi.Tracker;
-const album = 'SELECT DISTINCT rdf:type(?album) tracker:id(?album) as id (SELECT nmm:artistName(?artist)
WHERE { ?album nmm:albumArtist ?artist } LIMIT 1) AS artist nie:title(?album) as title nie:title(?album) as
album tracker:coalesce( (SELECT GROUP_CONCAT(nmm:artistName(?artist), ",") WHERE { ?album nmm:albumArtist
?artist }), (SELECT GROUP_CONCAT((SELECT nmm:artistName(nmm:performer(?_12)) as perf WHERE { ?_12
nmm:musicAlbum ?album } GROUP BY ?perf), ",") as album_performer WHERE { }) ) as author
xsd:integer(tracker:coalesce(nmm:albumTrackCount(?album), (SELECT COUNT(?_1) WHERE { ?_1 nmm:musicAlbum
?album; tracker:available "true" }))) as childcount (SELECT fn:year-from-dateTime(?c) WHERE { ?_2
nmm:musicAlbum ?album; nie:contentCreated ?c; tracker:available "true" } LIMIT 1) as publishing-date { ?album
a nmm:MusicAlbum FILTER (EXISTS { ?_3 nmm:musicAlbum ?album; tracker:available "true" }) } ORDER BY
?album_artist ?albumyear nie:title(?album)';
+const album = 'SELECT DISTINCT rdf:type(?album) tracker:id(?album) as id (SELECT nmm:artistName(?artist)
WHERE { ?album nmm:albumArtist ?artist } LIMIT 1) AS artist nie:title(?album) as title nie:title(?album) as
album tracker:coalesce( (SELECT GROUP_CONCAT(nmm:artistName(?artist), ",") WHERE { ?album nmm:albumArtist
?artist }), (SELECT GROUP_CONCAT((SELECT nmm:artistName(nmm:performer(?_12)) as perf WHERE { ?_12
nmm:musicAlbum ?album } GROUP BY ?perf), ",") as album_performer WHERE { }) ) as author
xsd:integer(tracker:coalesce(nmm:albumTrackCount(?album), (SELECT COUNT(?_1) WHERE { ?_1 nmm:musicAlbum
?album; tracker:available "true" }))) as childcount (SELECT fn:year-from-dateTime(?c) WHERE { ?_2
nmm:musicAlbum ?album; nie:contentCreated ?c; tracker:available "true" } LIMIT 1) as publishing-date { ?album
a nmm:MusicAlbum FILTER (EXISTS { ?_3 nmm:musicAlbum ?album; tracker:available "true" }) } ORDER BY
nie:title(?album) ?author ?albumyear';
+
+const artist = 'SELECT DISTINCT rdf:type(?album) tracker:id(?album) as id (SELECT nmm:artistName(?artist)
WHERE { ?album nmm:albumArtist ?artist } LIMIT 1) AS artist nie:title(?album) as title nie:title(?album) as
album tracker:coalesce( (SELECT GROUP_CONCAT(nmm:artistName(?artist), ",") WHERE { ?album nmm:albumArtist
?artist }), (SELECT GROUP_CONCAT((SELECT nmm:artistName(nmm:performer(?_12)) as perf WHERE { ?_12
nmm:musicAlbum ?album } GROUP BY ?perf), ",") as album_performer WHERE { }) ) as author
xsd:integer(tracker:coalesce(nmm:albumTrackCount(?album), (SELECT COUNT(?_1) WHERE { ?_1 nmm:musicAlbum
?album; tracker:available "true" }))) as childcount (SELECT fn:year-from-dateTime(?c) WHERE { ?_2
nmm:musicAlbum ?album; nie:contentCreated ?c; tracker:available "true" } LIMIT 1) as publishing-date { ?album
a nmm:MusicAlbum FILTER (EXISTS { ?_3 nmm:musicAlbum ?album; tracker:available "true" }) } ORDER BY ?author
?albumyear nie:title(?album)';
const album_count = 'SELECT COUNT(?album) AS childcount WHERE { ?album a nmm:MusicAlbum }';
diff --git a/src/view.js b/src/view.js
index cfc17fa..bc4bed9 100644
--- a/src/view.js
+++ b/src/view.js
@@ -399,5 +399,76 @@ const Artists = new Lang.Class({
_init: function(header_bar, player) {
this.parent("Artists", header_bar);
+ this._artists = {};
+ this._artistAlbumsWidget = new Gtk.VBox();
+ this.view.set_view_type(Gd.MainViewType.LIST);
+ this.view.set_hexpand(false);
+ this._artistAlbumsWidget.set_hexpand(true);
+ var scrolledWindow = new Gtk.ScrolledWindow();
+ scrolledWindow.set_policy(
+ Gtk.PolicyType.NEVER,
+ Gtk.PolicyType.AUTOMATIC);
+ scrolledWindow.add(this._artistAlbumsWidget)
+ this._grid.attach(scrolledWindow, 1, 0, 1, 1);
+ this._addListRenderers();
+ this.show_all();
+
+ },
+
+ _addListRenderers: function() {
+ let listWidget = this.view.get_generic_view();
+
+ var cols = listWidget.get_columns()
+ var cells = cols[0].get_cells()
+ cells[2].visible = false
+
+ let typeRenderer =
+ new Gd.StyledTextRenderer({ xpad: 0 });
+ typeRenderer.set_property("ellipsize", 3);
+ typeRenderer.set_property("xalign", 0.0);
+ typeRenderer.set_property("yalign", 0.5);
+ typeRenderer.set_property("height", 48);
+ listWidget.add_renderer(typeRenderer, Lang.bind(this,
+ function(col, cell, model, iter) {
+ typeRenderer.text = model.get_value(iter, 0);
+ }));
+ },
+
+ _onItemActivated: function (widget, id, path) {
+ var children = this._artistAlbumsWidget.get_children();
+ for (var i=0; i<children.length; i++)
+ this._artistAlbumsWidget.remove(children[i])
+ var iter = this._model.get_iter (path)[1];
+ var artist = this._model.get_value (iter, 0);
+ var albums = this._artists[artist.toLowerCase()]["albums"]
+ var artistAlbums = new Widgets.ArtistAlbums(artist, albums);
+ this._artistAlbumsWidget.pack_start(artistAlbums, true, true, 0)
+ //this._artistAlbumsWidget.update(artist, albums);
+ },
+
+ _addItem: function (source, param, item) {
+ if( item == null )
+ return
+ var artist = "Unknown"
+ if (item.get_author() != null)
+ artist = item.get_author();
+ if (item.get_string(Grl.METADATA_KEY_ARTIST) != null)
+ artist = item.get_string(Grl.METADATA_KEY_ARTIST)
+ if (this._artists[artist.toLowerCase()] == undefined) {
+ var iter = this._model.append();
+ this._artists[artist.toLowerCase()] = {"iter": iter, "albums": []}
+ this._model.set(
+ iter,
+ [0, 1, 2, 3],
+ [artist, artist, artist, artist]
+ );
+ }
+ this._artists[artist.toLowerCase()]["albums"].push(item)
+ },
+
+ populate: function () {
+ if(grilo.tracker != null) {
+ grilo.populateArtists(this._offset, Lang.bind(this, this._addItem, null));
+ }
},
});
diff --git a/src/widgets.js b/src/widgets.js
index aefdac1..616942c 100644
--- a/src/widgets.js
+++ b/src/widgets.js
@@ -216,3 +216,57 @@ const AlbumWidget = new Lang.Class({
},
});
+
+
+const ArtistAlbums = new Lang.Class({
+ Name: "ArtistAlbumsWidget",
+ Extends: Gtk.VBox,
+
+ _init: function (artist, albums) {
+ this.artist = artist
+ this.albums = albums
+ this.parent();
+ this.set_border_width(24)
+ this.label = new Gtk.Label()
+ this.label.set_markup("<b>" + this.artist + "</b>")
+ this.label.set_alignment(0.0, 0.5)
+ this.pack_start(this.label, false, false, 0)
+ this.pack_start(new Gtk.HSeparator(), false, false, 12)
+ for (var i=0; i < albums.length; i++)
+ this.pack_start(new ArtistAlbumWidget(artist, albums[i]), false, false, 9);
+ this.show_all();
+ },
+});
+
+const ArtistAlbumWidget = new Lang.Class({
+ Name: "ArtistAlbumWidget",
+ Extends: Gtk.HBox,
+
+ _init: function (artist, album) {
+ this.parent();
+ this.album = album;
+ this.cover = new Gtk.Image();
+ this.title = new Gtk.Label();
+ this.title.set_ellipsize(2);
+ var pixbuf = albumArtCache.lookup (128, artist, album.get_title());
+ if (pixbuf == null) {
+ let path = "/usr/share/icons/gnome/scalable/places/folder-music-symbolic.svg";
+ pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(path, -1, 128, true);
+ }
+ this.cover.set_from_pixbuf (pixbuf);
+ this.pack_start(this.cover, false, false, 0)
+ var vbox = new Gtk.VBox()
+ this.pack_start(vbox, true, true, 32)
+ this.title.set_markup("<span color='grey'><b>" + album.get_title() + "</b></span>")
+ var tracks = [];
+ grilo.getAlbumSongs(album.get_id(), Lang.bind(this, function (source, prefs, track) {
+ if (track != null) {
+ tracks.push(track);
+ this.title.set_markup("<span color='grey'><b>" + album.get_title() + "</b> (" +
track.get_creation_date() + ")</span>")
+ }
+ }));
+ this.title.set_alignment(0.0, 0.5)
+ vbox.pack_start(this.title, false, false, 0)
+ this.show_all()
+ },
+});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]