[the-board/tracker: 3/14] [model] Initial code in PageManager to connect to Tracker



commit 5edddf6b650ebc9dfcae4f6d0bca9e2e69094560
Author: Lucas Rocha <lucasr lucasr org>
Date:   Sat May 7 23:43:48 2011 +0100

    [model] Initial code in PageManager to connect to Tracker

 src/js/model/pageManager.js |   60 +++++++++++++++++++++++++++++++++---------
 1 files changed, 47 insertions(+), 13 deletions(-)
---
diff --git a/src/js/model/pageManager.js b/src/js/model/pageManager.js
index 29b0038..5f29661 100644
--- a/src/js/model/pageManager.js
+++ b/src/js/model/pageManager.js
@@ -3,14 +3,17 @@ const Lang = imports.lang;
 const Mainloop = imports.mainloop;
 const Signals = imports.signals;
 
+// gi imports
+const GIO = imports.gi.Gio;
+const Tracker = imports.gi.Tracker;
+
 // model imports
 const PageModel = imports.model.pageModel;
 
 let State = {
     IDLE : 0,
-    LOADING_PAGES_FILE : 1,
-    LOADING_PAGES : 2,
-    LOADED : 3
+    CONNECTING : 1,
+    READY : 2
 }
 
 const _SAVE_PAGES_TIMEOUT = 5;
@@ -23,10 +26,30 @@ PageManager.prototype = {
     _init : function(args) {
         args = args || {};
 
+        this._connection = null;
+
         this._pagesToSave = [];
         this._saving = false;
 
         this._state = State.IDLE; 
+
+        this._connectToTracker();
+    },
+
+    _connectToTracker : function() {
+        if (this._connection) {
+            return;
+        }
+
+        // Now we're in connecting state
+        this._setState(State.CONNECTING);
+
+        // This will allow to cancell operation is necessary
+        this._getConnectionCancellable = new GIO.Cancellable();
+
+        Tracker.SparqlConnection.get_async(this._getConnectionCancellable,
+                                           Lang.bind(this, this._onGetConnectionAsync),
+                                           null);
     },
 
     _setState : function(state) {
@@ -61,10 +84,6 @@ PageManager.prototype = {
                           path: this._pagesDir + '/' + filename,
                           isNew: isNew };
 
-        if (id in this._pagesIndex) {
-            modelArgs.title = this._pagesIndex[id].title;
-        }
-
         let pageModel = new PageModel.PageModel(modelArgs);
 
         pageModel._PageManager_dirtyChangedId =
@@ -123,13 +142,28 @@ PageManager.prototype = {
             this._saving = false;
         };
 
-        let onPagesIndexSaved = function() {
-            this._savePageModels(this._pagesToSave,
-                                 Lang.bind(this, onPageModelsSaved));
-        };
+        this._savePageModels(this._pagesToSave,
+                             Lang.bind(this, onPageModelsSaved));
+    },
+
+    _onGetConnectionAsync : function(source, result, data) {
+        let cancellable = this._getConnectionCancellable;
+        delete this._getConnectionCancellable;
+
+        // If operation has been cancelled, we just stop
+        if (cancellable.is_cancelled()) {
+            return;
+        }
 
-        this._syncPagesWithIndex(this._pagesToSave);
-        this._savePagesIndex(Lang.bind(this, onPagesIndexSaved));
+        try {
+            this._connection = Tracker.SparqlConnection.get_finish(result);
+        } catch(e) {
+            log("PageManager: failed to connect to Tracker");
+        }
+
+        if (this._connection) {
+            this._setState(State.READY);
+        }
     },
 
     _onPageModelDirtyChanged : function(pageModel) {



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