[gnome-documents] collections: re-implement support for collections as items in the view



commit 219e149ea2143eb0b6fa24d57329d98c8a11e01f
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Wed Nov 9 12:01:11 2011 -0500

    collections: re-implement support for collections as items in the view
    
    Instead of going through a separate query to the tracker model, just
    mark collections as such from the list of results we get back from the
    tracker store in the main query.

 src/Makefile-js.am |    1 -
 src/application.js |    3 +-
 src/collections.js |  145 ----------------------------------------------------
 src/documents.js   |   35 +++++++++++--
 src/embed.js       |    6 ++
 src/global.js      |    1 +
 src/mainToolbar.js |   58 +++++++++++++--------
 src/manager.js     |    3 -
 src/query.js       |   11 ----
 src/searchbar.js   |    4 ++
 10 files changed, 79 insertions(+), 188 deletions(-)
---
diff --git a/src/Makefile-js.am b/src/Makefile-js.am
index a3c2587..ca6a8b3 100644
--- a/src/Makefile-js.am
+++ b/src/Makefile-js.am
@@ -2,7 +2,6 @@ jsdir = $(pkgdatadir)/js/
 dist_js_DATA = \
     application.js \
     changeMonitor.js \
-    collections.js \
     documents.js \
     embed.js \
     error.js \
diff --git a/src/application.js b/src/application.js
index 28cd5bc..b4f236c 100644
--- a/src/application.js
+++ b/src/application.js
@@ -33,7 +33,6 @@ const GLib = imports.gi.GLib;
 const Tracker = imports.gi.Tracker;
 
 const ChangeMonitor = imports.changeMonitor;
-const Collections = imports.collections;
 const Documents = imports.documents;
 const Error = imports.error;
 const Format = imports.format;
@@ -147,7 +146,7 @@ Application.prototype = {
                         Global.searchTypeManager = new Searchbar.SearchTypeManager();
                         Global.queryBuilder = new Query.QueryBuilder();
                         Global.changeMonitor = new ChangeMonitor.TrackerChangeMonitor();
-                        Global.collectionManager = new Collections.CollectionManager();
+                        Global.collectionManager = new Manager.BaseManager();
                         Global.documentManager = new Documents.DocumentManager();
                         Global.trackerController = new TrackerController.TrackerController();
                         Global.selectionController = new Selections.SelectionController();
diff --git a/src/documents.js b/src/documents.js
index 526c6de..8408e31 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -66,6 +66,7 @@ DocCommon.prototype = {
 
         this.favorite = false;
         this.shared = false;
+        this.collection = false;
 
         this.thumbnailed = false;
 
@@ -120,8 +121,7 @@ DocCommon.prototype = {
 
         this.mimeType = cursor.get_string(Query.QueryColumns.MIMETYPE)[0];
         this.rdfType = cursor.get_string(Query.QueryColumns.RDFTYPE)[0];
-
-        this.updateTypeDescription();
+        this._updateInfoFromType();
 
         // sanitize
         if (!this.uri)
@@ -168,6 +168,13 @@ DocCommon.prototype = {
         this.updateIconFromType();
     },
 
+    _updateInfoFromType: function() {
+        if (this.rdfType.indexOf('nfo#DataContainer') != -1)
+            this.collection = true;
+
+        this.updateTypeDescription();
+    },
+
     _createSymbolicEmblem: function(name) {
         let pix = Gd.create_symbolic_icon(name, Utils.getIconSize());
 
@@ -238,6 +245,15 @@ DocCommon.prototype = {
 
     setFavorite: function(favorite) {
         TrackerUtils.setFavorite(this.id, favorite, null);
+    },
+
+    getWhere: function() {
+        let retval = '';
+
+        if (this.collection)
+            retval = '{ ?urn nie:isPartOf <' + this.id + '> }';
+
+        return retval;
     }
 };
 Signals.addSignalMethods(DocCommon.prototype);
@@ -478,6 +494,8 @@ GoogleDocument.prototype = {
             description = _("Spreadsheet");
         else if (this.rdfType.indexOf('nfo#Presentation') != -1)
             description = _("Presentation");
+        else if (this.rdfType.indexOf('nfo#DataContainer') != -1)
+            description = _("Collection");
         else
             description = _("Document");
 
@@ -568,6 +586,9 @@ DocumentManager.prototype = {
 
                     doc.destroy();
                     this.removeItemById(changeEvent.urn);
+
+                    if (doc.collection)
+                        Global.collectionManager.removeItemById(changeEvent.urn);
                 }
             }
         }
@@ -617,6 +638,9 @@ DocumentManager.prototype = {
 
         this.addItem(doc);
         this._model.documentAdded(doc);
+
+        if (doc.collection)
+            Global.collectionManager.addItem(doc);
     },
 
     clear: function() {
@@ -631,8 +655,11 @@ DocumentManager.prototype = {
 
     setActiveItem: function(doc) {
         if (Manager.BaseManager.prototype.setActiveItem.call(this, doc)) {
-            let recentManager = Gtk.RecentManager.get_default();
-            recentManager.add_item(this.getActiveItem().uri);
+
+            if (doc) {
+                let recentManager = Gtk.RecentManager.get_default();
+                recentManager.add_item(doc.uri);
+            }
         }
     },
 
diff --git a/src/embed.js b/src/embed.js
index 3a1441f..6dda296 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -215,6 +215,12 @@ ViewEmbed.prototype  = {
 
     _onActiveItemChanged: function() {
         let doc = Global.documentManager.getActiveItem();
+        let collection = Global.collectionManager.getItemById(doc.id);
+
+        if (collection) {
+            Global.collectionManager.setActiveItem(collection);
+            return;
+        }
 
         // switch to preview mode, and schedule the spinnerbox to
         // move in if the document is not loaded by the timeout
diff --git a/src/global.js b/src/global.js
index b3d2659..fdc301f 100644
--- a/src/global.js
+++ b/src/global.js
@@ -20,6 +20,7 @@
  */
 
 let application = null;
+let collectionManager = null;
 let connection = null;
 let connectionQueue = null;
 let documentManager = null;
diff --git a/src/mainToolbar.js b/src/mainToolbar.js
index bc4a741..386ef6b 100644
--- a/src/mainToolbar.js
+++ b/src/mainToolbar.js
@@ -42,6 +42,7 @@ MainToolbar.prototype = {
         this._model = null;
         this._collectionId = 0;
         this._selectionChangedId = 0;
+        this._overviewBack = null;
 
         this.widget = new Gtk.Toolbar({ icon_size: Gtk.IconSize.MENU });
         this.widget.get_style_context().add_class(Gtk.STYLE_CLASS_MENUBAR);
@@ -118,6 +119,26 @@ MainToolbar.prototype = {
     _populateForOverview: function() {
         this.widget.set_style(Gtk.ToolbarStyle.ICONS);
 
+        this._overviewBack = new Gtk.ToolButton({ icon_name: 'go-previous-symbolic',
+                                                  no_show_all: true });
+        this._overviewBack.get_style_context().add_class('raised');
+        this.widget.insert(this._overviewBack, 0);
+
+        this._overviewBack.connect('clicked', Lang.bind(this,
+            function() {
+                // go back to the general overview
+                Global.collectionManager.setActiveItem(null);
+            }));
+
+        let item2 = new Gtk.ToolItem();
+        this._whereLabel = new Gtk.Label({ margin_left: 12 });
+        item2.add(this._whereLabel);
+        this.widget.insert(item2, 1);
+
+        let separator = new Gtk.SeparatorToolItem({ draw: false });
+        separator.set_expand(true);
+        this.widget.insert(separator, 2);
+
         let iconView = new Gtk.ToggleButton({ child: new Gtk.Image({ icon_name: 'view-grid-symbolic',
                                                                      pixel_size: 16 }) });
         iconView.get_style_context().add_class('linked');
@@ -140,32 +161,22 @@ MainToolbar.prototype = {
         box.add(iconView);
         box.add(listView);
 
-        let item = new Gtk.ToolItem();
-        item.add(box);
-
-        this.widget.insert(item, 0);
-
-        let item2 = new Gtk.ToolItem();
-        this._whereLabel = new Gtk.Label({ margin_left: 12 });
-        item2.add(this._whereLabel);
-        this.widget.insert(item2, 1);
-
-        let separator = new Gtk.SeparatorToolItem({ draw: false });
-        separator.set_expand(true);
-        this.widget.insert(separator, 2);
-
-        let item3 = new Gtk.ToggleToolButton({ icon_name: 'emblem-default-symbolic' });
-        item3.get_style_context().add_class('raised');
+        let item3 = new Gtk.ToolItem({ margin_right: 12 });
+        item3.add(box);
         this.widget.insert(item3, 3);
 
-        item3.connect('toggled', Lang.bind(this,
+        let item4 = new Gtk.ToggleToolButton({ icon_name: 'emblem-default-symbolic' });
+        item4.get_style_context().add_class('raised');
+        this.widget.insert(item4, 4);
+
+        item4.connect('toggled', Lang.bind(this,
             function(button) {
                 // toggle selection mode if the button is toggled
                 let isToggled = button.get_active();
                 Global.selectionController.setSelectionMode(isToggled);
             }));
         // set initial state
-        item3.set_active(Global.selectionController.getSelectionMode());
+        item4.set_active(Global.selectionController.getSelectionMode());
 
         // connect to active collection changes while in this mode
         this._collectionId =
@@ -242,10 +253,13 @@ MainToolbar.prototype = {
     _onActiveCollection: function() {
         let item = Global.collectionManager.getActiveItem();
 
-        if (!item)
-            return;
-
-        this._whereLabel.set_markup(('<b>%s</b>').format(item.name));
+        if (item) {
+            this._overviewBack.show();
+            this._whereLabel.set_markup(('<b>%s</b>').format(item.title));
+        } else {
+            this._overviewBack.hide();
+            this._whereLabel.set_text('');
+        }
     },
 
     _onWindowModeChanged: function() {
diff --git a/src/manager.js b/src/manager.js
index 9c84eb0..b75a05e 100644
--- a/src/manager.js
+++ b/src/manager.js
@@ -60,9 +60,6 @@ BaseManager.prototype = {
     },
 
     setActiveItem: function(item) {
-        if (!item)
-            return false;
-
         if (item != this._activeItem) {
             this._activeItem = item;
             this.emit('active-changed', this._activeItem);
diff --git a/src/query.js b/src/query.js
index fb44b90..224c3f5 100644
--- a/src/query.js
+++ b/src/query.js
@@ -184,16 +184,5 @@ QueryBuilder.prototype = {
             '}';
 
         return new Query(sparql);
-    },
-
-    buildCollectionsQuery: function() {
-        let sparql = 'SELECT ?urn nie:title(?urn) nie:dataSource(?urn) WHERE { ' +
-            '{ ?urn a nfo:DataContainer } ' +
-            '{ ?doc nie:isPartOf ?urn } ' +
-            'FILTER ((fn:starts-with (nao:identifier(?urn), "gd:collection")) &&' +
-            Global.sourceManager.getFilter() +
-            ')}';
-
-        return new Query(sparql);
     }
 };
diff --git a/src/searchbar.js b/src/searchbar.js
index 2a145d4..fccc22c 100644
--- a/src/searchbar.js
+++ b/src/searchbar.js
@@ -139,6 +139,10 @@ SearchTypeManager.prototype = {
 
         this.addItem(new SearchType({ id: 'all',
                                       name: _("All") }));
+        this.addItem(new SearchType({ id: 'collections',
+                                      name: _("Collections"),
+                                      filter: '((fn:contains(rdf:type(?urn), \"nfo#DataContainer\")) && '
+                                              + '(fn:starts-with(nao:identifier(?urn), \"gd:collection\")))' }));
         this.addItem(new SearchType({ id: 'pdf',
                                       name: _("PDF Documents"),
                                       filter: 'fn:contains(nie:mimeType(?urn), \"application/pdf\")' }));



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