[gnome-documents] window: use the new source-id property on the loader



commit 8f4c66b3f65af7babe4649dc0c012a5d3bbcc8bd
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Thu Jul 21 02:24:00 2011 -0400

    window: use the new source-id property on the loader
    
    So we support GData documents too.

 src/mainWindow.js |   37 +++++++++++++++++++++++++------------
 src/view.js       |    3 ++-
 2 files changed, 27 insertions(+), 13 deletions(-)
---
diff --git a/src/mainWindow.js b/src/mainWindow.js
index ea2fbf2..320f3a4 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -55,6 +55,9 @@ MainWindow.prototype = {
         this._loaderTimeout = 0;
         this._loaderSignal = 0;
 
+        //TODO save this in GSettings?
+        this._currentSourceId = 'all';
+
         this.window = new Gtk.Window({ type: Gtk.WindowType.TOPLEVEL,
                                        window_position: Gtk.WindowPosition.CENTER,
                                        title: _('Documents') });
@@ -162,26 +165,32 @@ MainWindow.prototype = {
 
     _onModelCreated: function() {
         this.view.setModel(this._model.model);
-        this._model.populateForOverview();
+        this._model.populateForOverview(this._currentSourceId);
     },
 
     _onDeleteEvent: function() {
         Main.application.quit();
     },
 
-    _onViewItemActivated: function(view, uri) {
+    _onViewItemActivated: function(view, uri, resource) {
         if (this._loaderTimeout != 0) {
             Mainloop.source_remove(this._loaderTimeout);
             this._loaderTimeout = 0;
         }
 
-        this._pdfLoader = new Gd.PdfLoader();
-        this._loaderSignal =
-            this._pdfLoader.connect('notify::document', Lang.bind(this, this._onDocumentLoaded));
-        this._pdfLoader.uri = uri;
+        log('activated, resource ' + resource);
+
+        this._model.sourceIdFromResourceUrn(resource, Lang.bind(this,
+            function(sourceId) {
+                log('source ' + sourceId);
+                this._pdfLoader = new Gd.PdfLoader({ source_id: sourceId });
+                this._loaderSignal =
+                    this._pdfLoader.connect('notify::document', Lang.bind(this, this._onDocumentLoaded));
+                this._pdfLoader.uri = uri;
 
-        this._loaderTimeout = Mainloop.timeout_add(_PDF_LOADER_TIMEOUT,
-                                                   Lang.bind(this, this._onPdfLoaderTimeout));
+                this._loaderTimeout = Mainloop.timeout_add(_PDF_LOADER_TIMEOUT,
+                                                           Lang.bind(this, this._onPdfLoaderTimeout));
+            }));
     },
 
     _onPdfLoaderTimeout: function() {
@@ -199,7 +208,6 @@ MainWindow.prototype = {
         let document = loader.document;
         let model = EvView.DocumentModel.new_with_document(document);
 
-        this._pdfLoader = null;
         this._loaderSignal = 0;
 
         if (this._loaderTimeout) {
@@ -214,14 +222,18 @@ MainWindow.prototype = {
     },
 
     _onToolbarBackClicked: function() {
-        if (this._pdfLoader && this._loaderSignal) {
+        if (this._loaderSignal) {
             this._pdfLoader.disconnect(this._loaderSignal);
             this._loaderSignal = 0;
-            this._pdfLoader = null;
         }
 
-        if (this._preview)
+        this._pdfLoader.cleanup_document();
+        this._pdfLoader = null;
+
+        if (this._preview) {
             this._preview.destroy();
+            this._preview = null;
+        }
 
         this._sidebar.widget.show();
         this._toolbar.setOverview();
@@ -254,6 +266,7 @@ MainWindow.prototype = {
     },
 
     _onSourceFilterChanged: function(sidebar, id) {
+        this._currentSourceId = id;
         this._model.setAccountFilter(id);
     }
 }
diff --git a/src/view.js b/src/view.js
index 80496e8..613d887 100644
--- a/src/view.js
+++ b/src/view.js
@@ -55,8 +55,9 @@ View.prototype = {
     activateItem: function(path) {
         let iter = this.model.get_iter(path)[1];
         let uri = this.model.get_value(iter, TrackerModel.ModelColumns.URI);
+        let resource = this.model.get_value(iter, TrackerModel.ModelColumns.RESOURCE_URN);
 
-        this.emit('item-activated', uri);
+        this.emit('item-activated', uri, resource);
     }
 };
 Signals.addSignalMethods(View.prototype);



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