[sushi] mimehandler: check for registered super types if we fail mime matching



commit 9576ce6160b53c4e4f21d16ee8fde6d4d0d94d23
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Thu May 12 18:32:31 2011 -0400

    mimehandler: check for registered super types if we fail mime matching
    
    Before falling back to the FallbackRenderer; this is especially useful
    for text files.

 src/js/ui/mimeHandler.js |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)
---
diff --git a/src/js/ui/mimeHandler.js b/src/js/ui/mimeHandler.js
index 4330ca4..e8625c2 100644
--- a/src/js/ui/mimeHandler.js
+++ b/src/js/ui/mimeHandler.js
@@ -1,5 +1,7 @@
 const FallbackRenderer = imports.ui.fallbackRenderer;
 
+let Gio = imports.gi.Gio;
+
 let _mimeHandler = null;
 
 function MimeHandler() {
@@ -34,9 +36,20 @@ MimeHandler.prototype = {
     },
 
     getObject: function(mime) {
-        if (this._mimeTypes[mime])
+        if (this._mimeTypes[mime]) {
+            /* first, try a direct match with the mimetype itself */
             return this._mimeTypes[mime];
-        else
+        } else {
+            /* if this fails, try to see if we have any handlers
+             * registered for a parent type.
+             */
+            for (key in this._mimeTypes) {
+                if (Gio.content_type_is_a (mime, key))
+                    return this._mimeTypes[key];
+            }
+
+            /* finally, resort to the fallback renderer */
             return this._fallbackRenderer;
+        }
     }
-}
\ No newline at end of file
+}



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