class wxMimeTextFile
{
public:
- wxMimeTextFile()
+ wxMimeTextFile()
{
}
-
+
wxMimeTextFile(const wxString& fname)
{
m_fname = fname;
}
-
+
bool Open()
{
wxFFile file( m_fname );
if (!file.IsOpened())
return false;
-
+
size_t size = file.Length();
wxCharBuffer buffer( size );
file.Read( (void*) (const char*) buffer, size );
-
+
// Check for valid UTF-8 here?
wxString all = wxString::FromUTF8( buffer, size );
-
+
wxStringTokenizer tok( all, "\n" );
while (tok.HasMoreTokens())
{
}
return true;
}
-
+
unsigned int GetLineCount() const { return m_text.GetCount(); }
wxString &GetLine( unsigned int line ) { return m_text[line]; }
wxString sTmp = GetLine(i).AfterFirst(wxT('='));
return sTmp;
}
-
+
private:
wxArrayString m_text;
wxString m_fname;
wxMimeTextFile file(filename);
if ( !file.Open() )
return;
-
+
// Here, only type 'Application' should be considered.
int nIndex = file.pIndexOf( "Type=" );
if (nIndex != wxNOT_FOUND && file.GetCmd(nIndex) != "application")
cont = dir.GetNext(&filename);
}
-#if 0
+#if 0
// RR: I'm not sure this makes any sense. On my system we'll just
// scan the YAST2 and other useless directories
-
+
// Look recursively into subdirs
cont = dir.GetFirst(&filename, wxEmptyString, wxDIR_DIRS);
while (cont)
void wxMimeTypesManagerImpl::LoadXDGGlobs(const wxString& filename)
{
+ if ( !wxFileName::FileExists(filename) )
+ return;
+
wxLogTrace(TRACE_MIME, wxT("loading XDG globs file from %s"), filename.c_str());
wxMimeTextFile file(filename);
{
// set the flag first to prevent recursion
m_initialized = true;
-
+
wxString wm = wxTheApp->GetTraits()->GetDesktopEnvironment();
-
+
if (wm == wxT("KDE"))
Initialize( wxMAILCAP_KDE );
else if (wm == wxT("GNOME"))
#ifdef __VMS
// XDG tables are never installed on OpenVMS
return;
-#endif
+#else
// Read MIME type - extension associations
LoadXDGGlobs( "/usr/share/mime/globs" );
xdgDataDirs += ':';
xdgDataDirs += sExtraDir;
}
-
+
wxArrayString dirs;
wxStringTokenizer tokenizer(xdgDataDirs, ":");
while ( tokenizer.HasMoreTokens() )
{
if (textfile.GetLine(i).Find(wxT("=")) != wxNOT_FOUND)
{
- wxString mimeType = textfile.GetVerb(i);
wxString desktopFile = textfile.GetCmd(i);
-
+
if (deskTopFilesSeen.Index(desktopFile) == wxNOT_FOUND)
{
deskTopFilesSeen.Add(desktopFile);
if (desktopPath.Last() != '/') desktopPath += '/';
desktopPath += "applications/";
desktopPath += desktopFile;
-
+
if (wxFileExists(desktopPath))
LoadXDGApp(desktopPath);
}
}
}
}
+#endif
}
// clear data so you can read another group of WM files
int nIndex = m_aTypes.Index(mimeType);
if ( nIndex == wxNOT_FOUND )
{
- // new file type
- m_aTypes.Add(mimeType);
- m_aIcons.Add(strIcon);
- m_aEntries.Add(entry ? entry : new wxMimeTypeCommands);
+ // We put MIME types containing "application" at the end, so that
+ // if the MIME type for the extention "htm" is searched for, it will
+ // rather find "text/html" than "application/x-mozilla-bookmarks".
+ if (mimeType.Find( "application" ) == 0)
+ {
+ // new file type
+ m_aTypes.Add(mimeType);
+ m_aIcons.Add(strIcon);
+ m_aEntries.Add(entry ? entry : new wxMimeTypeCommands);
+
+ // change nIndex so we can use it below to add the extensions
+ m_aExtensions.Add(wxEmptyString);
+ nIndex = m_aExtensions.size() - 1;
- // change nIndex so we can use it below to add the extensions
- m_aExtensions.Add(wxEmptyString);
- nIndex = m_aExtensions.size() - 1;
+ m_aDescriptions.Add(strDesc);
+ }
+ else
+ {
+ // new file type
+ m_aTypes.Insert(mimeType,0);
+ m_aIcons.Insert(strIcon,0);
+ m_aEntries.Insert(entry ? entry : new wxMimeTypeCommands,0);
+
+ // change nIndex so we can use it below to add the extensions
+ m_aExtensions.Insert(wxEmptyString,0);
+ nIndex = 0;
- m_aDescriptions.Add(strDesc);
+ m_aDescriptions.Insert(strDesc,0);
+ }
}
else // yes, we already have it
{
// found
wxFileType *fileType = new wxFileType;
fileType->m_impl->Init(this, n);
-
+
return fileType;
}
}
// first look for an exact match
int index = m_aTypes.Index(mimetype);
-
+
if ( index != wxNOT_FOUND )
{
fileType = new wxFileType;