contents up previous next

wxfiletype

this class holds information about a given file type. file type is the same as mime type under unix, but under windows it corresponds more to an extension than to mime type (in fact, several extensions may correspond to a file type). this object may be created in several different ways: the program might know the file extension and wish to find out the corresponding mime type or, conversely, it might want to find the right extension for the file to which it writes the contents of given mime type. depending on how it was created some fields may be unknown so the return value of all the accessors must be checked: false will be returned if the corresponding information couldn't be found.

the objects of this class are never created by the application code but are returned by wxmimetypesmanager::getfiletypefrommimetype and wxmimetypesmanager::getfiletypefromextension methods. but it is your responsibility to delete the returned pointer when you're done with it!

a brief reminder about what the mime types are (see the rfc 1341 for more information): basically, it is just a pair category/type (for example, "text/plain") where the category is a basic indication of what a file is. examples of categories are "application", "image", "text", "binary", and type is a precise definition of the document format: "plain" in the example above means just ascii text without any formatting, while "text/html" is the html document source.

a mime type may have one or more associated extensions: "text/plain" will typically correspond to the extension ".txt", but may as well be associated with ".ini" or ".conf".

derived from

none

include files

<wx/mimetype.h>

see also

wxmimetypesmanager

members

messageparameters class
wxfiletype::wxfiletype
wxfiletype::~wxfiletype
wxfiletype::getmimetype
wxfiletype::getmimetypes
wxfiletype::getextensions
wxfiletype::geticon
wxfiletype::getdescription
wxfiletype::getopencommand
wxfiletype::getprintcommand
wxfiletype::expandcommand


messageparameters class

one of the most common usages of mime is to encode an e-mail message. the mime type of the encoded message is an example of a message parameter. these parameters are found in the message headers ("content-xxx"). at the very least, they must specify the mime type and the version of mime used, but almost always they provide additional information about the message such as the original file name or the charset (for the text documents).

these parameters may be useful to the program used to open, edit, view or print the message, so, for example, an e-mail client program will have to pass them to this program. because wxfiletype itself can not know about these parameters, it uses messageparameters class to query them. the default implementation only requires the caller to provide the file name (always used by the program to be called - it must know which file to open) and the mime type and supposes that there are no other parameters. if you wish to supply additional parameters, you must derive your own class from messageparameters and override getparamvalue() function, for example:

// provide the message parameters for the mime type manager
class mailmessageparameters : public wxfiletype::messageparameters
{
public:
   mailmessageparameters(const wxstring& filename,
                         const wxstring& mimetype)
      : wxfiletype::messageparameters(filename, mimetype)
   {
   }

   virtual wxstring getparamvalue(const wxstring& name) const
   {
       // parameter names are not case-sensitive
       if ( name.cmpnocase("charset") == 0 )
           return "us-ascii";
       else
           return wxfiletype::messageparameters::getparamvalue(name);
   }
};
now you only need to create an object of this class and pass it to, for example, getopencommand like this:

wxstring command;
if ( filetype->getopencommand(&command,
                              mailmessageparameters("foo.txt", "text/plain")) )
{
    // the full command for opening the text documents is in 'command'
    // (it might be "notepad foo.txt" under windows or "cat foo.txt" under unix)
}
else
{
    // we don't know how to handle such files...
}
windows: as only the file name is used by the program associated with the given extension anyhow (but no other message parameters), there is no need to ever derive from messageparameters class for a windows-only program.


wxfiletype::wxfiletype

wxfiletype()

the default constructor is private because you should never create objects of this type: they are only returned by wxmimetypesmanager methods.


wxfiletype::~wxfiletype

~wxfiletype()

the destructor of this class is not virtual, so it should not be derived from.


wxfiletype::getmimetype

bool getmimetype(wxstring* mimetype)

if the function returns true, the string pointed to by mimetype is filled with full mime type specification for this file type: for example, "text/plain".


wxfiletype::getmimetypes

bool getmimetype(wxarraystring& mimetypes)

same as getmimetype but returns array of mime types. this array will contain only one item in most cases but sometimes, notably under unix with kde, may contain more mime types. this happens when one file extension is mapped to different mime types by kde, mailcap and mime.types.


wxfiletype::getextensions

bool getextensions(wxarraystring& extensions)

if the function returns true, the array extensions is filled with all extensions associated with this file type: for example, it may contain the following two elements for the mime type "text/html" (notice the absence of the leading dot): "html" and "htm".

windows: this function is currently not implemented: there is no (efficient) way to retrieve associated extensions from the given mime type on this platform, so it will only return true if the wxfiletype object was created by getfiletypefromextension function in the first place.


wxfiletype::geticon

bool geticon(wxiconlocation * iconloc)

if the function returns true, the iconloc is filled with the location of the icon for this mime type. a wxicon may be created from iconloc later.

windows: the function returns the icon shown by explorer for the files of the specified type.

mac: this function is not implemented and always returns false.

unix: mime manager gathers information about icons from gnome and kde settings and thus geticon's success depends on availability of these desktop environments.


wxfiletype::getdescription

bool getdescription(wxstring* desc)

if the function returns true, the string pointed to by desc is filled with a brief description for this file type: for example, "text document" for the "text/plain" mime type.


wxfiletype::getopencommand

bool getopencommand(wxstring* command, messageparameters& params)

wxstring getopencommand(const wxstring& filename)

with the first version of this method, if the true is returned, the string pointed to by command is filled with the command which must be executed (see wxexecute) in order to open the file of the given type. in this case, the name of the file as well as any other parameters is retrieved from messageparameters class.

in the second case, only the filename is specified and the command to be used to open this kind of file is returned directly. an empty string is returned to indicate that an error occurred (typically meaning that there is no standard way to open this kind of files).


wxfiletype::getprintcommand

bool getprintcommand(wxstring* command,messageparameters& params)

if the function returns true, the string pointed to by command is filled with the command which must be executed (see wxexecute) in order to print the file of the given type. the name of the file is retrieved from messageparameters class.


wxfiletype::expandcommand

static wxstring expandcommand(const wxstring& command, messageparameters& params)

this function is primarily intended for getopencommand and getprintcommand usage but may be also used by the application directly if, for example, you want to use some non-default command to open the file.

the function replaces all occurrences of

format specification with
%s the full file name
%t the mime type
%{param} the value of the parameter param

using the messageparameters object you pass to it.

if there is no '%s' in the command string (and the string is not empty), it is assumed that the command reads the data on stdin and so the effect is the same as "< %s" were appended to the string.

unlike all other functions of this class, there is no error return for this function.