All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Public Member Functions | Static Public Member Functions | List of all members
BMimeType Class Reference

A class that represents a MIME (Multi-purpose Internet Mail Extensions) type string. More...

Public Member Functions

 BMimeType ()
 Creates an uninitialized BMimeType object.
 
 BMimeType (const char *mimeType)
 Creates a BMimeType object and initializes it to the supplied MIME type.
 
virtual ~BMimeType ()
 Frees all resources associated with this object.
 
bool Contains (const BMimeType *type) const
 Returns whether this MIME type is a supertype of or equals the supplied one.
 
status_t Delete ()
 Removes the MIME type from the MIME database.
 
status_t GetAppHint (entry_ref *ref) const
 Fetches an entry_ref that serves as a hint as to where the MIME type's preferred application might live.
 
status_t GetAttrInfo (BMessage *info) const
 Fetches from the MIME database a BMessage describing the attributes typically associated with files of the given MIME type.
 
status_t GetFileExtensions (BMessage *extensions) const
 Fetches the MIME type's associated filename extensions from the MIME database.
 
status_t GetIcon (BBitmap *icon, icon_size size) const
 Fetches the large or mini icon associated with the MIME type.
 
status_t GetIcon (uint8 **_data, size_t *_size) const
 Fetches the vector icon associated with the MIME type The icon data is returned in data.
 
status_t GetIconForType (const char *type, BBitmap *icon, icon_size which) const
 Fetches the large or mini icon used by an application of this type for files of the given type.
 
status_t GetIconForType (const char *type, uint8 **_data, size_t *_size) const
 Fetches the vector icon used by an application of this type for files of the given type.
 
status_t GetLongDescription (char *description) const
 Fetches the MIME type's long description from the MIME database.
 
status_t GetPreferredApp (char *signature, app_verb verb=B_OPEN) const
 Fetches the signature of the preferred application from the MIME database.
 
status_t GetShortDescription (char *description) const
 Fetches the MIME type's short description from the MIME database.
 
status_t GetSnifferRule (BString *result) const
 Retrieves the MIME type's sniffer rule.
 
status_t GetSupertype (BMimeType *supertype) const
 Gets the supertype of the MIME type represented by this object.
 
status_t GetSupportingApps (BMessage *signatures) const
 Fetches a BMessage containing a list of MIME signatures of applications that are able to handle files of this MIME type.
 
status_t InitCheck () const
 Returns the result of the most recent constructor or SetTo() call.
 
status_t Install ()
 Adds the MIME type to the MIME database.
 
bool IsInstalled () const
 Returns whether or not this type is currently installed in the MIME database.
 
bool IsSupertypeOnly () const
 Returns whether this objects represents a supertype.
 
bool IsValid () const
 Returns whether the object represents a valid MIME type.
 
bool operator== (const BMimeType &type) const
 Returns whether this and the supplied MIME type are equal.
 
bool operator== (const char *type) const
 Returns whether this and the supplied MIME type are equal.
 
status_t SetAppHint (const entry_ref *ref)
 Sets the app hint field for the MIME type.
 
status_t SetAttrInfo (const BMessage *info)
 Sets the description of the attributes typically associated with files of the given MIME type.
 
status_t SetFileExtensions (const BMessage *extensions)
 Sets the list of filename extensions associated with the MIME type.
 
status_t SetIcon (const BBitmap *icon, icon_size size)
 Sets the large or mini icon for the MIME type.
 
status_t SetIcon (const uint8 *data, size_t size)
 Sets the vector icon for the MIME type.
 
status_t SetIconForType (const char *type, const BBitmap *icon, icon_size which)
 Sets the large or mini icon used by an application of this type for files of the given type.
 
status_t SetIconForType (const char *type, const uint8 *data, size_t size)
 Sets the icon used by an application of this type for files of the given type.
 
status_t SetLongDescription (const char *description)
 Sets the long description field for the MIME type.
 
status_t SetPreferredApp (const char *signature, app_verb verb=B_OPEN)
 Sets the preferred application for the MIME type.
 
status_t SetShortDescription (const char *description)
 Sets the short description field for the MIME type.
 
status_t SetSnifferRule (const char *)
 Sets the MIME type's sniffer rule.
 
status_t SetTo (const char *mimeType)
 Initializes this object to the supplied MIME type.
 
status_t SetType (const char *mimeType)
 Initializes this object to the supplied MIME type.
 
const char * Type () const
 Returns the MIME string represented by this object.
 
void Unset ()
 Returns the object to an uninitialized state.
 

Static Public Member Functions

static status_t CheckSnifferRule (const char *rule, BString *parseError)
 Checks whether a MIME sniffer rule is valid or not.
 
static status_t GetInstalledSupertypes (BMessage *supertypes)
 Fetches a BMessage listing all the MIME supertypes currently installed in the MIME database.
 
static status_t GetInstalledTypes (BMessage *types)
 Fetches a BMessage listing all the MIME types currently installed in the MIME database.
 
static status_t GetInstalledTypes (const char *supertype, BMessage *subtypes)
 Fetches a BMessage listing all the MIME subtypes of the given supertype currently installed in the MIME database.
 
static status_t GetWildcardApps (BMessage *wildcardApps)
 Fetches a BMessage containing a list of MIME signatures of applications that are able to handle files of any type.
 
static status_t GuessMimeType (const char *filename, BMimeType *type)
 Guesses a MIME type for the given filename.
 
static status_t GuessMimeType (const entry_ref *file, BMimeType *type)
 Guesses a MIME type for the entry referred to by the given entry_ref.
 
static status_t GuessMimeType (const void *buffer, int32 length, BMimeType *type)
 Guesses a MIME type for the supplied chunk of data.
 
static bool IsValid (const char *mimeType)
 Returns whether the given string represents a valid MIME type.
 
static status_t StartWatching (BMessenger target)
 Starts monitoring the MIME database for a given target.
 
static status_t StopWatching (BMessenger target)
 Stops monitoring the MIME database for a given target (previously started via StartWatching()).
 

Detailed Description

A class that represents a MIME (Multi-purpose Internet Mail Extensions) type string.

MIME types use, has grown beyond describing the content of email to describe the content types of applications and file formats.

MIME types consist of a supertype and a subtype.

Since
BeOS R3

Constructor & Destructor Documentation

◆ BMimeType() [1/2]

BMimeType::BMimeType ( )

Creates an uninitialized BMimeType object.

Since
BeOS R3

◆ BMimeType() [2/2]

BMimeType::BMimeType ( const char *  mimeType)

Creates a BMimeType object and initializes it to the supplied MIME type.

The supplied string must specify a valid MIME type or supertype.

Parameters
mimeTypeThe MIME string.
See also
SetTo() for further information.
Since
BeOS R3

◆ ~BMimeType()

BMimeType::~BMimeType ( )
virtual

Frees all resources associated with this object.

Since
BeOS R3

Member Function Documentation

◆ CheckSnifferRule()

status_t BMimeType::CheckSnifferRule ( const char *  rule,
BString parseError 
)
static

Checks whether a MIME sniffer rule is valid or not.

A MIME sniffer rule is valid, if it is well-formed with respect to the following grammar and fulfills some further conditions listed thereafter:

	Rule			::= LWS Priority LWS ExprList LWS
	ExprList		::= Expression (LWS Expression)*
	Expression		::= "(" LWS (PatternList | RPatternList) LWS ")"
						| Range LWS "(" LWS PatternList LWS ")"
	RPatternList	::= RPattern (LWS "|" LWS RPattern)*
	PatternList		::= Pattern (LWS "|" LWS Pattern)*
	RPattern		::= Range LWS Pattern
	Pattern			::= PString [ LWS "&" LWS Mask ]
	Range			::=	"[" LWS SDecimal [LWS ":" LWS SDecimal] LWS "]"

	Priority		::= Float
	Mask			::= PString
	PString			::= HexString | QuotedString | Octal [UnquotedString]
						EscapedChar [UnquotedString]
	HexString		::= "0x" HexPair HexPair*
	HexPair			::= HexChar HexChar
	QuotedString	::= '"' QChar QChar* '"' | "'" QChar QChar* "'"
	Octal			::= "\" OctChar [OctChar [OctChar]]
	SDecimal		::= ["+" | "-"] Decimal
	Decimal			::= DecChar DecChar*
	Float			::= Fixed [("E" | "e") Decimal]
	Fixed			::= SDecimal ["." [Decimal]] | [SDecimal] "." Decimal
	UnquotedString	::= UChar UChar*
	LWS				::= LWSChar*

	LWSChar			::= LF | " " | TAB
	OctChar			::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7"
	DecChar			::= OctChar | "8" | "9"
	HexChar			::= DecChar | "a" | "b" | "c" | "d" | "e" | "A" | "B" | "C"
						| "D" | "E"
	Char			:: <any character>
	QChar			::= <Char except "\", "&", "'" and '"'> | EscapedChar
	EscapedChar		::= "\" Char
	UChar			::= <QChar except LWSChar>

	Conditions:
	(checked)
	- If a mask is specified for a pattern, this mask must have the same
	  length as the pattern string.
	(not checked)
	- 0 <= Priority <= 1
	- 0 <= Range begin <= Range end
	- Rules of the form "() | () | ..." are invalid.

	Examples:
	- 1.0 ('ABCD')
	  The file must start with the string "ABCD". The priority of the rule
	  is 1.0 (maximal).
	- 0.8 [0:3] ('ABCD' | 'abcd')
	  The file must contain the string "ABCD" or "abcd" starting somewhere in
	  the first four bytes. The rule priority is 0.8.
	- 0.5 ([0:3] 'ABCD' | [0:3] 'abcd' | [13] 'EFGH')
	  The file must contain the string "ABCD" or "abcd" starting somewhere in
	  the first four bytes or the string "EFGH" at position 13. The rule
	  priority is 0.5.
	- 0.8 [0:3] ('ABCD' & 0xff00ffff | 'abcd' & 0xffff00ff)
	  The file must contain the string "A.CD" or "ab.d" (whereas "." is an
	  arbitrary character) starting somewhere in the first four bytes. The
	  rule priority is 0.8.

	Real examples:
	- 0.20 ([0]"//" | [0]"/\*" | [0:32]"#include" | [0:32]"#ifndef"
	        | [0:32]"#ifdef")
	  text/x-source-code
	- 0.70 ("8BPS  \000\000\000\000" & 0xffffffff0000ffffffff )
	  image/x-photoshop
Parameters
ruleThe rule string.
parseErrorA pointer to a pre-allocated BString into which a description of the parse error is written (if any), may be NULL.
Returns
A status code.
Return values
B_OKThe supplied sniffer rule is valid.
B_BAD_VALUENULL rule.
B_BAD_MIME_SNIFFER_RULEThe supplied sniffer rule is not valid. A description of the error is written to parseError, if supplied.
B_NO_INITBMimeType was uninitialized.
Since
Haiku R1

◆ Contains()

bool BMimeType::Contains ( const BMimeType type) const

Returns whether this MIME type is a supertype of or equals the supplied one.

Parameters
typeThe MIME type.
Returns
true, if this MIME type is a supertype of or equals the supplied one, false otherwise.
Since
BeOS R3

◆ Delete()

status_t BMimeType::Delete ( )

Removes the MIME type from the MIME database.

To check if the MIME type is already installed, call IsInstalled(). To add the MIME type to the database, call Install().

Note
Calling BMimeType::Delete() does not uninitialize or otherwise deallocate the BMimeType object; it simply removes the type from the database.
Returns
B_OK on success or another error code on failure.
Since
BeOS R3

◆ GetAppHint()

status_t BMimeType::GetAppHint ( entry_ref ref) const

Fetches an entry_ref that serves as a hint as to where the MIME type's preferred application might live.

The app hint is a path that identifies the executable that should be used when launching an application that has this signature. For example, when Tracker needs to launch an app of type "application/YourAppHere", it asks the database for the application hint. This hint is converted to an entry_ref before it is passed to the caller. Of course, the path may not point to an application, or it might point to an application with the wrong signature (and so on); that's why this is merely a hint.

The entry_ref pointed to by ref must be pre-allocated.

Parameters
refPointer to a pre-allocated entry_ref into which the location of the app hint is copied. If the function fails, the contents of the entry_ref are undefined.
Returns
A status code, B_OK on success or an error code otherwise.
Return values
B_OKThe ref was retrieved successfully.
B_ENTRY_NOT_FOUNDNo app hint existed for the given ref.
B_NO_INITBMimeType was uninitialized.
Since
BeOS R3

◆ GetAttrInfo()

status_t BMimeType::GetAttrInfo ( BMessage info) const

Fetches from the MIME database a BMessage describing the attributes typically associated with files of the given MIME type.

The attribute information is returned in a pre-allocated BMessage pointed to by the info parameter (note that the any prior contents of the message will be destroyed). If the method succeeds, the format of the BMessage pointed to by info will be the following:

field name type element[0..n]
"attr:name" B_STRING_TYPE The name of each attribute
"attr:public_name" B_STRING_TYPE The human-readable name of each attribute
"attr:type" B_INT32_TYPE The type code for each attribute
"attr:viewable" B_BOOL_TYPE For each attribute: true if the attribute is public, false if it's private
"attr:editable" B_BOOL_TYPE For each attribute: true if the attribute should be user editable, false if not

The BMessage::what value is set to decimal 233, but is otherwise meaningless.

Parameters
infoPointer to a pre-allocated BMessage into which information about the MIME type's associated file attributes is stored.
Returns
B_OK on success or another error code on failure.
See also
SetAttrInfo()
Since
BeOS R3

◆ GetFileExtensions()

status_t BMimeType::GetFileExtensions ( BMessage extensions) const

Fetches the MIME type's associated filename extensions from the MIME database.

The MIME database associates a list of filename extensions (a character string following the rightmost dot, ".", character in the filename) with each type. These extensions can then be used to help determine the type of any untyped files that may be encountered.

The list of extensions is returned in a pre-allocated BMessage pointed to by the extensions parameter (note that the any prior contents of the message will be destroyed). If the method succeeds, the format of the BMessage pointed to by extensions will be the following:

  • The message's "extensions" field will contain an indexed array of strings, one for each extension. The extensions are given without the preceding "." character by convention.
  • The message's "type" field will be a string containing the MIME type whose associated file extensions you are fetching.
  • The what member of the BMessage will be set to 234, but is otherwise irrelevant.

Note that any other fields present in the BMessage passed to the most recent SetFileExtensions() call will also be returned.

Parameters
extensionsPointer to a pre-allocated BMessage into which the MIME type's associated file extensions will be stored.
Returns
B_OK on success or another error code on failure.
See also
SetFileExtensions()
Since
BeOS R3

◆ GetIcon() [1/2]

status_t BMimeType::GetIcon ( BBitmap icon,
icon_size  size 
) const

Fetches the large or mini icon associated with the MIME type.

The icon is copied into the BBitmap pointed to by icon. The bitmap must be the proper size: 32x32 for the large icon, 16x16 for the mini icon. Additionally, the bitmap must be in the B_CMAP8 color space (8-bit color).

Parameters
iconPointer to a pre-allocated BBitmap of proper size and colorspace into which the icon is copied.
sizeValue that specifies which icon to return. Currently B_LARGE_ICON and B_MINI_ICON are supported.
Returns
A status code.
Return values
B_OKEverything went fine.
B_ENTRY_NOT_FOUNDNo icon of the given size exists for the given type.
B_NO_INITBMimeType was uninitialized.
Since
BeOS R3

◆ GetIcon() [2/2]

status_t BMimeType::GetIcon ( uint8 **  data,
size_t *  size 
) const

Fetches the vector icon associated with the MIME type The icon data is returned in data.

Parameters
dataPointer in which the allocated icon data is returned. You need to delete the buffer when you are done with it.
sizePointer in which the size of the allocated icon data is returned.
Returns
A status code.
Return values
B_OKEverything went fine.
B_ENTRY_NOT_FOUNDNo icon of the given size found for the given type.
B_NO_INITBMimeType was uninitialized.
Since
BeOS R3

◆ GetIconForType() [1/2]

status_t BMimeType::GetIconForType ( const char *  type,
BBitmap icon,
icon_size  which 
) const

Fetches the large or mini icon used by an application of this type for files of the given type.

This can be confusing, so here's how this function is intended to be used:

  • The actual BMimeType object should be set to the MIME signature of an application for whom you want to look up custom icons for custom MIME types.
  • The type parameter specifies the file type whose custom icon you are fetching.

The type of the BMimeType object is not required to actually be a subtype of "application/"; that is the intended use however, and calling GetIconForType() on a non-application type will likely return B_ENTRY_NOT_FOUND.

The icon is copied into the BBitmap pointed to by icon. The bitmap must be the proper size: 32x32 for the large icon, 16x16 for the mini icon. Additionally, the bitmap must be in the B_CMAP8 color space (8-bit color).

Parameters
typePointer to a pre-allocated string containing the MIME type whose custom icon you wish to fetch.
iconPointer to a pre-allocated BBitmap of proper size and colorspace into which the icon is copied.
whichValue that specifies which icon to return. Currently B_LARGE_ICON and B_MINI_ICON are supported.
Returns
A status code, B_OK on success or an error code otherwise.
Return values
B_OKSuccess
B_ENTRY_NOT_FOUNDNo icon of the given size exists for the given type.
B_NO_INITBMimeType was uninitialized.
Since
BeOS R3

◆ GetIconForType() [2/2]

status_t BMimeType::GetIconForType ( const char *  type,
uint8 **  _data,
size_t *  _size 
) const

Fetches the vector icon used by an application of this type for files of the given type.

The icon data is returned in data. See the other GetIconForType() for more information.

Parameters
typePointer to a pre-allocated string containing the MIME type whose custom icon you wish to fetch.
_dataPointer in which the allocated icon data is returned. You need to delete the buffer when you are done with it.
_sizePointer in which the size of the allocated icon data is filled out.
Returns
A status code, B_OK on success or an error code otherwise.
Return values
B_OKSuccess.
B_ENTRY_NOT_FOUNDNo icon of the given size exists for the given type.
B_NO_INITBMimeType was uninitialized.
Since
Haiku R1

◆ GetInstalledSupertypes()

status_t BMimeType::GetInstalledSupertypes ( BMessage supertypes)
static

Fetches a BMessage listing all the MIME supertypes currently installed in the MIME database.

The types are copied into the "super_types" field of the passed-in BMessage. The BMessage must be pre-allocated.

Parameters
supertypesPointer to a pre-allocated BMessage into which the MIME supertypes will be copied.
Returns
B_OK on success or another error code on failure.
Since
BeOS R3

◆ GetInstalledTypes() [1/2]

status_t BMimeType::GetInstalledTypes ( BMessage types)
static

Fetches a BMessage listing all the MIME types currently installed in the MIME database.

The types are copied into the "types" field of the passed-in BMessage. The BMessage must be pre-allocated.

Parameters
typesPointer to a pre-allocated BMessage into which the MIME types will be copied.
Returns
B_OK on success or another error code on failure.
Since
BeOS R3

◆ GetInstalledTypes() [2/2]

status_t BMimeType::GetInstalledTypes ( const char *  supertype,
BMessage types 
)
static

Fetches a BMessage listing all the MIME subtypes of the given supertype currently installed in the MIME database.

The types are copied into the "types" field of the passed-in BMessage. The BMessage must be pre-allocated.

Parameters
supertypePointer to a string containing the MIME supertype whose subtypes you wish to retrieve.
typesPointer to a pre-allocated BMessage into which the appropriate MIME subtypes will be copied.
Returns
B_OK on success or another error code on failure.
Since
BeOS R3

◆ GetLongDescription()

status_t BMimeType::GetLongDescription ( char *  description) const

Fetches the MIME type's long description from the MIME database.

The string pointed to by description must be long enough to hold the long description; a length of B_MIME_TYPE_LENGTH is recommended.

Parameters
descriptionPointer to a pre-allocated string into which the long description is copied. If the function fails, the contents of the string are undefined.
Returns
A status code.
Return values
B_OKSuccess
B_ENTRY_NOT_FOUNDNo long description exists for the given type.
B_NO_INITBMimeType was uninitialized.
See also
SetLongDescription()
Since
BeOS R3

◆ GetPreferredApp()

status_t BMimeType::GetPreferredApp ( char *  signature,
app_verb  verb = B_OPEN 
) const

Fetches the signature of the preferred application from the MIME database.

The preferred app is the application that's used to access a file when, for example, the user double-clicks the file in a Tracker window. Unless the file identifies in its attributes a "custom" preferred app, Tracker will ask the file type database for the preferred app that's associated with the file's type.

The string pointed to by signature must be long enough to hold the preferred applications signature; a length of B_MIME_TYPE_LENGTH is recommended.

Parameters
signaturePointer to a pre-allocated string into which the signature of the preferred app is copied. If the function fails, the contents of the string are undefined.
verbapp_verb value that specifies the type of access for which you are requesting the preferred app. Currently, the only supported app verb is B_OPEN.
Returns
A status code.
Return values
B_OKSuccess
B_ENTRY_NOT_FOUNDNo preferred app exists for the given type and app_verb.
B_NO_INITBMimeType was uninitialized.
See also
SetPreferredApp()
Since
BeOS R3

◆ GetShortDescription()

status_t BMimeType::GetShortDescription ( char *  description) const

Fetches the MIME type's short description from the MIME database.

The string pointed to by description must be long enough to hold the short description; a length of B_MIME_TYPE_LENGTH is recommended.

Parameters
descriptionPointer to a pre-allocated string into which the long description is copied. If the function fails, the contents of the string are undefined.
Returns
A status code.
Return values
B_OKSuccess
B_ENTRY_NOT_FOUNDNo short description exists for the given type.
B_NO_INITBMimeType was uninitialized.
See also
SetShortDescription()
Since
BeOS R3

◆ GetSnifferRule()

status_t BMimeType::GetSnifferRule ( BString result) const

Retrieves the MIME type's sniffer rule.

Parameters
resultPointer to a pre-allocated BString into which the value is copied.
Returns
A status code.
Return values
B_OKEverything went fine.
B_BAD_VALUENULL result or uninitialized BMimeType.
B_ENTRY_NOT_FOUNDThe MIME type is not installed.
B_NO_INITBMimeType was uninitialized.
See also
SetSnifferRule()
Since
Haiku R1

◆ GetSupertype()

status_t BMimeType::GetSupertype ( BMimeType supertype) const

Gets the supertype of the MIME type represented by this object.

The supplied object is initialized to this object's supertype. If this BMimeType is not properly initialized, the supplied object will be Unset().

Parameters
supertypeA pointer to the BMimeType object that shall be initialized to this object's supertype.
Returns
A status code.
Return values
B_OKEverything went fine.
B_BAD_VALUENULL superType, this object is not initialized, or this object is a supertype only.
B_NO_INITBMimeType was uninitialized.
Since
BeOS R3

◆ GetSupportingApps()

status_t BMimeType::GetSupportingApps ( BMessage signatures) const

Fetches a BMessage containing a list of MIME signatures of applications that are able to handle files of this MIME type.

If successful, the BMessage containing the MIME signatures will be of the following format:

field name type contains
"applications" B_STRING_TYPE[] An array of MIME signatures. The first n signatures (where n is the value in the "be:sub" field of the message) are able to handle the full type (supertype and subtype). The remaining signatures are of applications that handle the supertype only.
"be:sub" B_INT32_TYPE The number of applications in the "applications" array that can handle the object's full MIME type. These applications are listed first in the array. This field is omitted if the object represents a supertype only.
"be:super" B_INT32_TYPE The number of applications in the "applications" array that can handle the object's supertype (not counting those that can handle the full type). These applications are listed after the full-MIME-type supporters. By definition, the GetWildcardApps() function never returns supertype-only apps.

The BMessage::what value is meaningless and should be ignored.

Parameters
signaturesPointer to a pre-allocated BMessage into which the signatures of the supporting applications will be copied.
Returns
B_OK on success or an error code on failure.
See also
SetSupportingApps()
Since
BeOS R3

◆ GetWildcardApps()

status_t BMimeType::GetWildcardApps ( BMessage wild_ones)
static

Fetches a BMessage containing a list of MIME signatures of applications that are able to handle files of any type.

This function is the same as calling GetSupportingApps() on a BMimeType object initialized to a MIME type of] "application/octet-stream".

Parameters
wild_onesPointer to a pre-allocated BMessage into which signatures of applications supporting files of any type are copied.
Returns
B_OK on success or another error code on failure.
See also
GetSupportingApps() for details on the format of the data returned in the BMessage pointed to by wild_ones.
Since
BeOS R3

◆ GuessMimeType() [1/3]

status_t BMimeType::GuessMimeType ( const char *  filename,
BMimeType type 
)
static

Guesses a MIME type for the given filename.

Only the filename itself is taken into consideration (in particular its name extension), not the entry it refers to. I.e. an entry with that name doesn't need to exist at all.

Parameters
filenameThe filename.
typePointer to a pre-allocated BMimeType which is set to the resulting MIME type.
Returns
A status code.
Return values
B_OKEverything went fine.
B_BAD_VALUENULL ref or result.
B_NO_INITBMimeType was uninitialized.
Since
Haiku R1

◆ GuessMimeType() [2/3]

status_t BMimeType::GuessMimeType ( const entry_ref file,
BMimeType type 
)
static

Guesses a MIME type for the entry referred to by the given entry_ref.

This version of GuessMimeType() combines the features of the other versions: First the data of the given file are checked (sniffed). Only if the result of this operation is inconclusive, i.e. "application/octet-stream", the filename is examined for extensions.

Parameters
filePointer to the entry_ref referring to the entry.
typePointer to a pre-allocated BMimeType which is set to the resulting MIME type.
Returns
A status code.
Return values
B_OKEverything went fine.
B_BAD_VALUENULL ref or result.
B_NAME_NOT_FOUNDref refers to an abstract entry.
B_NO_INITBMimeType was uninitialized.
Since
Haiku R1

◆ GuessMimeType() [3/3]

status_t BMimeType::GuessMimeType ( const void *  buffer,
int32  length,
BMimeType type 
)
static

Guesses a MIME type for the supplied chunk of data.

Parameters
bufferPointer to the data buffer.
lengthSize of the buffer in bytes.
typePointer to a pre-allocated BMimeType which is set to the resulting MIME type.
Returns
A status code.
Return values
B_OKEverything went fine.
B_BAD_VALUENULL buffer or result.
B_NO_INITBMimeType was uninitialized.
Since
Haiku R1

◆ InitCheck()

status_t BMimeType::InitCheck ( ) const

Returns the result of the most recent constructor or SetTo() call.

Returns
B_OK If the object is properly initialized, a specific error code otherwise.
Since
BeOS R3

◆ Install()

status_t BMimeType::Install ( )

Adds the MIME type to the MIME database.

To check if the MIME type is already installed, call IsInstalled(). To remove the MIME type from the database, call Delete().

Note
The R5 implementation returns random values if the type is already installed, so be sure to check IsInstalled() first.
Returns
B_OK on success or another error code on failure.
See also
Delete()
Since
BeOS R3

◆ IsInstalled()

bool BMimeType::IsInstalled ( ) const

Returns whether or not this type is currently installed in the MIME database.

To add the MIME type to the database, call Install(). To remove the MIME type from the database, call Delete().

Returns
A bool indicating whether or not this type is currently installed in the MIME database.
Return values
trueThe MIME type is currently installed in the database.
falseThe MIME type is not currently installed in the database.
Since
BeOS R3

◆ IsSupertypeOnly()

bool BMimeType::IsSupertypeOnly ( ) const

Returns whether this objects represents a supertype.

Returns
true, if the object is properly initialized and represents a supertype, false otherwise.
Since
BeOS R3

◆ IsValid() [1/2]

bool BMimeType::IsValid ( ) const

Returns whether the object represents a valid MIME type.

Returns
true, if the object is properly initialized, false otherwise.
See also
SetTo() for further information.
Since
BeOS R3

◆ IsValid() [2/2]

bool BMimeType::IsValid ( const char *  string)
static

Returns whether the given string represents a valid MIME type.

Parameters
stringThe MIME type string.
Returns
true, if the given string represents a valid MIME type.
See also
SetTo() for further information.
Since
BeOS R3

◆ operator==() [1/2]

bool BMimeType::operator== ( const BMimeType type) const

Returns whether this and the supplied MIME type are equal.

Two BMimeType objects are said to be equal if they represent the same MIME string, ignoring case, or if both are not initialized.

Warning
In BeOS R5 two uninitialized BMimeType objects were not considered to be equal, in Haiku they are.
Parameters
typeThe BMimeType to be compared with.
Returns
true, if the objects are equal, false otherwise.
Since
BeOS R3

◆ operator==() [2/2]

bool BMimeType::operator== ( const char *  type) const

Returns whether this and the supplied MIME type are equal.

A BMimeType objects equals a MIME string, if its MIME string equals the latter one, ignoring case, or if it is uninitialized and the MIME string is NULL.

Warning
In BeOS R5 an uninitialized BMimeType object was not considered to be equal to NULL, in Haiku it is.
Parameters
typeThe MIME string to be compared with.
Returns
true, if the MIME types are equal, false otherwise.
Since
BeOS R4

◆ SetAppHint()

status_t BMimeType::SetAppHint ( const entry_ref ref)

Sets the app hint field for the MIME type.

The app hint is a path that identifies the executable that should be used when launching an application that has this signature. For example, when Tracker needs to launch an app of type "application/YourAppHere", it asks the database for the application hint. This hint is converted to an entry_ref before it is passed to the caller. Of course, the path may not point to an application, or it might point to an application with the wrong signature (and so on); that's why this is merely a hint.

The entry_ref pointed to by ref must be pre-allocated. It must be a valid entry_ref (i.e. entry_ref(-1, -1, "some_file") will trigger an error), but it need not point to an existing file, nor need it actually point to an application. That's not to say that it shouldn't; such an entry_ref would render the app hint useless.

Parameters
refPointer to a pre-allocated entry_ref containting the location of the new app hint
Returns
B_OK on success or another error code on failure.
Return values
B_OKThe ref was retrieved successfully.
B_NO_INITBMimeType was uninitialized.
B_BAD_VALUEref was NULL.
Since
BeOS R3

◆ SetAttrInfo()

since BeOS R3 *status_t BMimeType::SetAttrInfo ( const BMessage info)

Sets the description of the attributes typically associated with files of the given MIME type.

The attribute information is technically arbitrary, but the expected format of the BMessage pointed to by the info parameter is as follows:

field name type element[0..n]
"attr:name" B_STRING_TYPE The name of each attribute
"attr:public_name" B_STRING_TYPE The human-readable name of each attribute
"attr:type" B_INT32_TYPE The type code for each attribute
"attr:viewable" B_BOOL_TYPE For each attribute: true if the attribute is public, false if it's private
"attr:editable" B_BOOL_TYPE For each attribute: true if the attribute should be user editable, false if not

The BMessage::what value is ignored.

Parameters
infoPointer to a pre-allocated and properly formatted BMessage containing information about the file attributes typically associated with the MIME type.
Returns
B_OK on success or another error code on failure.
Since
BeOS R3

◆ SetFileExtensions()

status_t BMimeType::SetFileExtensions ( const BMessage extensions)

Sets the list of filename extensions associated with the MIME type.

The MIME database associates a list of filename extensions (a character string following the rightmost dot, ".", character in the filename) with each type. These extensions can then be used to help determine the type of any untyped files that may be encountered.

The list of extensions is given in a pre-allocated BMessage pointed to by the extensions parameter. The format of the message should be as follows:

  • The message's "extensions" field should contain an indexed array of strings, one for each extension. The extensions are to be given without the preceding "." character (i.e. "html" or "mp3", not ".html" or ".mp3" ).
  • The what member of the BMessage is ignored.
Note
Any other fields present in the BMessage will currently be retained and returned by calls to GetFileExtensions(); however, this may change in the future, so it is recommended that you not rely on this behavior, and that no other fields be present. Also, note that no checking is performed to verify the BMessage is properly formatted; it's up to you to do things right.

Finally, bear in mind that SetFileExtensions() clobbers the existing set of extensions. If you want to augment a type's extensions, you should retrieve the existing set, add the new ones, and then call SetFileExtensions().

Parameters
extensionsPointer to a pre-allocated, properly formatted BMessage containing the new list of file extensions to associate with this MIME type.
Returns
B_OK on success or another error code on failure.
Since
BeOS R3

◆ SetIcon() [1/2]

status_t BMimeType::SetIcon ( const BBitmap icon,
icon_size  which 
)

Sets the large or mini icon for the MIME type.

The icon is copied from the BBitmap pointed to by icon. The bitmap must be the proper size: 32x32 for the large icon, 16x16 for the mini icon. Additionally, the bitmap must be in the B_CMAP8 color space (8-bit color).

If you want to erase the current icon, pass NULL as the icon argument.

Parameters
iconPointer to a pre-allocated BBitmap of proper size and colorspace containing the new icon, or NULL to clear the current icon.
whichValue that specifies which icon to update. Currently B_LARGE_ICON and B_MINI_ICON are supported.
Returns
B_OK on success or another error code on failure.
Since
BeOS R3

◆ SetIcon() [2/2]

status_t BMimeType::SetIcon ( const uint8 data,
size_t  size 
)

Sets the vector icon for the MIME type.

The icon is copied from the provided data which must contain size bytes.

If you want to erase the current icon, pass NULL as the data argument.

Parameters
dataPointer to a buffer containing the new icon, or NULL to clear the current icon.
sizeSize of the provided buffer.
Returns
B_OK on success or another error code on failure.
Since
Haiku R1

◆ SetIconForType() [1/2]

status_t BMimeType::SetIconForType ( const char *  type,
const BBitmap icon,
icon_size  which 
)

Sets the large or mini icon used by an application of this type for files of the given type.

This can be confusing, so here's how this function is intended to be used:

  • The actual BMimeType object should be set to the MIME signature of an application to whom you want to assign custom icons for custom MIME types.
  • The type parameter specifies the file type whose custom icon you are setting.

The type of the BMimeType object is not required to actually be a subtype of "application/"; that is the intended use however, and application-specific icons are not expected to be present for non-application types.

The icon is copied from the BBitmap pointed to by icon. The bitmap must be the proper size: 32x32 for the large icon, 16x16 for the mini icon.

If you want to erase the current icon, pass NULL as the icon argument.

Parameters
typePointer to a pre-allocated string containing the MIME type whose custom icon you wish to set.
iconPointer to a pre-allocated BBitmap of proper size and colorspace containing the new icon, or NULL to clear the current icon.
whichValue that specifies which icon to update. Currently B_LARGE_ICON and B_MINI_ICON are supported.
Returns
B_OK on success or another error code on failure.
Since
BeOS R3

◆ SetIconForType() [2/2]

status_t BMimeType::SetIconForType ( const char *  type,
const uint8 data,
size_t  dataSize 
)

Sets the icon used by an application of this type for files of the given type.

This can be confusing, so here's how this function is intended to be used:

  • The actual BMimeType object should be set to the MIME signature of an application to whom you want to assign custom icons for custom MIME types.
  • The type parameter specifies the file type whose custom icon you are setting.

The type of the BMimeType object is not required to actually be a subtype of "application/"; that is the intended use however, and application-specific icons are not expected to be present for non-application types.

The icon is copied from the BBitmap pointed to by icon. The bitmap must be the proper size: 32x32 for the large icon, 16x16 for the mini icon.

If you want to erase the current icon, pass NULL as the icon argument.

Parameters
typePointer to a pre-allocated string containing the MIME type whose custom icon you wish to set.
dataPointer to a pre-allocated uint8 array of the proper size to contain the new icon, or NULL to clear the current icon.
dataSizeThe size of data in bytes.
Returns
B_OK on success or another error code on failure.
Since
Haiku R1

◆ SetLongDescription()

status_t BMimeType::SetLongDescription ( const char *  description)

Sets the long description field for the MIME type.

The string pointed to by description must be of length less than B_MIME_TYPE_LENGTH characters.

Note
If the MIME type is not installed, it will first be installed, and then the long description will be set.
Parameters
descriptionPointer to a pre-allocated string containing the new long description
Returns
B_OK on success or another error code on failure.
Since
BeOS R3

◆ SetPreferredApp()

status_t BMimeType::SetPreferredApp ( const char *  signature,
app_verb  verb = B_OPEN 
)

Sets the preferred application for the MIME type.

The preferred app is the application that's used to access a file when, for example, the user double-clicks the file in a Tracker window. Unless the file identifies in its attributes a "custom" preferred app, Tracker will ask the file type database for the preferred app that's associated with the file's type.

The string pointed to by signature must be of length less than B_MIME_TYPE_LENGTH characters.

Note
If the MIME type is not installed, it will first be installed, and then the preferred app will be set.
Parameters
signaturePointer to a pre-allocated string containing the signature of the new preferred app.
verbapp_verb value that specifies the type of access for which you are setting the preferred app. Currently, the only supported app verb is B_OPEN.
Returns
B_OK on success or another error code on failure.

◆ SetShortDescription()

status_t BMimeType::SetShortDescription ( const char *  description)

Sets the short description field for the MIME type.

The string pointed to by description must be of length less than B_MIME_TYPE_LENGTH characters.

Note
If the MIME type is not installed, it will first be installed, and then the short description will be set.
Parameters
descriptionPointer to a pre-allocated string containing the new short description.
Returns
B_OK on success or another error code on failure.
Since
BeOS R3

◆ SetSnifferRule()

status_t BMimeType::SetSnifferRule ( const char *  rule)

Sets the MIME type's sniffer rule.

If the supplied rule is NULL, the MIME type's sniffer rule is unset.

SetSnifferRule() does also return B_OK, if the type is not installed, but the call will have no effect in this case.

Parameters
ruleThe rule string, may be NULL.
Returns
A status code.
Return values
B_OKEverything went fine.
B_BAD_VALUEUninitialized BMimeType.
B_BAD_MIME_SNIFFER_RULEThe supplied sniffer rule is invalid.
B_NO_INITBMimeType was uninitialized.
See also
CheckSnifferRule()
Since
Haiku R1

◆ SetTo()

status_t BMimeType::SetTo ( const char *  mimeType)

Initializes this object to the supplied MIME type.

The supplied string must specify a valid MIME type or supertype. Valid MIME types are given by the following grammar:

MIMEType ::= Supertype "/" [ Subtype ] Supertype ::= "application" | "audio" | "image" | "message" | "multipart" | "text" | "video" Subtype ::= MIMEChar MIMEChar* MIMEChar ::= any character except white spaces, CTLs and '/', '<', '>', '@',, ',', ';', ':', '"', '(', ')', '[', ']', '?', '=', '\' (Note: RFC1341 also forbits '.', but it is allowed here.)

Currently the supertype is not restricted to one of the seven types given, but can be an arbitrary string (obeying the same rule as the subtype). Nevertheless it is a very bad idea to use another supertype. The supplied MIME string is copied; the caller retains the ownership.

Parameters
mimeTypeThe MIME string.
Returns
A status code.
Return values
B_OKEverything went fine.
B_BAD_VALUEInvalid mimeType string.
B_NO_INITBMimeType was uninitialized.
B_NO_MEMORYInsufficient memory to copy the MIME string.
Since
BeOS R3

◆ SetType()

status_t BMimeType::SetType ( const char *  mimeType)

Initializes this object to the supplied MIME type.

Since
BeOS R3

◆ StartWatching()

status_t BMimeType::StartWatching ( BMessenger  target)
static

Starts monitoring the MIME database for a given target.

Until StopWatching() is called for the target, an update message is sent to it whenever the MIME database changes.

Parameters
targetA BMessenger identifying the target for the update messages.
Returns
B_OK on success or another error code on failure.
Since
BeOS R4

◆ StopWatching()

status_t BMimeType::StopWatching ( BMessenger  target)
static

Stops monitoring the MIME database for a given target (previously started via StartWatching()).

Parameters
targetA BMessenger identifying the target for the update messages.
Returns
B_OK on success or another error code on failure.
Since
BeOS R4

◆ Type()

const char * BMimeType::Type ( ) const

Returns the MIME string represented by this object.

Returns
The MIME string, if the object is properly initialized, NULL otherwise.
Since
BeOS R3

◆ Unset()

void BMimeType::Unset ( )

Returns the object to an uninitialized state.

Since
BeOS R3