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

List:       kde-commits
Subject:    KDE/kdelibs/kdecore/services
From:       Friedrich W. H. Kossebau <kossebau () kde ! org>
Date:       2009-09-28 21:29:00
Message-ID: 1254173340.211759.31364.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1029060 by kossebau:

added: overloads of methods findByContent() and findByNameAndContent(), using a \
QIODevice instead of a QByteArray

http://reviewboard.kde.org/r/1696/


 M  +15 -0     kmimetype.cpp  
 M  +34 -0     kmimetype.h  


--- trunk/KDE/kdelibs/kdecore/services/kmimetype.cpp #1029059:1029060
@@ -421,6 +421,14 @@
     return findByUrlHelper(url, mode, false, &buffer, accuracy);
 }
 
+KMimeType::Ptr KMimeType::findByNameAndContent( const QString& name, QIODevice* \
device, +                                                mode_t mode, int* accuracy )
+{
+    KUrl url;
+    url.setPath(name);
+    return findByUrlHelper(url, mode, false, device, accuracy);
+}
+
 QString KMimeType::extractKnownExtension(const QString &fileName)
 {
     QString pattern;
@@ -437,6 +445,13 @@
         &buffer, KMimeTypeFactory::AllRules, accuracy, cache );
 }
 
+KMimeType::Ptr KMimeType::findByContent( QIODevice* device, int* accuracy )
+{
+    QByteArray cache;
+    return KMimeTypeFactory::self()->findFromContent(
+        device, KMimeTypeFactory::AllRules, accuracy, cache );
+}
+
 KMimeType::Ptr KMimeType::findByFileContent( const QString &fileName, int *accuracy \
)  {
     checkEssentialMimeTypes();
--- trunk/KDE/kdelibs/kdecore/services/kmimetype.h #1029059:1029060
@@ -223,6 +223,40 @@
                                      mode_t mode = 0, int *accuracy=0 );
 
     /**
+     * Tries to find out the MIME type of a data chunk by looking for
+     * certain magic numbers and characteristic strings in it.
+     *
+     * @param device the IO device providing the data to examine
+     * @param accuracy If not a null pointer, *accuracy is set to the
+     *          accuracy of the match (which is in the range 0..100)
+     * @return a pointer to the KMimeType. "application/octet-stream" is
+     *          returned if the type can not be found this way.
+     * @since 4.4
+     */
+    static Ptr findByContent( QIODevice* device, int* accuracy = 0 );
+
+    /**
+     * Tries to find out the MIME type of filename/url and a data chunk.
+     * Whether to trust the extension or the data depends on the results of both \
approaches, +     * and is determined automatically.
+     *
+     * This method is useful for instance in the get() method of kioslaves, and \
anywhere else +     * where a filename is associated with some data which is \
available immediately. +     *
+     * @param name the filename or url representing this data.
+     * Only used for the extension, not used as a local filename.
+     * @param device the IO device providing the data to examine when the extension \
isn't conclusive in itself +     * @param mode the mode of the file (used, for \
example, to identify executables) +     * @param accuracy If not a null pointer, \
*accuracy is set to the +     *          accuracy of the match (which is in the range \
0..100) +     * @return a pointer to the KMimeType. "application/octet-stream" is
+     *          returned if the type can not be found this way.
+     * @since 4.4
+     */
+    static Ptr findByNameAndContent( const QString& name, QIODevice* device,
+                                     mode_t mode = 0, int* accuracy = 0 );
+
+    /**
      * Tries to find out the MIME type of a file by looking for
      * certain magic numbers and characteristic strings in it.
      * This function is similar to the previous one. Note that the


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

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