1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/unix/mimetype.cpp
3 // Purpose: classes and functions to manage MIME types
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence (part of wxExtra library)
10 /////////////////////////////////////////////////////////////////////////////
12 // for compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
19 #if wxUSE_MIMETYPE && wxUSE_FILE && wxUSE_TEXTFILE
21 #include "wx/unix/mimetype.h"
24 #include "wx/dynarray.h"
25 #include "wx/string.h"
32 #include "wx/confbase.h"
35 #include "wx/textfile.h"
37 #include "wx/tokenzr.h"
38 #include "wx/iconloc.h"
39 #include "wx/filename.h"
41 #include "wx/apptrait.h"
43 // other standard headers
53 wxMimeTextFile(const wxString
& fname
)
60 wxFFile
file( m_fname
);
64 size_t size
= file
.Length();
65 wxCharBuffer
buffer( size
);
66 file
.Read( (void*) (const char*) buffer
, size
);
68 // Check for valid UTF-8 here?
69 wxString all
= wxString::FromUTF8( buffer
, size
);
71 wxStringTokenizer
tok( all
, "\n" );
72 while (tok
.HasMoreTokens())
74 wxString t
= tok
.GetNextToken();
76 if ((!!t
) && (t
.Find( "comment" ) != 0) && (t
.Find( "generic" ) != 0))
82 unsigned int GetLineCount() const { return m_text
.GetCount(); }
83 wxString
&GetLine( unsigned int line
) { return m_text
[line
]; }
85 int pIndexOf(const wxString
& sSearch
,
86 bool bIncludeComments
= false,
89 wxString sTest
= sSearch
;
91 for(size_t i
= iStart
; i
< GetLineCount(); i
++)
93 wxString sLine
= GetLine(i
);
94 if(bIncludeComments
|| ! sLine
.StartsWith(wxT("#")))
96 if(sLine
.StartsWith(sTest
))
103 wxString
GetVerb(size_t i
)
105 if (i
> GetLineCount() )
106 return wxEmptyString
;
108 wxString sTmp
= GetLine(i
).BeforeFirst(wxT('='));
112 wxString
GetCmd(size_t i
)
114 if (i
> GetLineCount() )
115 return wxEmptyString
;
117 wxString sTmp
= GetLine(i
).AfterFirst(wxT('='));
122 wxArrayString m_text
;
126 // ----------------------------------------------------------------------------
128 // ----------------------------------------------------------------------------
130 // MIME code tracing mask
131 #define TRACE_MIME wxT("mime")
134 // Read a XDG *.desktop file of type 'Application'
135 void wxMimeTypesManagerImpl::LoadXDGApp(const wxString
& filename
)
137 wxLogTrace(TRACE_MIME
, wxT("loading XDG file %s"), filename
.c_str());
139 wxMimeTextFile
file(filename
);
143 // Here, only type 'Application' should be considered.
144 int nIndex
= file
.pIndexOf( "Type=" );
145 if (nIndex
!= wxNOT_FOUND
&& file
.GetCmd(nIndex
) != "application")
148 // The hidden entry specifies a file to be ignored.
149 nIndex
= file
.pIndexOf( "Hidden=" );
150 if (nIndex
!= wxNOT_FOUND
&& file
.GetCmd(nIndex
) == "true")
153 // Semicolon separated list of mime types handled by the application.
154 nIndex
= file
.pIndexOf( wxT("MimeType=") );
155 if (nIndex
== wxNOT_FOUND
)
157 wxString mimetypes
= file
.GetCmd (nIndex
);
159 // Name of the application
161 nIndex
= wxNOT_FOUND
;
162 #if wxUSE_INTL // try "Name[locale name]" first
163 wxLocale
*locale
= wxGetLocale();
165 nIndex
= file
.pIndexOf(_T("Name[")+locale
->GetName()+_T("]="));
167 if(nIndex
== wxNOT_FOUND
)
168 nIndex
= file
.pIndexOf( wxT("Name=") );
169 if(nIndex
!= wxNOT_FOUND
)
170 nameapp
= file
.GetCmd(nIndex
);
172 // Icon of the application.
173 wxString nameicon
, namemini
;
174 nIndex
= wxNOT_FOUND
;
175 #if wxUSE_INTL // try "Icon[locale name]" first
177 nIndex
= file
.pIndexOf(_T("Icon[")+locale
->GetName()+_T("]="));
179 if(nIndex
== wxNOT_FOUND
)
180 nIndex
= file
.pIndexOf( wxT("Icon=") );
181 if(nIndex
!= wxNOT_FOUND
) {
182 nameicon
= wxString(wxT("--icon ")) + file
.GetCmd(nIndex
);
183 namemini
= wxString(wxT("--miniicon ")) + file
.GetCmd(nIndex
);
186 // Replace some of the field code in the 'Exec' entry.
187 // TODO: deal with %d, %D, %n, %N, %k and %v (but last one is deprecated)
188 nIndex
= file
.pIndexOf( wxT("Exec=") );
189 if (nIndex
== wxNOT_FOUND
)
191 wxString sCmd
= file
.GetCmd(nIndex
);
192 // we expect %f; others including %F and %U and %u are possible
193 sCmd
.Replace(wxT("%F"), wxT("%f"));
194 sCmd
.Replace(wxT("%U"), wxT("%f"));
195 sCmd
.Replace(wxT("%u"), wxT("%f"));
196 if (0 == sCmd
.Replace ( wxT("%f"), wxT("%s") ))
197 sCmd
= sCmd
+ wxT(" %s");
198 sCmd
.Replace(wxT("%c"), nameapp
);
199 sCmd
.Replace(wxT("%i"), nameicon
);
200 sCmd
.Replace(wxT("%m"), namemini
);
202 wxStringTokenizer
tokenizer(mimetypes
, _T(";"));
203 while(tokenizer
.HasMoreTokens()) {
204 wxString mimetype
= tokenizer
.GetNextToken().Lower();
205 nIndex
= m_aTypes
.Index(mimetype
);
206 if(nIndex
!= wxNOT_FOUND
) { // is this a known MIME type?
207 wxMimeTypeCommands
* entry
= m_aEntries
[nIndex
];
208 entry
->AddOrReplaceVerb(wxT("open"), sCmd
);
213 void wxMimeTypesManagerImpl::LoadXDGAppsFilesFromDir(const wxString
& dirname
)
215 // Don't complain if we don't have permissions to read - it confuses users
218 if(! wxDir::Exists(dirname
))
221 if ( !dir
.IsOpened() )
225 // Look into .desktop files
226 bool cont
= dir
.GetFirst(&filename
, _T("*.desktop"), wxDIR_FILES
);
229 wxFileName
p(dirname
, filename
);
230 LoadXDGApp( p
.GetFullPath() );
231 cont
= dir
.GetNext(&filename
);
235 // RR: I'm not sure this makes any sense. On my system we'll just
236 // scan the YAST2 and other useless directories
238 // Look recursively into subdirs
239 cont
= dir
.GetFirst(&filename
, wxEmptyString
, wxDIR_DIRS
);
242 wxFileName
p(dirname
, wxEmptyString
);
243 p
.AppendDir(filename
);
244 LoadXDGAppsFilesFromDir( p
.GetPath() );
245 cont
= dir
.GetNext(&filename
);
251 // ----------------------------------------------------------------------------
252 // wxFileTypeImpl (Unix)
253 // ----------------------------------------------------------------------------
255 wxString
wxFileTypeImpl::GetExpandedCommand(const wxString
& verb
, const wxFileType::MessageParameters
& params
) const
259 while ( (i
< m_index
.GetCount() ) && sTmp
.empty() )
261 sTmp
= m_manager
->GetCommand( verb
, m_index
[i
] );
265 return wxFileType::ExpandCommand(sTmp
, params
);
268 bool wxFileTypeImpl::GetIcon(wxIconLocation
*iconLoc
) const
272 while ( (i
< m_index
.GetCount() ) && sTmp
.empty() )
274 sTmp
= m_manager
->m_aIcons
[m_index
[i
]];
283 iconLoc
->SetFileName(sTmp
);
289 bool wxFileTypeImpl::GetMimeTypes(wxArrayString
& mimeTypes
) const
292 size_t nCount
= m_index
.GetCount();
293 for (size_t i
= 0; i
< nCount
; i
++)
294 mimeTypes
.Add(m_manager
->m_aTypes
[m_index
[i
]]);
299 size_t wxFileTypeImpl::GetAllCommands(wxArrayString
*verbs
,
300 wxArrayString
*commands
,
301 const wxFileType::MessageParameters
& params
) const
303 wxString vrb
, cmd
, sTmp
;
305 wxMimeTypeCommands
* sPairs
;
307 // verbs and commands have been cleared already in mimecmn.cpp...
308 // if we find no entries in the exact match, try the inexact match
309 for (size_t n
= 0; ((count
== 0) && (n
< m_index
.GetCount())); n
++)
311 // list of verb = command pairs for this mimetype
312 sPairs
= m_manager
->m_aEntries
[m_index
[n
]];
314 for ( i
= 0; i
< sPairs
->GetCount(); i
++ )
316 vrb
= sPairs
->GetVerb(i
);
317 // some gnome entries have "." inside
318 vrb
= vrb
.AfterLast(wxT('.'));
319 cmd
= sPairs
->GetCmd(i
);
322 cmd
= wxFileType::ExpandCommand(cmd
, params
);
324 if ( vrb
.IsSameAs(wxT("open")))
327 verbs
->Insert(vrb
, 0u);
329 commands
->Insert(cmd
, 0u);
345 bool wxFileTypeImpl::GetExtensions(wxArrayString
& extensions
)
347 const wxString strExtensions
= m_manager
->GetExtension(m_index
[0]);
350 // one extension in the space or comma-delimited list
352 wxString::const_iterator end
= strExtensions
.end();
353 for ( wxString::const_iterator p
= strExtensions
.begin(); /* nothing */; ++p
)
355 if ( p
== end
|| *p
== wxT(' ') || *p
== wxT(',') )
357 if ( !strExt
.empty() )
359 extensions
.Add(strExt
);
362 //else: repeated spaces
363 // (shouldn't happen, but it's not that important if it does happen)
368 else if ( *p
== wxT('.') )
370 // remove the dot from extension (but only if it's the first char)
371 if ( !strExt
.empty() )
375 //else: no, don't append it
386 // set an arbitrary command:
387 // could adjust the code to ask confirmation if it already exists and
388 // overwriteprompt is true, but this is currently ignored as *Associate* has
389 // no overwrite prompt
391 wxFileTypeImpl::SetCommand(const wxString
& cmd
,
392 const wxString
& verb
,
393 bool WXUNUSED(overwriteprompt
))
395 wxArrayString strExtensions
;
396 wxString strDesc
, strIcon
;
398 wxArrayString strTypes
;
399 GetMimeTypes(strTypes
);
400 if ( strTypes
.IsEmpty() )
403 wxMimeTypeCommands
*entry
= new wxMimeTypeCommands();
404 entry
->Add(verb
+ wxT("=") + cmd
+ wxT(" %s "));
407 size_t nCount
= strTypes
.GetCount();
408 for ( size_t i
= 0; i
< nCount
; i
++ )
410 if ( m_manager
->DoAssociation
419 // DoAssociation() took ownership of entry, don't delete it below
430 // ignore index on the grounds that we only have one icon in a Unix file
431 bool wxFileTypeImpl::SetDefaultIcon(const wxString
& strIcon
, int WXUNUSED(index
))
436 wxArrayString strExtensions
;
439 wxArrayString strTypes
;
440 GetMimeTypes(strTypes
);
441 if ( strTypes
.IsEmpty() )
444 wxMimeTypeCommands
*entry
= new wxMimeTypeCommands();
446 size_t nCount
= strTypes
.GetCount();
447 for ( size_t i
= 0; i
< nCount
; i
++ )
449 if ( m_manager
->DoAssociation
458 // we don't need to free entry now, DoAssociation() took ownership
470 // ----------------------------------------------------------------------------
471 // wxMimeTypesManagerImpl (Unix)
472 // ----------------------------------------------------------------------------
474 wxMimeTypesManagerImpl::wxMimeTypesManagerImpl()
476 m_initialized
= false;
479 void wxMimeTypesManagerImpl::InitIfNeeded()
481 if ( !m_initialized
)
483 // set the flag first to prevent recursion
484 m_initialized
= true;
486 wxString wm
= wxTheApp
->GetTraits()->GetDesktopEnvironment();
488 if (wm
== wxT("KDE"))
489 Initialize( wxMAILCAP_KDE
);
490 else if (wm
== wxT("GNOME"))
491 Initialize( wxMAILCAP_GNOME
);
497 // read system and user mailcaps and other files
498 void wxMimeTypesManagerImpl::Initialize(int mailcapStyles
,
499 const wxString
& sExtraDir
)
502 // XDG tables are never installed on OpenVMS
506 // Load desktop files for Gnome, and then override them with the Gnome defaults.
507 // We will override them one desktop file at a time, rather
508 // than one mime type at a time, but it should be a reasonable
511 wxString xdgDataHome
= wxGetenv("XDG_DATA_HOME");
512 if ( xdgDataHome
.empty() )
513 xdgDataHome
= wxGetHomeDir() + "/.local/share";
514 wxString xdgDataDirs
= wxGetenv("XDG_DATA_DIRS");
515 if ( xdgDataDirs
.empty() )
517 xdgDataDirs
= "/usr/local/share:/usr/share";
518 if (mailcapStyles
& wxMAILCAP_GNOME
)
519 xdgDataDirs
+= ":/usr/share/gnome:/opt/gnome/share";
520 if (mailcapStyles
& wxMAILCAP_KDE
)
521 xdgDataDirs
+= ":/usr/share/kde3:/opt/kde3/share";
523 if ( !sExtraDir
.empty() )
526 xdgDataDirs
+= sExtraDir
;
530 wxStringTokenizer
tokenizer(xdgDataDirs
, ":");
531 while ( tokenizer
.HasMoreTokens() )
533 wxString p
= tokenizer
.GetNextToken();
536 dirs
.insert(dirs
.begin(), xdgDataHome
);
538 wxString defaultsList
;
540 for (i
= 0; i
< dirs
.GetCount(); i
++)
542 wxString f
= dirs
[i
];
543 if (f
.Last() != '/') f
+= '/';
544 f
+= "applications/defaults.list";
552 // Load application files and associate them to corresponding mime types.
553 size_t nDirs
= dirs
.GetCount();
554 for (size_t nDir
= 0; nDir
< nDirs
; nDir
++)
556 wxString dirStr
= dirs
[nDir
];
557 if (dirStr
.Last() != '/') dirStr
+= '/';
558 dirStr
+= "applications";
559 LoadXDGAppsFilesFromDir(dirStr
);
562 if (!defaultsList
.IsEmpty())
564 wxArrayString deskTopFilesSeen
;
566 wxMimeTextFile
textfile(defaultsList
);
567 if ( textfile
.Open() )
569 int nIndex
= textfile
.pIndexOf( wxT("[Default Applications]") );
570 if (nIndex
!= wxNOT_FOUND
)
572 for (i
= nIndex
+1; i
< textfile
.GetLineCount(); i
++)
574 if (textfile
.GetLine(i
).Find(wxT("=")) != wxNOT_FOUND
)
576 wxString mimeType
= textfile
.GetVerb(i
);
577 wxString desktopFile
= textfile
.GetCmd(i
);
579 if (deskTopFilesSeen
.Index(desktopFile
) == wxNOT_FOUND
)
581 deskTopFilesSeen
.Add(desktopFile
);
583 for (j
= 0; j
< dirs
.GetCount(); j
++)
585 wxString desktopPath
= dirs
[j
];
586 if (desktopPath
.Last() != '/') desktopPath
+= '/';
587 desktopPath
+= "applications/";
588 desktopPath
+= desktopFile
;
590 if (wxFileExists(desktopPath
))
591 LoadXDGApp(desktopPath
);
602 // clear data so you can read another group of WM files
603 void wxMimeTypesManagerImpl::ClearData()
607 m_aExtensions
.Clear();
608 m_aDescriptions
.Clear();
610 WX_CLEAR_ARRAY(m_aEntries
);
614 wxMimeTypesManagerImpl::~wxMimeTypesManagerImpl()
619 wxFileType
* wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo
& ftInfo
)
623 wxString strType
= ftInfo
.GetMimeType();
624 wxString strDesc
= ftInfo
.GetDescription();
625 wxString strIcon
= ftInfo
.GetIconFile();
627 wxMimeTypeCommands
*entry
= new wxMimeTypeCommands();
629 if ( ! ftInfo
.GetOpenCommand().empty())
630 entry
->Add(wxT("open=") + ftInfo
.GetOpenCommand() + wxT(" %s "));
631 if ( ! ftInfo
.GetPrintCommand().empty())
632 entry
->Add(wxT("print=") + ftInfo
.GetPrintCommand() + wxT(" %s "));
634 // now find where these extensions are in the data store and remove them
635 wxArrayString sA_Exts
= ftInfo
.GetExtensions();
636 wxString sExt
, sExtStore
;
638 size_t nExtCount
= sA_Exts
.GetCount();
639 for (i
=0; i
< nExtCount
; i
++)
641 sExt
= sA_Exts
.Item(i
);
643 // clean up to just a space before and after
644 sExt
.Trim().Trim(false);
645 sExt
= wxT(' ') + sExt
+ wxT(' ');
646 size_t nCount
= m_aExtensions
.GetCount();
647 for (nIndex
= 0; nIndex
< nCount
; nIndex
++)
649 sExtStore
= m_aExtensions
.Item(nIndex
);
650 if (sExtStore
.Replace(sExt
, wxT(" ") ) > 0)
651 m_aExtensions
.Item(nIndex
) = sExtStore
;
655 if ( !DoAssociation(strType
, strIcon
, entry
, sA_Exts
, strDesc
) )
658 return GetFileTypeFromMimeType(strType
);
661 bool wxMimeTypesManagerImpl::DoAssociation(const wxString
& strType
,
662 const wxString
& strIcon
,
663 wxMimeTypeCommands
*entry
,
664 const wxArrayString
& strExtensions
,
665 const wxString
& strDesc
)
667 int nIndex
= AddToMimeData(strType
, strIcon
, entry
, strExtensions
, strDesc
, true);
669 if ( nIndex
== wxNOT_FOUND
)
675 int wxMimeTypesManagerImpl::AddToMimeData(const wxString
& strType
,
676 const wxString
& strIcon
,
677 wxMimeTypeCommands
*entry
,
678 const wxArrayString
& strExtensions
,
679 const wxString
& strDesc
,
680 bool replaceExisting
)
684 // ensure mimetype is always lower case
685 wxString mimeType
= strType
.Lower();
687 // is this a known MIME type?
688 int nIndex
= m_aTypes
.Index(mimeType
);
689 if ( nIndex
== wxNOT_FOUND
)
692 m_aTypes
.Add(mimeType
);
693 m_aIcons
.Add(strIcon
);
694 m_aEntries
.Add(entry
? entry
: new wxMimeTypeCommands
);
696 // change nIndex so we can use it below to add the extensions
697 m_aExtensions
.Add(wxEmptyString
);
698 nIndex
= m_aExtensions
.size() - 1;
700 m_aDescriptions
.Add(strDesc
);
702 else // yes, we already have it
704 if ( replaceExisting
)
706 // if new description change it
707 if ( !strDesc
.empty())
708 m_aDescriptions
[nIndex
] = strDesc
;
710 // if new icon change it
711 if ( !strIcon
.empty())
712 m_aIcons
[nIndex
] = strIcon
;
716 delete m_aEntries
[nIndex
];
717 m_aEntries
[nIndex
] = entry
;
720 else // add data we don't already have ...
722 // if new description add only if none
723 if ( m_aDescriptions
[nIndex
].empty() )
724 m_aDescriptions
[nIndex
] = strDesc
;
726 // if new icon and no existing icon
727 if ( m_aIcons
[nIndex
].empty() )
728 m_aIcons
[nIndex
] = strIcon
;
730 // add any new entries...
733 wxMimeTypeCommands
*entryOld
= m_aEntries
[nIndex
];
735 size_t count
= entry
->GetCount();
736 for ( size_t i
= 0; i
< count
; i
++ )
738 const wxString
& verb
= entry
->GetVerb(i
);
739 if ( !entryOld
->HasVerb(verb
) )
741 entryOld
->AddOrReplaceVerb(verb
, entry
->GetCmd(i
));
745 // as we don't store it anywhere, it won't be deleted later as
746 // usual -- do it immediately instead
752 // always add the extensions to this mimetype
753 wxString
& exts
= m_aExtensions
[nIndex
];
755 // add all extensions we don't have yet
757 size_t count
= strExtensions
.GetCount();
758 for ( size_t i
= 0; i
< count
; i
++ )
760 ext
= strExtensions
[i
];
763 if ( exts
.Find(ext
) == wxNOT_FOUND
)
769 // check data integrity
770 wxASSERT( m_aTypes
.GetCount() == m_aEntries
.GetCount() &&
771 m_aTypes
.GetCount() == m_aExtensions
.GetCount() &&
772 m_aTypes
.GetCount() == m_aIcons
.GetCount() &&
773 m_aTypes
.GetCount() == m_aDescriptions
.GetCount() );
778 wxFileType
* wxMimeTypesManagerImpl::GetFileTypeFromExtension(const wxString
& ext
)
785 size_t count
= m_aExtensions
.GetCount();
786 for ( size_t n
= 0; n
< count
; n
++ )
788 wxStringTokenizer
tk(m_aExtensions
[n
], wxT(' '));
790 while ( tk
.HasMoreTokens() )
792 // consider extensions as not being case-sensitive
793 if ( tk
.GetNextToken().IsSameAs(ext
, false /* no case */) )
796 wxFileType
*fileType
= new wxFileType
;
797 fileType
->m_impl
->Init(this, n
);
807 wxFileType
* wxMimeTypesManagerImpl::GetFileTypeFromMimeType(const wxString
& mimeType
)
811 wxFileType
* fileType
= NULL
;
812 // mime types are not case-sensitive
813 wxString
mimetype(mimeType
);
814 mimetype
.MakeLower();
816 // first look for an exact match
817 int index
= m_aTypes
.Index(mimetype
);
818 if ( index
!= wxNOT_FOUND
)
820 fileType
= new wxFileType
;
821 fileType
->m_impl
->Init(this, index
);
824 // then try to find "text/*" as match for "text/plain" (for example)
825 // NB: if mimeType doesn't contain '/' at all, BeforeFirst() will return
826 // the whole string - ok.
829 wxString strCategory
= mimetype
.BeforeFirst(wxT('/'));
831 size_t nCount
= m_aTypes
.GetCount();
832 for ( size_t n
= 0; n
< nCount
; n
++ )
834 if ( (m_aTypes
[n
].BeforeFirst(wxT('/')) == strCategory
) &&
835 m_aTypes
[n
].AfterFirst(wxT('/')) == wxT("*") )
842 if ( index
!= wxNOT_FOUND
)
844 // don't throw away fileType that was already found
846 fileType
= new wxFileType
;
847 fileType
->m_impl
->Init(this, index
);
853 wxString
wxMimeTypesManagerImpl::GetCommand(const wxString
& verb
, size_t nIndex
) const
855 wxString command
, testcmd
, sV
, sTmp
;
856 sV
= verb
+ wxT("=");
858 // list of verb = command pairs for this mimetype
859 wxMimeTypeCommands
* sPairs
= m_aEntries
[nIndex
];
862 size_t nCount
= sPairs
->GetCount();
863 for ( i
= 0; i
< nCount
; i
++ )
865 sTmp
= sPairs
->GetVerbCmd (i
);
866 if ( sTmp
.Contains(sV
) )
867 command
= sTmp
.AfterFirst(wxT('='));
873 void wxMimeTypesManagerImpl::AddFallback(const wxFileTypeInfo
& filetype
)
878 const wxArrayString
& exts
= filetype
.GetExtensions();
879 size_t nExts
= exts
.GetCount();
880 for ( size_t nExt
= 0; nExt
< nExts
; nExt
++ )
883 extensions
+= wxT(' ');
885 extensions
+= exts
[nExt
];
888 AddMimeTypeInfo(filetype
.GetMimeType(),
890 filetype
.GetDescription());
893 void wxMimeTypesManagerImpl::AddMimeTypeInfo(const wxString
& strMimeType
,
894 const wxString
& strExtensions
,
895 const wxString
& strDesc
)
897 // reading mailcap may find image/* , while
898 // reading mime.types finds image/gif and no match is made
899 // this means all the get functions don't work fix this
901 wxString sTmp
= strExtensions
;
904 sTmp
.Trim().Trim(false);
906 while (!sTmp
.empty())
908 sExts
.Add(sTmp
.AfterLast(wxT(' ')));
909 sTmp
= sTmp
.BeforeLast(wxT(' '));
912 AddToMimeData(strMimeType
, strIcon
, NULL
, sExts
, strDesc
, true);
915 size_t wxMimeTypesManagerImpl::EnumAllFileTypes(wxArrayString
& mimetypes
)
921 size_t count
= m_aTypes
.GetCount();
922 for ( size_t n
= 0; n
< count
; n
++ )
924 // don't return template types from here (i.e. anything containg '*')
925 const wxString
&type
= m_aTypes
[n
];
926 if ( type
.Find(wxT('*')) == wxNOT_FOUND
)
932 return mimetypes
.GetCount();
935 // ----------------------------------------------------------------------------
936 // writing to MIME type files
937 // ----------------------------------------------------------------------------
939 bool wxMimeTypesManagerImpl::Unassociate(wxFileType
*ft
)
943 wxArrayString sMimeTypes
;
944 ft
->GetMimeTypes(sMimeTypes
);
947 size_t nCount
= sMimeTypes
.GetCount();
948 for (i
= 0; i
< nCount
; i
++)
950 const wxString
&sMime
= sMimeTypes
.Item(i
);
951 int nIndex
= m_aTypes
.Index(sMime
);
952 if ( nIndex
== wxNOT_FOUND
)
954 // error if we get here ??
959 m_aTypes
.RemoveAt(nIndex
);
960 m_aEntries
.RemoveAt(nIndex
);
961 m_aExtensions
.RemoveAt(nIndex
);
962 m_aDescriptions
.RemoveAt(nIndex
);
963 m_aIcons
.RemoveAt(nIndex
);
966 // check data integrity
967 wxASSERT( m_aTypes
.GetCount() == m_aEntries
.GetCount() &&
968 m_aTypes
.GetCount() == m_aExtensions
.GetCount() &&
969 m_aTypes
.GetCount() == m_aIcons
.GetCount() &&
970 m_aTypes
.GetCount() == m_aDescriptions
.GetCount() );
976 // wxUSE_MIMETYPE && wxUSE_FILE && wxUSE_TEXTFILE