1 /////////////////////////////////////////////////////////////////////////////
 
   3 // Purpose:     SWIG interface stuff for wxJoystick
 
   7 // Created:     18-June-1999
 
   9 // Copyright:   (c) 2003 by Total Control Software
 
  10 // Licence:     wxWindows license
 
  11 /////////////////////////////////////////////////////////////////////////////
 
  16 //---------------------------------------------------------------------------
 
  20 #include <wx/mimetype.h>
 
  23 //---------------------------------------------------------------------------
 
  27     wxMAILCAP_STANDARD = 1,
 
  28     wxMAILCAP_NETSCAPE = 2,
 
  38 // wxFileTypeInfo: static container of information accessed via wxFileType.
 
  43     wxFileTypeInfo(const wxString& mimeType,
 
  44                    const wxString& openCmd,
 
  45                    const wxString& printCmd,
 
  46                    const wxString& desc);
 
  49     // the array elements correspond to the parameters of the ctor above in
 
  51     %Rename(FileTypeInfoSequence,, wxFileTypeInfo(const wxArrayString& sArray));
 
  53     // invalid item - use this to terminate the array passed to
 
  54     // wxMimeTypesManager::AddFallbacks
 
  55     %Rename(NullFileTypeInfo,, wxFileTypeInfo());
 
  58     // test if this object can be used
 
  62     void SetIcon(const wxString& iconFile, int iconIndex = 0);
 
  65     void SetShortDesc(const wxString& shortDesc);
 
  68     const wxString& GetMimeType() const;
 
  70     // get the open command
 
  71     const wxString& GetOpenCommand() const;
 
  73     // get the print command
 
  74     const wxString& GetPrintCommand() const;
 
  76     // get the short description (only used under Win32 so far)
 
  77     const wxString& GetShortDesc() const;
 
  79     // get the long, user visible description
 
  80     const wxString& GetDescription() const;
 
  82     // get the array of all extensions
 
  83     const wxArrayString& GetExtensions() const;
 
  84     int GetExtensionsCount() const;
 
  87     const wxString& GetIconFile() const;
 
  88     int GetIconIndex() const;
 
  93 //---------------------------------------------------------------------------
 
  95 // wxFileType: gives access to all information about the files of given type.
 
  97 // This class holds information about a given "file type". File type is the
 
  98 // same as MIME type under Unix, but under Windows it corresponds more to an
 
  99 // extension than to MIME type (in fact, several extensions may correspond to a
 
 100 // file type). This object may be created in many different ways and depending
 
 101 // on how it was created some fields may be unknown so the return value of all
 
 102 // the accessors *must* be checked!
 
 107 //     // TODO: Make a wxPyMessageParameters with virtual GetParamValue...
 
 109 //     // An object of this class must be passed to Get{Open|Print}Command. The
 
 110 //     // default implementation is trivial and doesn't know anything at all about
 
 111 //     // parameters, only filename and MIME type are used (so it's probably ok for
 
 112 //     // Windows where %{param} is not used anyhow)
 
 113 //     class MessageParameters
 
 117 //         MessageParameters(const wxString& filename=wxPyEmptyString,
 
 118 //                           const wxString& mimetype=wxPyEmptyString);
 
 120 //         // accessors (called by GetOpenCommand)
 
 122 //         const wxString& GetFileName() const;
 
 124 //         const wxString& GetMimeType() const;;
 
 126 //         // override this function in derived class
 
 127 //         virtual wxString GetParamValue(const wxString& name) const;
 
 129 //         // virtual dtor as in any base class
 
 130 //         virtual ~MessageParameters();
 
 134     // ctor from static data
 
 135     wxFileType(const wxFileTypeInfo& ftInfo);
 
 139     // return the MIME type for this file type
 
 141         PyObject* GetMimeType() {
 
 143             if (self->GetMimeType(&str)) 
 
 144                 return wx2PyString(str);
 
 149         PyObject* GetMimeTypes() {
 
 151             if (self->GetMimeTypes(arr))
 
 152                 return wxArrayString2PyList_helper(arr);
 
 159     // Get all extensions associated with this file type
 
 161         PyObject* GetExtensions() {
 
 163             if (self->GetExtensions(arr))
 
 164                 return wxArrayString2PyList_helper(arr);
 
 172         // Get the icon corresponding to this file type
 
 176             if (self->GetIcon(&loc))
 
 177                 return new wxIcon(loc);
 
 182         // Get the icon corresponding to this file type, the name of the file
 
 183         // where this icon resides, and its index in this file if applicable.
 
 184         PyObject* GetIconInfo() {
 
 186             if (self->GetIcon(&loc)) {
 
 187                 wxString iconFile = loc.GetFileName();
 
 190                 iconIndex = loc.GetIndex();
 
 192                 // Make a tuple and put the values in it
 
 193                 bool blocked = wxPyBeginBlockThreads();
 
 194                 PyObject* tuple = PyTuple_New(3);
 
 195                 PyTuple_SetItem(tuple, 0, wxPyConstructObject(new wxIcon(loc),
 
 196                                                               wxT("wxIcon"), true));
 
 197                 PyTuple_SetItem(tuple, 1, wx2PyString(iconFile));
 
 198                 PyTuple_SetItem(tuple, 2, PyInt_FromLong(iconIndex));
 
 199                 wxPyEndBlockThreads(blocked);
 
 208         // get a brief file type description ("*.txt" => "text document")
 
 209         PyObject* GetDescription() {
 
 211             if (self->GetDescription(&str)) 
 
 212                 return wx2PyString(str);
 
 219     // get the command to open/execute the file of given type
 
 221         PyObject* GetOpenCommand(const wxString& filename,
 
 222                                  const wxString& mimetype=wxPyEmptyString) {
 
 224             if (self->GetOpenCommand(&str, wxFileType::MessageParameters(filename, mimetype))) 
 
 225                 return wx2PyString(str);
 
 232     // get the command to print the file of given type
 
 234         PyObject* GetPrintCommand(const wxString& filename,
 
 235                                   const wxString& mimetype=wxPyEmptyString) {
 
 237             if (self->GetPrintCommand(&str, wxFileType::MessageParameters(filename, mimetype))) 
 
 238                 return wx2PyString(str);
 
 245     // Get all commands defined for this file type
 
 247         PyObject* GetAllCommands(const wxString& filename,
 
 248                                  const wxString& mimetype=wxPyEmptyString) {
 
 250             wxArrayString commands;
 
 251             if (self->GetAllCommands(&verbs, &commands,
 
 252                                      wxFileType::MessageParameters(filename, mimetype))) {
 
 253                 bool blocked = wxPyBeginBlockThreads();
 
 254                 PyObject* tuple = PyTuple_New(2);
 
 255                 PyTuple_SetItem(tuple, 0, wxArrayString2PyList_helper(verbs));
 
 256                 PyTuple_SetItem(tuple, 1, wxArrayString2PyList_helper(commands));
 
 257                 wxPyEndBlockThreads(blocked);
 
 266     // set an arbitrary command, ask confirmation if it already exists and
 
 267     // overwriteprompt is True
 
 268     bool SetCommand(const wxString& cmd, const wxString& verb,
 
 269                     bool overwriteprompt = true);
 
 271     bool SetDefaultIcon(const wxString& cmd = wxPyEmptyString, int index = 0);
 
 274     // remove the association for this filetype from the system MIME database:
 
 275     // notice that it will only work if the association is defined in the user
 
 276     // file/registry part, we will never modify the system-wide settings
 
 280         // expand a string in the format of GetOpenCommand (which may contain
 
 281         // '%s' and '%t' format specificators for the file name and mime type
 
 282         // and %{param} constructions).
 
 284         static wxString ExpandCommand(const wxString& command,
 
 285                                       const wxString& filename,
 
 286                                       const wxString& mimetype=wxPyEmptyString) {
 
 287             return wxFileType::ExpandCommand(command,
 
 288                                              wxFileType::MessageParameters(filename, mimetype));
 
 296 //---------------------------------------------------------------------------
 
 298 // See also wxPy_ReinitStockObjects in helpers.cpp
 
 299 wxMimeTypesManager* const wxTheMimeTypesManager;
 
 302 // wxMimeTypesManager: interface to system MIME database.
 
 304 // This class accesses the information about all known MIME types and allows
 
 305 // the application to retrieve information (including how to handle data of
 
 306 // given type) about them.
 
 307 class wxMimeTypesManager
 
 310     // static helper functions
 
 311     // -----------------------
 
 313         // check if the given MIME type is the same as the other one: the
 
 314         // second argument may contain wildcards ('*'), but not the first. If
 
 315         // the types are equal or if the mimeType matches wildcard the function
 
 316         // returns True, otherwise it returns False
 
 317     static bool IsOfType(const wxString& mimeType, const wxString& wildcard);
 
 320     wxMimeTypesManager();
 
 322     // loads data from standard files according to the mailcap styles
 
 323     // specified: this is a bitwise OR of wxMailcapStyle values
 
 325     // use the extraDir parameter if you want to look for files in another
 
 327     void Initialize(int mailcapStyle = wxMAILCAP_ALL,
 
 328                     const wxString& extraDir = wxPyEmptyString);
 
 330     // and this function clears all the data from the manager
 
 333     // Database lookup: all functions return a pointer to wxFileType object
 
 334     // whose methods may be used to query it for the information you're
 
 335     // interested in. If the return value is !NULL, caller is responsible for
 
 337     // get file type from file extension
 
 338     %newobject GetFileTypeFromExtension;
 
 339     wxFileType *GetFileTypeFromExtension(const wxString& ext);
 
 341     // get file type from MIME type (in format <category>/<format>)
 
 342     %newobject GetFileTypeFromMimeType;
 
 343     wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
 
 345     // other operations: return True if there were no errors or False if there
 
 346     // were some unreckognized entries (the good entries are always read anyhow)
 
 349     // read in additional file (the standard ones are read automatically)
 
 350     // in mailcap format (see mimetype.cpp for description)
 
 352     // 'fallback' parameter may be set to True to avoid overriding the
 
 353     // settings from other, previously parsed, files by this one: normally,
 
 354     // the files read most recently would override the older files, but with
 
 355     // fallback == True this won't happen
 
 356     bool ReadMailcap(const wxString& filename, bool fallback = false);
 
 358     // read in additional file in mime.types format
 
 359     bool ReadMimeTypes(const wxString& filename);
 
 361     // enumerate all known MIME types
 
 363         PyObject* EnumAllFileTypes() {
 
 365             self->EnumAllFileTypes(arr);
 
 366             return wxArrayString2PyList_helper(arr);
 
 370     // these functions can be used to provide default values for some of the
 
 371     // MIME types inside the program itself (you may also use
 
 372     // ReadMailcap(filenameWithDefaultTypes, True /* use as fallback */) to
 
 373     // achieve the same goal, but this requires having this info in a file).
 
 375     void AddFallback(const wxFileTypeInfo& ft);
 
 378     // create or remove associations
 
 380     // create a new association using the fields of wxFileTypeInfo (at least
 
 381     // the MIME type and the extension should be set)
 
 382     // if the other fields are empty, the existing values should be left alone
 
 383     %newobject Associate;
 
 384     wxFileType *Associate(const wxFileTypeInfo& ftInfo);
 
 387     bool Unassociate(wxFileType *ft) ;
 
 389     ~wxMimeTypesManager();
 
 392 //---------------------------------------------------------------------------
 
 394 //---------------------------------------------------------------------------
 
 395 //---------------------------------------------------------------------------