X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7dc3cc31af71522b8fc55b7f97bcba7f5ef9eac5..d608dde1d73fdbacbe05ddf81c252da945c2e71a:/include/wx/unix/mimetype.h diff --git a/include/wx/unix/mimetype.h b/include/wx/unix/mimetype.h index 2677c1ffe7..28407b23b6 100644 --- a/include/wx/unix/mimetype.h +++ b/include/wx/unix/mimetype.h @@ -30,12 +30,13 @@ WX_DEFINE_ARRAY(MailCapEntry *, ArrayTypeEntries); // this is the real wxMimeTypesManager for Unix class WXDLLEXPORT wxMimeTypesManagerImpl { -friend class WXDLLEXPORT wxFileTypeImpl; // give it access to m_aXXX variables - public: - // ctor loads all info into memory for quicker access later on - // TODO it would be nice to load them all, but parse on demand only... + // ctor and dtor wxMimeTypesManagerImpl(); + ~wxMimeTypesManagerImpl(); + + // load all data into memory - done when it is needed for the first time + void Initialize(); // implement containing class functions wxFileType *GetFileTypeFromExtension(const wxString& ext); @@ -58,6 +59,9 @@ public: const wxString& strTest, const wxString& strDesc); + // add a new record to the user .mailcap/.mime.types files + wxFileType *Associate(const wxFileTypeInfo& ftInfo); + // accessors // get the string containing space separated extensions for the given // file type @@ -67,29 +71,47 @@ public: static ArrayIconHandlers& GetIconHandlers(); private: + void InitIfNeeded() + { + if ( !m_initialized ) { + // set the flag first to prevent recursion + m_initialized = TRUE; + Initialize(); + } + } + wxArrayString m_aTypes, // MIME types m_aDescriptions, // descriptions (just some text) m_aExtensions; // space separated list of extensions ArrayTypeEntries m_aEntries; // commands and tests for this file type + // are we initialized? + bool m_initialized; + // head of the linked list of the icon handlers static ArrayIconHandlers ms_iconHandlers; + + // give it access to m_aXXX variables + friend class WXDLLEXPORT wxFileTypeImpl; }; + + class WXDLLEXPORT wxFileTypeImpl { public: // initialization functions void Init(wxMimeTypesManagerImpl *manager, size_t index) - { m_manager = manager; m_index = index; } + { m_manager = manager; m_index.Add(index); } // accessors bool GetExtensions(wxArrayString& extensions); bool GetMimeType(wxString *mimeType) const - { *mimeType = m_manager->m_aTypes[m_index]; return TRUE; } + { *mimeType = m_manager->m_aTypes[m_index[0]]; return TRUE; } + bool GetMimeTypes(wxArrayString& mimeTypes) const; bool GetIcon(wxIcon *icon) const; bool GetDescription(wxString *desc) const - { *desc = m_manager->m_aDescriptions[m_index]; return TRUE; } + { *desc = m_manager->m_aDescriptions[m_index[0]]; return TRUE; } bool GetOpenCommand(wxString *openCmd, const wxFileType::MessageParameters& params) const @@ -103,6 +125,9 @@ public: return GetExpandedCommand(printCmd, params, FALSE); } + // remove the record for this file type + bool Unassociate(); + private: // get the entry which passes the test (may return NULL) MailCapEntry *GetEntry(const wxFileType::MessageParameters& params) const; @@ -113,11 +138,9 @@ private: bool open) const; wxMimeTypesManagerImpl *m_manager; - size_t m_index; // in the wxMimeTypesManagerImpl arrays + wxArrayInt m_index; // in the wxMimeTypesManagerImpl arrays }; - - #endif // wxUSE_FILE