Another vi modeline.
[profile/ivi/cowhide.git] / examples / hoofbeats / javascripts / library.js
index 82a6986..6a5d570 100644 (file)
@@ -1,7 +1,9 @@
+/* vi: set et sw=4 ts=4 si: */
 $(function() {
     var library = function() {
         // For readability:
         this.initialized = false;
+
         this.fetchCount = 100;
         this.fetchOffset = 0;
         this.mediaItems = [];
@@ -20,51 +22,56 @@ $(function() {
                 "type", "EXACTLY", "VIDEO");
             this.typeFilter = new tizen.CompositeFilter(
                 "UNION", [this.audioTypeFilter, this.videoTypeFilter]);
-
-            this.sortMode = new tizen.SortMode("trackNumber", "ASC");
-            this.mediaSource = tizen.mediacontent.getLocalMediaSource();
         };
 
         this.scan = function() {
+            this.deferred = new $.Deferred();
             this.initialize()
 
             this.mediaItems = [];
             this.fetchOffset = 0;
 
-            this.mediaSource.findItems(
-                this.findItemsCB.bind(this),
+            tizen.content.find(
+                this.findCB.bind(this),
                 this.errorCB.bind(this),
                 null,
                 this.typeFilter,
-                this.sortMode,
+                null,
                 this.fetchCount,
                 this.fetchOffset);
+
+            return this.deferred.promise();
         };
 
         this.errorCB = function(error) {
             console.log("Error: " + error.name);
+            this.deferred.reject();
             throw new Error(error.name);
         };
 
-        this.findItemsCB = function(items) {
+        this.findCB = function(items) {
             var self = this;
 
             items.forEach(function(item, index, items) {
                 self.mediaItems.push(item);
-                console.log("Item added to the library: " + item.title);
+                window.MusicBrainz.getArtist(item.name).done(function(data) {
+                    console.log(data);
+                });
             });
 
             if (items.length == this.fetchCount) {
                 // There *might* be more items.
                 this.fetchOffset += this.fetchCount;
-                this.mediaSource.findItems(
-                    this.findItemsCB.bind(this),
+                tizen.content.find(
+                    this.findCB.bind(this),
                     this.errorCB.bind(this),
                     null,
                     this.typeFilter,
-                    this.sortMode,
+                    null,
                     this.fetchCount,
                     this.fetchOffset);
+            } else {
+                self.deferred.resolve();
             }
         };
     };