[gnome-music/artistcss: 2/2] implement an empty view when there is no music



commit 2dbf358493ead423f0b7a6a6bfa7a3787d243ecf
Author: Eslam Mostafa <cseslam gmail com>
Date:   Fri May 10 01:05:52 2013 +0200

    implement an empty view when there is no music

 src/view.js   |   12 ++++++++++++
 src/window.js |   21 +++++++++++++++++----
 2 files changed, 29 insertions(+), 4 deletions(-)
---
diff --git a/src/view.js b/src/view.js
index 5624918..1d99e07 100644
--- a/src/view.js
+++ b/src/view.js
@@ -275,6 +275,18 @@ const ViewContainer = new Lang.Class({
 });
 Signals.addSignalMethods(ViewContainer.prototype);
 
+const Empty = new Lang.Class({
+    Name: "EmptyView",
+
+    _init: function(header_bar){
+        let builder = new Gtk.Builder();
+        builder.add_from_resource('/org/gnome/music/EmptyView.ui');
+        let widget = builder.get_object('container');
+        this.header_bar.setState(1);
+    },
+
+});
+
 const Albums = new Lang.Class({
     Name: "AlbumsView",
     Extends: ViewContainer,
diff --git a/src/window.js b/src/window.js
index 4559f52..0c2561f 100644
--- a/src/window.js
+++ b/src/window.js
@@ -29,6 +29,10 @@ const _ = imports.gettext.gettext;
 const Toolbar = imports.toolbar;
 const Views = imports.view;
 const Player = imports.player;
+const Query = imports.query;
+
+const Tracker = imports.gi.Tracker;
+const tracker = Tracker.SparqlConnection.get (null);
 
 const MainWindow = new Lang.Class({
     Name: "MainWindow",
@@ -63,11 +67,20 @@ const MainWindow = new Lang.Class({
         this._box.pack_start(this._stack, true, true, 0);
         this._box.pack_start(this.player.eventBox, false, false, 0);
         this.add(this._box);
+        let count = -1;
+            let cursor = tracker.query(Query.songs_count, null)
+            if (cursor != null && cursor.next(null))
+                count = cursor.get_integer(0);
+        print("Songs Count: "+count);
 
-        this.views[0] = new Views.Albums(this.toolbar, this.player);
-        this.views[1] = new Views.Artists(this.toolbar, this.player);
-        this.views[2] = new Views.Songs(this.toolbar, this.player);
-        this.views[3] = new Views.Playlists(this.toolbar, this.player);
+        if(count != 0) {
+            this.views[0] = new Views.Albums(this.toolbar, this.player);
+            this.views[1] = new Views.Artists(this.toolbar, this.player);
+            this.views[2] = new Views.Songs(this.toolbar, this.player);
+            this.views[3] = new Views.Playlists(this.toolbar, this.player);
+        } else {
+            this.views[0] = new Views.Empty(this.toolbar)
+        }
 
         for (let i in this.views) {
             this._stack.add_titled(


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