[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdenetwork/kpf/src
From:       Waldo Bastian <bastian () kde ! org>
Date:       2004-03-26 12:34:52
Message-ID: 20040326123452.24A70999B () office ! kde ! org
[Download RAW message or body]

CVS commit by waba: 

Improve mimetype detection. (BR55973)
Patch by Mikael Andersson
CCMAIL: 55973-done@bugs.kde.org


  M +20 -10    Resource.cpp   1.9


--- kdenetwork/kpf/src/Resource.cpp  #1.8:1.9
@@ -29,5 +29,5 @@
 #include <kglobal.h>
 
-#include <kmimemagic.h>
+#include <kmimetype.h>
 
 #include "Utils.h"
@@ -326,14 +326,24 @@ namespace KPF
     if (d->fileInfo.isDir())
       return "text/html; charset=utf-8";
+    QString serviceType = KMimeType::findByPath( d->root + d->path )->name();
 
-    KMimeMagicResult * r = KMimeMagic::self()->findFileType(d->root + d->path);
-
-    // Send "text/plain" as the mime type of the resource if we can't
-    // get a more authoritative response from KMimeMagic.
-
-    if (0 == r)
-      return "text/plain";
-    else
-      return r->mimeType();
+   /* 
+     Look at magic numbers only if findByPath couldn't come up with something
+     reasonable. 
+    */
+    if (serviceType == KMimeType::defaultMimeType())
+    {
+        int accuracy;
+        QString contentServiceType = KMimeType::findByFileContent( d->root + d->path,&accuracy)->name();
+        /*
+          Use reliable information ( from magic number ) only. Ignore any exotic
+          matches and leave as defaultMimeType for any such hard-to-identify documents.
+        */
+        if (accuracy == 100)
+        {
+            serviceType = contentServiceType;
+        }
+    }
+    return serviceType;
   }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic