[gnome-music] Make the CollectionView songs clickable, to play them



commit 3793c0173991b5f78a2dabb65a12503c9deb3d09
Author: CÃsar GarcÃa Tapia <cesar garcia tapia openshine com>
Date:   Mon Oct 29 15:49:28 2012 +0100

    Make the CollectionView songs clickable, to play them

 src/music-app.vala            |    5 +++++
 src/music-playlist-songs.vala |   29 ++++++++++++++++++++++++++---
 src/music-playlist-view.vala  |    5 +++++
 3 files changed, 36 insertions(+), 3 deletions(-)
---
diff --git a/src/music-app.vala b/src/music-app.vala
index 0936ef1..59da043 100644
--- a/src/music-app.vala
+++ b/src/music-app.vala
@@ -185,6 +185,7 @@ private class Music.App {
         notebook.append_page (collectionView.actor, null);
 
         playlistView = new Music.PlaylistView ();
+        playlistView.song_selected.connect (on_playlistview_song_selected);
         notebook.append_page (playlistView.actor, null);
 
         player = new Music.Player ();
@@ -223,6 +224,10 @@ private class Music.App {
         }
     }
 
+    private void on_playlistview_song_selected (Grl.Media media) {
+        player.load (media);
+    }
+
     private void on_browse_history_changed () {
         if (browse_history.get_length () > 1) {
             topbar.set_collection_back_button_visible (true);
diff --git a/src/music-playlist-songs.vala b/src/music-playlist-songs.vala
index 4a64bc8..9e78e91 100644
--- a/src/music-playlist-songs.vala
+++ b/src/music-playlist-songs.vala
@@ -20,6 +20,9 @@ using Gee;
 
 private class Music.PlaylistSongs {
     public Gtk.Widget actor { get { return alignment; } }
+
+    public signal void song_selected (Grl.Media media);
+
     private Gtk.Alignment alignment;
     private Gtk.Grid grid;
 
@@ -56,14 +59,23 @@ private class Music.PlaylistSongs {
             options.set_flags (Grl.ResolutionFlags.NORMAL);
 
             var id = media.get_id ();
+
             var query = @"SELECT rdf:type (?song)
                                  ?song
                                  tracker:id(?song) AS id
                                  nie:title(?song) AS title
                                  ?duration
+                                 ?url
+                                 tracker:coalesce (nie:title(?album), '') AS site
+                                 tracker:coalesce (nmm:artistName(?artist), '') AS author
                           WHERE { ?song a nmm:MusicPiece;
                                         nfo:duration ?duration;
-                                        nmm:musicAlbum ?album FILTER (tracker:id (?album) = $id ) }";
+                                        nie:url ?url;
+                                        nmm:musicAlbum ?album FILTER (tracker:id (?album) = $id ) .
+                                  OPTIONAL { ?song nmm:musicAlbum ?album } .
+                                  OPTIONAL { ?album nmm:albumArtist ?artist }
+                          }";
+            debug (query);
 
             foreach (var source in source_list.values) {
                 source.query (query, keys, options, (source, query_id, media, remaining, error) => {
@@ -73,11 +85,17 @@ private class Music.PlaylistSongs {
         }
     }
 
-        private void load_item_cb (Grl.Media? media,
+    private void load_item_cb (Grl.Media? media,
                                uint remaining) {
         if (media != null) {
-            var title = new Gtk.Label (media.get_title ());
+            var title_string = media.get_title ();
+            var title = new Gtk.Label (null);
+            title.set_markup (@"<a href=''>$title_string</a>");
             title.set_alignment (0, (float)0.5);
+            title.activate_link.connect (() => {
+                on_title_clicked (media);
+                return true;
+            });
             title.show();
 
             var duration = media.get_duration ();
@@ -91,6 +109,11 @@ private class Music.PlaylistSongs {
         }
     }
 
+    private void on_title_clicked (Grl.Media media) {
+        song_selected (media);
+
+    }
+
     private void set_grl () {
         var registry = Grl.Registry.get_default ();
 
diff --git a/src/music-playlist-view.vala b/src/music-playlist-view.vala
index df11ed9..ba0ef0e 100644
--- a/src/music-playlist-view.vala
+++ b/src/music-playlist-view.vala
@@ -21,6 +21,8 @@ using Gee;
 private class Music.PlaylistView {
     public Gtk.Widget actor { get { return scrolled_window; } }
 
+    public signal void song_selected (Grl.Media media);
+
     private Gtk.ScrolledWindow scrolled_window;
     private Music.AlbumInfoBox album_info_box;
     private Music.PlaylistSongs playlist_songs;
@@ -42,6 +44,9 @@ private class Music.PlaylistView {
 
         /* Playlist songs Box */
         playlist_songs = new Music.PlaylistSongs ();
+        playlist_songs.song_selected.connect ((media) => {
+            song_selected (media);
+        });
         layout.pack_start (playlist_songs.actor, false, false);
 
         scrolled_window = new Gtk.ScrolledWindow (null, null);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]