[gnome-music/allartists] view all artists and load more button



commit fc01cdf55a25afdd621a2f32758ac17eead83f41
Author: Eslam Mostafa <cseslam gmail com>
Date:   Sun May 19 20:32:29 2013 +0200

    view all artists and load more button

 src/grilo.js   |   11 ++++++++
 src/view.js    |   77 ++++++++++++++++++++++++++++++++++++++++++--------------
 src/widgets.js |    5 +--
 3 files changed, 71 insertions(+), 22 deletions(-)
---
diff --git a/src/grilo.js b/src/grilo.js
index d597715..2bd1a1c 100644
--- a/src/grilo.js
+++ b/src/grilo.js
@@ -100,6 +100,17 @@ const Grilo = new Lang.Class({
                 Lang.bind(this, callback, null));
     },
 
+    getAllAlbums: function (callback) {
+        var query =  Query.album;
+        var options = Grl.OperationOptions.new(null);
+        options.set_flags (Grl.ResolutionFlags.FULL | Grl.ResolutionFlags.IDLE_RELAY);
+        grilo.tracker.query(
+            query,
+                [Grl.METADATA_KEY_ID, Grl.METADATA_KEY_TITLE, Grl.METADATA_KEY_ARTIST, 
Grl.METADATA_KEY_CREATION_DATE],
+                options,
+                Lang.bind(this, callback, null));
+    },
+
     _searchCallback: function search_cb () {
         log ("yeah");
     },
diff --git a/src/view.js b/src/view.js
index 525b11f..2b40959 100644
--- a/src/view.js
+++ b/src/view.js
@@ -51,7 +51,6 @@ function extractFileName(uri) {
 
 const grilo = Grilo.grilo;
 
-
 const LoadMoreButton = new Lang.Class({
     Name: 'LoadMoreButton',
     _init: function(counter) {
@@ -470,25 +469,39 @@ const Artists = new Lang.Class({
         this._artists = {};
         this.countQuery = Query.artist_count;
         this._artistAlbumsWidget = new Gtk.Frame({
-            shadow_type:    Gtk.ShadowType.NONE
+            shadow_type: Gtk.ShadowType.NONE
         });
         this.view.set_view_type(Gd.MainViewType.LIST);
         this.view.set_hexpand(false);
         this._artistAlbumsWidget.set_hexpand(true);
         this.view.get_style_context().add_class("artist-panel");
         this.view.get_generic_view().get_selection().set_mode(Gtk.SelectionMode.SINGLE);
-        var scrolledWindow = new Gtk.ScrolledWindow();
+        this.albumsCountQuery = Query.album_count;
+        let loadMoreBtn = new LoadMoreButton(this._getRemainingAlbumsCount);
+        let scrolledWindow = new Gtk.ScrolledWindow();
         scrolledWindow.set_policy(
             Gtk.PolicyType.NEVER,
             Gtk.PolicyType.AUTOMATIC);
         scrolledWindow.add(this._artistAlbumsWidget);
         this._grid.attach(new Gtk.Separator({orientation: Gtk.Orientation.VERTICAL}), 1, 0, 1, 1)
         this._grid.attach(scrolledWindow, 2, 0, 1, 1);
+        this._grid.attach(loadMoreBtn.widget, 2, 1, 1, 1);
         this._addListRenderers();
         if(Gtk.Settings.get_default().gtk_application_prefer_dark_theme)
             this.view.get_generic_view().get_style_context().add_class("artist-panel-dark");
         else
             this.view.get_generic_view().get_style_context().add_class("artist-panel-white");
+        this._albumsOffset = 0;
+        var iter = this._model.append();
+        this._artists["All Artists".toLowerCase()] = {"iter": iter, "albums": []};
+        this._model.set(
+            iter,
+            [0, 1, 2, 3],
+            ["All Artists", "All Artists", "All Artists", "All Artists"]
+        );
+        this.emit("artist-added");
+        this.view.emit('item-activated', "0", this._model.get_path(iter));
+        loadMoreBtn.widget.connect("clicked", Lang.bind(this, this.populateAlbums));
         this.show_all();
 
     },
@@ -496,9 +509,9 @@ const Artists = new Lang.Class({
     _addListRenderers: function() {
         let listWidget = this.view.get_generic_view();
 
-        var cols = listWidget.get_columns()
-        var cells = cols[0].get_cells()
-        cells[2].visible = false
+        var cols = listWidget.get_columns();
+        var cells = cols[0].get_cells();
+        cells[2].visible = false;
 
         let typeRenderer =
             new Gd.StyledTextRenderer({ xpad: 0 });
@@ -516,10 +529,16 @@ const Artists = new Lang.Class({
     _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"]
+            this._artistAlbumsWidget.remove(children[i]);
+        if(id == "All Artists") {
+            var artist = "All Artists"
+            this.populateAlbums();
+        }
+        else {
+            var iter = this._model.get_iter (path)[1];
+            var artist = this._model.get_value (iter, 0);
+        }
+        var albums = this._artists[artist.toLowerCase()]["albums"];
         this.artistAlbums = new Widgets.ArtistAlbums(artist, albums, this.player);
         this._artistAlbumsWidget.add(this.artistAlbums);
         //this._artistAlbumsWidget.update(artist, albums);
@@ -528,22 +547,22 @@ const Artists = new Lang.Class({
     _addItem: function (source, param, item) {
         this._offset += 1;
         if( item == null )
-            return
-        var artist = "Unknown"
+            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)
+            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._artists[artist.toLowerCase()] = {"iter": iter, "albums": []};
             this._model.set(
-            iter,
-            [0, 1, 2, 3],
-            [artist, artist, artist, artist]
-        );
+                iter,
+                [0, 1, 2, 3],
+                [artist, artist, artist, artist]
+            );
         }
-        this._artists[artist.toLowerCase()]["albums"].push(item)
+        this._artists[artist.toLowerCase()]["albums"].push(item);
         this.emit("artist-added");
     },
 
@@ -553,4 +572,24 @@ const Artists = new Lang.Class({
             //FIXME: We're emitting this too early, need to wait for all artists to be filled in
         }
     },
+
+    populateAlbums: function () {
+        if (grilo.tracker != null) {
+            grilo.populateAlbums (this._albumsOffset, Lang.bind(this, 
+                function (source, prefs, album) {
+                    this._artists["All Artists".toLowerCase()]["albums"].push(album);
+                    this._albumsOffset += 1;
+            }));
+        }
+    },
+
+    _getRemainingAlbumsCount: function () {
+        let count = -1;
+        if (this.albumsCountQuery != null) {
+            let cursor = tracker.query(this.albumsCountQuery, null)
+            if (cursor != null && cursor.next(null))
+                count = cursor.get_integer(0);
+        }
+        return ( count - this._offset);
+    },
 });
diff --git a/src/widgets.js b/src/widgets.js
index e0ff3d6..82ee8b4 100644
--- a/src/widgets.js
+++ b/src/widgets.js
@@ -264,7 +264,6 @@ const ArtistAlbums = new Lang.Class({
                 GObject.TYPE_BOOLEAN
                 ]);
 
-
         this.pack_start(this.ui.get_object("ArtistAlbumsWidget"), false, false, 0);
         var hbox = new Gtk.Box({orientation: Gtk.Orientation.VERTICAL});
         hbox.set_spacing(48);
@@ -315,6 +314,7 @@ const ArtistAlbums = new Lang.Class({
         return false;
 
     },
+
     cleanModel: function(){
         let [res, iter] = this.model.get_iter_first();
         if (!res)
@@ -328,8 +328,8 @@ const ArtistAlbums = new Lang.Class({
             songWidget.title.set_markup("<span>" + escapedTitle + "</span>");
         } while(this.model.iter_next(iter));
         return false;
+    },
 
-    }
 });
 Signals.addSignalMethods(ArtistAlbums.prototype);
 
@@ -451,6 +451,5 @@ const ArtistAlbumWidget = new Lang.Class({
         this.player.setPlaylist ("Artist", this.album, widget.model, widget.iter, 5);
         this.player.setPlaying(true);
     },
-
 });
 Signals.addSignalMethods(ArtistAlbumWidget.prototype);


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