Slightly less hacky way to get the KDE icon theme name.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25814 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2004-02-15 12:57:23 +00:00
parent 7dfdce6b02
commit 1027433607

View File

@@ -573,17 +573,17 @@ void wxMimeTypesManagerImpl::LoadGnomeDataFromKeyFile(const wxString& filename,
else if (sTmp.Contains( wxT("icon_filename=") ) ) else if (sTmp.Contains( wxT("icon_filename=") ) )
{ {
curIconFile = sTmp.AfterFirst(wxT('=')); curIconFile = sTmp.AfterFirst(wxT('='));
if (!wxFileExists(curIconFile)) if (!wxFileExists(curIconFile))
{ {
size_t nDirs = dirs.GetCount(); size_t nDirs = dirs.GetCount();
for (size_t nDir = 0; nDir < nDirs; nDir++) for (size_t nDir = 0; nDir < nDirs; nDir++)
{ {
wxFileName newFile( curIconFile ); wxFileName newFile( curIconFile );
newFile.SetPath( dirs[nDir] ); newFile.SetPath( dirs[nDir] );
newFile.AppendDir( wxT("pixmaps") ); newFile.AppendDir( wxT("pixmaps") );
newFile.AppendDir( wxT("document-icons") ); newFile.AppendDir( wxT("document-icons") );
newFile.SetExt( wxT("png") ); newFile.SetExt( wxT("png") );
if (newFile.FileExists()) if (newFile.FileExists())
curIconFile = newFile.GetFullPath(); curIconFile = newFile.GetFullPath();
} }
@@ -679,7 +679,7 @@ void wxMimeTypesManagerImpl::LoadGnomeMimeTypesFromMimeFile(const wxString& file
wxLogTrace(TRACE_MIME, wxLogTrace(TRACE_MIME,
wxT("--- At end of Gnome file finding mimetype %s ---"), wxT("--- At end of Gnome file finding mimetype %s ---"),
curMimeType.c_str()); curMimeType.c_str());
AddMimeTypeInfo(curMimeType, curExtList, wxEmptyString); AddMimeTypeInfo(curMimeType, curExtList, wxEmptyString);
} }
@@ -783,18 +783,18 @@ void wxMimeTypesManagerImpl::LoadGnomeMimeFilesFromDir(
cont = dir2.GetFirst(&filename, wxT("gnome-*.png"), wxDIR_FILES); cont = dir2.GetFirst(&filename, wxT("gnome-*.png"), wxDIR_FILES);
while ( cont ) while ( cont )
{ {
wxString mimeType = filename; wxString mimeType = filename;
mimeType.Remove( 0, 6 ); // remove "gnome-" mimeType.Remove( 0, 6 ); // remove "gnome-"
mimeType.Remove( mimeType.Len()-4, 4 ); // remove ".png" mimeType.Remove( mimeType.Len()-4, 4 ); // remove ".png"
int pos = mimeType.Find( wxT("-") ); int pos = mimeType.Find( wxT("-") );
if (pos != wxNOT_FOUND) if (pos != wxNOT_FOUND)
{ {
mimeType.SetChar( pos, wxT('/') ); mimeType.SetChar( pos, wxT('/') );
wxString iconFile = dirname; wxString iconFile = dirname;
iconFile << wxT("/"); iconFile << wxT("/");
iconFile << filename; iconFile << filename;
AddToMimeData ( mimeType, iconFile, NULL, strExtensions, strDesc, TRUE ); AddToMimeData ( mimeType, iconFile, NULL, strExtensions, strDesc, TRUE );
} }
cont = dir2.GetNext(&filename); cont = dir2.GetNext(&filename);
} }
@@ -803,14 +803,21 @@ void wxMimeTypesManagerImpl::LoadGnomeMimeFilesFromDir(
void wxMimeTypesManagerImpl::GetGnomeMimeInfo(const wxString& sExtraDir) void wxMimeTypesManagerImpl::GetGnomeMimeInfo(const wxString& sExtraDir)
{ {
wxArrayString dirs; wxArrayString dirs;
dirs.Add(wxT("/opt/gnome/share"));
wxString gnomedir = wxGetenv( wxT("GNOMEDIR") );;
if (!gnomedir.empty())
{
gnomedir << wxT("/share");
dirs.Add( gnomedir );
}
dirs.Add(wxT("/usr/share")); dirs.Add(wxT("/usr/share"));
dirs.Add(wxT("/usr/local/share")); dirs.Add(wxT("/usr/local/share"));
wxString gnomedir; gnomedir = wxGetHomeDir();
wxGetHomeDir( &gnomedir ); gnomedir << wxT("/.gnome");
gnomedir += wxT("/.gnome");
dirs.Add( gnomedir ); dirs.Add( gnomedir );
if (!sExtraDir.empty()) dirs.Add( sExtraDir ); if (!sExtraDir.empty()) dirs.Add( sExtraDir );
size_t nDirs = dirs.GetCount(); size_t nDirs = dirs.GetCount();
@@ -838,20 +845,21 @@ void wxMimeTypesManagerImpl::GetGnomeMimeInfo(const wxString& sExtraDir)
// kde writing; see http://webcvs.kde.org/cgi-bin/cvsweb.cgi/~checkout~/kdelibs/kio/DESKTOP_ENTRY_STANDARD // 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??) // 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 (sTest.empty())
{ {
if (wxDir::Exists(sOK)) return TRUE; if (wxDir::Exists(sOK))
else return FALSE; return TRUE;
} else
return FALSE;
}
else else
{ {
wxString sStart = sOK + wxT("/") + sTest.BeforeFirst(wxT('/')); wxString sStart = sOK + wxT("/") + sTest.BeforeFirst(wxT('/'));
if (!wxDir::Exists(sStart)) wxMkdir(sStart); if (!wxDir::Exists(sStart)) wxMkdir(sStart);
wxString sEnd = sTest.AfterFirst(wxT('/')); wxString sEnd = sTest.AfterFirst(wxT('/'));
return CheckKDEDirsExist(sStart, sEnd); return CheckKDEDirsExist(sStart, sEnd);
} }
} }
@@ -959,8 +967,6 @@ bool wxMimeTypesManagerImpl::WriteKDEMimeFile(int index, bool delete_index)
appoutfile.Close (); appoutfile.Close ();
return bTemp; return bTemp;
} }
void wxMimeTypesManagerImpl::LoadKDELinksForMimeSubtype(const wxString& dirbase, void wxMimeTypesManagerImpl::LoadKDELinksForMimeSubtype(const wxString& dirbase,
@@ -1037,7 +1043,6 @@ void wxMimeTypesManagerImpl::LoadKDELinksForMimeSubtype(const wxString& dirbase,
} }
sExts.Add(mime_extension); sExts.Add(mime_extension);
// ok, now we can take care of icon: // ok, now we can take care of icon:
nIndex = file.pIndexOf(_T("Icon=")); nIndex = file.pIndexOf(_T("Icon="));
@@ -1046,8 +1051,8 @@ void wxMimeTypesManagerImpl::LoadKDELinksForMimeSubtype(const wxString& dirbase,
strIcon = file.GetCmd(nIndex); strIcon = file.GetCmd(nIndex);
wxLogTrace(TRACE_MIME, wxT(" icon %s"), strIcon.c_str()); wxLogTrace(TRACE_MIME, wxT(" icon %s"), strIcon.c_str());
//it could be the real path, but more often a short name //it could be the real path, but more often a short name
if (!wxFileExists(strIcon)) if (!wxFileExists(strIcon))
{ {
// icon is just the short name // icon is just the short name
@@ -1057,16 +1062,16 @@ void wxMimeTypesManagerImpl::LoadKDELinksForMimeSubtype(const wxString& dirbase,
// in many locations, at least ~/.kde and $KDEDIR // in many locations, at least ~/.kde and $KDEDIR
size_t nDir, nDirs = icondirs.GetCount(); size_t nDir, nDirs = icondirs.GetCount();
for ( nDir = 0; nDir < nDirs; nDir++ ) for ( nDir = 0; nDir < nDirs; nDir++ )
{ {
wxFileName fname( icondirs[nDir], strIcon ); wxFileName fname( icondirs[nDir], strIcon );
fname.SetExt( wxT("png") ); fname.SetExt( wxT("png") );
if (fname.FileExists()) if (fname.FileExists())
{ {
strIcon = fname.GetFullPath(); strIcon = fname.GetFullPath();
wxLogTrace(TRACE_MIME, wxT(" iconfile %s"), strIcon.c_str()); wxLogTrace(TRACE_MIME, wxT(" iconfile %s"), strIcon.c_str());
break; break;
} }
} }
} }
} }
} }
@@ -1160,55 +1165,85 @@ void wxMimeTypesManagerImpl::GetKDEMimeInfo(const wxString& sExtraDir)
wxArrayString dirs; wxArrayString dirs;
wxArrayString icondirs; wxArrayString icondirs;
// the variable KDEDIR is set when KDE is running // the variable $KDEDIR is set when KDE is running
const wxChar *kdedir = wxGetenv( wxT("KDEDIR") ); wxString kdedir = wxGetenv( wxT("KDEDIR") );
if (kdedir) if (!kdedir.empty())
{ {
wxFileName configFile( kdedir, wxEmptyString ); // $(KDEDIR)/share/config/kdeglobals holds info
configFile.AppendDir( wxT("share") ); // the current icons theme
#if 0 wxFileName configFile( kdedir, wxEmptyString );
configFile.AppendDir( wxT("config") ); configFile.AppendDir( wxT("share") );
configFile.SetName( wxT("kdeglobals") ); configFile.AppendDir( wxT("config") );
configFile.SetName( wxT("kdeglobals") );
if (configFile.FileExists())
{
wxFileConfig config( wxEmptyString, wxEmptyString, configFile.GetFullPath() );
// $(KDEDIR)/share/config -> $(KDEDIR)/share
configFile.RemoveDir( configFile.GetDirCount()-1 );
// $(KDEDIR)/share/ -> $(KDEDIR)/share/icons
configFile.AppendDir( wxT("icons") );
wxFileConfig config( wxEmptyString, wxEmptyString, configFile.GetFullPath() ); // Check for entry
wxString theme; config.SetPath( wxT("Icons") );
config.SetPath( wxT("Icons") ); wxString theme;
config.Read( wxT("Theme"), theme ); if (config.Read( wxT("Theme"), &theme ))
configFile.AppendDir( theme );
configFile.RemoveDir( configFile.GetDirCount()-1 ); else
configFile.AppendDir( wxT("icons") ); configFile.AppendDir( wxT("default.kde") );
configFile.AppendDir( theme ); }
#else else
configFile.AppendDir( wxT("icons") ); {
configFile.AppendDir( wxT("crystalsvg") ); // $(KDEDIR)/share/config -> $(KDEDIR)/share
#endif configFile.RemoveDir( configFile.GetDirCount()-1 );
// $(KDEDIR)/share/ -> $(KDEDIR)/share/icons
if (!wxDir::Exists(configFile.GetPath())) configFile.AppendDir( wxT("icons") );
{ // $(KDEDIR)/share/icons -> $(KDEDIR)/share/icons/default.kde
configFile.RemoveDir( configFile.GetDirCount()-1 ); configFile.AppendDir( wxT("default.kde") );
configFile.AppendDir( wxT("crystal") ); }
}
configFile.SetName( wxEmptyString );
if (!wxDir::Exists(configFile.GetPath()))
{ // Just try a few likely icons theme names
configFile.RemoveDir( configFile.GetDirCount()-1 );
configFile.AppendDir( wxT("default.kde") ); if (!wxDir::Exists(configFile.GetPath()))
} {
configFile.RemoveDir( configFile.GetDirCount()-1 );
if (wxDir::Exists(configFile.GetPath())) configFile.AppendDir( wxT("default.kde") );
{ }
configFile.AppendDir( wxT("32x32") );
configFile.AppendDir( wxT("mimetypes") ); if (!wxDir::Exists(configFile.GetPath()))
icondirs.Add( configFile.GetFullPath() ); {
} configFile.RemoveDir( configFile.GetDirCount()-1 );
configFile.AppendDir( wxT("default") );
}
if (!wxDir::Exists(configFile.GetPath()))
{
configFile.RemoveDir( configFile.GetDirCount()-1 );
configFile.AppendDir( wxT("crystalsvg") );
}
if (!wxDir::Exists(configFile.GetPath()))
{
configFile.RemoveDir( configFile.GetDirCount()-1 );
configFile.AppendDir( wxT("crystal") );
}
if (wxDir::Exists(configFile.GetPath()))
{
configFile.AppendDir( wxT("32x32") );
configFile.AppendDir( wxT("mimetypes") );
icondirs.Add( configFile.GetFullPath() );
}
} }
// settings in ~/.kde have maximal priority // settings in ~/.kde have maximal priority
dirs.Add(wxGetHomeDir() + wxT("/.kde/share")); dirs.Add(wxGetHomeDir() + wxT("/.kde/share"));
icondirs.Add(wxGetHomeDir() + wxT("/.kde/share/icons/")); icondirs.Add(wxGetHomeDir() + wxT("/.kde/share/icons/"));
if ( kdedir ) if (kdedir)
{ {
dirs.Add( wxString(kdedir) + wxT("/share") ); dirs.Add( wxString(kdedir) + wxT("/share") );
icondirs.Add( wxString(kdedir) + wxT("/share/icons/") ); icondirs.Add( wxString(kdedir) + wxT("/share/icons/") );
@@ -1429,17 +1464,17 @@ void wxMimeTypesManagerImpl::InitIfNeeded()
{ {
// set the flag first to prevent recursion // set the flag first to prevent recursion
m_initialized = TRUE; m_initialized = TRUE;
#if 0 #if 0
wxString wm = wxGetenv( wxT("WINDOWMANAGER") ); wxString wm = wxGetenv( wxT("WINDOWMANAGER") );
if (wm.Find( wxT("kde") ) != wxNOT_FOUND) if (wm.Find( wxT("kde") ) != wxNOT_FOUND)
Initialize( wxMAILCAP_KDE|wxMAILCAP_STANDARD ); Initialize( wxMAILCAP_KDE|wxMAILCAP_STANDARD );
else if (wm.Find( wxT("gnome") ) != wxNOT_FOUND) else if (wm.Find( wxT("gnome") ) != wxNOT_FOUND)
Initialize( wxMAILCAP_GNOME|wxMAILCAP_STANDARD ); Initialize( wxMAILCAP_GNOME|wxMAILCAP_STANDARD );
else else
#endif #endif
Initialize(); Initialize();
} }
} }