[gnome-documents] documents: query and store a mimetype description



commit 865a16e218610fb06ee91765cb86d8d0561b97d7
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Wed Aug 31 13:16:47 2011 -0400

    documents: query and store a mimetype description
    
    It will be useful to show in the list view later.

 src/documents.js |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 src/query.js     |   18 +++++++++-------
 src/utils.js     |   22 +++----------------
 3 files changed, 68 insertions(+), 30 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index 284aeb5..d7fcf5e 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -54,10 +54,14 @@ DocCommon.prototype = {
         this.mtime = null;
         this.resourceUrn = null;
         this.favorite = null;
-        this._type = null;
         this.pixbuf = null;
         this.defaultAppName = null;
 
+        this.mimeType = null;
+        this.rdfType = null;
+        this.typeDescription = null;
+        this.sourceName = null;
+
         this.favorite = false;
         this.shared = false;
 
@@ -115,8 +119,11 @@ DocCommon.prototype = {
         this.resourceUrn = cursor.get_string(Query.QueryColumns.RESOURCE_URN)[0];
         this.favorite = cursor.get_boolean(Query.QueryColumns.FAVORITE);
 
-        this._type = cursor.get_string(Query.QueryColumns.TYPE)[0];
-        this.pixbuf = Utils.pixbufFromRdfType(this._type);
+        this.mimeType = cursor.get_string(Query.QueryColumns.MIMETYPE)[0];
+        this.rdfType = cursor.get_string(Query.QueryColumns.RDFTYPE)[0];
+        this._updateIconFromType();
+
+        this.updateTypeDescription();
 
         // sanitize
         if (!this.uri)
@@ -134,8 +141,31 @@ DocCommon.prototype = {
         this.refreshIcon();
     },
 
+    _updateIconFromType: function() {
+        let icon = null;
+
+        if (this.mimeType)
+            icon = Gio.content_type_get_icon(this.mimeType);
+
+        if (!icon)
+            icon = Utils.iconFromRdfType(this.rdfType);
+
+        let iconInfo =
+            Gtk.IconTheme.get_default().lookup_by_gicon(icon, Utils.getIconSize(),
+                                                        Gtk.IconLookupFlags.FORCE_SIZE |
+                                                        Gtk.IconLookupFlags.GENERIC_FALLBACK);
+
+        if (iconInfo != null) {
+            try {
+                this.pixbuf = iconInfo.load_icon();
+            } catch (e) {
+                log('Unable to load pixbuf: ' + e.toString());
+            }
+        }
+    },
+
     refreshIcon: function() {
-        this.pixbuf = Utils.pixbufFromRdfType(this._type);
+        this._updateIconFromType();
         this.checkEffectsAndUpdateInfo();
     },
 
@@ -231,6 +261,12 @@ LocalDocument.prototype = {
 
     _init: function(cursor) {
         DocCommon.prototype._init.call(this, cursor);
+
+        this.sourceName = _("Local");
+    },
+
+    updateTypeDescription: function() {
+        this.typeDescription = Gio.content_type_get_description(this.mimeType);
     },
 
     refreshIcon: function() {
@@ -350,6 +386,7 @@ GoogleDocument.prototype = {
         // overridden
         this.identifier = cursor.get_string(Query.QueryColumns.IDENTIFIER)[0];
         this.defaultAppName = _("Google Docs");
+        this.sourceName = _("Google");
     },
 
     _createGDataEntry: function(cancellable, callback) {
@@ -402,6 +439,19 @@ GoogleDocument.prototype = {
             }));
     },
 
+    updateTypeDescription: function() {
+        let description;
+
+        if (this.rdfType.indexOf('nfo#Spreadsheet') != -1)
+            description = _("Spreadsheet");
+        else if (this.rdfType.indexOf('nfo#Presentation') != -1)
+            description = _("Presentation");
+        else
+            description = _("Document");
+
+        this.typeDescription = description;
+    },
+
     populateFromCursor: function(cursor) {
         this.shared = cursor.get_boolean(Query.QueryColumns.SHARED);
 
diff --git a/src/query.js b/src/query.js
index 76c6378..560eb36 100644
--- a/src/query.js
+++ b/src/query.js
@@ -28,14 +28,15 @@ const QueryColumns = {
     URN: 0,
     URI: 1,
     FILENAME: 2,
-    TITLE: 3,
-    AUTHOR: 4,
-    MTIME: 5,
-    IDENTIFIER: 6,
-    TYPE: 7,
-    RESOURCE_URN: 8,
-    FAVORITE: 9,
-    SHARED: 10
+    MIMETYPE: 3,
+    TITLE: 4,
+    AUTHOR: 5,
+    MTIME: 6,
+    IDENTIFIER: 7,
+    RDFTYPE: 8,
+    RESOURCE_URN: 9,
+    FAVORITE: 10,
+    SHARED: 11
 };
 
 function QueryBuilder() {
@@ -144,6 +145,7 @@ QueryBuilder.prototype = {
             'SELECT DISTINCT ?urn ' + // urn
             'nie:url(?urn) ' + // uri
             'nfo:fileName(?urn)' + // filename
+            'nie:mimeType(?urn)' + // mimetype
             'nie:title(?urn) ' + // title
             'tracker:coalesce(nco:fullname(?creator), nco:fullname(?publisher), \'\') ' + // author
             'tracker:coalesce(nfo:fileLastModified(?urn), nie:contentLastModified(?urn)) AS ?mtime ' + // mtime
diff --git a/src/utils.js b/src/utils.js
index 74afe81..348234d 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -19,6 +19,7 @@
  *
  */
 
+const Gio = imports.gi.Gio;
 const Gtk = imports.gi.Gtk;
 
 const Documents = imports.documents;
@@ -33,32 +34,17 @@ function getIconSize() {
     return Global.settings.get_boolean('list-view') ? _LIST_VIEW_SIZE : _ICON_VIEW_SIZE;
 }
 
-function pixbufFromRdfType(type) {
+function iconFromRdfType(type) {
     let iconName;
-    let iconInfo = null;
-    let pixbuf = null;
 
     if (type.indexOf('nfo#Spreadsheet') != -1)
         iconName = 'x-office-spreadsheet';
     else if (type.indexOf('nfo#Presentation') != -1)
-    iconName = 'x-office-presentation';
+        iconName = 'x-office-presentation';
     else
         iconName = 'x-office-document';
 
-    iconInfo =
-        Gtk.IconTheme.get_default().lookup_icon(iconName, getIconSize(),
-                                                Gtk.IconLookupFlags.FORCE_SIZE |
-                                                Gtk.IconLookupFlags.GENERIC_FALLBACK);
-
-    if (iconInfo != null) {
-        try {
-            pixbuf = iconInfo.load_icon();
-        } catch (e) {
-            log('Unable to load pixbuf: ' + e.toString());
-        }
-    }
-
-    return pixbuf;
+    return new Gio.ThemedIcon({ name: iconName });
 }
 
 function getURNsFromPaths(paths, model) {



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