Skip to content

Commit

Permalink
Try standard XDG location for documents directory
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@53093 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
  • Loading branch information
JulianSmart committed Apr 8, 2008
1 parent a6a5ab2 commit 16dc7f8
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/common/stdpbase.cpp
Expand Up @@ -34,6 +34,11 @@
#include "wx/filename.h"
#include "wx/stdpaths.h"

#if defined(__UNIX__) && !defined(__WXMAC__)
#include "wx/log.h"
#include "wx/textfile.h"
#endif

// ----------------------------------------------------------------------------
// module globals
// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -96,6 +101,43 @@ wxString wxStandardPathsBase::GetUserLocalDataDir() const

wxString wxStandardPathsBase::GetDocumentsDir() const
{
#if defined(__UNIX__) && !defined(__WXMAC__)
{
wxLogNull logNull;
wxString homeDir = wxFileName::GetHomeDir();
wxString configPath;
if (wxGetenv(wxT("XDG_CONFIG_HOME")))
configPath = wxGetenv(wxT("XDG_CONFIG_HOME"));
else
configPath = homeDir + wxT("/.config");
wxString dirsFile = configPath + wxT("/user-dirs.dirs");
if (wxFileExists(dirsFile))
{
wxTextFile textFile;
if (textFile.Open(dirsFile))
{
size_t i;
for (i = 0; i < textFile.GetLineCount(); i++)
{
wxString line(textFile[i]);
int pos = line.Find(wxT("XDG_DOCUMENTS_DIR"));
if (pos != wxNOT_FOUND)
{
wxString value = line.AfterFirst(wxT('='));
value.Replace(wxT("$HOME"), homeDir);
value.Trim(true);
value.Trim(false);
if (!value.IsEmpty() && wxDirExists(value))
return value;
else
break;
}
}
}
}
}
#endif

return wxFileName::GetHomeDir();
}

Expand Down

0 comments on commit 16dc7f8

Please sign in to comment.