C# Class Kimono.KMimeType

Inheritance: Kimono.KServiceType, IDisposable
ファイルを表示 Open project: 0xd34df00d/Qross Class Usage Examples

Public Methods

Method Description
AllMimeTypes ( ) : List Get all the mimetypes. Useful for showing the list of available mimetypes. More memory consuming than the ones above, don't use unless really necessary.
AllParentMimeTypes ( ) : List Return all parent mimetypes of this mimetype, direct or indirect. This includes the parent(s) of its parent(s), etc. If this mimetype is an alias, the list also contains the canonical name for this mimetype. The usual reason to use this method is to look for a setting which is stored per mimetype (like PreviewJob does).
Comment ( ) : string
Comment ( Kimono.KUrl url ) : string Returns the descriptive comment associated with the MIME type. The url argument is unused, but provided so that KMimeType derived classes can use it.
DefaultMimeType ( ) : string Returns the name of the default mimetype. Always application/octet-stream, but this method exists for performance purposes.
DefaultMimeTypePtr ( ) : KMimeType Returns the default mimetype. Always application/octet-stream. This can be used to check the result of mimeType(name).
Dispose ( ) : void
ExtractKnownExtension ( string fileName ) : string Determines the extension from a filename (or full path) using the mimetype database. This allows to extract "tar.bz2" for foo.tar.bz2 but still return "txt" for my.doc.with.dots.txt
FavIconForUrl ( Kimono.KUrl url ) : string Return the "favicon" (see http://www.favicon.com) for the given url, if available. Does NOT attempt to download the favicon, it only returns one that is already available. If unavailable, returns string(). name="url" the URL of the favicon
FindByContent ( Qyoto.QByteArray data ) : KMimeType
FindByContent ( Qyoto.QByteArray data, int &accuracy ) : KMimeType Tries to find out the MIME type of a data chunk by looking for certain magic numbers and characteristic strings in it. name="data" the data to examine name="accuracy" If not a null pointer, accuracy is set to the accuracy of the match (which is in the range 0..100)
FindByFileContent ( string fileName ) : KMimeType
FindByFileContent ( string fileName, int &accuracy ) : KMimeType 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. name="fileName" the path to the file name="accuracy" If not a null pointer, accuracy is set to the accuracy of the match (which is in the range 0..100)
FindByNameAndContent ( string name, Qyoto.QByteArray data ) : KMimeType
FindByNameAndContent ( string name, Qyoto.QByteArray data, long mode ) : KMimeType
FindByNameAndContent ( string name, Qyoto.QByteArray data, long mode, int &accuracy ) : KMimeType 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. name="name" the filename or url representing this data. Only used for the extension, not used as a local filename. name="data" the data to examine when the extension isn't conclusive in itself name="mode" the mode of the file (used, for example, to identify executables) name="accuracy" If not a null pointer, accuracy is set to the accuracy of the match (which is in the range 0..100)
FindByPath ( string path ) : KMimeType
FindByPath ( string path, long mode ) : KMimeType
FindByPath ( string path, long mode, bool fast_mode ) : KMimeType
FindByPath ( string path, long mode, bool fast_mode, int &accuracy ) : KMimeType Finds a KMimeType with the given url. This function looks at mode_t first. If that does not help it looks at the extension. This is fine for FTP, FILE, TAR and friends, but is not for HTTP ( cgi scripts! ). You should use KRun instead, but this function returns immediately while KRun is async. If no extension matches, then the file contents will be examined if the URL is a local file, or "application/octet-stream" is returned otherwise. Equivalent to
 KUrl u; u.setPath(path); return findByUrl( u, mode, true, fast_mode ); 
name="path" the path to the file name="mode" the mode of the file (used, for example, to identify executables) name="fast_mode" If set to true no disk access is allowed to find out the mimetype. The result may be suboptimal, but it is fast. name="accuracy" If not a null pointer, accuracy is set to the accuracy of the match (which is in the range 0..100)
FindByUrl ( Kimono.KUrl url ) : KMimeType
FindByUrl ( Kimono.KUrl url, long mode ) : KMimeType
FindByUrl ( Kimono.KUrl url, long mode, bool is_local_file ) : KMimeType
FindByUrl ( Kimono.KUrl url, long mode, bool is_local_file, bool fast_mode ) : KMimeType
FindByUrl ( Kimono.KUrl url, long mode, bool is_local_file, bool fast_mode, int &accuracy ) : KMimeType Finds a KMimeType with the given url. This function looks at mode_t first. If that does not help it looks at the extension. This is fine for FTP, FILE, TAR and friends, but is not for HTTP ( cgi scripts! ). You should use KRun instead, but this function returns immediately while KRun is async. If no extension matches, then the file contents will be examined if the URL is a local file, or "application/octet-stream" is returned otherwise. name="url" Is the right most URL with a filesystem protocol. It is up to you to find out about that if you have a nested URL. For example "http://localhost/mist.gz#gzip:/decompress" would have to pass the "http://..." URL part, while "file:/tmp/x.tar#tar:/src/test.gz#gzip:/decompress" would have to pass the "tar:/..." part of the URL, since gzip is a filter protocol and not a filesystem protocol. name="mode" the mode of the file (used, for example, to identify executables) name="is_local_file" true if the file is local; false if not, or if you don't know. name="fast_mode" If set to true no disk access is allowed to find out the mimetype. The result may be suboptimal, but it is fast. name="accuracy" if set, the accuracy of the result, between 0 and 100. For instance, when the extension was used to determine the mimetype, the accuracy is set to 80, as per the shared-mime spec. Some 'magic' rules (used when !fast_mode) have an accuracy > 80 (and have priority over the filename, others are < 80).
IconName ( ) : string
IconName ( Kimono.KUrl url ) : string Return the filename of the icon associated with the mimetype. Use KIconLoader.LoadMimeTypeIcon to load the icon. The url argument is unused, but is provided so that KMimeType-derived classes can use it (e.g. KFolderType uses the URL to return one out of 2 icons)
IconNameForUrl ( Kimono.KUrl url ) : string
IconNameForUrl ( Kimono.KUrl url, long mode ) : string Return the filename of the icon associated with the mimetype, for a given url. Use KIconLoader.LoadMimeTypeIcon to load the icon. name="url" URL for the file name="mode" the mode of the file. The mode may modify the icon with overlays that show special properties of the icon. Use 0 for default
Is ( string mimeTypeName ) : bool Do not use name()=="somename" anymore, to check for a given mimetype. For mimetype inheritance to work, use is("somename") instead. Warning, do not use inherits(), that's the servicetype inheritance concept! is() also supports mimetype aliases.
IsBinaryData ( string fileName ) : bool Returns whether a file has an internal format that is not human readable. This is much more generic than "not mime.Is(text/plain)". Many application file formats (like rtf and postscript) are based on text, but text that the user should rarely ever see.
IsBufferBinaryData ( Qyoto.QByteArray data ) : bool Returns whether a buffer has an internal format that is not human readable. This is much more generic than "not mime.Is(text/plain)". Many application file formats (like rtf and postscript) are based on text, but text that the user should rarely ever see.
IsDefault ( ) : bool
KMimeType ( QDataStream str, int offset ) : System The stream must already be positionned at the correct offset
KMimeType ( string fullpath, string name, string comment ) : System Construct a mimetype and take all information from an XML file. name="fullpath" the path to the xml that describes the mime type name="name" the name of the mimetype (usually the end of the path) name="comment" the comment associated with the mimetype
MimeType ( string name ) : KMimeType
MimeType ( string name, KMimeType options ) : KMimeType Retrieve a pointer to the mime type name . Very important: Don't store the result in a KMimeType ! Also note that you get a new KMimeType pointer every time you call this. Don't ever write code that compares mimetype pointers, compare names instead. name="name" the name of the mime type
ParentMimeTypes ( ) : List If this mimetype is a subclass of one or more other mimetypes, return the list of those mimetypes. For instance a application/javascript is a special kind of text/plain, so the definition of application/javascript says sub-class-of type="text/plain" Another example: application/x-shellscript is a subclass of two other mimetypes, application/x-executable and text/plain. (Note that this notion doesn't map to the servicetype inheritance mechanism, since an application that handles the specific type doesn't necessarily handle the base type. The opposite is true though.)
Patterns ( ) : List Retrieve the list of patterns associated with the MIME Type.

Protected Methods

Method Description
CreateProxy ( ) : void
InternalClearData ( ) : void
KMimeType ( Type dummy ) : System
SetParentMimeType ( string parent ) : void
SetPatterns ( List patterns ) : void The stream must already be positioned at the correct offsetConstruct a mimetype and take all information from an XML file. name="fullpath" the path to the xml that describes the mime type name="name" the name of the mimetype (usually the end of the path) name="comment" the comment associated with the mimetype

Private Methods

Method Description
KMimeType ( ) : System

Method Details

AllMimeTypes() public static method

Get all the mimetypes. Useful for showing the list of available mimetypes. More memory consuming than the ones above, don't use unless really necessary.
public static AllMimeTypes ( ) : List
return List

AllParentMimeTypes() public method

Return all parent mimetypes of this mimetype, direct or indirect. This includes the parent(s) of its parent(s), etc. If this mimetype is an alias, the list also contains the canonical name for this mimetype. The usual reason to use this method is to look for a setting which is stored per mimetype (like PreviewJob does).
public AllParentMimeTypes ( ) : List
return List

Comment() public method

public Comment ( ) : string
return string

Comment() public method

Returns the descriptive comment associated with the MIME type. The url argument is unused, but provided so that KMimeType derived classes can use it.
public Comment ( Kimono.KUrl url ) : string
url Kimono.KUrl
return string

CreateProxy() protected method

protected CreateProxy ( ) : void
return void

DefaultMimeType() public static method

Returns the name of the default mimetype. Always application/octet-stream, but this method exists for performance purposes.
public static DefaultMimeType ( ) : string
return string

DefaultMimeTypePtr() public static method

Returns the default mimetype. Always application/octet-stream. This can be used to check the result of mimeType(name).
public static DefaultMimeTypePtr ( ) : KMimeType
return KMimeType

Dispose() public method

public Dispose ( ) : void
return void

ExtractKnownExtension() public static method

Determines the extension from a filename (or full path) using the mimetype database. This allows to extract "tar.bz2" for foo.tar.bz2 but still return "txt" for my.doc.with.dots.txt
public static ExtractKnownExtension ( string fileName ) : string
fileName string
return string

FavIconForUrl() public static method

Return the "favicon" (see http://www.favicon.com) for the given url, if available. Does NOT attempt to download the favicon, it only returns one that is already available. If unavailable, returns string(). name="url" the URL of the favicon
public static FavIconForUrl ( Kimono.KUrl url ) : string
url Kimono.KUrl
return string

FindByContent() public static method

public static FindByContent ( Qyoto.QByteArray data ) : KMimeType
data Qyoto.QByteArray
return KMimeType

FindByContent() public static method

Tries to find out the MIME type of a data chunk by looking for certain magic numbers and characteristic strings in it. name="data" the data to examine name="accuracy" If not a null pointer, accuracy is set to the accuracy of the match (which is in the range 0..100)
public static FindByContent ( Qyoto.QByteArray data, int &accuracy ) : KMimeType
data Qyoto.QByteArray
accuracy int
return KMimeType

FindByFileContent() public static method

public static FindByFileContent ( string fileName ) : KMimeType
fileName string
return KMimeType

FindByFileContent() public static method

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. name="fileName" the path to the file name="accuracy" If not a null pointer, accuracy is set to the accuracy of the match (which is in the range 0..100)
public static FindByFileContent ( string fileName, int &accuracy ) : KMimeType
fileName string
accuracy int
return KMimeType

FindByNameAndContent() public static method

public static FindByNameAndContent ( string name, Qyoto.QByteArray data ) : KMimeType
name string
data Qyoto.QByteArray
return KMimeType

FindByNameAndContent() public static method

public static FindByNameAndContent ( string name, Qyoto.QByteArray data, long mode ) : KMimeType
name string
data Qyoto.QByteArray
mode long
return KMimeType

FindByNameAndContent() public static method

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. name="name" the filename or url representing this data. Only used for the extension, not used as a local filename. name="data" the data to examine when the extension isn't conclusive in itself name="mode" the mode of the file (used, for example, to identify executables) name="accuracy" If not a null pointer, accuracy is set to the accuracy of the match (which is in the range 0..100)
public static FindByNameAndContent ( string name, Qyoto.QByteArray data, long mode, int &accuracy ) : KMimeType
name string
data Qyoto.QByteArray
mode long
accuracy int
return KMimeType

FindByPath() public static method

public static FindByPath ( string path ) : KMimeType
path string
return KMimeType

FindByPath() public static method

public static FindByPath ( string path, long mode ) : KMimeType
path string
mode long
return KMimeType

FindByPath() public static method

public static FindByPath ( string path, long mode, bool fast_mode ) : KMimeType
path string
mode long
fast_mode bool
return KMimeType

FindByPath() public static method

Finds a KMimeType with the given url. This function looks at mode_t first. If that does not help it looks at the extension. This is fine for FTP, FILE, TAR and friends, but is not for HTTP ( cgi scripts! ). You should use KRun instead, but this function returns immediately while KRun is async. If no extension matches, then the file contents will be examined if the URL is a local file, or "application/octet-stream" is returned otherwise. Equivalent to
 KUrl u; u.setPath(path); return findByUrl( u, mode, true, fast_mode ); 
name="path" the path to the file name="mode" the mode of the file (used, for example, to identify executables) name="fast_mode" If set to true no disk access is allowed to find out the mimetype. The result may be suboptimal, but it is fast. name="accuracy" If not a null pointer, accuracy is set to the accuracy of the match (which is in the range 0..100)
public static FindByPath ( string path, long mode, bool fast_mode, int &accuracy ) : KMimeType
path string
mode long
fast_mode bool
accuracy int
return KMimeType

FindByUrl() public static method

public static FindByUrl ( Kimono.KUrl url ) : KMimeType
url Kimono.KUrl
return KMimeType

FindByUrl() public static method

public static FindByUrl ( Kimono.KUrl url, long mode ) : KMimeType
url Kimono.KUrl
mode long
return KMimeType

FindByUrl() public static method

public static FindByUrl ( Kimono.KUrl url, long mode, bool is_local_file ) : KMimeType
url Kimono.KUrl
mode long
is_local_file bool
return KMimeType

FindByUrl() public static method

public static FindByUrl ( Kimono.KUrl url, long mode, bool is_local_file, bool fast_mode ) : KMimeType
url Kimono.KUrl
mode long
is_local_file bool
fast_mode bool
return KMimeType

FindByUrl() public static method

Finds a KMimeType with the given url. This function looks at mode_t first. If that does not help it looks at the extension. This is fine for FTP, FILE, TAR and friends, but is not for HTTP ( cgi scripts! ). You should use KRun instead, but this function returns immediately while KRun is async. If no extension matches, then the file contents will be examined if the URL is a local file, or "application/octet-stream" is returned otherwise. name="url" Is the right most URL with a filesystem protocol. It is up to you to find out about that if you have a nested URL. For example "http://localhost/mist.gz#gzip:/decompress" would have to pass the "http://..." URL part, while "file:/tmp/x.tar#tar:/src/test.gz#gzip:/decompress" would have to pass the "tar:/..." part of the URL, since gzip is a filter protocol and not a filesystem protocol. name="mode" the mode of the file (used, for example, to identify executables) name="is_local_file" true if the file is local; false if not, or if you don't know. name="fast_mode" If set to true no disk access is allowed to find out the mimetype. The result may be suboptimal, but it is fast. name="accuracy" if set, the accuracy of the result, between 0 and 100. For instance, when the extension was used to determine the mimetype, the accuracy is set to 80, as per the shared-mime spec. Some 'magic' rules (used when !fast_mode) have an accuracy > 80 (and have priority over the filename, others are < 80).
public static FindByUrl ( Kimono.KUrl url, long mode, bool is_local_file, bool fast_mode, int &accuracy ) : KMimeType
url Kimono.KUrl
mode long
is_local_file bool
fast_mode bool
accuracy int
return KMimeType

IconName() public method

public IconName ( ) : string
return string

IconName() public method

Return the filename of the icon associated with the mimetype. Use KIconLoader.LoadMimeTypeIcon to load the icon. The url argument is unused, but is provided so that KMimeType-derived classes can use it (e.g. KFolderType uses the URL to return one out of 2 icons)
public IconName ( Kimono.KUrl url ) : string
url Kimono.KUrl
return string

IconNameForUrl() public static method

public static IconNameForUrl ( Kimono.KUrl url ) : string
url Kimono.KUrl
return string

IconNameForUrl() public static method

Return the filename of the icon associated with the mimetype, for a given url. Use KIconLoader.LoadMimeTypeIcon to load the icon. name="url" URL for the file name="mode" the mode of the file. The mode may modify the icon with overlays that show special properties of the icon. Use 0 for default
public static IconNameForUrl ( Kimono.KUrl url, long mode ) : string
url Kimono.KUrl
mode long
return string

InternalClearData() protected method

protected InternalClearData ( ) : void
return void

Is() public method

Do not use name()=="somename" anymore, to check for a given mimetype. For mimetype inheritance to work, use is("somename") instead. Warning, do not use inherits(), that's the servicetype inheritance concept! is() also supports mimetype aliases.
public Is ( string mimeTypeName ) : bool
mimeTypeName string
return bool

IsBinaryData() public static method

Returns whether a file has an internal format that is not human readable. This is much more generic than "not mime.Is(text/plain)". Many application file formats (like rtf and postscript) are based on text, but text that the user should rarely ever see.
public static IsBinaryData ( string fileName ) : bool
fileName string
return bool

IsBufferBinaryData() public static method

Returns whether a buffer has an internal format that is not human readable. This is much more generic than "not mime.Is(text/plain)". Many application file formats (like rtf and postscript) are based on text, but text that the user should rarely ever see.
public static IsBufferBinaryData ( Qyoto.QByteArray data ) : bool
data Qyoto.QByteArray
return bool

IsDefault() public method

public IsDefault ( ) : bool
return bool

KMimeType() public method

The stream must already be positionned at the correct offset
public KMimeType ( QDataStream str, int offset ) : System
str Qyoto.QDataStream
offset int
return System

KMimeType() protected method

protected KMimeType ( Type dummy ) : System
dummy System.Type
return System

KMimeType() public method

Construct a mimetype and take all information from an XML file. name="fullpath" the path to the xml that describes the mime type name="name" the name of the mimetype (usually the end of the path) name="comment" the comment associated with the mimetype
public KMimeType ( string fullpath, string name, string comment ) : System
fullpath string
name string
comment string
return System

MimeType() public static method

public static MimeType ( string name ) : KMimeType
name string
return KMimeType

MimeType() public static method

Retrieve a pointer to the mime type name . Very important: Don't store the result in a KMimeType ! Also note that you get a new KMimeType pointer every time you call this. Don't ever write code that compares mimetype pointers, compare names instead. name="name" the name of the mime type
public static MimeType ( string name, KMimeType options ) : KMimeType
name string
options KMimeType
return KMimeType

ParentMimeTypes() public method

If this mimetype is a subclass of one or more other mimetypes, return the list of those mimetypes. For instance a application/javascript is a special kind of text/plain, so the definition of application/javascript says sub-class-of type="text/plain" Another example: application/x-shellscript is a subclass of two other mimetypes, application/x-executable and text/plain. (Note that this notion doesn't map to the servicetype inheritance mechanism, since an application that handles the specific type doesn't necessarily handle the base type. The opposite is true though.)
public ParentMimeTypes ( ) : List
return List

Patterns() public method

Retrieve the list of patterns associated with the MIME Type.
public Patterns ( ) : List
return List

SetParentMimeType() protected method

protected SetParentMimeType ( string parent ) : void
parent string
return void

SetPatterns() protected method

The stream must already be positioned at the correct offset Construct a mimetype and take all information from an XML file. name="fullpath" the path to the xml that describes the mime type name="name" the name of the mimetype (usually the end of the path) name="comment" the comment associated with the mimetype
protected SetPatterns ( List patterns ) : void
patterns List
return void