git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54734
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
class wxMimeTextFile
{
public:
class wxMimeTextFile
{
public:
wxMimeTextFile(const wxString& fname)
{
m_fname = fname;
}
wxMimeTextFile(const wxString& fname)
{
m_fname = fname;
}
bool Open()
{
wxFFile file( m_fname );
if (!file.IsOpened())
return false;
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 );
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 );
// Check for valid UTF-8 here?
wxString all = wxString::FromUTF8( buffer, size );
wxStringTokenizer tok( all, "\n" );
while (tok.HasMoreTokens())
{
wxStringTokenizer tok( all, "\n" );
while (tok.HasMoreTokens())
{
unsigned int GetLineCount() const { return m_text.GetCount(); }
wxString &GetLine( unsigned int line ) { return m_text[line]; }
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;
}
wxString sTmp = GetLine(i).AfterFirst(wxT('='));
return sTmp;
}
private:
wxArrayString m_text;
wxString m_fname;
private:
wxArrayString m_text;
wxString m_fname;
wxMimeTextFile file(filename);
if ( !file.Open() )
return;
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")
// Here, only type 'Application' should be considered.
int nIndex = file.pIndexOf( "Type=" );
if (nIndex != wxNOT_FOUND && file.GetCmd(nIndex) != "application")
cont = dir.GetNext(&filename);
}
cont = dir.GetNext(&filename);
}
// RR: I'm not sure this makes any sense. On my system we'll just
// scan the YAST2 and other useless directories
// 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)
// Look recursively into subdirs
cont = dir.GetFirst(&filename, wxEmptyString, wxDIR_DIRS);
while (cont)
void wxMimeTypesManagerImpl::LoadXDGGlobs(const wxString& filename)
{
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);
wxLogTrace(TRACE_MIME, wxT("loading XDG globs file from %s"), filename.c_str());
wxMimeTextFile file(filename);
ext.Remove( 0, 2 );
wxArrayString exts;
exts.Add( ext );
ext.Remove( 0, 2 );
wxArrayString exts;
exts.Add( ext );
AddToMimeData(mime, wxEmptyString, NULL, exts, wxEmptyString, true );
}
}
AddToMimeData(mime, wxEmptyString, NULL, exts, wxEmptyString, true );
}
}
{
// set the flag first to prevent recursion
m_initialized = true;
{
// set the flag first to prevent recursion
m_initialized = true;
wxString wm = wxTheApp->GetTraits()->GetDesktopEnvironment();
wxString wm = wxTheApp->GetTraits()->GetDesktopEnvironment();
if (wm == wxT("KDE"))
Initialize( wxMAILCAP_KDE );
else if (wm == wxT("GNOME"))
if (wm == wxT("KDE"))
Initialize( wxMAILCAP_KDE );
else if (wm == wxT("GNOME"))
xdgDataDirs += ':';
xdgDataDirs += sExtraDir;
}
xdgDataDirs += ':';
xdgDataDirs += sExtraDir;
}
wxArrayString dirs;
wxStringTokenizer tokenizer(xdgDataDirs, ":");
while ( tokenizer.HasMoreTokens() )
wxArrayString dirs;
wxStringTokenizer tokenizer(xdgDataDirs, ":");
while ( tokenizer.HasMoreTokens() )
{
wxString mimeType = textfile.GetVerb(i);
wxString desktopFile = textfile.GetCmd(i);
{
wxString mimeType = textfile.GetVerb(i);
wxString desktopFile = textfile.GetCmd(i);
if (deskTopFilesSeen.Index(desktopFile) == wxNOT_FOUND)
{
deskTopFilesSeen.Add(desktopFile);
if (deskTopFilesSeen.Index(desktopFile) == wxNOT_FOUND)
{
deskTopFilesSeen.Add(desktopFile);
if (desktopPath.Last() != '/') desktopPath += '/';
desktopPath += "applications/";
desktopPath += desktopFile;
if (desktopPath.Last() != '/') desktopPath += '/';
desktopPath += "applications/";
desktopPath += desktopFile;
if (wxFileExists(desktopPath))
LoadXDGApp(desktopPath);
}
if (wxFileExists(desktopPath))
LoadXDGApp(desktopPath);
}
// first look for an exact match
int index = m_aTypes.Index(mimetype);
// first look for an exact match
int index = m_aTypes.Index(mimetype);
if ( index != wxNOT_FOUND )
{
fileType = new wxFileType;
if ( index != wxNOT_FOUND )
{
fileType = new wxFileType;