X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/678ebfcdaecdf8db7c5d8ba0bb71ca6f60b4d719..b1727cfef7e084b0ba52b69fbe948379d66981da:/src/unix/mimetype.cpp diff --git a/src/unix/mimetype.cpp b/src/unix/mimetype.cpp index faf0bd2d6c..e0bce49d8d 100644 --- a/src/unix/mimetype.cpp +++ b/src/unix/mimetype.cpp @@ -6,7 +6,7 @@ // Created: 23.09.98 // RCS-ID: $Id$ // Copyright: (c) 1998 Vadim Zeitlin -// Licence: wxWindows license (part of wxExtra library) +// Licence: wxWindows licence (part of wxExtra library) ///////////////////////////////////////////////////////////////////////////// // known bugs; there may be others!! chris elliott, biol75@york.ac.uk 27 Mar 01 @@ -40,10 +40,6 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ - #pragma implementation "mimetype.h" -#endif - // for compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -59,10 +55,6 @@ #ifndef WX_PRECOMP #include "wx/string.h" - #if wxUSE_GUI - #include "wx/icon.h" - - #endif #endif //WX_PRECOMP @@ -77,6 +69,8 @@ #include "wx/dir.h" #include "wx/utils.h" #include "wx/tokenzr.h" +#include "wx/iconloc.h" +#include "wx/filename.h" #include "wx/unix/mimetype.h" @@ -105,7 +99,7 @@ public: // add a new verb with the command or replace the old value void AddOrReplaceVerb(const wxString& verb, const wxString& cmd) { - int n = m_verbs.Index(verb, FALSE /* ignore case */); + int n = m_verbs.Index(verb, false /* ignore case */); if ( n == wxNOT_FOUND ) { m_verbs.Add(verb); @@ -167,7 +161,7 @@ public: wxMimeTextFile () : wxTextFile () {}; wxMimeTextFile (const wxString& strFile) : wxTextFile (strFile) { }; - int pIndexOf(const wxString & sSearch, bool bIncludeComments = FALSE, int iStart = 0) + int pIndexOf(const wxString & sSearch, bool bIncludeComments = false, int iStart = 0) { size_t i = iStart; int nResult = wxNOT_FOUND; @@ -205,19 +199,19 @@ public: bool CommentLine(int nIndex) { - if (nIndex <0) return FALSE; - if (nIndex >= (int)GetLineCount() ) return FALSE; + if (nIndex <0) return false; + if (nIndex >= (int)GetLineCount() ) return false; GetLine(nIndex) = GetLine(nIndex).Prepend(wxT("#")); - return TRUE; + return true; } bool CommentLine(const wxString & sTest) { int nIndex = pIndexOf(sTest); - if (nIndex <0) return FALSE; - if (nIndex >= (int)GetLineCount() ) return FALSE; + if (nIndex <0) return false; + if (nIndex >= (int)GetLineCount() ) return false; GetLine(nIndex) = GetLine(nIndex).Prepend(wxT("#")); - return TRUE; + return true; } wxString GetVerb (size_t i) @@ -364,25 +358,25 @@ bool wxMimeTypesManagerImpl::CheckGnomeDirsExist () wxString gnomedir; wxGetHomeDir( &gnomedir ); wxString sTmp = gnomedir; - sTmp = sTmp + "/.gnome"; + sTmp = sTmp + wxT("/.gnome"); if (! wxDir::Exists ( sTmp ) ) { if (!wxMkdir ( sTmp )) { - wxFAIL_MSG (wxString ("Failed to create directory\n.gnome in \nCheckGnomeDirsExist") + sTmp ); - return FALSE; + wxLogError(_("Failed to create directory %s/.gnome."), sTmp.c_str()); + return false; } } - sTmp = sTmp + "/mime-info"; + sTmp = sTmp + wxT("/mime-info"); if (! wxDir::Exists ( sTmp ) ) { if (!wxMkdir ( sTmp )) { - wxFAIL_MSG (wxString ("Failed to create directory\nmime-info in \nCheckGnomeDirsExist") + sTmp ); - return FALSE; + wxLogError(_("Failed to create directory %s/mime-info."), sTmp.c_str()); + return false; } } - return TRUE; + return true; } @@ -393,14 +387,18 @@ bool wxMimeTypesManagerImpl::WriteGnomeKeyFile(int index, bool delete_index) wxString gnomedir; wxGetHomeDir( &gnomedir ); - wxMimeTextFile outfile ( gnomedir + "/.gnome/mime-info/user.keys"); + wxMimeTextFile outfile ( gnomedir + wxT("/.gnome/mime-info/user.keys")); // if this fails probably Gnome is not installed ?? // create it anyway as a private mime store +#if defined(__WXGTK20__) && wxUSE_UNICODE + if (! outfile.Open ( wxConvUTF8) ) +#else if (! outfile.Open () ) +#endif { - if (delete_index) return FALSE; - if (!CheckGnomeDirsExist() ) return FALSE; + if (delete_index) return false; + if (!CheckGnomeDirsExist() ) return false; outfile.Create (); } @@ -432,8 +430,8 @@ bool wxMimeTypesManagerImpl::WriteGnomeKeyFile(int index, bool delete_index) wxMimeTypeCommands sOld; size_t nOld = nIndex + 1; - bool oldEntryEnd = FALSE; - while ( (nOld < outfile.GetLineCount() )&& (oldEntryEnd == FALSE )) + bool oldEntryEnd = false; + while ( (nOld < outfile.GetLineCount() )&& (!oldEntryEnd)) { sTmp = outfile.GetLine(nOld); if ( (sTmp[0u] == wxT('\t')) || (sTmp[0u] == wxT('#')) ) @@ -447,7 +445,7 @@ bool wxMimeTypesManagerImpl::WriteGnomeKeyFile(int index, bool delete_index) } // next mimetpye ??or blank line else - oldEntryEnd = TRUE; + oldEntryEnd = true; } // list of entries in our data; these should all be in sOld, // though sOld may also contain other entries , eg flags @@ -462,13 +460,13 @@ bool wxMimeTypesManagerImpl::WriteGnomeKeyFile(int index, bool delete_index) } //sOld should also contain the icon if ( !m_aIcons[index].empty() ) - sOld.AddOrReplaceVerb ( wxT( "icon-filename"), m_aIcons[index] ); + sOld.AddOrReplaceVerb ( wxT("icon-filename"), m_aIcons[index] ); for (i=0; i < sOld.GetCount(); i++) { sTmp = sOld.GetVerbCmd(i); sTmp.Replace( wxT("%s"), wxT("%f") ); - sTmp = wxT ( "\t") + sTmp; + sTmp = wxT("\t") + sTmp; nIndex ++; outfile.InsertLine ( sTmp, nIndex ); } @@ -484,13 +482,13 @@ bool wxMimeTypesManagerImpl::WriteGnomeMimeFile(int index, bool delete_index) wxString gnomedir; wxGetHomeDir( &gnomedir ); - wxMimeTextFile outfile ( gnomedir + "/.gnome/mime-info/user.mime"); + wxMimeTextFile outfile ( gnomedir + wxT("/.gnome/mime-info/user.mime")); // if this fails probably Gnome is not installed ?? // create it anyway as a private mime store if (! outfile.Open () ) { - if (delete_index) return FALSE; - if (!CheckGnomeDirsExist() ) return FALSE; + if (delete_index) return false; + if (!CheckGnomeDirsExist() ) return false; outfile.Create (); } wxString strType = m_aTypes[index]; @@ -498,7 +496,7 @@ bool wxMimeTypesManagerImpl::WriteGnomeMimeFile(int index, bool delete_index) if ( nIndex == wxNOT_FOUND ) { outfile.AddLine ( strType ); - outfile.AddLine ( wxT( "\text:") + m_aExtensions.Item(index) ); + outfile.AddLine ( wxT("\text:") + m_aExtensions.Item(index) ); } else { @@ -510,13 +508,13 @@ bool wxMimeTypesManagerImpl::WriteGnomeMimeFile(int index, bool delete_index) else {// check for next line being the right one to replace ?? wxString sOld = outfile.GetLine(nIndex+1); - if (sOld.Contains(wxT("\text: "))) + if (sOld.Contains( wxT("\text: "))) { - outfile.GetLine(nIndex+1) = wxT( "\text: ") + m_aExtensions.Item(index); + outfile.GetLine(nIndex+1) = wxT("\text: ") + m_aExtensions.Item(index); } else { - outfile.InsertLine(wxT( "\text: ") + m_aExtensions.Item(index), nIndex + 1 ); + outfile.InsertLine( wxT("\text: ") + m_aExtensions.Item(index), nIndex + 1 ); } } } @@ -525,10 +523,15 @@ bool wxMimeTypesManagerImpl::WriteGnomeMimeFile(int index, bool delete_index) } -void wxMimeTypesManagerImpl::LoadGnomeDataFromKeyFile(const wxString& filename) +void wxMimeTypesManagerImpl::LoadGnomeDataFromKeyFile(const wxString& filename, + const wxArrayString& dirs) { wxTextFile textfile(filename); +#if defined(__WXGTK20__) && wxUSE_UNICODE + if ( !textfile.Open( wxConvUTF8) ) +#else if ( !textfile.Open() ) +#endif return; wxLogTrace(TRACE_MIME, wxT("--- Opened Gnome file %s ---"), filename.c_str()); @@ -556,10 +559,31 @@ void wxMimeTypesManagerImpl::LoadGnomeDataFromKeyFile(const wxString& filename) wxString sTmp(pc); if (sTmp.Contains(wxT("=")) ) { + // GNOME 1: if (sTmp.Contains( wxT("icon-filename=") ) ) { curIconFile = sTmp.AfterFirst(wxT('=')); } + // GNOME 2: + else if (sTmp.Contains( wxT("icon_filename=") ) ) + { + curIconFile = sTmp.AfterFirst(wxT('=')); + + if (!wxFileExists(curIconFile)) + { + size_t nDirs = dirs.GetCount(); + for (size_t nDir = 0; nDir < nDirs; nDir++) + { + wxFileName newFile( curIconFile ); + newFile.SetPath( dirs[nDir] ); + newFile.AppendDir( wxT("pixmaps") ); + newFile.AppendDir( wxT("document-icons") ); + newFile.SetExt( wxT("png") ); + if (newFile.FileExists()) + curIconFile = newFile.GetFullPath(); + } + } + } else //: some other field, { //may contain lines like this (RH7) @@ -575,7 +599,7 @@ void wxMimeTypesManagerImpl::LoadGnomeDataFromKeyFile(const wxString& filename) // for now ignore lines with flags in...FIX sTmp = sTmp.AfterLast(wxT(']')); sTmp = sTmp.AfterLast(wxT('\t')); - sTmp.Trim(FALSE).Trim(); + sTmp.Trim(false).Trim(); if (0 == sTmp.Replace ( wxT("%f"), wxT("%s") )) sTmp = sTmp + wxT(" %s"); entry->Add(sTmp); @@ -603,11 +627,9 @@ void wxMimeTypesManagerImpl::LoadGnomeDataFromKeyFile(const wxString& filename) // ignore blank lines nLine ++; } // end of while, save any data + if (! curMimeType.empty()) - { AddToMimeData ( curMimeType, curIconFile, entry, strExtensions, strDesc); - } - } @@ -617,8 +639,10 @@ void wxMimeTypesManagerImpl::LoadGnomeMimeTypesFromMimeFile(const wxString& file wxTextFile textfile(filename); if ( !textfile.Open() ) return; - wxLogTrace(TRACE_MIME, wxT("--- Opened Gnome file %s ---"), - filename.c_str()); + + wxLogTrace(TRACE_MIME, + wxT("--- Opened Gnome file %s ---"), + filename.c_str()); // values for the entry being parsed wxString curMimeType, curExtList; @@ -630,7 +654,7 @@ void wxMimeTypesManagerImpl::LoadGnomeMimeTypesFromMimeFile(const wxString& file if ( nLine < nLineCount ) { pc = textfile[nLine].c_str(); - if ( *pc == _T('#') ) + if ( *pc == wxT('#') ) { // skip comments continue; @@ -645,10 +669,11 @@ void wxMimeTypesManagerImpl::LoadGnomeMimeTypesFromMimeFile(const wxString& file if ( !pc || !*pc ) { // end of the entry - if ( !!curMimeType && !!curExtList ) + if ( !curMimeType.empty() && !curExtList.empty() ) { - wxLogTrace(TRACE_MIME, wxT("--- At end of Gnome file finding mimetype %s ---"), - curMimeType.c_str()); + wxLogTrace(TRACE_MIME, + wxT("--- At end of Gnome file finding mimetype %s ---"), + curMimeType.c_str()); AddMimeTypeInfo(curMimeType, curExtList, wxEmptyString); } @@ -665,32 +690,32 @@ void wxMimeTypesManagerImpl::LoadGnomeMimeTypesFromMimeFile(const wxString& file } // what do we have here? - if ( *pc == _T('\t') ) + if ( *pc == wxT('\t') ) { // this is a field=value ling pc++; // skip leading TAB - static const int lenField = 4; // strlen("ext:") - if ( wxStrncmp(pc, _T("ext:"), lenField) == 0 ) + static const int lenField = 5; // strlen("ext: ") + if ( wxStrncmp(pc, wxT("ext: "), lenField) == 0 ) { - // skip ' ' which follows and take everything left until the end - // of line - curExtList = pc + lenField + 1; + // skip it and take everything left until the end of line + curExtList = pc + lenField; } //else: some other field, we don't care } else { // this is the start of the new section - wxLogTrace(TRACE_MIME, wxT("--- In Gnome file finding mimetype %s ---"), - curMimeType.c_str()); + wxLogTrace(TRACE_MIME, + wxT("--- In Gnome file finding mimetype %s ---"), + curMimeType.c_str()); if (! curMimeType.empty()) AddMimeTypeInfo(curMimeType, curExtList, wxEmptyString); curMimeType.Empty(); - while ( *pc != _T(':') && *pc != _T('\0') ) + while ( *pc != wxT(':') && *pc != wxT('\0') ) { curMimeType += *pc++; } @@ -699,13 +724,14 @@ void wxMimeTypesManagerImpl::LoadGnomeMimeTypesFromMimeFile(const wxString& file } -void wxMimeTypesManagerImpl::LoadGnomeMimeFilesFromDir(const wxString& dirbase) +void wxMimeTypesManagerImpl::LoadGnomeMimeFilesFromDir( + const wxString& dirbase, const wxArrayString& dirs) { - wxASSERT_MSG( !!dirbase && !wxEndsWithPathSeparator(dirbase), + wxASSERT_MSG( !dirbase.empty() && !wxEndsWithPathSeparator(dirbase), _T("base directory shouldn't end with a slash") ); wxString dirname = dirbase; - dirname << _T("/mime-info"); + dirname << wxT("/mime-info"); if ( !wxDir::Exists(dirname) ) return; @@ -715,10 +741,11 @@ void wxMimeTypesManagerImpl::LoadGnomeMimeFilesFromDir(const wxString& dirbase) return; // we will concatenate it with filename to get the full path below - dirname += _T('/'); + dirname += wxT('/'); wxString filename; - bool cont = dir.GetFirst(&filename, _T("*.mime"), wxDIR_FILES); + bool cont; + cont = dir.GetFirst(&filename, _T("*.mime"), wxDIR_FILES); while ( cont ) { LoadGnomeMimeTypesFromMimeFile(dirname + filename); @@ -729,32 +756,75 @@ void wxMimeTypesManagerImpl::LoadGnomeMimeFilesFromDir(const wxString& dirbase) cont = dir.GetFirst(&filename, _T("*.keys"), wxDIR_FILES); while ( cont ) { - LoadGnomeDataFromKeyFile(dirname + filename); + LoadGnomeDataFromKeyFile(dirname + filename, dirs); cont = dir.GetNext(&filename); } -} + // Hack alert: We scan all icons and deduce the + // mime-type from the file name. + dirname = dirbase; + dirname << wxT("/pixmaps/document-icons"); + // these are always empty in this file + wxArrayString strExtensions; + wxString strDesc; + if ( !wxDir::Exists(dirname) ) + { + // Jst test for default GPE dir also + dirname = wxT("/usr/share/gpe/pixmaps/default/filemanager/document-icons"); + + if ( !wxDir::Exists(dirname) ) + return; + } + + wxDir dir2( dirname ); + + cont = dir2.GetFirst(&filename, wxT("gnome-*.png"), wxDIR_FILES); + while ( cont ) + { + wxString mimeType = filename; + mimeType.Remove( 0, 6 ); // remove "gnome-" + mimeType.Remove( mimeType.Len()-4, 4 ); // remove ".png" + int pos = mimeType.Find( wxT("-") ); + if (pos != wxNOT_FOUND) + { + mimeType.SetChar( pos, wxT('/') ); + wxString iconFile = dirname; + iconFile << wxT("/"); + iconFile << filename; + AddToMimeData ( mimeType, iconFile, NULL, strExtensions, strDesc, true ); + } + + cont = dir2.GetNext(&filename); + } +} void wxMimeTypesManagerImpl::GetGnomeMimeInfo(const wxString& sExtraDir) { - wxArrayString dirs; - dirs.Add(_T("/usr/share")); - dirs.Add(_T("/usr/local/share")); - wxString gnomedir; - wxGetHomeDir( &gnomedir ); - gnomedir += _T("/.gnome"); + wxString gnomedir = wxGetenv( wxT("GNOMEDIR") );; + if (!gnomedir.empty()) + { + gnomedir << wxT("/share"); + dirs.Add( gnomedir ); + } + + dirs.Add(wxT("/usr/share")); + dirs.Add(wxT("/usr/local/share")); + + gnomedir = wxGetHomeDir(); + gnomedir << wxT("/.gnome"); dirs.Add( gnomedir ); + if (!sExtraDir.empty()) dirs.Add( sExtraDir ); size_t nDirs = dirs.GetCount(); for ( size_t nDir = 0; nDir < nDirs; nDir++ ) { - LoadGnomeMimeFilesFromDir(dirs[nDir]); + LoadGnomeMimeFilesFromDir(dirs[nDir], dirs); } } @@ -776,20 +846,21 @@ void wxMimeTypesManagerImpl::GetGnomeMimeInfo(const wxString& sExtraDir) // kde writing; see http://webcvs.kde.org/cgi-bin/cvsweb.cgi/~checkout~/kdelibs/kio/DESKTOP_ENTRY_STANDARD // for now write to .kdelnk but should eventually do .desktop instead (in preference??) -bool wxMimeTypesManagerImpl::CheckKDEDirsExist ( const wxString & sOK, const wxString & sTest ) - - { +bool wxMimeTypesManagerImpl::CheckKDEDirsExist ( const wxString &sOK, const wxString &sTest ) +{ if (sTest.empty()) - { - if (wxDir::Exists(sOK)) return TRUE; - else return FALSE; - } + { + if (wxDir::Exists(sOK)) + return true; + else + return false; + } else - { - wxString sStart = sOK + wxT("/") + sTest.BeforeFirst(wxT('/')); - if (!wxDir::Exists(sStart)) wxMkdir(sStart); - wxString sEnd = sTest.AfterFirst(wxT('/')); - return CheckKDEDirsExist(sStart, sEnd); + { + wxString sStart = sOK + wxT("/") + sTest.BeforeFirst(wxT('/')); + if (!wxDir::Exists(sStart)) wxMkdir(sStart); + wxString sEnd = sTest.AfterFirst(wxT('/')); + return CheckKDEDirsExist(sStart, sEnd); } } @@ -808,7 +879,7 @@ bool wxMimeTypesManagerImpl::WriteKDEMimeFile(int index, bool delete_index) { bTemp = mimeoutfile.Create (sTmp); // some unknown error eg out of disk space - if (!bTemp) return FALSE; + if (!bTemp) return false; } sTmp = wxT(".kde/share/applnk/"); @@ -821,7 +892,7 @@ bool wxMimeTypesManagerImpl::WriteKDEMimeFile(int index, bool delete_index) { bTemp = appoutfile.Create (sTmp); // some unknown error eg out of disk space - if (!bTemp) return FALSE; + if (!bTemp) return false; } // fixed data; write if new file @@ -890,15 +961,13 @@ bool wxMimeTypesManagerImpl::WriteKDEMimeFile(int index, bool delete_index) //other actions as well as open } - bTemp = FALSE; - if (mimeoutfile.Write ()) bTemp = TRUE; + bTemp = false; + if (mimeoutfile.Write ()) bTemp = true; mimeoutfile.Close (); - if (appoutfile.Write ()) bTemp = TRUE; + if (appoutfile.Write ()) bTemp = true; appoutfile.Close (); return bTemp; - - } void wxMimeTypesManagerImpl::LoadKDELinksForMimeSubtype(const wxString& dirbase, @@ -909,16 +978,19 @@ void wxMimeTypesManagerImpl::LoadKDELinksForMimeSubtype(const wxString& dirbase, wxMimeTextFile file; if ( !file.Open(dirbase + filename) ) return; + wxLogTrace(TRACE_MIME, wxT("loading KDE file %s"), + (dirbase+filename).c_str()); + wxMimeTypeCommands * entry = new wxMimeTypeCommands; wxArrayString sExts; wxString mimetype, mime_desc, strIcon; - int nIndex = file.pIndexOf ("MimeType="); + int nIndex = file.pIndexOf( wxT("MimeType=") ); if (nIndex == wxNOT_FOUND) { // construct mimetype from the directory name and the basename of the // file (it always has .kdelnk extension) - mimetype << subdir << _T('/') << filename.BeforeLast(_T('.')); + mimetype << subdir << wxT('/') << filename.BeforeLast( wxT('.') ); } else mimetype = file.GetCmd (nIndex); @@ -952,7 +1024,7 @@ void wxMimeTypesManagerImpl::LoadKDELinksForMimeSubtype(const wxString& dirbase, nIndex = file.pIndexOf(_T("Patterns=")); if ( nIndex != wxNOT_FOUND ) { - wxString exts = file.GetCmd (nIndex);; + wxString exts = file.GetCmd (nIndex); wxStringTokenizer tokenizer(exts, _T(";")); while ( tokenizer.HasMoreTokens() ) @@ -972,14 +1044,16 @@ void wxMimeTypesManagerImpl::LoadKDELinksForMimeSubtype(const wxString& dirbase, } sExts.Add(mime_extension); - // ok, now we can take care of icon: nIndex = file.pIndexOf(_T("Icon=")); if ( nIndex != wxNOT_FOUND ) { strIcon = file.GetCmd(nIndex); + wxLogTrace(TRACE_MIME, wxT(" icon %s"), strIcon.c_str()); //it could be the real path, but more often a short name + + if (!wxFileExists(strIcon)) { // icon is just the short name @@ -989,11 +1063,17 @@ void wxMimeTypesManagerImpl::LoadKDELinksForMimeSubtype(const wxString& dirbase, // in many locations, at least ~/.kde and $KDEDIR size_t nDir, nDirs = icondirs.GetCount(); for ( nDir = 0; nDir < nDirs; nDir++ ) - if (wxFileExists(icondirs[nDir] + strIcon)) + { + wxFileName fnameIcon( strIcon ); + wxFileName fname( icondirs[nDir], fnameIcon.GetName() ); + fname.SetExt( wxT("png") ); + if (fname.FileExists()) { - strIcon.Prepend(icondirs[nDir]); + strIcon = fname.GetFullPath(); + wxLogTrace(TRACE_MIME, wxT(" iconfile %s"), strIcon.c_str()); break; } + } } } } @@ -1030,6 +1110,9 @@ void wxMimeTypesManagerImpl::LoadKDELinksForMimeType(const wxString& dirbase, if ( !dir.IsOpened() ) return; + wxLogTrace(TRACE_MIME, wxT("--- Loading from KDE directory %s ---"), + dirname.c_str()); + dirname += _T('/'); wxString filename; @@ -1053,7 +1136,7 @@ void wxMimeTypesManagerImpl::LoadKDELinksForMimeType(const wxString& dirbase, void wxMimeTypesManagerImpl::LoadKDELinkFilesFromDir(const wxString& dirbase, const wxArrayString& icondirs) { - wxASSERT_MSG( !!dirbase && !wxEndsWithPathSeparator(dirbase), + wxASSERT_MSG( !dirbase.empty() && !wxEndsWithPathSeparator(dirbase), _T("base directory shouldn't end with a slash") ); wxString dirname = dirbase; @@ -1084,16 +1167,103 @@ void wxMimeTypesManagerImpl::GetKDEMimeInfo(const wxString& sExtraDir) wxArrayString dirs; wxArrayString icondirs; + // FIXME: This code is heavily broken. There are three bugs in it: + // 1) it uses only KDEDIR, which is deprecated, instead of using + // list of paths from KDEDIRS and using KDEDIR only if KDEDIRS + // is not set + // 2) it doesn't look into ~/.kde/share/config/kdeglobals where + // user's settings are stored and thus *ignores* user's settings + // instead of respecting them + // 3) it "tries to guess KDEDIR" and "tries a few likely theme + // names", both of which is completely arbitrary; instead, the + // code should give up if KDEDIR(S) is not set and/or the icon + // theme cannot be determined, because it means that the user is + // not using KDE (and thus is not interested in KDE icons anyway) + + // the variable $KDEDIR is set when KDE is running + wxString kdedir = wxGetenv( wxT("KDEDIR") ); + + if (!kdedir.empty()) + { + // $(KDEDIR)/share/config/kdeglobals holds info + // the current icons theme + wxFileName configFile( kdedir, wxEmptyString ); + configFile.AppendDir( wxT("share") ); + configFile.AppendDir( wxT("config") ); + configFile.SetName( wxT("kdeglobals") ); + + wxTextFile config; + if (configFile.FileExists() && config.Open(configFile.GetFullPath())) + { + // $(KDEDIR)/share/config -> $(KDEDIR)/share + configFile.RemoveDir( configFile.GetDirCount()-1 ); + // $(KDEDIR)/share/ -> $(KDEDIR)/share/icons + configFile.AppendDir( wxT("icons") ); + + // Check for entry + wxString theme(wxT("default.kde")); + size_t cnt = config.GetLineCount(); + for (size_t i = 0; i < cnt; i++) + { + if (config[i].StartsWith(wxT("Theme="), &theme/*rest*/)) + break; + } + configFile.AppendDir(theme); + } + else + { + // $(KDEDIR)/share/config -> $(KDEDIR)/share + configFile.RemoveDir( configFile.GetDirCount()-1 ); + // $(KDEDIR)/share/ -> $(KDEDIR)/share/icons + configFile.AppendDir( wxT("icons") ); + // $(KDEDIR)/share/icons -> $(KDEDIR)/share/icons/default.kde + configFile.AppendDir( wxT("default.kde") ); + } + + configFile.SetName( wxEmptyString ); + configFile.AppendDir( wxT("32x32") ); + configFile.AppendDir( wxT("mimetypes") ); + + // Just try a few likely icons theme names + + int pos = configFile.GetDirCount()-3; + + if (!wxDir::Exists(configFile.GetPath())) + { + configFile.RemoveDir( pos ); + configFile.InsertDir( pos, wxT("default.kde") ); + } + + if (!wxDir::Exists(configFile.GetPath())) + { + configFile.RemoveDir( pos ); + configFile.InsertDir( pos, wxT("default") ); + } + + if (!wxDir::Exists(configFile.GetPath())) + { + configFile.RemoveDir( pos ); + configFile.InsertDir( pos, wxT("crystalsvg") ); + } + + if (!wxDir::Exists(configFile.GetPath())) + { + configFile.RemoveDir( pos ); + configFile.InsertDir( pos, wxT("crystal") ); + } + + if (wxDir::Exists(configFile.GetPath())) + icondirs.Add( configFile.GetFullPath() ); + } + // settings in ~/.kde have maximal priority - dirs.Add(wxGetHomeDir() + _T("/.kde/share")); - icondirs.Add(wxGetHomeDir() + _T("/.kde/share/icons/")); + dirs.Add(wxGetHomeDir() + wxT("/.kde/share")); + icondirs.Add(wxGetHomeDir() + wxT("/.kde/share/icons/")); - // the variable KDEDIR is set when KDE is running - const char *kdedir = getenv("KDEDIR"); - if ( kdedir ) + if (kdedir) { - dirs.Add(wxString(kdedir) + _T("/share")); - icondirs.Add(wxString(kdedir) + _T("/share/icons/")); + dirs.Add( wxString(kdedir) + wxT("/share") ); + icondirs.Add( wxString(kdedir) + wxT("/share/icons/") ); } else { @@ -1132,12 +1302,9 @@ wxString wxFileTypeImpl::GetExpandedCommand(const wxString & verb, const wxFileT return wxFileType::ExpandCommand(sTmp, params); } -bool wxFileTypeImpl::GetIcon(wxIcon *icon, - wxString *iconFile /*= NULL */, - int *iconIndex /*= NULL*/) const +bool wxFileTypeImpl::GetIcon(wxIconLocation *iconLoc) const { -#if wxUSE_GUI wxString sTmp; size_t i = 0; while ( (i < m_index.GetCount() ) && sTmp.empty() ) @@ -1145,25 +1312,15 @@ bool wxFileTypeImpl::GetIcon(wxIcon *icon, sTmp = m_manager->m_aIcons[m_index[i]]; i ++; } - if ( sTmp.empty () ) return FALSE; - - wxIcon icn; - - if (sTmp.Right(4).MakeUpper() == _T(".XPM")) - icn = wxIcon(sTmp); - else - icn = wxIcon(sTmp, wxBITMAP_TYPE_ANY); + if ( sTmp.empty () ) + return false; - if ( icn.Ok() ) + if ( iconLoc ) { - *icon = icn; - if (iconFile) *iconFile = sTmp; - if (iconIndex) *iconIndex = 0; - return TRUE; + iconLoc->SetFileName(sTmp); } -#endif // wxUSE_GUI - return FALSE; + return true; } @@ -1173,7 +1330,7 @@ wxFileTypeImpl::GetMimeTypes(wxArrayString& mimeTypes) const mimeTypes.Clear(); for (size_t i = 0; i < m_index.GetCount(); i++) mimeTypes.Add(m_manager->m_aTypes[m_index[i]]); - return TRUE; + return true; } @@ -1253,14 +1410,17 @@ bool wxFileTypeImpl::GetExtensions(wxArrayString& extensions) } } - return TRUE; + return true; } // set an arbitrary command, // could adjust the code to ask confirmation if it already exists and -// overwriteprompt is TRUE, but this is currently ignored as *Associate* has +// overwriteprompt is true, but this is currently ignored as *Associate* has // no overwrite prompt -bool wxFileTypeImpl::SetCommand(const wxString& cmd, const wxString& verb, bool overwriteprompt /*= TRUE*/) +bool +wxFileTypeImpl::SetCommand(const wxString& cmd, + const wxString& verb, + bool WXUNUSED(overwriteprompt)) { wxArrayString strExtensions; wxString strDesc, strIcon; @@ -1270,23 +1430,23 @@ bool wxFileTypeImpl::SetCommand(const wxString& cmd, const wxString& verb, bool wxArrayString strTypes; GetMimeTypes (strTypes); - if (strTypes.GetCount() < 1) return FALSE; + if (strTypes.GetCount() < 1) return false; size_t i; - bool Ok = TRUE; + bool Ok = true; for (i = 0; i < strTypes.GetCount(); i++) { if (!m_manager->DoAssociation (strTypes[i], strIcon, entry, strExtensions, strDesc)) - Ok = FALSE; + Ok = false; } return Ok; } // ignore index on the grouds that we only have one icon in a Unix file -bool wxFileTypeImpl::SetDefaultIcon(const wxString& strIcon /*= wxEmptyString*/, int /*index = 0*/) +bool wxFileTypeImpl::SetDefaultIcon(const wxString& strIcon, int WXUNUSED(index)) { - if (strIcon.empty()) return FALSE; + if (strIcon.empty()) return false; wxArrayString strExtensions; wxString strDesc; @@ -1294,14 +1454,14 @@ bool wxFileTypeImpl::SetDefaultIcon(const wxString& strIcon /*= wxEmptyString*/, wxArrayString strTypes; GetMimeTypes (strTypes); - if (strTypes.GetCount() < 1) return FALSE; + if (strTypes.GetCount() < 1) return false; size_t i; - bool Ok = TRUE; + bool Ok = true; for (i = 0; i < strTypes.GetCount(); i++) { if (!m_manager->DoAssociation (strTypes[i], strIcon, entry, strExtensions, strDesc)) - Ok = FALSE; + Ok = false; } return Ok; @@ -1314,10 +1474,30 @@ bool wxFileTypeImpl::SetDefaultIcon(const wxString& strIcon /*= wxEmptyString*/, wxMimeTypesManagerImpl::wxMimeTypesManagerImpl() { - m_initialized = FALSE; + m_initialized = false; m_mailcapStylesInited = 0; } +void wxMimeTypesManagerImpl::InitIfNeeded() +{ + if ( !m_initialized ) + { + // set the flag first to prevent recursion + m_initialized = true; + +#if 0 + wxString wm = wxGetenv( wxT("WINDOWMANAGER") ); + + if (wm.Find( wxT("kde") ) != wxNOT_FOUND) + Initialize( wxMAILCAP_KDE|wxMAILCAP_STANDARD ); + else if (wm.Find( wxT("gnome") ) != wxNOT_FOUND) + Initialize( wxMAILCAP_GNOME|wxMAILCAP_STANDARD ); + else +#endif + Initialize(); + } +} + // read system and user mailcaps and other files void wxMimeTypesManagerImpl::Initialize(int mailcapStyles, const wxString& sExtraDir) @@ -1328,11 +1508,11 @@ void wxMimeTypesManagerImpl::Initialize(int mailcapStyles, GetMimeInfo(sExtraDir); // read GNOME tables - if ( mailcapStyles & wxMAILCAP_GNOME) + if (mailcapStyles & wxMAILCAP_GNOME) GetGnomeMimeInfo(sExtraDir); // read KDE tables - if ( mailcapStyles & wxMAILCAP_KDE) + if (mailcapStyles & wxMAILCAP_KDE) GetKDEMimeInfo(sExtraDir); m_mailcapStylesInited |= mailcapStyles; @@ -1346,6 +1526,7 @@ void wxMimeTypesManagerImpl::ClearData() m_aExtensions.Clear (); m_aDescriptions.Clear (); + WX_CLEAR_ARRAY(m_aEntries); m_aEntries.Empty(); m_mailcapStylesInited = 0; @@ -1354,8 +1535,6 @@ void wxMimeTypesManagerImpl::ClearData() wxMimeTypesManagerImpl::~wxMimeTypesManagerImpl() { ClearData(); - - WX_CLEAR_ARRAY(m_aEntries); } @@ -1405,7 +1584,7 @@ bool wxMimeTypesManagerImpl::WriteToMimeTypes (int index, bool delete_index) { // check we have the right manager if (! ( m_mailcapStylesInited & wxMAILCAP_STANDARD) ) - return FALSE; + return false; bool bTemp; wxString strHome = wxGetenv(wxT("HOME")); @@ -1420,18 +1599,18 @@ bool wxMimeTypesManagerImpl::WriteToMimeTypes (int index, bool delete_index) } else { - if (delete_index) return FALSE; + if (delete_index) return false; bTemp = file.Create(strUserMailcap); } if (bTemp) { int nIndex; - // test for netscape's header and return FALSE if its found + // test for netscape's header and return false if its found nIndex = file.pIndexOf (wxT("#--Netscape")); if (nIndex != wxNOT_FOUND) { - wxASSERT_MSG(FALSE,wxT("Error in .mime.types \nTrying to mix Netscape and Metamail formats\nFile not modiifed")); - return FALSE; + wxASSERT_MSG(false,wxT("Error in .mime.types \nTrying to mix Netscape and Metamail formats\nFile not modiifed")); + return false; } // write it in alternative format // get rid of unwanted entries @@ -1459,7 +1638,7 @@ bool wxMimeTypesManagerImpl::WriteToNSMimeTypes (int index, bool delete_index) { //check we have the right managers if (! ( m_mailcapStylesInited & wxMAILCAP_NETSCAPE) ) - return FALSE; + return false; bool bTemp; wxString strHome = wxGetenv(wxT("HOME")); @@ -1474,7 +1653,7 @@ bool wxMimeTypesManagerImpl::WriteToNSMimeTypes (int index, bool delete_index) } else { - if (delete_index) return FALSE; + if (delete_index) return false; bTemp = file.Create(strUserMailcap); } if (bTemp) @@ -1483,8 +1662,8 @@ bool wxMimeTypesManagerImpl::WriteToNSMimeTypes (int index, bool delete_index) // write it in the format that Netscape uses int nIndex; // test for netscape's header and insert if required... - // this is a comment so use TRUE - nIndex = file.pIndexOf (wxT("#--Netscape"), TRUE); + // this is a comment so use true + nIndex = file.pIndexOf (wxT("#--Netscape"), true); if (nIndex == wxNOT_FOUND) { // either empty file or metamail format @@ -1492,8 +1671,8 @@ bool wxMimeTypesManagerImpl::WriteToNSMimeTypes (int index, bool delete_index) // metamail entreies if (file.GetLineCount () > 0) { - wxASSERT_MSG(FALSE, wxT(".mime.types File not in Netscape format\nNo entries written to\n.mime.types or to .mailcap")); - return FALSE; + wxASSERT_MSG(false, wxT(".mime.types File not in Netscape format\nNo entries written to\n.mime.types or to .mailcap")); + return false; } file.InsertLine (wxT( "#--Netscape Communications Corporation MIME Information" ), 0); nIndex = 0; @@ -1528,7 +1707,7 @@ bool wxMimeTypesManagerImpl::WriteToNSMimeTypes (int index, bool delete_index) } } wxString sExts = m_aExtensions.Item(index); - sTmp = wxT("exts=\"") + sExts.Trim(FALSE).Trim() + wxT("\""); + sTmp = wxT("exts=\"") + sExts.Trim(false).Trim() + wxT("\""); if (!delete_index) { nIndex ++; @@ -1547,7 +1726,7 @@ bool wxMimeTypesManagerImpl::WriteToMailCap (int index, bool delete_index) //check we have the right managers if ( !( ( m_mailcapStylesInited & wxMAILCAP_NETSCAPE) || ( m_mailcapStylesInited & wxMAILCAP_STANDARD) ) ) - return FALSE; + return false; bool bTemp; wxString strHome = wxGetenv(wxT("HOME")); @@ -1562,7 +1741,7 @@ bool wxMimeTypesManagerImpl::WriteToMailCap (int index, bool delete_index) } else { - if (delete_index) return FALSE; + if (delete_index) return false; bTemp = file.Create(strUserMailcap); } if (bTemp) @@ -1624,13 +1803,13 @@ bool wxMimeTypesManagerImpl::WriteToMailCap (int index, bool delete_index) s = sT.GetNextToken(); while ( ! s.empty() ) { - bool bKnownToken = FALSE; - if (s.Contains(wxT("description="))) bKnownToken = TRUE; - if (s.Contains(wxT("x11-bitmap="))) bKnownToken = TRUE; + bool bKnownToken = false; + if (s.Contains(wxT("description="))) bKnownToken = true; + if (s.Contains(wxT("x11-bitmap="))) bKnownToken = true; size_t i; for (i=0; i < entries->GetCount(); i++) { - if (s.Contains(entries->GetVerb(i))) bKnownToken = TRUE; + if (s.Contains(entries->GetVerb(i))) bKnownToken = true; } if (!bKnownToken) { @@ -1706,7 +1885,7 @@ wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo& ftInfo) { sExt = sA_Exts.Item(i); //clean up to just a space before and after - sExt.Trim().Trim(FALSE); + sExt.Trim().Trim(false); sExt = wxT(' ') + sExt + wxT(' '); for (nIndex = 0; nIndex < m_aExtensions.GetCount(); nIndex ++) { @@ -1729,44 +1908,44 @@ bool wxMimeTypesManagerImpl::DoAssociation(const wxString& strType, const wxArrayString& strExtensions, const wxString& strDesc) { - int nIndex = AddToMimeData(strType, strIcon, entry, strExtensions, strDesc, TRUE); + int nIndex = AddToMimeData(strType, strIcon, entry, strExtensions, strDesc, true); if ( nIndex == wxNOT_FOUND ) - return FALSE; + return false; - return WriteMimeInfo (nIndex, FALSE); + return WriteMimeInfo (nIndex, false); } bool wxMimeTypesManagerImpl::WriteMimeInfo(int nIndex, bool delete_mime ) { - bool ok = TRUE; + bool ok = true; if ( m_mailcapStylesInited & wxMAILCAP_STANDARD ) { // write in metamail format; if (WriteToMimeTypes (nIndex, delete_mime) ) if ( WriteToMailCap (nIndex, delete_mime) ) - ok = FALSE; + ok = false; } if ( m_mailcapStylesInited & wxMAILCAP_NETSCAPE ) { // write in netsacpe format; if (WriteToNSMimeTypes (nIndex, delete_mime) ) if ( WriteToMailCap (nIndex, delete_mime) ) - ok = FALSE; + ok = false; } if (m_mailcapStylesInited & wxMAILCAP_GNOME) { // write in Gnome format; if (WriteGnomeMimeFile (nIndex, delete_mime) ) if (WriteGnomeKeyFile (nIndex, delete_mime) ) - ok = FALSE; + ok = false; } if (m_mailcapStylesInited & wxMAILCAP_KDE) { // write in KDE format; if (WriteKDEMimeFile (nIndex, delete_mime) ) - ok = FALSE; + ok = false; } return ok; @@ -1794,7 +1973,8 @@ int wxMimeTypesManagerImpl::AddToMimeData(const wxString& strType, m_aEntries.Add(entry ? entry : new wxMimeTypeCommands); // change nIndex so we can use it below to add the extensions - nIndex = m_aExtensions.Add(wxEmptyString); + m_aExtensions.Add(wxEmptyString); + nIndex = m_aExtensions.size() - 1; m_aDescriptions.Add(strDesc); } @@ -1840,6 +2020,10 @@ int wxMimeTypesManagerImpl::AddToMimeData(const wxString& strType, entryOld->AddOrReplaceVerb(verb, entry->GetCmd(i)); } } + + // as we don't store it anywhere, it won't be deleted later as + // usual -- do it immediately instead + delete entry; } } } @@ -1885,7 +2069,7 @@ wxMimeTypesManagerImpl::GetFileTypeFromExtension(const wxString& ext) while ( tk.HasMoreTokens() ) { // consider extensions as not being case-sensitive - if ( tk.GetNextToken().IsSameAs(ext, FALSE /* no case */) ) + if ( tk.GetNextToken().IsSameAs(ext, false /* no case */) ) { // found wxFileType *fileType = new wxFileType; @@ -1996,7 +2180,7 @@ void wxMimeTypesManagerImpl::AddMimeTypeInfo(const wxString& strMimeType, wxString sTmp = strExtensions; wxArrayString sExts; - sTmp.Trim().Trim(FALSE); + sTmp.Trim().Trim(false); while (!sTmp.empty()) { @@ -2004,7 +2188,7 @@ void wxMimeTypesManagerImpl::AddMimeTypeInfo(const wxString& strMimeType, sTmp = sTmp.BeforeLast(wxT(' ')); } - AddToMimeData (strMimeType, strIcon, NULL, sExts, strDesc, TRUE); + AddToMimeData (strMimeType, strIcon, NULL, sExts, strDesc, true); } void wxMimeTypesManagerImpl::AddMailcapInfo(const wxString& strType, @@ -2023,7 +2207,7 @@ void wxMimeTypesManagerImpl::AddMailcapInfo(const wxString& strType, wxString strIcon; wxArrayString strExtensions; - AddToMimeData (strType, strIcon, entry, strExtensions, strDesc, TRUE); + AddToMimeData (strType, strIcon, entry, strExtensions, strDesc, true); } @@ -2033,15 +2217,20 @@ bool wxMimeTypesManagerImpl::ReadMimeTypes(const wxString& strFileName) strFileName.c_str()); wxTextFile file(strFileName); +#if defined(__WXGTK20__) && wxUSE_UNICODE + if ( !file.Open( wxConvUTF8) ) +#else if ( !file.Open() ) - return FALSE; +#endif + return false; // the information we extract wxString strMimeType, strDesc, strExtensions; size_t nLineCount = file.GetLineCount(); const wxChar *pc = NULL; - for ( size_t nLine = 0; nLine < nLineCount; nLine++ ) { + for ( size_t nLine = 0; nLine < nLineCount; nLine++ ) + { if ( pc == NULL ) { // now we're at the start of the line pc = file[nLine].c_str(); @@ -2099,8 +2288,7 @@ bool wxMimeTypesManagerImpl::ReadMimeTypes(const wxString& strFileName) // the string is quoted and ends at the matching quote pEnd = wxStrchr(++pc, wxT('"')); if ( pEnd == NULL ) { - wxLogWarning(_("Mime.types file %s, line %d: unterminated " - "quoted string."), + wxLogWarning(_("Mime.types file %s, line %d: unterminated quoted string."), strFileName.c_str(), nLine + 1); } } @@ -2126,7 +2314,7 @@ bool wxMimeTypesManagerImpl::ReadMimeTypes(const wxString& strFileName) // if there is something left, it may be either a '\\' to continue // the line or the next field of the same entry bool entryEnded = *pc == wxT('\0'), - nextFieldOnSameLine = FALSE; + nextFieldOnSameLine = false; if ( !entryEnded ) { nextFieldOnSameLine = ((*pc != wxT('\\')) || (pc[1] != wxT('\0'))); } @@ -2141,14 +2329,19 @@ bool wxMimeTypesManagerImpl::ReadMimeTypes(const wxString& strFileName) else if ( strLHS == wxT("exts") ) { strExtensions = strRHS; } - else { + else if ( strLHS == _T("icon") ) + { // this one is simply ignored: it usually refers to Netscape // built in icons which are useless for us anyhow - if ( strLHS != _T("icon") ) - { - wxLogWarning(_("Unknown field in file %s, line %d: '%s'."), - strFileName.c_str(), nLine + 1, strLHS.c_str()); - } + } + else if ( !strLHS.StartsWith(_T("x-")) ) + { + // we suppose that all fields starting with "X-" are + // unregistered extensions according to the standard practice, + // but it may be worth telling the user about other junk in + // his mime.types file + wxLogWarning(_("Unknown field in file %s, line %d: '%s'."), + strFileName.c_str(), nLine + 1, strLHS.c_str()); } if ( !entryEnded ) { @@ -2184,7 +2377,7 @@ bool wxMimeTypesManagerImpl::ReadMimeTypes(const wxString& strFileName) pc = NULL; } - return TRUE; + return true; } // ---------------------------------------------------------------------------- @@ -2209,7 +2402,7 @@ struct MailcapLineData needsterminal, copiousoutput; - MailcapLineData() { testfailed = needsterminal = copiousoutput = FALSE; } + MailcapLineData() { testfailed = needsterminal = copiousoutput = false; } }; // process a non-standard (i.e. not the first or second one) mailcap field @@ -2220,7 +2413,7 @@ wxMimeTypesManagerImpl::ProcessOtherMailcapField(MailcapLineData& data, if ( curField.empty() ) { // we don't care - return TRUE; + return true; } // is this something of the form foo=bar? @@ -2231,8 +2424,8 @@ wxMimeTypesManagerImpl::ProcessOtherMailcapField(MailcapLineData& data, wxString lhs = curField.BeforeFirst(wxT('=')), rhs = curField.AfterFirst(wxT('=')); - lhs.Trim(TRUE); // from right - rhs.Trim(FALSE); // from left + lhs.Trim(true); // from right + rhs.Trim(false); // from left // it might be quoted if ( !rhs.empty() && rhs[0u] == wxT('"') && rhs.Last() == wxT('"') ) @@ -2257,7 +2450,7 @@ wxMimeTypesManagerImpl::ProcessOtherMailcapField(MailcapLineData& data, wxT("Test '%s' for mime type '%s' failed, skipping."), rhs.c_str(), data.type.c_str()); - data.testfailed = TRUE; + data.testfailed = true; } } else if ( lhs == wxT("desc") ) @@ -2283,21 +2476,21 @@ wxMimeTypesManagerImpl::ProcessOtherMailcapField(MailcapLineData& data, // so it must be a simple flag if ( curField == wxT("needsterminal") ) { - data.needsterminal = TRUE; + data.needsterminal = true; } else if ( curField == wxT("copiousoutput")) { // copiousoutput impies that the viewer is a console program data.needsterminal = - data.copiousoutput = TRUE; + data.copiousoutput = true; } else if ( !IsKnownUnimportantField(curField) ) { - return FALSE; + return false; } } - return TRUE; + return true; } bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName, @@ -2307,8 +2500,12 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName, strFileName.c_str()); wxTextFile file(strFileName); +#if defined(__WXGTK20__) && wxUSE_UNICODE + if ( !file.Open( wxConvUTF8) ) +#else if ( !file.Open() ) - return FALSE; +#endif + return false; // indices of MIME types (in m_aTypes) we already found in this file // @@ -2351,7 +2548,7 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName, // the flags and field values on the current line MailcapLineData data; - bool cont = TRUE; + bool cont = true; while ( cont ) { switch ( *pc ) @@ -2365,13 +2562,11 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName, if ( nLine == nLineCount - 1 ) { // something is wrong, bail out - cont = FALSE; + cont = false; - wxLogDebug(wxT("Mailcap file %s, line %d: " - "'\\' on the end of the last line " - "ignored."), + wxLogDebug(wxT("Mailcap file %s, line %lu: '\\' on the end of the last line ignored."), strFileName.c_str(), - nLine + 1); + (unsigned long)nLine + 1); } else { @@ -2390,13 +2585,13 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName, break; case wxT('\0'): - cont = FALSE; // end of line reached, exit the loop + cont = false; // end of line reached, exit the loop // fall through to still process this field case wxT(';'): // trim whitespaces from both sides - curField.Trim(TRUE).Trim(FALSE); + curField.Trim(true).Trim(false); switch ( currentToken ) { @@ -2433,11 +2628,9 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName, // this might be useful for the programmer wxLogDebug ( - wxT("Mailcap file %s, line %d: " - "unknown field '%s' for the " - "MIME type '%s' ignored."), + wxT("Mailcap file %s, line %lu: unknown field '%s' for the MIME type '%s' ignored."), strFileName.c_str(), - nLine + 1, + (unsigned long)nLine + 1, curField.c_str(), data.type.c_str() ); @@ -2445,7 +2638,7 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName, else if ( data.testfailed ) { // skip this entry entirely - cont = FALSE; + cont = false; } // it already has this value @@ -2474,8 +2667,7 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName, // check that we really read something reasonable if ( currentToken < Field_Other ) { - wxLogWarning(_("Mailcap file %s, line %d: incomplete entry " - "ignored."), + wxLogWarning(_("Mailcap file %s, line %d: incomplete entry ignored."), strFileName.c_str(), nLine + 1); continue; @@ -2504,7 +2696,8 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName, if ( data.needsterminal ) { - data.cmdOpen.Printf(_T("xterm -e sh -c '%s'"), data.cmdOpen.c_str()); + data.cmdOpen = wxString::Format(_T("xterm -e sh -c '%s'"), + data.cmdOpen.c_str()); } if ( !data.cmdOpen.empty() ) @@ -2520,16 +2713,17 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName, // the fall back entries have the lowest priority, by definition if ( fallback ) { - overwrite = FALSE; + overwrite = false; } else { // have we seen this one before? int nIndex = m_aTypes.Index(data.type); - // and if we have, was it in this file? + // and if we have, was it in this file? if not, we should + // overwrite the previously seen one overwrite = nIndex == wxNOT_FOUND || - aIndicesSeenHere.Index(nIndex) != wxNOT_FOUND; + aIndicesSeenHere.Index(nIndex) == wxNOT_FOUND; } wxLogTrace(TRACE_MIME, _T("mailcap %s: %s [%s]"), @@ -2552,7 +2746,7 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName, } } - return TRUE; + return true; } size_t wxMimeTypesManagerImpl::EnumAllFileTypes(wxArrayString& mimetypes) @@ -2594,11 +2788,11 @@ bool wxMimeTypesManagerImpl::Unassociate(wxFileType *ft) if ( nIndex == wxNOT_FOUND) { // error if we get here ?? - return FALSE; + return false; } else { - WriteMimeInfo(nIndex, TRUE ); + WriteMimeInfo(nIndex, true ); m_aTypes.RemoveAt(nIndex); m_aEntries.RemoveAt(nIndex); m_aExtensions.RemoveAt(nIndex); @@ -2612,7 +2806,7 @@ bool wxMimeTypesManagerImpl::Unassociate(wxFileType *ft) m_aTypes.Count() == m_aIcons.Count() && m_aTypes.Count() == m_aDescriptions.Count() ); - return TRUE; + return true; } // ---------------------------------------------------------------------------- @@ -2632,10 +2826,10 @@ static bool IsKnownUnimportantField(const wxString& fieldAll) for ( size_t n = 0; n < WXSIZEOF(knownFields); n++ ) { if ( field.CmpNoCase(knownFields[n]) == 0 ) - return TRUE; + return true; } - return FALSE; + return false; } #endif