[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: KIO patch
From: Bernd Gehrmann <bernd () physik ! hu-berlin ! de>
Date: 2001-10-05 19:16:55
[Download RAW message or body]
What about adding the two methods findByContent() and
findByFileNameContent() to KMimeType, and marking
KMimeMagic and KMimeMagicResult as deprecated? This
would make a much simpler and more consistent API
IMO.
On a related thing, what is KService::allowAsDefault()
good for? I can't find any service where it's used,
and also "AllowDefault" does not appear in DESKTOP_
ENTRY_STANDARD. Similarly, what is KServiceOffer::allowAsDefault()
good for. Since keditfiletype always writes AllowAsDefault=true
to profilerc, KServiceOffer::allowAsDefault() seems to
be always equal to KServiceOffer::service()->allowAsDefault().
Bernd.
(currently trying to write some documentation about the
whole MIME stuff...)
["patch" (TEXT/PLAIN)]
Index: kmimetype.h
===================================================================
RCS file: /home/kde/kdelibs/kio/kmimetype.h,v
retrieving revision 1.58
diff -u -r1.58 kmimetype.h
--- kmimetype.h 2000/12/11 19:47:35 1.58
+++ kmimetype.h 2001/10/05 19:06:51
@@ -228,6 +228,21 @@
*/
static Ptr findByURL( const KURL& _url, mode_t _mode = 0,
bool _is_local_file = false, bool _fast_mode = false );
+ /**
+ * Tries to find out the MIME type of a data chunk by looking for
+ * certain magic numbers and characteristic strings in it.
+ * Returns application/octet-stream of the type can not be found
+ * this way.
+ */
+ static Ptr KMimeType::findByContent( const QByteArray &data );
+ /**
+ * 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
+ * file name is not used for determining the file type, it is just
+ * used for loading the file's contents.
+ */
+ static Ptr KMimeType::findByFileNameContent( const QString &fileName );
/**
* Get all the mimetypes.
Index: kmimetype.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/kmimetype.cpp,v
retrieving revision 1.136
diff -u -r1.136 kmimetype.cpp
--- kmimetype.cpp 2001/09/25 12:04:11 1.136
+++ kmimetype.cpp 2001/10/05 19:06:52
@@ -245,6 +245,22 @@
return mimeType( result->mimeType() );
}
+KMimeType::Ptr KMimeType::findByContent( const QByteArray &data )
+{
+ KMimeMagicResult *result = KMimeMagic::self()->findBufferType(data);
+ QString type = (result && result->isValid())?
+ result->mimeType() : defaultMimeType();
+ return mimeType( result->mimeType() );
+}
+
+KMimeType::Ptr KMimeType::findByFileNameContent( const QString &fileName )
+{
+ KMimeMagicResult *result = KMimeMagic::self()->findFileType(fileName);
+ QString type = (result && result->isValid())?
+ result->mimeType() : defaultMimeType();
+ return mimeType( result->mimeType() );
+}
+
KMimeType::KMimeType( const QString & _fullpath, const QString& _type, const QString& _icon,
const QString& _comment, const QStringList& _patterns )
: KServiceType( _fullpath, _type, _icon, _comment )
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic