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     size_t GetExtensionsCount() const;
 
  87     const wxString& GetIconFile() const;
 
  88     int GetIconIndex() const;
 
  90     %property(Description, GetDescription, doc="See `GetDescription`");
 
  91     %property(Extensions, GetExtensions, doc="See `GetExtensions`");
 
  92     %property(ExtensionsCount, GetExtensionsCount, doc="See `GetExtensionsCount`");
 
  93     %property(IconFile, GetIconFile, doc="See `GetIconFile`");
 
  94     %property(IconIndex, GetIconIndex, doc="See `GetIconIndex`");
 
  95     %property(MimeType, GetMimeType, doc="See `GetMimeType`");
 
  96     %property(OpenCommand, GetOpenCommand, doc="See `GetOpenCommand`");
 
  97     %property(PrintCommand, GetPrintCommand, doc="See `GetPrintCommand`");
 
  98     %property(ShortDesc, GetShortDesc, SetShortDesc, doc="See `GetShortDesc` and `SetShortDesc`");
 
 103 //---------------------------------------------------------------------------
 
 105 // wxFileType: gives access to all information about the files of given type.
 
 107 // This class holds information about a given "file type". File type is the
 
 108 // same as MIME type under Unix, but under Windows it corresponds more to an
 
 109 // extension than to MIME type (in fact, several extensions may correspond to a
 
 110 // file type). This object may be created in many different ways and depending
 
 111 // on how it was created some fields may be unknown so the return value of all
 
 112 // the accessors *must* be checked!
 
 117 //     // TODO: Make a wxPyMessageParameters with virtual GetParamValue...
 
 119 //     // An object of this class must be passed to Get{Open|Print}Command. The
 
 120 //     // default implementation is trivial and doesn't know anything at all about
 
 121 //     // parameters, only filename and MIME type are used (so it's probably ok for
 
 122 //     // Windows where %{param} is not used anyhow)
 
 123 //     class MessageParameters
 
 127 //         MessageParameters(const wxString& filename=wxPyEmptyString,
 
 128 //                           const wxString& mimetype=wxPyEmptyString);
 
 130 //         // accessors (called by GetOpenCommand)
 
 132 //         const wxString& GetFileName() const;
 
 134 //         const wxString& GetMimeType() const;;
 
 136 //         // override this function in derived class
 
 137 //         virtual wxString GetParamValue(const wxString& name) const;
 
 139 //         // virtual dtor as in any base class
 
 140 //         virtual ~MessageParameters();
 
 144     // ctor from static data
 
 145     wxFileType(const wxFileTypeInfo& ftInfo);
 
 149     // return the MIME type for this file type
 
 151         PyObject* GetMimeType() {
 
 153             if (self->GetMimeType(&str)) 
 
 154                 return wx2PyString(str);
 
 159         PyObject* GetMimeTypes() {
 
 161             if (self->GetMimeTypes(arr))
 
 162                 return wxArrayString2PyList_helper(arr);
 
 169     // Get all extensions associated with this file type
 
 171         PyObject* GetExtensions() {
 
 173             if (self->GetExtensions(arr))
 
 174                 return wxArrayString2PyList_helper(arr);
 
 182         // Get the icon corresponding to this file type
 
 186             if (self->GetIcon(&loc))
 
 187                 return new wxIcon(loc);
 
 192         // Get the icon corresponding to this file type, the name of the file
 
 193         // where this icon resides, and its index in this file if applicable.
 
 194         PyObject* GetIconInfo() {
 
 196             if (self->GetIcon(&loc)) {
 
 197                 wxString iconFile = loc.GetFileName();
 
 200                 iconIndex = loc.GetIndex();
 
 202                 // Make a tuple and put the values in it
 
 203                 wxPyBlock_t blocked = wxPyBeginBlockThreads();
 
 204                 PyObject* tuple = PyTuple_New(3);
 
 205                 PyTuple_SetItem(tuple, 0, wxPyConstructObject(new wxIcon(loc),
 
 206                                                               wxT("wxIcon"), true));
 
 207                 PyTuple_SetItem(tuple, 1, wx2PyString(iconFile));
 
 208                 PyTuple_SetItem(tuple, 2, PyInt_FromLong(iconIndex));
 
 209                 wxPyEndBlockThreads(blocked);
 
 218         // get a brief file type description ("*.txt" => "text document")
 
 219         PyObject* GetDescription() {
 
 221             if (self->GetDescription(&str)) 
 
 222                 return wx2PyString(str);
 
 229     // get the command to open/execute the file of given type
 
 231         PyObject* GetOpenCommand(const wxString& filename,
 
 232                                  const wxString& mimetype=wxPyEmptyString) {
 
 234             if (self->GetOpenCommand(&str, wxFileType::MessageParameters(filename, mimetype))) 
 
 235                 return wx2PyString(str);
 
 242     // get the command to print the file of given type
 
 244         PyObject* GetPrintCommand(const wxString& filename,
 
 245                                   const wxString& mimetype=wxPyEmptyString) {
 
 247             if (self->GetPrintCommand(&str, wxFileType::MessageParameters(filename, mimetype))) 
 
 248                 return wx2PyString(str);
 
 255     // Get all commands defined for this file type
 
 257         PyObject* GetAllCommands(const wxString& filename,
 
 258                                  const wxString& mimetype=wxPyEmptyString) {
 
 260             wxArrayString commands;
 
 261             if (self->GetAllCommands(&verbs, &commands,
 
 262                                      wxFileType::MessageParameters(filename, mimetype))) {
 
 263                 wxPyBlock_t blocked = wxPyBeginBlockThreads();
 
 264                 PyObject* tuple = PyTuple_New(2);
 
 265                 PyTuple_SetItem(tuple, 0, wxArrayString2PyList_helper(verbs));
 
 266                 PyTuple_SetItem(tuple, 1, wxArrayString2PyList_helper(commands));
 
 267                 wxPyEndBlockThreads(blocked);
 
 276     // set an arbitrary command, ask confirmation if it already exists and
 
 277     // overwriteprompt is True
 
 278     bool SetCommand(const wxString& cmd, const wxString& verb,
 
 279                     bool overwriteprompt = true);
 
 281     bool SetDefaultIcon(const wxString& cmd = wxPyEmptyString, int index = 0);
 
 284     // remove the association for this filetype from the system MIME database:
 
 285     // notice that it will only work if the association is defined in the user
 
 286     // file/registry part, we will never modify the system-wide settings
 
 290         // expand a string in the format of GetOpenCommand (which may contain
 
 291         // '%s' and '%t' format specificators for the file name and mime type
 
 292         // and %{param} constructions).
 
 294         static wxString ExpandCommand(const wxString& command,
 
 295                                       const wxString& filename,
 
 296                                       const wxString& mimetype=wxPyEmptyString) {
 
 297             return wxFileType::ExpandCommand(command,
 
 298                                              wxFileType::MessageParameters(filename, mimetype));
 
 302     %property(AllCommands, GetAllCommands, doc="See `GetAllCommands`");
 
 303     %property(Description, GetDescription, doc="See `GetDescription`");
 
 304     %property(Extensions, GetExtensions, doc="See `GetExtensions`");
 
 305     %property(Icon, GetIcon, doc="See `GetIcon`");
 
 306     %property(IconInfo, GetIconInfo, doc="See `GetIconInfo`");
 
 307     %property(MimeType, GetMimeType, doc="See `GetMimeType`");
 
 308     %property(MimeTypes, GetMimeTypes, doc="See `GetMimeTypes`");
 
 309     %property(OpenCommand, GetOpenCommand, doc="See `GetOpenCommand`");
 
 310     %property(PrintCommand, GetPrintCommand, doc="See `GetPrintCommand`");
 
 315 //---------------------------------------------------------------------------
 
 317 wxMimeTypesManager* const wxTheMimeTypesManager;
 
 320 // wxMimeTypesManager: interface to system MIME database.
 
 322 // This class accesses the information about all known MIME types and allows
 
 323 // the application to retrieve information (including how to handle data of
 
 324 // given type) about them.
 
 325 class wxMimeTypesManager
 
 328     // static helper functions
 
 329     // -----------------------
 
 331         // check if the given MIME type is the same as the other one: the
 
 332         // second argument may contain wildcards ('*'), but not the first. If
 
 333         // the types are equal or if the mimeType matches wildcard the function
 
 334         // returns True, otherwise it returns False
 
 335     static bool IsOfType(const wxString& mimeType, const wxString& wildcard);
 
 338     wxMimeTypesManager();
 
 340     // loads data from standard files according to the mailcap styles
 
 341     // specified: this is a bitwise OR of wxMailcapStyle values
 
 343     // use the extraDir parameter if you want to look for files in another
 
 345     void Initialize(int mailcapStyle = wxMAILCAP_ALL,
 
 346                     const wxString& extraDir = wxPyEmptyString);
 
 348     // and this function clears all the data from the manager
 
 351     // Database lookup: all functions return a pointer to wxFileType object
 
 352     // whose methods may be used to query it for the information you're
 
 353     // interested in. If the return value is !NULL, caller is responsible for
 
 355     // get file type from file extension
 
 356     %newobject GetFileTypeFromExtension;
 
 357     wxFileType *GetFileTypeFromExtension(const wxString& ext);
 
 359     // get file type from MIME type (in format <category>/<format>)
 
 360     %newobject GetFileTypeFromMimeType;
 
 361     wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
 
 363     // other operations: return True if there were no errors or False if there
 
 364     // were some unrecognized entries (the good entries are always read anyhow)
 
 367     // read in additional file (the standard ones are read automatically)
 
 368     // in mailcap format (see mimetype.cpp for description)
 
 370     // 'fallback' parameter may be set to True to avoid overriding the
 
 371     // settings from other, previously parsed, files by this one: normally,
 
 372     // the files read most recently would override the older files, but with
 
 373     // fallback == True this won't happen
 
 374     bool ReadMailcap(const wxString& filename, bool fallback = false);
 
 376     // read in additional file in mime.types format
 
 377     bool ReadMimeTypes(const wxString& filename);
 
 379     // enumerate all known MIME types
 
 381         PyObject* EnumAllFileTypes() {
 
 383             self->EnumAllFileTypes(arr);
 
 384             return wxArrayString2PyList_helper(arr);
 
 388     // these functions can be used to provide default values for some of the
 
 389     // MIME types inside the program itself (you may also use
 
 390     // ReadMailcap(filenameWithDefaultTypes, True /* use as fallback */) to
 
 391     // achieve the same goal, but this requires having this info in a file).
 
 393     void AddFallback(const wxFileTypeInfo& ft);
 
 396     // create or remove associations
 
 398     // create a new association using the fields of wxFileTypeInfo (at least
 
 399     // the MIME type and the extension should be set)
 
 400     // if the other fields are empty, the existing values should be left alone
 
 401     %newobject Associate;
 
 402     wxFileType *Associate(const wxFileTypeInfo& ftInfo);
 
 405     bool Unassociate(wxFileType *ft) ;
 
 407     ~wxMimeTypesManager();
 
 410 //---------------------------------------------------------------------------
 
 412 //---------------------------------------------------------------------------
 
 413 //---------------------------------------------------------------------------